blob: 322728d8d76cd3f87d9fb5e7b5045c3d61455bc5 [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"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090048
49 // determines if the dependent will be part of the APEX payload
50 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090051}
52
53var (
Jiyong Park0f80c182020-01-31 02:49:53 +090054 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090055 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090056 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 Park0f80c182020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090064 rroTag = dependencyTag{name: "rro", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Paul Duffin50cbefd2020-03-10 13:44:19 +000096 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090097 "art_cmdlineparser_headers",
98 "art_disassembler_headers",
99 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "bionic_libc_platform_headers",
101 "core-repackaged-icu4j",
102 "cpp-define-generator-asm-support",
103 "cpp-define-generator-definitions",
104 "crtbegin_dynamic",
105 "crtbegin_dynamic1",
106 "crtbegin_so1",
107 "crtbrand",
Jiyong Park0f80c182020-01-31 02:49:53 +0900108 "dex2oat_headers",
109 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900110 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 "javavm_headers",
112 "jni_platform_headers",
113 "libPlatformProperties",
114 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000115 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900116 "libandroidicuinit",
117 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000118 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900119 "libdexfile_all_headers",
120 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000121 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900122 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000123 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900124 "libfdlibm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900125 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000126 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900127 "libicuuc_headers",
128 "libicuuc_stubdata",
129 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000131 "liblzma",
132 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900133 "libnativebridge-headers",
134 "libnativehelper_header_only",
135 "libnativeloader-headers",
136 "libnpt_headers",
137 "libopenjdkjvmti_headers",
138 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000139 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900140 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000141 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900142 "libv8",
143 "libv8base",
144 "libv8gen",
145 "libv8platform",
146 "libv8sampler",
147 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000148 "libvixl",
149 "libvixld",
150 "libz",
151 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000153 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000154 m["com.android.art.debug"] = artApexContents
155 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000156 //
157 // Module separator
158 //
159 m["com.android.bluetooth.updatable"] = []string{
160 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "android.hardware.bluetooth.a2dp@1.0",
162 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900163 "android.hardware.bluetooth@1.0",
164 "android.hardware.bluetooth@1.1",
165 "android.hardware.graphics.bufferqueue@1.0",
166 "android.hardware.graphics.bufferqueue@2.0",
167 "android.hardware.graphics.common@1.0",
168 "android.hardware.graphics.common@1.1",
169 "android.hardware.graphics.common@1.2",
170 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000171 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900172 "android.hidl.token@1.0",
173 "android.hidl.token@1.0-utils",
174 "avrcp-target-service",
175 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 "bluetooth-protos-lite",
177 "bluetooth.mapsapi",
178 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900179 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900180 "ipmemorystore-aidl-interfaces-V5-java",
181 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900182 "internal_include_headers",
183 "lib-bt-packets",
184 "lib-bt-packets-avrcp",
185 "lib-bt-packets-base",
186 "libFraunhoferAAC",
187 "libaudio-a2dp-hw-utils",
188 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900189 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000190 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900191 "libbluetooth-types",
192 "libbluetooth-types-header",
193 "libbluetooth_gd",
194 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000195 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "libbt-audio-hal-interface",
197 "libbt-bta",
198 "libbt-common",
199 "libbt-hci",
200 "libbt-platform-protos-lite",
201 "libbt-protos-lite",
202 "libbt-sbc-decoder",
203 "libbt-sbc-encoder",
204 "libbt-stack",
205 "libbt-utils",
206 "libbtcore",
207 "libbtdevice",
208 "libbte",
209 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000210 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000211 "libevent",
212 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900213 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900214 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900215 "libmedia_headers",
216 "libmodpb64",
217 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900218 "libstagefright_foundation_headers",
219 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000220 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900221 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000222 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900223 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000224 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900225 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900226 "net-utils-services-common",
227 "netd_aidl_interface-unstable-java",
228 "netd_event_listener_interface-java",
229 "netlink-client",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900230 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900231 "sap-api-java-static",
232 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000233 }
234 //
235 // Module separator
236 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900237 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000238 //
239 // Module separator
240 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libnativehelper_header_only",
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 }
244 //
245 // Module separator
246 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900247 m["com.android.neuralnetworks"] = []string{
248 "android.hardware.neuralnetworks@1.0",
249 "android.hardware.neuralnetworks@1.1",
250 "android.hardware.neuralnetworks@1.2",
251 "android.hardware.neuralnetworks@1.3",
252 "android.hidl.allocator@1.0",
253 "android.hidl.memory.token@1.0",
254 "android.hidl.memory@1.0",
255 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900256 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900257 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900258 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900259 "libprocpartition",
260 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900261 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000262 //
263 // Module separator
264 //
265 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000266 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 "android.hardware.cas.native@1.0",
268 "android.hardware.cas@1.0",
269 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000270 "android.hardware.configstore@1.0",
271 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000272 "android.hardware.graphics.allocator@2.0",
273 "android.hardware.graphics.allocator@3.0",
274 "android.hardware.graphics.bufferqueue@1.0",
275 "android.hardware.graphics.bufferqueue@2.0",
276 "android.hardware.graphics.common@1.0",
277 "android.hardware.graphics.common@1.1",
278 "android.hardware.graphics.common@1.2",
279 "android.hardware.graphics.mapper@2.0",
280 "android.hardware.graphics.mapper@2.1",
281 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900282 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000283 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900284 "android.hidl.allocator@1.0",
285 "android.hidl.memory.token@1.0",
286 "android.hidl.memory@1.0",
287 "android.hidl.token@1.0",
288 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900289 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900290 "gl_headers",
291 "libEGL",
292 "libEGL_blobCache",
293 "libEGL_getProcAddress",
294 "libFLAC",
295 "libFLAC-config",
296 "libFLAC-headers",
297 "libGLESv2",
298 "libaacextractor",
299 "libamrextractor",
300 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900301 "libaudio_system_headers",
302 "libaudioclient",
303 "libaudioclient_headers",
304 "libaudiofoundation",
305 "libaudiofoundation_headers",
306 "libaudiomanager",
307 "libaudiopolicy",
308 "libaudioutils",
309 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900310 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900311 "libbluetooth-types-header",
312 "libbufferhub",
313 "libbufferhub_headers",
314 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900315 "libc_malloc_debug_backtrace",
316 "libcamera_client",
317 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900318 "libdexfile_external_headers",
319 "libdexfile_support",
320 "libdvr_headers",
321 "libexpat",
322 "libfifo",
323 "libflacextractor",
324 "libgrallocusage",
325 "libgraphicsenv",
326 "libgui",
327 "libgui_headers",
328 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900329 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900330 "liblzma",
331 "libmath",
332 "libmedia",
333 "libmedia_codeclist",
334 "libmedia_headers",
335 "libmedia_helper",
336 "libmedia_helper_headers",
337 "libmedia_midiiowrapper",
338 "libmedia_omx",
339 "libmediautils",
340 "libmidiextractor",
341 "libmkvextractor",
342 "libmp3extractor",
343 "libmp4extractor",
344 "libmpeg2extractor",
345 "libnativebase_headers",
346 "libnativebridge-headers",
347 "libnativebridge_lazy",
348 "libnativeloader-headers",
349 "libnativeloader_lazy",
350 "libnativewindow_headers",
351 "libnblog",
352 "liboggextractor",
353 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900354 "libpdx",
355 "libpdx_default_transport",
356 "libpdx_headers",
357 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900358 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900359 "libsonivox",
360 "libspeexresampler",
361 "libspeexresampler",
362 "libstagefright_esds",
363 "libstagefright_flacdec",
364 "libstagefright_flacdec",
365 "libstagefright_foundation",
366 "libstagefright_foundation_headers",
367 "libstagefright_foundation_without_imemory",
368 "libstagefright_headers",
369 "libstagefright_id3",
370 "libstagefright_metadatautils",
371 "libstagefright_mpeg2extractor",
372 "libstagefright_mpeg2support",
373 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900374 "libui",
375 "libui_headers",
376 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900377 "libvibrator",
378 "libvorbisidec",
379 "libwavextractor",
380 "libwebm",
381 "media_ndk_headers",
382 "media_plugin_headers",
383 "updatable-media",
384 }
385 //
386 // Module separator
387 //
388 m["com.android.media.swcodec"] = []string{
389 "android.frameworks.bufferhub@1.0",
390 "android.hardware.common-ndk_platform",
391 "android.hardware.configstore-utils",
392 "android.hardware.configstore@1.0",
393 "android.hardware.configstore@1.1",
394 "android.hardware.graphics.allocator@2.0",
395 "android.hardware.graphics.allocator@3.0",
396 "android.hardware.graphics.bufferqueue@1.0",
397 "android.hardware.graphics.bufferqueue@2.0",
398 "android.hardware.graphics.common-ndk_platform",
399 "android.hardware.graphics.common@1.0",
400 "android.hardware.graphics.common@1.1",
401 "android.hardware.graphics.common@1.2",
402 "android.hardware.graphics.mapper@2.0",
403 "android.hardware.graphics.mapper@2.1",
404 "android.hardware.graphics.mapper@3.0",
405 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000406 "android.hardware.media.bufferpool@2.0",
407 "android.hardware.media.c2@1.0",
408 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900409 "android.hardware.media@1.0",
410 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000411 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900412 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000413 "android.hidl.safe_union@1.0",
414 "android.hidl.token@1.0",
415 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900416 "libEGL",
417 "libFLAC",
418 "libFLAC-config",
419 "libFLAC-headers",
420 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900421 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900422 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900423 "libaudio_system_headers",
424 "libaudioutils",
425 "libaudioutils",
426 "libaudioutils_fixedfft",
427 "libavcdec",
428 "libavcenc",
429 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000430 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900431 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900432 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900433 "libbluetooth-types-header",
434 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900435 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000436 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900437 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000438 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900439 "libcodec2_hidl@1.1",
440 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000441 "libcodec2_soft_aacdec",
442 "libcodec2_soft_aacenc",
443 "libcodec2_soft_amrnbdec",
444 "libcodec2_soft_amrnbenc",
445 "libcodec2_soft_amrwbdec",
446 "libcodec2_soft_amrwbenc",
447 "libcodec2_soft_av1dec_gav1",
448 "libcodec2_soft_avcdec",
449 "libcodec2_soft_avcenc",
450 "libcodec2_soft_common",
451 "libcodec2_soft_flacdec",
452 "libcodec2_soft_flacenc",
453 "libcodec2_soft_g711alawdec",
454 "libcodec2_soft_g711mlawdec",
455 "libcodec2_soft_gsmdec",
456 "libcodec2_soft_h263dec",
457 "libcodec2_soft_h263enc",
458 "libcodec2_soft_hevcdec",
459 "libcodec2_soft_hevcenc",
460 "libcodec2_soft_mp3dec",
461 "libcodec2_soft_mpeg2dec",
462 "libcodec2_soft_mpeg4dec",
463 "libcodec2_soft_mpeg4enc",
464 "libcodec2_soft_opusdec",
465 "libcodec2_soft_opusenc",
466 "libcodec2_soft_rawdec",
467 "libcodec2_soft_vorbisdec",
468 "libcodec2_soft_vp8dec",
469 "libcodec2_soft_vp8enc",
470 "libcodec2_soft_vp9dec",
471 "libcodec2_soft_vp9enc",
472 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000473 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900474 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000475 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900476 "libfmq",
477 "libgav1",
478 "libgralloctypes",
479 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000480 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900481 "libgsm",
482 "libgui_bufferqueue_static",
483 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000484 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900485 "libhardware_headers",
486 "libhevcdec",
487 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000488 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900489 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000490 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900491 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000492 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900493 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900494 "libmpeg2dec",
495 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000496 "libnativebridge_lazy",
497 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900498 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900499 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000500 "libscudo_wrapper",
501 "libsfplugin_ccodec_utils",
502 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900503 "libstagefright_amrnbdec",
504 "libstagefright_amrnbenc",
505 "libstagefright_amrwbdec",
506 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000507 "libstagefright_bufferpool@2.0.1",
508 "libstagefright_bufferqueue_helper",
509 "libstagefright_enc_common",
510 "libstagefright_flacdec",
511 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900512 "libstagefright_foundation_headers",
513 "libstagefright_headers",
514 "libstagefright_m4vh263dec",
515 "libstagefright_m4vh263enc",
516 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000517 "libsync",
518 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900519 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000520 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000521 "libvorbisidec",
522 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900523 "libyuv",
524 "libyuv_static",
525 "media_ndk_headers",
526 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000527 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900528 }
529 //
530 // Module separator
531 //
532 m["com.android.mediaprovider"] = []string{
533 "MediaProvider",
534 "MediaProviderGoogle",
535 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900536 "libbase_ndk",
537 "libfuse",
538 "libfuse_jni",
539 "libnativehelper_header_only",
540 }
541 //
542 // Module separator
543 //
544 m["com.android.permission"] = []string{
545 "androidx.annotation_annotation",
546 "androidx.annotation_annotation-nodeps",
547 "androidx.lifecycle_lifecycle-common",
548 "androidx.lifecycle_lifecycle-common-java8",
549 "androidx.lifecycle_lifecycle-common-java8-nodeps",
550 "androidx.lifecycle_lifecycle-common-nodeps",
551 "kotlin-annotations",
552 "kotlin-stdlib",
553 "kotlin-stdlib-jdk7",
554 "kotlin-stdlib-jdk8",
555 "kotlinx-coroutines-android",
556 "kotlinx-coroutines-android-nodeps",
557 "kotlinx-coroutines-core",
558 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900559 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000560 }
561 //
562 // Module separator
563 //
564 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900565 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900566 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900567 "libc_aeabi",
568 "libc_bionic",
569 "libc_bionic_ndk",
570 "libc_bootstrap",
571 "libc_common",
572 "libc_common_shared",
573 "libc_common_static",
574 "libc_dns",
575 "libc_dynamic_dispatch",
576 "libc_fortify",
577 "libc_freebsd",
578 "libc_freebsd_large_stack",
579 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "libc_init_dynamic",
581 "libc_init_static",
582 "libc_jemalloc_wrapper",
583 "libc_netbsd",
584 "libc_nomalloc",
585 "libc_nopthread",
586 "libc_openbsd",
587 "libc_openbsd_large_stack",
588 "libc_openbsd_ndk",
589 "libc_pthread",
590 "libc_static_dispatch",
591 "libc_syscalls",
592 "libc_tzcode",
593 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libdebuggerd",
595 "libdebuggerd_common_headers",
596 "libdebuggerd_handler_core",
597 "libdebuggerd_handler_fallback",
598 "libdexfile_external_headers",
599 "libdexfile_support",
600 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900601 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900602 "libjemalloc5",
603 "liblinker_main",
604 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 "liblz4",
606 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900607 "libprocinfo",
608 "libpropertyinfoparser",
609 "libscudo",
610 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900611 "libsystemproperties",
612 "libtombstoned_client_static",
613 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900614 "libz",
615 "libziparchive",
616 }
617 //
618 // Module separator
619 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900620 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900621 "libnativehelper_compat_libc++",
622 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900623 "libcgrouprc",
624 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900625 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900626 "libvndksupport",
627 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000628 }
629 //
630 // Module separator
631 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900632 m["com.android.wifi"] = []string{
633 "PlatformProperties",
634 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900635 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900636 "android.hardware.wifi-V1.1-java",
637 "android.hardware.wifi-V1.2-java",
638 "android.hardware.wifi-V1.3-java",
639 "android.hardware.wifi-V1.4-java",
640 "android.hardware.wifi.hostapd-V1.0-java",
641 "android.hardware.wifi.hostapd-V1.1-java",
642 "android.hardware.wifi.hostapd-V1.2-java",
643 "android.hardware.wifi.supplicant-V1.0-java",
644 "android.hardware.wifi.supplicant-V1.1-java",
645 "android.hardware.wifi.supplicant-V1.2-java",
646 "android.hardware.wifi.supplicant-V1.3-java",
647 "android.hidl.base-V1.0-java",
648 "android.hidl.manager-V1.0-java",
649 "android.hidl.manager-V1.1-java",
650 "android.hidl.manager-V1.2-java",
651 "androidx.annotation_annotation",
652 "androidx.annotation_annotation-nodeps",
653 "bouncycastle-unbundled",
654 "dnsresolver_aidl_interface-V2-java",
655 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900656 "framework-wifi-pre-jarjar",
657 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900658 "ipmemorystore-aidl-interfaces-V3-java",
659 "ipmemorystore-aidl-interfaces-java",
660 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900661 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900662 "libwifi-jni",
663 "net-utils-services-common",
664 "netd_aidl_interface-V2-java",
665 "netd_aidl_interface-unstable-java",
666 "netd_event_listener_interface-java",
667 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900668 "networkstack-client",
669 "services.net",
670 "wifi-lite-protos",
671 "wifi-nano-protos",
672 "wifi-service-pre-jarjar",
673 "wifi-service-resources",
674 "prebuilt_androidx.annotation_annotation-nodeps",
675 }
676 //
677 // Module separator
678 //
679 m["com.android.sdkext"] = []string{
680 "fmtlib_ndk",
681 "libbase_ndk",
682 "libprotobuf-cpp-lite-ndk",
683 }
684 //
685 // Module separator
686 //
687 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900688 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900689 }
690 //
691 // Module separator
692 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000693 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900694 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900695 "libclang_rt",
696 "libgcc_stripped",
697 "libprofile-clang-extras",
698 "libprofile-clang-extras_ndk",
699 "libprofile-extras",
700 "libprofile-extras_ndk",
701 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900702 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000703 return m
704}
705
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900706func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900707 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800708 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900709 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900710 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700711 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900712 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900713
Jooyung Han31c470b2019-10-18 16:26:59 +0900714 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900715 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900716
717 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
718 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
719 sort.Strings(*apexFileContextsInfos)
720 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
721 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900722}
723
Jooyung Han31c470b2019-10-18 16:26:59 +0900724func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
725 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
726 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
727}
728
Jiyong Parkd1063c12019-07-17 20:08:41 +0900729func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900730 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900731 ctx.BottomUp("apex", apexMutator).Parallel()
732 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
733 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900734 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900735}
736
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900737// Mark the direct and transitive dependencies of apex bundles so that they
738// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900739func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900740 if !mctx.Module().Enabled() {
741 return
742 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800743 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900744 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000745 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900746 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900747 ApexName: mctx.ModuleName(),
748 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100749 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900750 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900751 directDep = true
752 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800753 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900754 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900755 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900756
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800757 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900758 return
759 }
760
Paul Duffin923e8a52020-03-30 15:33:32 +0100761 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900762
Jiyong Parkf760cae2020-02-12 07:53:12 +0900763 mctx.VisitDirectDeps(func(child android.Module) {
764 depName := mctx.OtherModuleName(child)
765 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100766 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800767 android.UpdateApexDependency(apexBundles, depName, directDep)
768 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900769 }
770 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900771}
772
Jiyong Park89e850a2020-04-07 16:37:39 +0900773// mark if a module cannot be available to platform. A module cannot be available
774// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
775// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
776func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
777 // Host and recovery are not considered as platform
778 if mctx.Host() || mctx.Module().InstallInRecovery() {
779 return
780 }
781
782 if am, ok := mctx.Module().(android.ApexModule); ok {
783 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
784
785 // In a rare case when a lib is marked as available only to an apex
786 // but the apex doesn't exist. This can happen in a partial manifest branch
787 // like master-art. Currently, libstatssocket in the stats APEX is causing
788 // this problem.
789 // Include the lib in platform because the module SDK that ought to provide
790 // it doesn't exist, so it would otherwise be left out completely.
791 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
792 // this check for libraries provided by SDKs.
793 if !availableToPlatform && !android.InAnyApex(am.Name()) {
794 availableToPlatform = true
795 }
796
797 // If any of the dep is not available to platform, this module is also considered
798 // as being not available to platform even if it has "//apex_available:platform"
799 mctx.VisitDirectDeps(func(child android.Module) {
800 if !am.DepIsInSameApex(mctx, child) {
801 // if the dependency crosses apex boundary, don't consider it
802 return
803 }
804 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
805 availableToPlatform = false
806 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
807 }
808 })
809
810 // Exception 1: stub libraries and native bridge libraries are always available to platform
811 if cc, ok := mctx.Module().(*cc.Module); ok &&
812 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
813 availableToPlatform = true
814 }
815
816 // Exception 2: bootstrap bionic libraries are also always available to platform
817 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
818 availableToPlatform = true
819 }
820
821 if !availableToPlatform {
822 am.SetNotAvailableForPlatform()
823 }
824 }
825}
826
Paul Duffin65347702020-03-31 15:23:40 +0100827// If a module in an APEX depends on a module from an SDK then it needs an APEX
828// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
829func inAnySdk(module android.Module) bool {
830 if sa, ok := module.(android.SdkAware); ok {
831 return sa.IsInAnySdk()
832 }
833
834 return false
835}
836
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900837// Create apex variations if a module is included in APEX(s).
838func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900839 if !mctx.Module().Enabled() {
840 return
841 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900842 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900843 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000844 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900845 // apex bundle itself is mutated so that it and its modules have same
846 // apex variant.
847 apexBundleName := mctx.ModuleName()
848 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900849 } else if o, ok := mctx.Module().(*OverrideApex); ok {
850 apexBundleName := o.GetOverriddenModuleName()
851 if apexBundleName == "" {
852 mctx.ModuleErrorf("base property is not set")
853 return
854 }
855 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900856 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900857
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900858}
Sundong Ahne9b55722019-09-06 17:37:42 +0900859
Jooyung Han7a78a922019-10-08 21:59:58 +0900860var (
861 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
862 apexFileContextsInfosMutex sync.Mutex
863)
864
865func apexFileContextsInfos(config android.Config) *[]string {
866 return config.Once(apexFileContextsInfosKey, func() interface{} {
867 return &[]string{}
868 }).(*[]string)
869}
870
Jooyung Han54aca7b2019-11-20 02:26:02 +0900871func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900872 apexFileContextsInfosMutex.Lock()
873 defer apexFileContextsInfosMutex.Unlock()
874 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900875 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900876}
877
Sundong Ahne9b55722019-09-06 17:37:42 +0900878func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900879 if !mctx.Module().Enabled() {
880 return
881 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900882 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900883 var variants []string
884 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
885 case "image":
886 variants = append(variants, imageApexType, flattenedApexType)
887 case "zip":
888 variants = append(variants, zipApexType)
889 case "both":
890 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
891 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900892 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900893 return
894 }
895
896 modules := mctx.CreateLocalVariations(variants...)
897
898 for i, v := range variants {
899 switch v {
900 case imageApexType:
901 modules[i].(*apexBundle).properties.ApexType = imageApex
902 case zipApexType:
903 modules[i].(*apexBundle).properties.ApexType = zipApex
904 case flattenedApexType:
905 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900906 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900907 modules[i].(*apexBundle).MakeAsSystemExt()
908 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900909 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900910 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900911 } else if _, ok := mctx.Module().(*OverrideApex); ok {
912 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900913 }
914}
915
Jooyung Han5c998b92019-06-27 11:30:33 +0900916func apexUsesMutator(mctx android.BottomUpMutatorContext) {
917 if ab, ok := mctx.Module().(*apexBundle); ok {
918 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
919 }
920}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900921
Jooyung Handc782442019-11-01 03:14:38 +0900922var (
923 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
924)
925
926// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
927// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
928// which may cause compatibility issues. (e.g. libbinder)
929// Even though libbinder restricts its availability via 'apex_available' property and relies on
930// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
931// to avoid similar problems.
932func useVendorWhitelist(config android.Config) []string {
933 return config.Once(useVendorWhitelistKey, func() interface{} {
934 return []string{
935 // swcodec uses "vendor" variants for smaller size
936 "com.android.media.swcodec",
937 "test_com.android.media.swcodec",
938 }
939 }).([]string)
940}
941
942// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
943// called before the first call to useVendorWhitelist()
944func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
945 config.Once(useVendorWhitelistKey, func() interface{} {
946 return whitelist
947 })
948}
949
Jooyung Han01a868d2020-02-27 13:40:44 +0900950type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800951 // List of native libraries
952 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900953
Jooyung Han643adc42020-02-27 13:50:06 +0900954 // List of JNI libraries
955 Jni_libs []string
956
Alex Light9670d332019-01-29 18:07:33 -0800957 // List of native executables
958 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900959
Roland Levillain630846d2019-06-26 12:48:34 +0100960 // List of native tests
961 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800962}
Jooyung Han344d5432019-08-23 11:17:39 +0900963
Alex Light9670d332019-01-29 18:07:33 -0800964type apexMultilibProperties struct {
965 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900966 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800967
968 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900969 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800970
971 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900972 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800973
974 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900975 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800976
977 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900978 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800979}
980
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900981type apexBundleProperties struct {
982 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000983 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800984 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900985
Jiyong Park40e26a22019-02-08 02:53:06 +0900986 // AndroidManifest.xml file used for the zip container of this APEX bundle.
987 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800988 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900989
Roland Levillain411c5842019-09-19 16:37:20 +0100990 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
991 // device (/apex/<apex_name>).
992 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900993 Apex_name *string
994
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900995 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900996 // For platform APEXes, this should points to a file under /system/sepolicy
997 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
998 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900999
Jooyung Han01a868d2020-02-27 13:40:44 +09001000 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001001
1002 // List of java libraries that are embedded inside this APEX bundle
1003 Java_libs []string
1004
1005 // List of prebuilt files that are embedded inside this APEX bundle
1006 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001007
1008 // Name of the apex_key module that provides the private key to sign APEX
1009 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001010
Alex Light5098a612018-11-29 17:12:15 -08001011 // The type of APEX to build. Controls what the APEX payload is. Either
1012 // 'image', 'zip' or 'both'. Default: 'image'.
1013 Payload_type *string
1014
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001015 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1016 // or an android_app_certificate module name in the form ":module".
1017 Certificate *string
1018
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001019 // Whether this APEX is installable to one of the partitions. Default: true.
1020 Installable *bool
1021
Jiyong Parkda6eb592018-12-19 17:12:36 +09001022 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1023 // Default is false.
1024 Use_vendor *bool
1025
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001026 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1027 Ignore_system_library_special_case *bool
1028
Alex Light9670d332019-01-29 18:07:33 -08001029 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001030
Jiyong Parkf97782b2019-02-13 20:28:58 +09001031 // List of sanitizer names that this APEX is enabled for
1032 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001033
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001034 PreventInstall bool `blueprint:"mutated"`
1035
1036 HideFromMake bool `blueprint:"mutated"`
1037
Jooyung Han5c998b92019-06-27 11:30:33 +09001038 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1039 Provide_cpp_shared_libs *bool
1040
1041 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1042 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001043
1044 // A txt file containing list of files that are whitelisted to be included in this APEX.
1045 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001046
Sundong Ahnabb64432019-10-22 13:58:29 +09001047 // package format of this apex variant; could be non-flattened, flattened, or zip.
1048 // imageApex, zipApex or flattened
1049 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001050
Jiyong Parkd1063c12019-07-17 20:08:41 +09001051 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1052 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1053 // is implied. This value affects all modules included in this APEX. In other words, they are
1054 // also built with the SDKs specified here.
1055 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001056
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001057 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1058 // Should be only used in tests#.
1059 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001060
Dario Frenica913392020-04-27 18:21:11 +01001061 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1062 // Should be only used in tests#.
1063 Test_only_unsigned_payload *bool
1064
Jiyong Park956305c2020-01-09 12:32:06 +09001065 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001066
1067 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001068 // rules for making sure that the APEX is truly updatable.
1069 // - To be updatable, min_sdk_version should be set as well
1070 // This will also disable the size optimizations like symlinking to the system libs.
1071 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001072 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001073
1074 // The minimum SDK version that this apex must be compatibile with.
1075 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001076}
1077
1078type apexTargetBundleProperties struct {
1079 Target struct {
1080 // Multilib properties only for android.
1081 Android struct {
1082 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001083 }
Jooyung Han344d5432019-08-23 11:17:39 +09001084
Alex Light9670d332019-01-29 18:07:33 -08001085 // Multilib properties only for host.
1086 Host struct {
1087 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001088 }
Jooyung Han344d5432019-08-23 11:17:39 +09001089
Alex Light9670d332019-01-29 18:07:33 -08001090 // Multilib properties only for host linux_bionic.
1091 Linux_bionic struct {
1092 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001093 }
Jooyung Han344d5432019-08-23 11:17:39 +09001094
Alex Light9670d332019-01-29 18:07:33 -08001095 // Multilib properties only for host linux_glibc.
1096 Linux_glibc struct {
1097 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001098 }
1099 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001100}
1101
Jiyong Park5d790c32019-11-15 18:40:32 +09001102type overridableProperties struct {
1103 // List of APKs to package inside APEX
1104 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001105
Jiyong Park69aeba92020-04-24 21:16:36 +09001106 // List of runtime resource overlays (RROs) inside APEX
1107 Rros []string
1108
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001109 // Names of modules to be overridden. Listed modules can only be other binaries
1110 // (in Make or Soong).
1111 // This does not completely prevent installation of the overridden binaries, but if both
1112 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1113 // from PRODUCT_PACKAGES.
1114 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001115
1116 // Logging Parent value
1117 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001118
1119 // Apex Container Package Name.
1120 // Override value for attribute package:name in AndroidManifest.xml
1121 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001122}
1123
Alex Light5098a612018-11-29 17:12:15 -08001124type apexPackaging int
1125
1126const (
1127 imageApex apexPackaging = iota
1128 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001129 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001130)
1131
Sundong Ahnabb64432019-10-22 13:58:29 +09001132// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001133func (a apexPackaging) suffix() string {
1134 switch a {
1135 case imageApex:
1136 return imageApexSuffix
1137 case zipApex:
1138 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001139 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001140 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001141 }
1142}
1143
1144func (a apexPackaging) name() string {
1145 switch a {
1146 case imageApex:
1147 return imageApexType
1148 case zipApex:
1149 return zipApexType
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
Jiyong Parkf653b052019-11-18 15:39:01 +09001155type apexFileClass int
1156
1157const (
1158 etc apexFileClass = iota
1159 nativeSharedLib
1160 nativeExecutable
1161 shBinary
1162 pyBinary
1163 goBinary
1164 javaSharedLib
1165 nativeTest
1166 app
1167)
1168
Jiyong Park8fd61922018-11-08 02:50:25 +09001169func (class apexFileClass) NameInMake() string {
1170 switch class {
1171 case etc:
1172 return "ETC"
1173 case nativeSharedLib:
1174 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001175 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001176 return "EXECUTABLES"
1177 case javaSharedLib:
1178 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001179 case nativeTest:
1180 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001181 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001182 // b/142537672 Why isn't this APP? We want to have full control over
1183 // the paths and file names of the apk file under the flattend APEX.
1184 // If this is set to APP, then the paths and file names are modified
1185 // by the Make build system. For example, it is installed to
1186 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1187 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1188 // appends module name (which is <apexname>.<Appname> to the path.
1189 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001190 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001191 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001192 }
1193}
1194
Jiyong Parkf653b052019-11-18 15:39:01 +09001195// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001196type apexFile struct {
1197 builtFile android.Path
1198 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001199 installDir string
1200 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001201 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001202 // list of symlinks that will be created in installDir that point to this apexFile
1203 symlinks []string
Liz Kammer1c14a212020-05-12 15:26:55 -07001204 dataPaths android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001205 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001206 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001207
1208 requiredModuleNames []string
1209 targetRequiredModuleNames []string
1210 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001211
Colin Cross503c1d02020-01-28 14:00:53 -08001212 jacocoReportClassesFile android.Path // only for javalibs and apps
1213 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001214 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001215
1216 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001217}
1218
Jiyong Park1833cef2019-12-13 13:28:36 +09001219func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1220 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001221 builtFile: builtFile,
1222 moduleName: moduleName,
1223 installDir: installDir,
1224 class: class,
1225 module: module,
1226 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001227 if module != nil {
1228 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001229 ret.requiredModuleNames = module.RequiredModuleNames()
1230 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1231 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001232 }
1233 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001234}
1235
1236func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001237 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001238}
1239
Liz Kammer1c14a212020-05-12 15:26:55 -07001240func (af *apexFile) apexRelativePath(path string) string {
1241 return filepath.Join(af.installDir, path)
1242}
1243
Jiyong Park7cd10e32020-01-14 09:22:18 +09001244// Path() returns path of this apex file relative to the APEX root
1245func (af *apexFile) Path() string {
Liz Kammer1c14a212020-05-12 15:26:55 -07001246 return af.apexRelativePath(af.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001247}
1248
1249// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1250func (af *apexFile) SymlinkPaths() []string {
1251 var ret []string
1252 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001253 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001254 }
1255 return ret
1256}
1257
1258func (af *apexFile) AvailableToPlatform() bool {
1259 if af.module == nil {
1260 return false
1261 }
1262 if am, ok := af.module.(android.ApexModule); ok {
1263 return am.AvailableFor(android.AvailableToPlatform)
1264 }
1265 return false
1266}
1267
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001268type apexBundle struct {
1269 android.ModuleBase
1270 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001271 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001272 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001273
Jiyong Park5d790c32019-11-15 18:40:32 +09001274 properties apexBundleProperties
1275 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001276 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001277
Jooyung Hanf21c7972019-12-16 22:32:06 +09001278 // specific to apex_vndk modules
1279 vndkProperties apexVndkProperties
1280
Colin Crossa4925902018-11-16 11:36:28 -08001281 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001282 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001283 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001284
Jiyong Park03b68dd2019-07-26 23:20:40 +09001285 prebuiltFileToDelete string
1286
Jiyong Park42cca6c2019-04-01 11:15:50 +09001287 public_key_file android.Path
1288 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001289
1290 container_certificate_file android.Path
1291 container_private_key_file android.Path
1292
Jooyung Han54aca7b2019-11-20 02:26:02 +09001293 fileContexts android.Path
1294
Jiyong Park8fd61922018-11-08 02:50:25 +09001295 // list of files to be included in this apex
1296 filesInfo []apexFile
1297
Jiyong Park956305c2020-01-09 12:32:06 +09001298 // list of module names that should be installed along with this APEX
1299 requiredDeps []string
1300
Jiyong Park956305c2020-01-09 12:32:06 +09001301 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001302 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001303
Sundong Ahnabb64432019-10-22 13:58:29 +09001304 testApex bool
1305 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001306 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001307 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001308
Jooyung Han214bf372019-11-12 13:03:50 +09001309 manifestJsonOut android.WritablePath
1310 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001311
Jooyung Han002ab682020-01-08 01:57:58 +09001312 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001313 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001314 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001315 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1316 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001317
1318 // Suffix of module name in Android.mk
1319 // ".flattened", ".apex", ".zipapex", or ""
1320 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001321
1322 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001323
1324 // Whether to create symlink to the system file instead of having a file
1325 // inside the apex or not
1326 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001327
1328 // Struct holding the merged notice file paths in different formats
1329 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001330}
1331
Jiyong Park397e55e2018-10-24 21:09:55 +09001332func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001333 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001334 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001335 // Use *FarVariation* to be able to depend on modules having
1336 // conflicting variations with this module. This is required since
1337 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1338 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001339 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001340 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001341 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001342 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001343 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001344
Jooyung Han643adc42020-02-27 13:50:06 +09001345 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1346 {Mutator: "image", Variation: imageVariation},
1347 {Mutator: "link", Variation: "shared"},
1348 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1349 }...), jniLibTag, nativeModules.Jni_libs...)
1350
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001351 ctx.AddFarVariationDependencies(append(target.Variations(),
1352 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001353 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001354
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001355 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001356 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001357 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001358 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001359}
1360
Alex Light9670d332019-01-29 18:07:33 -08001361func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1362 if ctx.Os().Class == android.Device {
1363 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1364 } else {
1365 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1366 if ctx.Os().Bionic() {
1367 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1368 } else {
1369 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1370 }
1371 }
1372}
1373
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001374func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001375 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1376 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1377 }
1378
Jiyong Park397e55e2018-10-24 21:09:55 +09001379 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001380 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001381
1382 a.combineProperties(ctx)
1383
Jiyong Park397e55e2018-10-24 21:09:55 +09001384 has32BitTarget := false
1385 for _, target := range targets {
1386 if target.Arch.ArchType.Multilib == "lib32" {
1387 has32BitTarget = true
1388 }
1389 }
1390 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001391 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001392 // multilib.both
1393 addDependenciesForNativeModules(ctx,
1394 ApexNativeDependencies{
1395 Native_shared_libs: a.properties.Native_shared_libs,
1396 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001397 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001398 Binaries: nil,
1399 },
1400 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001401
Jiyong Park397e55e2018-10-24 21:09:55 +09001402 // Add native modules targetting both ABIs
1403 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001404 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001405 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001406 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001407
Alex Light3d673592019-01-18 14:37:31 -08001408 isPrimaryAbi := i == 0
1409 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001410 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001411 // multilib.first
1412 addDependenciesForNativeModules(ctx,
1413 ApexNativeDependencies{
1414 Native_shared_libs: nil,
1415 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001416 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001417 Binaries: a.properties.Binaries,
1418 },
1419 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001420
1421 // Add native modules targetting the first ABI
1422 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001423 a.properties.Multilib.First,
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,
Jooyung Han01a868d2020-02-27 13:40:44 +09001432 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001433 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001434 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001435
1436 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001437 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001438 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001439 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001440 case "lib64":
1441 // Add native modules targetting 64-bit ABI
1442 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001443 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001444 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001445 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001446
1447 if !has32BitTarget {
1448 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001449 a.properties.Multilib.Prefer32,
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 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001453
1454 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1455 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1456 if sanitizer == "hwaddress" {
1457 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001458 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001459 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001460 break
1461 }
1462 }
1463 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001464 }
1465
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001466 }
1467
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001468 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1469 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1470 // b/144532908
1471 archForPrebuiltEtc := config.Arches()[0]
1472 for _, arch := range config.Arches() {
1473 // Prefer 64-bit arch if there is any
1474 if arch.ArchType.Multilib == "lib64" {
1475 archForPrebuiltEtc = arch
1476 break
1477 }
1478 }
1479 ctx.AddFarVariationDependencies([]blueprint.Variation{
1480 {Mutator: "os", Variation: ctx.Os().String()},
1481 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1482 }, prebuiltTag, a.properties.Prebuilts...)
1483
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001484 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1485 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001486
Ulya Trafimovich44561882020-01-03 13:25:54 +00001487 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1488 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1489 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1490 javaLibTag, "jacocoagent")
1491 }
1492
Jiyong Park23c52b02019-02-02 13:13:47 +09001493 if String(a.properties.Key) == "" {
1494 ctx.ModuleErrorf("key is missing")
1495 return
1496 }
1497 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001498
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001499 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001500 if cert != "" {
1501 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001502 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001503
1504 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1505 if len(a.properties.Uses_sdks) > 0 {
1506 sdkRefs := []android.SdkRef{}
1507 for _, str := range a.properties.Uses_sdks {
1508 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1509 sdkRefs = append(sdkRefs, parsed)
1510 }
1511 a.BuildWithSdks(sdkRefs)
1512 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001513}
1514
Jiyong Park5d790c32019-11-15 18:40:32 +09001515func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1516 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1517 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001518 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1519 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001520}
1521
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001522func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1523 // direct deps of an APEX bundle are all part of the APEX bundle
1524 return true
1525}
1526
Colin Cross0ea8ba82019-06-06 14:33:29 -07001527func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001528 moduleName := ctx.ModuleName()
1529 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1530 // we check with the pseudo module name to see if its certificate is overridden.
1531 if a.vndkApex {
1532 moduleName = vndkApexName
1533 }
1534 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001535 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001536 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001537 }
1538 return String(a.properties.Certificate)
1539}
1540
Colin Cross41955e82019-05-29 14:40:35 -07001541func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1542 switch tag {
1543 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001544 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001545 default:
1546 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001547 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001548}
1549
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001550func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001551 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001552}
1553
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001554func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1555 return proptools.Bool(a.properties.Test_only_no_hashtree)
1556}
1557
Dario Frenica913392020-04-27 18:21:11 +01001558func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1559 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1560}
1561
Jiyong Park7c1dc612019-01-05 11:15:24 +09001562func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001563 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001564 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001565 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001566 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001567 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001568 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001569 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001570 }
1571}
1572
Jiyong Parkf97782b2019-02-13 20:28:58 +09001573func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1574 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1575 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1576 }
1577}
1578
Jiyong Park388ef3f2019-01-28 19:47:32 +09001579func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001580 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1581 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001582 }
1583
1584 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001585 globalSanitizerNames := []string{}
1586 if a.Host() {
1587 globalSanitizerNames = ctx.Config().SanitizeHost()
1588 } else {
1589 arches := ctx.Config().SanitizeDeviceArch()
1590 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1591 globalSanitizerNames = ctx.Config().SanitizeDevice()
1592 }
1593 }
1594 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001595}
1596
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001597var _ cc.Coverage = (*apexBundle)(nil)
1598
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001599func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001600 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001601}
1602
1603func (a *apexBundle) PreventInstall() {
1604 a.properties.PreventInstall = true
1605}
1606
1607func (a *apexBundle) HideFromMake() {
1608 a.properties.HideFromMake = true
1609}
1610
Jiyong Park956305c2020-01-09 12:32:06 +09001611func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1612 a.properties.IsCoverageVariant = coverage
1613}
1614
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001615func (a *apexBundle) EnableCoverageIfNeeded() {}
1616
Jiyong Parkf653b052019-11-18 15:39:01 +09001617// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001618func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001619 // Decide the APEX-local directory by the multilib of the library
1620 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001621 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001622 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001623 case "lib32":
1624 dirInApex = "lib"
1625 case "lib64":
1626 dirInApex = "lib64"
1627 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001628 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001629 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001630 }
Jooyung Han35155c42020-02-06 17:33:20 +09001631 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001632 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001633 // Special case for Bionic libs and other libs installed with them. This is
1634 // to prevent those libs from being included in the search path
1635 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1636 // those libs in the Runtime APEX are available via the legacy paths in
1637 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1638 // to the legacy paths and thus will be loaded into the default linker
1639 // namespace (aka "platform" namespace). If the libs are directly in
1640 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1641 // into the runtime linker namespace, which will result in double loading of
1642 // them, which isn't supported.
1643 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001644 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001645
Jiyong Parkf653b052019-11-18 15:39:01 +09001646 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001647 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001648}
1649
Jiyong Park1833cef2019-12-13 13:28:36 +09001650func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001651 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001652 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001653 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001654 }
Jooyung Han35155c42020-02-06 17:33:20 +09001655 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001656 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001657 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001658 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001659 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001660 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 Duffin581bbbe2020-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 Duffin581bbbe2020-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 Han39ee1192020-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 Han39ee1192020-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 Han39ee1192020-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 Parkcfaa1642020-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
Jiyong Park69aeba92020-04-24 21:16:36 +09001736func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1737 rroDir := "overlay"
1738 dirInApex := filepath.Join(rroDir, rro.Theme())
1739 fileToCopy := rro.OutputFile()
1740 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1741 af.certificate = rro.Certificate()
1742
1743 if a, ok := rro.(interface {
1744 OverriddenManifestPackageName() string
1745 }); ok {
1746 af.overriddenPackageName = a.OverriddenManifestPackageName()
1747 }
1748 return af
1749}
1750
Roland Levillain935639d2019-08-13 14:55:28 +01001751// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1752type flattenedApexContext struct {
1753 android.ModuleContext
1754}
1755
1756func (c *flattenedApexContext) InstallBypassMake() bool {
1757 return true
1758}
1759
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001760// Function called while walking an APEX's payload dependencies.
1761//
1762// Return true if the `to` module should be visited, false otherwise.
1763type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1764
Jiyong Park201cedd2020-02-07 17:25:49 +09001765// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001766func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001767 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001768 am, ok := child.(android.ApexModule)
1769 if !ok || !am.CanHaveApexVariants() {
1770 return false
1771 }
1772
1773 // Check for the direct dependencies that contribute to the payload
1774 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1775 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001776 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001777 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001778 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001779 return false
1780 }
1781
1782 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001783 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001784 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001785 }
1786
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001787 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001788 })
1789}
1790
Jooyung Han03b51852020-02-26 22:45:42 +09001791func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1792 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001793 intVer, err := android.ApiStrToNum(ctx, ver)
1794 if err != nil {
1795 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001796 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001797 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001798}
1799
Jiyong Park201cedd2020-02-07 17:25:49 +09001800// Ensures that the dependencies are marked as available for this APEX
1801func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1802 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1803 if ctx.Host() || a.testApex || a.vndkApex {
1804 return
1805 }
1806
Jiyong Park58d10902020-03-28 14:43:19 +09001807 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1808 // Requiring them and their transitive depencies with apex_available is not right
1809 // because they just add noise.
1810 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1811 return
1812 }
1813
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001814 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1815 if externalDep {
1816 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1817 return false
1818 }
1819
Jiyong Park201cedd2020-02-07 17:25:49 +09001820 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001821 fromName := ctx.OtherModuleName(from)
1822 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001823
1824 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1825 // do any of its dependencies.
1826 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1827 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1828 return false
1829 }
1830
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001831 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1832 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001833 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001834 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, ctx.GetPathString(true))
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001835 // Visit this module's dependencies to check and report any issues with their availability.
1836 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001837 })
1838}
1839
Jooyung Han548640b2020-04-27 12:10:30 +09001840func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1841 if proptools.Bool(a.properties.Updatable) {
1842 if String(a.properties.Min_sdk_version) == "" {
1843 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1844 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001845
1846 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001847 }
1848}
1849
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001850func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001851 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1852 switch a.properties.ApexType {
1853 case imageApex:
1854 if buildFlattenedAsDefault {
1855 a.suffix = imageApexSuffix
1856 } else {
1857 a.suffix = ""
1858 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001859
1860 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001861 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001862 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001863 }
1864 case zipApex:
1865 if proptools.String(a.properties.Payload_type) == "zip" {
1866 a.suffix = ""
1867 a.primaryApexType = true
1868 } else {
1869 a.suffix = zipApexSuffix
1870 }
1871 case flattenedApex:
1872 if buildFlattenedAsDefault {
1873 a.suffix = ""
1874 a.primaryApexType = true
1875 } else {
1876 a.suffix = flattenedSuffix
1877 }
Alex Light5098a612018-11-29 17:12:15 -08001878 }
1879
Roland Levillain630846d2019-06-26 12:48:34 +01001880 if len(a.properties.Tests) > 0 && !a.testApex {
1881 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1882 return
1883 }
1884
Jiyong Park0f80c182020-01-31 02:49:53 +09001885 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001886 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001887
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001888 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1889
Jooyung Hane1633032019-08-01 17:41:43 +09001890 // native lib dependencies
1891 var provideNativeLibs []string
1892 var requireNativeLibs []string
1893
Jooyung Han5c998b92019-06-27 11:30:33 +09001894 // Check if "uses" requirements are met with dependent apexBundles
1895 var providedNativeSharedLibs []string
1896 useVendor := proptools.Bool(a.properties.Use_vendor)
1897 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1898 if ctx.OtherModuleDependencyTag(m) != usesTag {
1899 return
1900 }
1901 otherName := ctx.OtherModuleName(m)
1902 other, ok := m.(*apexBundle)
1903 if !ok {
1904 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1905 return
1906 }
1907 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1908 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1909 return
1910 }
1911 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1912 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1913 return
1914 }
1915 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1916 })
1917
Jiyong Parkf653b052019-11-18 15:39:01 +09001918 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001919 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001920 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001921 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001922 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1923 return false
1924 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001925 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001926 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001927 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001928 case sharedLibTag, jniLibTag:
1929 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001930 if c, ok := child.(*cc.Module); ok {
1931 // bootstrap bionic libs are treated as provided by system
1932 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1933 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001934 }
Jooyung Han643adc42020-02-27 13:50:06 +09001935 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1936 fi.isJniLib = isJniLib
1937 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001938 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001939 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001940 propertyName := "native_shared_libs"
1941 if isJniLib {
1942 propertyName = "jni_libs"
1943 }
1944 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001945 }
1946 case executableTag:
1947 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001948 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001949 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001950 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001951 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001952 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001953 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001954 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001955 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001956 } else {
Alex Light778127a2019-02-27 14:19:50 -08001957 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 +09001958 }
1959 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001960 if javaLib, ok := child.(*java.Library); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01001961 af := apexFileForJavaLibrary(ctx, javaLib, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001962 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001963 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1964 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001965 filesInfo = append(filesInfo, af)
1966 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001967 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001968 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01001969 af := apexFileForJavaLibrary(ctx, sdkLib, sdkLib)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001970 if !af.Ok() {
1971 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1972 return false
1973 }
1974 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001975 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001976 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001977 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001978 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001979 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001980 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001981 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001982 return true // track transitive dependencies
1983 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001984 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001985 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001986 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001987 } else {
1988 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1989 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001990 case rroTag:
1991 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1992 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1993 } else {
1994 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1995 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001996 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001997 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001998 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001999 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2000 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002001 } else {
atrost6e126252020-01-27 17:01:16 +00002002 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002003 }
Roland Levillain630846d2019-06-26 12:48:34 +01002004 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002005 if ccTest, ok := child.(*cc.Module); ok {
2006 if ccTest.IsTestPerSrcAllTestsVariation() {
2007 // Multiple-output test module (where `test_per_src: true`).
2008 //
2009 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2010 // We do not add this variation to `filesInfo`, as it has no output;
2011 // however, we do add the other variations of this module as indirect
2012 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002013 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002014 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002015 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002016 af.class = nativeTest
2017 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002018 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002019 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002020 } else {
2021 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2022 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002023 case keyTag:
2024 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002025 a.private_key_file = key.private_key_file
2026 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002027 } else {
2028 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002029 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002030 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002031 case certificateTag:
2032 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002033 a.container_certificate_file = dep.Certificate.Pem
2034 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002035 } else {
2036 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2037 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002038 case android.PrebuiltDepTag:
2039 // If the prebuilt is force disabled, remember to delete the prebuilt file
2040 // that might have been installed in the previous builds
2041 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2042 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2043 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002044 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002045 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002046 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002047 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002048 // We cannot use a switch statement on `depTag` here as the checked
2049 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002050 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002051 if cc, ok := child.(*cc.Module); ok {
2052 if android.InList(cc.Name(), providedNativeSharedLibs) {
2053 // If we're using a shared library which is provided from other APEX,
2054 // don't include it in this APEX
2055 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002056 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002057 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002058 // If the dependency is a stubs lib, don't include it in this APEX,
2059 // but make sure that the lib is installed on the device.
2060 // In case no APEX is having the lib, the lib is installed to the system
2061 // partition.
2062 //
2063 // Always include if we are a host-apex however since those won't have any
2064 // system libraries.
Yo Chiang29555d52020-05-06 15:59:59 +08002065 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.BaseModuleName(), a.requiredDeps) {
2066 a.requiredDeps = append(a.requiredDeps, cc.BaseModuleName())
Roland Levillainf89cd092019-07-29 16:22:59 +01002067 }
Jooyung Hane1633032019-08-01 17:41:43 +09002068 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002069 // Don't track further
2070 return false
2071 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002072 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002073 af.transitiveDep = true
2074 filesInfo = append(filesInfo, af)
2075 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002076 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002077 } else if cc.IsTestPerSrcDepTag(depTag) {
2078 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002079 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002080 // Handle modules created as `test_per_src` variations of a single test module:
2081 // use the name of the generated test binary (`fileToCopy`) instead of the name
2082 // of the original test module (`depName`, shared by all `test_per_src`
2083 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002084 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002085 // these are not considered transitive dep
2086 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002087 filesInfo = append(filesInfo, af)
2088 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002089 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002090 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002091 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2092 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002093 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2094 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2095 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2096 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002097 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002098 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002099 }
2100 }
2101 }
2102 return false
2103 })
2104
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002105 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2106 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2107 // via the global boot image config.
2108 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002109 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002110 dirInApex := filepath.Join("javalib", arch.String())
2111 for _, f := range files {
2112 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002113 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002114 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002115 }
2116 }
2117 }
2118
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002119 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002120 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2121 return
2122 }
2123
Jiyong Park8fd61922018-11-08 02:50:25 +09002124 // remove duplicates in filesInfo
2125 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002126 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002127 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002128 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002129 if e, ok := encountered[dest]; !ok {
2130 encountered[dest] = f
2131 } else {
2132 // If a module is directly included and also transitively depended on
2133 // consider it as directly included.
2134 e.transitiveDep = e.transitiveDep && f.transitiveDep
2135 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002136 }
2137 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002138 var result []apexFile
2139 for _, v := range encountered {
2140 result = append(result, v)
2141 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002142 return result
2143 }
2144 filesInfo = removeDup(filesInfo)
2145
2146 // to have consistent build rules
2147 sort.Slice(filesInfo, func(i, j int) bool {
2148 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2149 })
2150
Jiyong Park8fd61922018-11-08 02:50:25 +09002151 a.installDir = android.PathForModuleInstall(ctx, "apex")
2152 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002153
Jooyung Han54aca7b2019-11-20 02:26:02 +09002154 if a.properties.ApexType != zipApex {
2155 if a.properties.File_contexts == nil {
2156 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2157 } else {
2158 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2159 if a.Platform() {
2160 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2161 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2162 }
2163 }
2164 }
2165 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2166 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2167 return
2168 }
2169 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002170 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2171 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2172 // the same library in the system partition, thus effectively sharing the same libraries
2173 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2174 // in the APEX.
2175 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2176 a.installable() &&
2177 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002178
Jiyong Park9d677202020-02-19 16:29:35 +09002179 // We don't need the optimization for updatable APEXes, as it might give false signal
2180 // to the system health when the APEXes are still bundled (b/149805758)
2181 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2182 a.linkToSystemLib = false
2183 }
2184
Jiyong Park638d30e2020-02-26 18:27:19 +09002185 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2186 if ctx.Host() {
2187 a.linkToSystemLib = false
2188 }
2189
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002190 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002191 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2192
2193 a.setCertificateAndPrivateKey(ctx)
2194 if a.properties.ApexType == flattenedApex {
2195 a.buildFlattenedApex(ctx)
2196 } else {
2197 a.buildUnflattenedApex(ctx)
2198 }
2199
Jooyung Han002ab682020-01-08 01:57:58 +09002200 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002201
2202 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002203}
2204
Artur Satayev8cf899a2020-04-15 17:29:42 +01002205// Enforce that Java deps of the apex are using stable SDKs to compile
2206func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2207 // Visit direct deps only. As long as we guarantee top-level deps are using
2208 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2209 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2210 tag := ctx.OtherModuleDependencyTag(module)
2211 switch tag {
2212 case javaLibTag, androidAppTag:
2213 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2214 if err := m.CheckStableSdkVersion(); err != nil {
2215 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2216 }
2217 }
2218 }
2219 })
2220}
2221
Jooyung Han5e9013b2020-03-10 06:23:13 +09002222func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002223 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002224 moduleName = normalizeModuleName(moduleName)
2225
2226 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2227 return true
2228 }
2229
2230 key = android.AvailableToAnyApex
2231 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2232 return true
2233 }
2234
2235 return false
2236}
2237
2238func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002239 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2240 // system. Trim the prefix for the check since they are confusing
2241 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2242 if strings.HasPrefix(moduleName, "libclang_rt.") {
2243 // This module has many arch variants that depend on the product being built.
2244 // We don't want to list them all
2245 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002246 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002247 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002248}
2249
Jooyung Han344d5432019-08-23 11:17:39 +09002250func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002251 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002252 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002253 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002254 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002255 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002256 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2257 })
Alex Light5098a612018-11-29 17:12:15 -08002258 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002259 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002260 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002261 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002262 return module
2263}
Jiyong Park30ca9372019-02-07 16:27:23 +09002264
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002265func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002266 bundle := newApexBundle()
2267 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002268 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002269 return bundle
2270}
2271
Jiyong Parkfce0b422020-02-11 03:56:06 +09002272// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2273// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002274func testApexBundleFactory() android.Module {
2275 bundle := newApexBundle()
2276 bundle.testApex = true
2277 return bundle
2278}
2279
Jiyong Parkfce0b422020-02-11 03:56:06 +09002280// apex packages other modules into an APEX file which is a packaging format for system-level
2281// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002282func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002283 return newApexBundle()
2284}
2285
Jiyong Park30ca9372019-02-07 16:27:23 +09002286//
2287// Defaults
2288//
2289type Defaults struct {
2290 android.ModuleBase
2291 android.DefaultsModuleBase
2292}
2293
Jiyong Park30ca9372019-02-07 16:27:23 +09002294func defaultsFactory() android.Module {
2295 return DefaultsFactory()
2296}
2297
2298func DefaultsFactory(props ...interface{}) android.Module {
2299 module := &Defaults{}
2300
2301 module.AddProperties(props...)
2302 module.AddProperties(
2303 &apexBundleProperties{},
2304 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002305 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002306 )
2307
2308 android.InitDefaultsModule(module)
2309 return module
2310}
Jiyong Park5d790c32019-11-15 18:40:32 +09002311
2312//
2313// OverrideApex
2314//
2315type OverrideApex struct {
2316 android.ModuleBase
2317 android.OverrideModuleBase
2318}
2319
2320func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2321 // All the overrides happen in the base module.
2322}
2323
2324// override_apex is used to create an apex module based on another apex module
2325// by overriding some of its properties.
2326func overrideApexFactory() android.Module {
2327 m := &OverrideApex{}
2328 m.AddProperties(&overridableProperties{})
2329
2330 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2331 android.InitOverrideModule(m)
2332 return m
2333}