blob: 3c3ba18969092eea9c7c5a87e973e1499efff4dc [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 Parkfa899442020-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 Parkfa899442020-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 Parkfa899442020-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 Parkfa899442020-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 Hansson5053c292020-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 Hansson5053c292020-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 Parkfa899442020-01-31 02:49:53 +090097 "art_cmdlineparser_headers",
98 "art_disassembler_headers",
99 "art_libartbase_headers",
Jiyong Parkfa899442020-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 Parkfa899442020-01-31 02:49:53 +0900108 "dex2oat_headers",
109 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900110 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900111 "javavm_headers",
112 "jni_platform_headers",
113 "libPlatformProperties",
114 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000115 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900116 "libandroidicuinit",
117 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000118 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900119 "libdexfile_all_headers",
120 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000121 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900122 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000123 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900124 "libfdlibm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900125 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000126 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900127 "libicuuc_headers",
128 "libicuuc_stubdata",
129 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900130 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000131 "liblzma",
132 "libmeminfo",
Jiyong Parkfa899442020-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 Hansson5053c292020-01-10 15:12:39 +0000139 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900140 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000141 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900142 "libv8",
143 "libv8base",
144 "libv8gen",
145 "libv8platform",
146 "libv8sampler",
147 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000148 "libvixl",
149 "libvixld",
150 "libz",
151 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900152 "perfetto_trace_protos",
Anton Hansson5053c292020-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 Hansson5053c292020-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 Hansson5053c292020-01-10 15:12:39 +0000161 "android.hardware.bluetooth.a2dp@1.0",
162 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-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 Hansson5053c292020-01-10 15:12:39 +0000171 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-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 Parkfa899442020-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 Parkfa899442020-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 Parkfa899442020-01-31 02:49:53 +0900189 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000190 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900191 "libbluetooth-types",
192 "libbluetooth-types-header",
193 "libbluetooth_gd",
194 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000195 "libbluetooth_jni",
Jiyong Parkfa899442020-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 Hansson5053c292020-01-10 15:12:39 +0000210 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000211 "libevent",
212 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900213 "libg722codec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900214 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libmedia_headers",
216 "libmodpb64",
217 "libosi",
Jiyong Parkfa899442020-01-31 02:49:53 +0900218 "libstagefright_foundation_headers",
219 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000220 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900221 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000222 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900223 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000224 "libz",
Jiyong Parkfa899442020-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 Parkfa899442020-01-31 02:49:53 +0900231 "sap-api-java-static",
232 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000233 }
234 //
235 // Module separator
236 //
237 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
238 //
239 // Module separator
240 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900241 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900242 "libnativehelper_header_only",
Jiyong Parkfa899442020-01-31 02:49:53 +0900243 }
Anton Hansson5053c292020-01-10 15:12:39 +0000244 //
245 // Module separator
246 //
Jiyong Parkfa899442020-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 Parkfa899442020-01-31 02:49:53 +0900256 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900257 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900258 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900259 "libprocpartition",
260 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900261 }
Anton Hansson5053c292020-01-10 15:12:39 +0000262 //
263 // Module separator
264 //
Anton Hansson5053c292020-01-10 15:12:39 +0000265 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900266 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000267 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900268 "android.hardware.cas@1.0",
269 "android.hardware.configstore-utils",
270 "android.hardware.configstore@1.0",
271 "android.hardware.configstore@1.1",
272 "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",
282 "android.hardware.media.omx@1.0",
283 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000284 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000285 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900286 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000287 "android.hidl.token@1.0",
288 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900289 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-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",
Anton Hansson5053c292020-01-10 15:12:39 +0000298 "libaacextractor",
299 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900300 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900301 "libaudio_system_headers",
302 "libaudioclient",
303 "libaudioclient_headers",
304 "libaudiofoundation",
305 "libaudiofoundation_headers",
306 "libaudiomanager",
307 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000308 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900309 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900310 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900311 "libbluetooth-types-header",
312 "libbufferhub",
313 "libbufferhub_headers",
314 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900315 "libc_malloc_debug_backtrace",
316 "libcamera_client",
317 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900318 "libdexfile_external_headers",
319 "libdexfile_support",
320 "libdvr_headers",
321 "libexpat",
322 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000323 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900324 "libgrallocusage",
325 "libgraphicsenv",
326 "libgui",
327 "libgui_headers",
328 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900329 "libinput",
Jiyong Parkfa899442020-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",
Anton Hansson5053c292020-01-10 15:12:39 +0000340 "libmidiextractor",
341 "libmkvextractor",
342 "libmp3extractor",
343 "libmp4extractor",
344 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900345 "libnativebase_headers",
346 "libnativebridge-headers",
347 "libnativebridge_lazy",
348 "libnativeloader-headers",
349 "libnativeloader_lazy",
350 "libnativewindow_headers",
351 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000352 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900353 "libpackagelistparser",
Jiyong Parkfa899442020-01-31 02:49:53 +0900354 "libpdx",
355 "libpdx_default_transport",
356 "libpdx_headers",
357 "libpdx_uds",
Jiyong Parkfa899442020-01-31 02:49:53 +0900358 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000359 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900360 "libspeexresampler",
361 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000362 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900363 "libstagefright_flacdec",
364 "libstagefright_foundation",
365 "libstagefright_foundation_headers",
366 "libstagefright_foundation_without_imemory",
367 "libstagefright_headers",
368 "libstagefright_id3",
369 "libstagefright_metadatautils",
370 "libstagefright_mpeg2extractor",
371 "libstagefright_mpeg2support",
372 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900373 "libui",
374 "libui_headers",
375 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900376 "libvibrator",
377 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000378 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900379 "libwebm",
380 "media_ndk_headers",
381 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000382 "updatable-media",
383 }
384 //
385 // Module separator
386 //
387 m["com.android.media.swcodec"] = []string{
388 "android.frameworks.bufferhub@1.0",
389 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900390 "android.hardware.configstore-utils",
391 "android.hardware.configstore@1.0",
392 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000393 "android.hardware.graphics.allocator@2.0",
394 "android.hardware.graphics.allocator@3.0",
395 "android.hardware.graphics.allocator@4.0",
396 "android.hardware.graphics.bufferqueue@1.0",
397 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900398 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000399 "android.hardware.graphics.common@1.0",
400 "android.hardware.graphics.common@1.1",
401 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000402 "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 Hansson5053c292020-01-10 15:12:39 +0000406 "android.hardware.media.bufferpool@2.0",
407 "android.hardware.media.c2@1.0",
408 "android.hardware.media.c2@1.1",
409 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900410 "android.hardware.media@1.0",
411 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000412 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900413 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000414 "android.hidl.safe_union@1.0",
415 "android.hidl.token@1.0",
416 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900417 "libEGL",
418 "libFLAC",
419 "libFLAC-config",
420 "libFLAC-headers",
421 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900422 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900423 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900424 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000425 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900426 "libaudioutils",
427 "libaudioutils_fixedfft",
428 "libavcdec",
429 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000430 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900431 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900432 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900433 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900434 "libbluetooth-types-header",
435 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000437 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900438 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000439 "libcodec2_hidl@1.0",
440 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900441 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000442 "libcodec2_soft_aacdec",
443 "libcodec2_soft_aacenc",
444 "libcodec2_soft_amrnbdec",
445 "libcodec2_soft_amrnbenc",
446 "libcodec2_soft_amrwbdec",
447 "libcodec2_soft_amrwbenc",
448 "libcodec2_soft_av1dec_gav1",
449 "libcodec2_soft_avcdec",
450 "libcodec2_soft_avcenc",
451 "libcodec2_soft_common",
452 "libcodec2_soft_flacdec",
453 "libcodec2_soft_flacenc",
454 "libcodec2_soft_g711alawdec",
455 "libcodec2_soft_g711mlawdec",
456 "libcodec2_soft_gsmdec",
457 "libcodec2_soft_h263dec",
458 "libcodec2_soft_h263enc",
459 "libcodec2_soft_hevcdec",
460 "libcodec2_soft_hevcenc",
461 "libcodec2_soft_mp3dec",
462 "libcodec2_soft_mpeg2dec",
463 "libcodec2_soft_mpeg4dec",
464 "libcodec2_soft_mpeg4enc",
465 "libcodec2_soft_opusdec",
466 "libcodec2_soft_opusenc",
467 "libcodec2_soft_rawdec",
468 "libcodec2_soft_vorbisdec",
469 "libcodec2_soft_vp8dec",
470 "libcodec2_soft_vp8enc",
471 "libcodec2_soft_vp9dec",
472 "libcodec2_soft_vp9enc",
473 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900474 "libdexfile_support",
475 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000476 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900477 "libfmq",
478 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000479 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900480 "libgrallocusage",
481 "libgraphicsenv",
482 "libgsm",
483 "libgui_bufferqueue_static",
484 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000485 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900486 "libhardware_headers",
487 "libhevcdec",
488 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000489 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900490 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900491 "liblzma",
492 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000493 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900494 "libmedia_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900495 "libmpeg2dec",
496 "libnativebase_headers",
497 "libnativebridge_lazy",
498 "libnativeloader_lazy",
499 "libnativewindow_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900500 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000501 "libscudo_wrapper",
502 "libsfplugin_ccodec_utils",
503 "libspeexresampler",
504 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900505 "libstagefright_amrnbdec",
506 "libstagefright_amrnbenc",
507 "libstagefright_amrwbdec",
508 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000509 "libstagefright_bufferpool@2.0.1",
510 "libstagefright_bufferqueue_helper",
511 "libstagefright_enc_common",
512 "libstagefright_flacdec",
513 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900514 "libstagefright_foundation_headers",
515 "libstagefright_headers",
516 "libstagefright_m4vh263dec",
517 "libstagefright_m4vh263enc",
518 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000519 "libsync",
520 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900521 "libui_headers",
522 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000523 "libvorbisidec",
524 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900525 "libyuv",
526 "libyuv_static",
527 "media_ndk_headers",
528 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000529 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000530 }
531 //
532 // Module separator
533 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900534 m["com.android.mediaprovider"] = []string{
535 "MediaProvider",
536 "MediaProviderGoogle",
537 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900538 "libbase_ndk",
539 "libfuse",
540 "libfuse_jni",
541 "libnativehelper_header_only",
542 }
543 //
544 // Module separator
545 //
546 m["com.android.permission"] = []string{
547 "androidx.annotation_annotation",
548 "androidx.annotation_annotation-nodeps",
549 "androidx.lifecycle_lifecycle-common",
550 "androidx.lifecycle_lifecycle-common-java8",
551 "androidx.lifecycle_lifecycle-common-java8-nodeps",
552 "androidx.lifecycle_lifecycle-common-nodeps",
553 "kotlin-annotations",
554 "kotlin-stdlib",
555 "kotlin-stdlib-jdk7",
556 "kotlin-stdlib-jdk8",
557 "kotlinx-coroutines-android",
558 "kotlinx-coroutines-android-nodeps",
559 "kotlinx-coroutines-core",
560 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900561 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900562 "GooglePermissionController",
563 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900564 }
Anton Hansson5053c292020-01-10 15:12:39 +0000565 //
566 // Module separator
567 //
Anton Hansson5053c292020-01-10 15:12:39 +0000568 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900569 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900570 "libarm-optimized-routines-math",
Jiyong Parkfa899442020-01-31 02:49:53 +0900571 "libc_aeabi",
572 "libc_bionic",
573 "libc_bionic_ndk",
574 "libc_bootstrap",
575 "libc_common",
576 "libc_common_shared",
577 "libc_common_static",
578 "libc_dns",
579 "libc_dynamic_dispatch",
580 "libc_fortify",
581 "libc_freebsd",
582 "libc_freebsd_large_stack",
583 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900584 "libc_init_dynamic",
585 "libc_init_static",
586 "libc_jemalloc_wrapper",
587 "libc_netbsd",
588 "libc_nomalloc",
589 "libc_nopthread",
590 "libc_openbsd",
591 "libc_openbsd_large_stack",
592 "libc_openbsd_ndk",
593 "libc_pthread",
594 "libc_static_dispatch",
595 "libc_syscalls",
596 "libc_tzcode",
597 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900598 "libdebuggerd",
599 "libdebuggerd_common_headers",
600 "libdebuggerd_handler_core",
601 "libdebuggerd_handler_fallback",
602 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000603 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900604 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900605 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900606 "libjemalloc5",
607 "liblinker_main",
608 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900609 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000610 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900611 "libprocinfo",
612 "libpropertyinfoparser",
613 "libscudo",
614 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900615 "libsystemproperties",
616 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000617 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900618 "libz",
619 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000620 }
621 //
622 // Module separator
623 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900624 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900625 "libnativehelper_compat_libc++",
626 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900627 "libcgrouprc",
628 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900629 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900630 "libvndksupport",
631 "tethering-aidl-interfaces-java",
632 }
Anton Hansson5053c292020-01-10 15:12:39 +0000633 //
634 // Module separator
635 //
636 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "PlatformProperties",
638 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900639 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900640 "android.hardware.wifi-V1.1-java",
641 "android.hardware.wifi-V1.2-java",
642 "android.hardware.wifi-V1.3-java",
643 "android.hardware.wifi-V1.4-java",
644 "android.hardware.wifi.hostapd-V1.0-java",
645 "android.hardware.wifi.hostapd-V1.1-java",
646 "android.hardware.wifi.hostapd-V1.2-java",
647 "android.hardware.wifi.supplicant-V1.0-java",
648 "android.hardware.wifi.supplicant-V1.1-java",
649 "android.hardware.wifi.supplicant-V1.2-java",
650 "android.hardware.wifi.supplicant-V1.3-java",
651 "android.hidl.base-V1.0-java",
652 "android.hidl.manager-V1.0-java",
653 "android.hidl.manager-V1.1-java",
654 "android.hidl.manager-V1.2-java",
655 "androidx.annotation_annotation",
656 "androidx.annotation_annotation-nodeps",
657 "bouncycastle-unbundled",
658 "dnsresolver_aidl_interface-V2-java",
659 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900660 "framework-wifi-pre-jarjar",
661 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900662 "ipmemorystore-aidl-interfaces-V3-java",
663 "ipmemorystore-aidl-interfaces-java",
664 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900665 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000666 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900667 "net-utils-services-common",
668 "netd_aidl_interface-V2-java",
669 "netd_aidl_interface-unstable-java",
670 "netd_event_listener_interface-java",
671 "netlink-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900672 "networkstack-client",
673 "services.net",
674 "wifi-lite-protos",
675 "wifi-nano-protos",
676 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000677 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900678 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000679 }
680 //
681 // Module separator
682 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900683 m["com.android.sdkext"] = []string{
684 "fmtlib_ndk",
685 "libbase_ndk",
686 "libprotobuf-cpp-lite-ndk",
687 }
688 //
689 // Module separator
690 //
691 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900692 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900693 }
694 //
695 // Module separator
696 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000697 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 "libclang_rt",
700 "libgcc_stripped",
701 "libprofile-clang-extras",
702 "libprofile-clang-extras_ndk",
703 "libprofile-extras",
704 "libprofile-extras_ndk",
705 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900706 }
Anton Hansson5053c292020-01-10 15:12:39 +0000707 return m
708}
709
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900710func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900711 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800712 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900713 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900714 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700715 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900716 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700717 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900718
Jooyung Han31c470b2019-10-18 16:26:59 +0900719 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900720 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900721
722 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
723 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
724 sort.Strings(*apexFileContextsInfos)
725 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
726 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900727}
728
Jooyung Han31c470b2019-10-18 16:26:59 +0900729func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
730 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
731 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
732}
733
Jiyong Parkd1063c12019-07-17 20:08:41 +0900734func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900735 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900736 ctx.BottomUp("apex", apexMutator).Parallel()
737 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
738 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900739 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900740}
741
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900742// Mark the direct and transitive dependencies of apex bundles so that they
743// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900744func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900745 if !mctx.Module().Enabled() {
746 return
747 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800748 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900749 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000750 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900751 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900752 ApexName: mctx.ModuleName(),
753 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100754 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900755 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900756 directDep = true
757 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800758 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900759 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900760 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900761
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800762 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900763 return
764 }
765
Paul Duffin923e8a52020-03-30 15:33:32 +0100766 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900767
Jiyong Parkf760cae2020-02-12 07:53:12 +0900768 mctx.VisitDirectDeps(func(child android.Module) {
769 depName := mctx.OtherModuleName(child)
770 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100771 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800772 android.UpdateApexDependency(apexBundles, depName, directDep)
773 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900774 }
775 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900776}
777
Jiyong Park89e850a2020-04-07 16:37:39 +0900778// mark if a module cannot be available to platform. A module cannot be available
779// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
780// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
781func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
782 // Host and recovery are not considered as platform
783 if mctx.Host() || mctx.Module().InstallInRecovery() {
784 return
785 }
786
787 if am, ok := mctx.Module().(android.ApexModule); ok {
788 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
789
790 // In a rare case when a lib is marked as available only to an apex
791 // but the apex doesn't exist. This can happen in a partial manifest branch
792 // like master-art. Currently, libstatssocket in the stats APEX is causing
793 // this problem.
794 // Include the lib in platform because the module SDK that ought to provide
795 // it doesn't exist, so it would otherwise be left out completely.
796 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
797 // this check for libraries provided by SDKs.
798 if !availableToPlatform && !android.InAnyApex(am.Name()) {
799 availableToPlatform = true
800 }
801
802 // If any of the dep is not available to platform, this module is also considered
803 // as being not available to platform even if it has "//apex_available:platform"
804 mctx.VisitDirectDeps(func(child android.Module) {
805 if !am.DepIsInSameApex(mctx, child) {
806 // if the dependency crosses apex boundary, don't consider it
807 return
808 }
809 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
810 availableToPlatform = false
811 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
812 }
813 })
814
815 // Exception 1: stub libraries and native bridge libraries are always available to platform
816 if cc, ok := mctx.Module().(*cc.Module); ok &&
817 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
818 availableToPlatform = true
819 }
820
821 // Exception 2: bootstrap bionic libraries are also always available to platform
822 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
823 availableToPlatform = true
824 }
825
826 if !availableToPlatform {
827 am.SetNotAvailableForPlatform()
828 }
829 }
830}
831
Paul Duffin65347702020-03-31 15:23:40 +0100832// If a module in an APEX depends on a module from an SDK then it needs an APEX
833// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
834func inAnySdk(module android.Module) bool {
835 if sa, ok := module.(android.SdkAware); ok {
836 return sa.IsInAnySdk()
837 }
838
839 return false
840}
841
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900842// Create apex variations if a module is included in APEX(s).
843func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900844 if !mctx.Module().Enabled() {
845 return
846 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900847 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900848 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000849 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900850 // apex bundle itself is mutated so that it and its modules have same
851 // apex variant.
852 apexBundleName := mctx.ModuleName()
853 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900854 } else if o, ok := mctx.Module().(*OverrideApex); ok {
855 apexBundleName := o.GetOverriddenModuleName()
856 if apexBundleName == "" {
857 mctx.ModuleErrorf("base property is not set")
858 return
859 }
860 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900861 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900862
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900863}
Sundong Ahne9b55722019-09-06 17:37:42 +0900864
Jooyung Han7a78a922019-10-08 21:59:58 +0900865var (
866 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
867 apexFileContextsInfosMutex sync.Mutex
868)
869
870func apexFileContextsInfos(config android.Config) *[]string {
871 return config.Once(apexFileContextsInfosKey, func() interface{} {
872 return &[]string{}
873 }).(*[]string)
874}
875
Jooyung Han54aca7b2019-11-20 02:26:02 +0900876func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900877 apexFileContextsInfosMutex.Lock()
878 defer apexFileContextsInfosMutex.Unlock()
879 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900880 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900881}
882
Sundong Ahne9b55722019-09-06 17:37:42 +0900883func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900884 if !mctx.Module().Enabled() {
885 return
886 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900887 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900888 var variants []string
889 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
890 case "image":
891 variants = append(variants, imageApexType, flattenedApexType)
892 case "zip":
893 variants = append(variants, zipApexType)
894 case "both":
895 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
896 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900897 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900898 return
899 }
900
901 modules := mctx.CreateLocalVariations(variants...)
902
903 for i, v := range variants {
904 switch v {
905 case imageApexType:
906 modules[i].(*apexBundle).properties.ApexType = imageApex
907 case zipApexType:
908 modules[i].(*apexBundle).properties.ApexType = zipApex
909 case flattenedApexType:
910 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900911 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900912 modules[i].(*apexBundle).MakeAsSystemExt()
913 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900914 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900915 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900916 } else if _, ok := mctx.Module().(*OverrideApex); ok {
917 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900918 }
919}
920
Jooyung Han5c998b92019-06-27 11:30:33 +0900921func apexUsesMutator(mctx android.BottomUpMutatorContext) {
922 if ab, ok := mctx.Module().(*apexBundle); ok {
923 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
924 }
925}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900926
Jooyung Handc782442019-11-01 03:14:38 +0900927var (
928 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
929)
930
931// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
932// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
933// which may cause compatibility issues. (e.g. libbinder)
934// Even though libbinder restricts its availability via 'apex_available' property and relies on
935// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
936// to avoid similar problems.
937func useVendorWhitelist(config android.Config) []string {
938 return config.Once(useVendorWhitelistKey, func() interface{} {
939 return []string{
940 // swcodec uses "vendor" variants for smaller size
941 "com.android.media.swcodec",
942 "test_com.android.media.swcodec",
943 }
944 }).([]string)
945}
946
947// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
948// called before the first call to useVendorWhitelist()
949func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
950 config.Once(useVendorWhitelistKey, func() interface{} {
951 return whitelist
952 })
953}
954
Jooyung Han01a868d2020-02-27 13:40:44 +0900955type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800956 // List of native libraries
957 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900958
Jooyung Han643adc42020-02-27 13:50:06 +0900959 // List of JNI libraries
960 Jni_libs []string
961
Alex Light9670d332019-01-29 18:07:33 -0800962 // List of native executables
963 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900964
Roland Levillain630846d2019-06-26 12:48:34 +0100965 // List of native tests
966 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800967}
Jooyung Han344d5432019-08-23 11:17:39 +0900968
Alex Light9670d332019-01-29 18:07:33 -0800969type apexMultilibProperties struct {
970 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900971 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800972
973 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900974 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800975
976 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900977 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800978
979 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900980 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800981
982 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900983 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800984}
985
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900986type apexBundleProperties struct {
987 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000988 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800989 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900990
Jiyong Park40e26a22019-02-08 02:53:06 +0900991 // AndroidManifest.xml file used for the zip container of this APEX bundle.
992 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800993 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900994
Roland Levillain411c5842019-09-19 16:37:20 +0100995 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
996 // device (/apex/<apex_name>).
997 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900998 Apex_name *string
999
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001000 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001001 // For platform APEXes, this should points to a file under /system/sepolicy
1002 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1003 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001004
Jooyung Han01a868d2020-02-27 13:40:44 +09001005 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001006
1007 // List of java libraries that are embedded inside this APEX bundle
1008 Java_libs []string
1009
1010 // List of prebuilt files that are embedded inside this APEX bundle
1011 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001012
1013 // Name of the apex_key module that provides the private key to sign APEX
1014 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001015
Alex Light5098a612018-11-29 17:12:15 -08001016 // The type of APEX to build. Controls what the APEX payload is. Either
1017 // 'image', 'zip' or 'both'. Default: 'image'.
1018 Payload_type *string
1019
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001020 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1021 // or an android_app_certificate module name in the form ":module".
1022 Certificate *string
1023
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001024 // Whether this APEX is installable to one of the partitions. Default: true.
1025 Installable *bool
1026
Jiyong Parkda6eb592018-12-19 17:12:36 +09001027 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1028 // Default is false.
1029 Use_vendor *bool
1030
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001031 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1032 Ignore_system_library_special_case *bool
1033
Alex Light9670d332019-01-29 18:07:33 -08001034 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001035
Jiyong Parkf97782b2019-02-13 20:28:58 +09001036 // List of sanitizer names that this APEX is enabled for
1037 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001038
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001039 PreventInstall bool `blueprint:"mutated"`
1040
1041 HideFromMake bool `blueprint:"mutated"`
1042
Jooyung Han5c998b92019-06-27 11:30:33 +09001043 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1044 Provide_cpp_shared_libs *bool
1045
1046 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1047 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001048
1049 // A txt file containing list of files that are whitelisted to be included in this APEX.
1050 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001051
Sundong Ahnabb64432019-10-22 13:58:29 +09001052 // package format of this apex variant; could be non-flattened, flattened, or zip.
1053 // imageApex, zipApex or flattened
1054 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001055
Jiyong Parkd1063c12019-07-17 20:08:41 +09001056 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1057 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1058 // is implied. This value affects all modules included in this APEX. In other words, they are
1059 // also built with the SDKs specified here.
1060 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001061
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001062 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1063 // Should be only used in tests#.
1064 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001065
Dario Freni98410fd2020-04-27 18:21:11 +01001066 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1067 // Should be only used in tests#.
1068 Test_only_unsigned_payload *bool
1069
Jiyong Park956305c2020-01-09 12:32:06 +09001070 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001071
1072 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001073 // rules for making sure that the APEX is truly updatable.
1074 // - To be updatable, min_sdk_version should be set as well
1075 // This will also disable the size optimizations like symlinking to the system libs.
1076 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001077 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001078
1079 // The minimum SDK version that this apex must be compatibile with.
1080 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001081}
1082
1083type apexTargetBundleProperties struct {
1084 Target struct {
1085 // Multilib properties only for android.
1086 Android 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.
1091 Host 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_bionic.
1096 Linux_bionic struct {
1097 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001098 }
Jooyung Han344d5432019-08-23 11:17:39 +09001099
Alex Light9670d332019-01-29 18:07:33 -08001100 // Multilib properties only for host linux_glibc.
1101 Linux_glibc struct {
1102 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001103 }
1104 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001105}
1106
Jiyong Park5d790c32019-11-15 18:40:32 +09001107type overridableProperties struct {
1108 // List of APKs to package inside APEX
1109 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001110
Jiyong Park69aeba92020-04-24 21:16:36 +09001111 // List of runtime resource overlays (RROs) inside APEX
1112 Rros []string
1113
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001114 // Names of modules to be overridden. Listed modules can only be other binaries
1115 // (in Make or Soong).
1116 // This does not completely prevent installation of the overridden binaries, but if both
1117 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1118 // from PRODUCT_PACKAGES.
1119 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001120
1121 // Logging Parent value
1122 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001123
1124 // Apex Container Package Name.
1125 // Override value for attribute package:name in AndroidManifest.xml
1126 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001127}
1128
Alex Light5098a612018-11-29 17:12:15 -08001129type apexPackaging int
1130
1131const (
1132 imageApex apexPackaging = iota
1133 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001134 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001135)
1136
Sundong Ahnabb64432019-10-22 13:58:29 +09001137// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001138func (a apexPackaging) suffix() string {
1139 switch a {
1140 case imageApex:
1141 return imageApexSuffix
1142 case zipApex:
1143 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001144 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001145 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001146 }
1147}
1148
1149func (a apexPackaging) name() string {
1150 switch a {
1151 case imageApex:
1152 return imageApexType
1153 case zipApex:
1154 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001155 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001156 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001157 }
1158}
1159
Jiyong Parkf653b052019-11-18 15:39:01 +09001160type apexFileClass int
1161
1162const (
1163 etc apexFileClass = iota
1164 nativeSharedLib
1165 nativeExecutable
1166 shBinary
1167 pyBinary
1168 goBinary
1169 javaSharedLib
1170 nativeTest
1171 app
1172)
1173
Jiyong Park8fd61922018-11-08 02:50:25 +09001174func (class apexFileClass) NameInMake() string {
1175 switch class {
1176 case etc:
1177 return "ETC"
1178 case nativeSharedLib:
1179 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001180 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001181 return "EXECUTABLES"
1182 case javaSharedLib:
1183 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001184 case nativeTest:
1185 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001186 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001187 // b/142537672 Why isn't this APP? We want to have full control over
1188 // the paths and file names of the apk file under the flattend APEX.
1189 // If this is set to APP, then the paths and file names are modified
1190 // by the Make build system. For example, it is installed to
1191 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1192 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1193 // appends module name (which is <apexname>.<Appname> to the path.
1194 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001195 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001196 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001197 }
1198}
1199
Jiyong Parkf653b052019-11-18 15:39:01 +09001200// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001201type apexFile struct {
1202 builtFile android.Path
1203 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001204 installDir string
1205 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001206 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001207 // list of symlinks that will be created in installDir that point to this apexFile
1208 symlinks []string
Liz Kammer1c14a212020-05-12 15:26:55 -07001209 dataPaths android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001210 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001211 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001212
1213 requiredModuleNames []string
1214 targetRequiredModuleNames []string
1215 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001216
Colin Cross503c1d02020-01-28 14:00:53 -08001217 jacocoReportClassesFile android.Path // only for javalibs and apps
1218 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001219 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001220
1221 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001222}
1223
Jiyong Park1833cef2019-12-13 13:28:36 +09001224func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1225 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001226 builtFile: builtFile,
1227 moduleName: moduleName,
1228 installDir: installDir,
1229 class: class,
1230 module: module,
1231 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001232 if module != nil {
1233 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001234 ret.requiredModuleNames = module.RequiredModuleNames()
1235 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1236 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001237 }
1238 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001239}
1240
1241func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001242 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001243}
1244
Liz Kammer1c14a212020-05-12 15:26:55 -07001245func (af *apexFile) apexRelativePath(path string) string {
1246 return filepath.Join(af.installDir, path)
1247}
1248
Jiyong Park7cd10e32020-01-14 09:22:18 +09001249// Path() returns path of this apex file relative to the APEX root
1250func (af *apexFile) Path() string {
Liz Kammer1c14a212020-05-12 15:26:55 -07001251 return af.apexRelativePath(af.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001252}
1253
1254// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1255func (af *apexFile) SymlinkPaths() []string {
1256 var ret []string
1257 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001258 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001259 }
1260 return ret
1261}
1262
1263func (af *apexFile) AvailableToPlatform() bool {
1264 if af.module == nil {
1265 return false
1266 }
1267 if am, ok := af.module.(android.ApexModule); ok {
1268 return am.AvailableFor(android.AvailableToPlatform)
1269 }
1270 return false
1271}
1272
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001273type apexBundle struct {
1274 android.ModuleBase
1275 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001276 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001277 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001278
Jiyong Park5d790c32019-11-15 18:40:32 +09001279 properties apexBundleProperties
1280 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001281 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001282
Jooyung Hanf21c7972019-12-16 22:32:06 +09001283 // specific to apex_vndk modules
1284 vndkProperties apexVndkProperties
1285
Colin Crossa4925902018-11-16 11:36:28 -08001286 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001287 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001288 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001289
Jiyong Park03b68dd2019-07-26 23:20:40 +09001290 prebuiltFileToDelete string
1291
Jiyong Park42cca6c2019-04-01 11:15:50 +09001292 public_key_file android.Path
1293 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001294
1295 container_certificate_file android.Path
1296 container_private_key_file android.Path
1297
Jooyung Han54aca7b2019-11-20 02:26:02 +09001298 fileContexts android.Path
1299
Jiyong Park8fd61922018-11-08 02:50:25 +09001300 // list of files to be included in this apex
1301 filesInfo []apexFile
1302
Jiyong Park956305c2020-01-09 12:32:06 +09001303 // list of module names that should be installed along with this APEX
1304 requiredDeps []string
1305
Jiyong Park956305c2020-01-09 12:32:06 +09001306 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001307 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001308
Sundong Ahnabb64432019-10-22 13:58:29 +09001309 testApex bool
1310 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001311 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001312 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001313
Jooyung Han214bf372019-11-12 13:03:50 +09001314 manifestJsonOut android.WritablePath
1315 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001316
Jooyung Han002ab682020-01-08 01:57:58 +09001317 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001318 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001319 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001320 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1321 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001322
1323 // Suffix of module name in Android.mk
1324 // ".flattened", ".apex", ".zipapex", or ""
1325 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001326
1327 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001328
1329 // Whether to create symlink to the system file instead of having a file
1330 // inside the apex or not
1331 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001332
1333 // Struct holding the merged notice file paths in different formats
1334 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001335}
1336
Jiyong Park397e55e2018-10-24 21:09:55 +09001337func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001338 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001339 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001340 // Use *FarVariation* to be able to depend on modules having
1341 // conflicting variations with this module. This is required since
1342 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1343 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001344 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001345 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001346 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001347 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001348 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001349
Jooyung Han643adc42020-02-27 13:50:06 +09001350 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1351 {Mutator: "image", Variation: imageVariation},
1352 {Mutator: "link", Variation: "shared"},
1353 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1354 }...), jniLibTag, nativeModules.Jni_libs...)
1355
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001356 ctx.AddFarVariationDependencies(append(target.Variations(),
1357 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001358 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001359
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001360 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001361 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001362 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001363 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001364}
1365
Alex Light9670d332019-01-29 18:07:33 -08001366func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1367 if ctx.Os().Class == android.Device {
1368 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1369 } else {
1370 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1371 if ctx.Os().Bionic() {
1372 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1373 } else {
1374 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1375 }
1376 }
1377}
1378
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001379func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001380 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1381 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1382 }
1383
Jiyong Park397e55e2018-10-24 21:09:55 +09001384 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001385 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001386
1387 a.combineProperties(ctx)
1388
Jiyong Park397e55e2018-10-24 21:09:55 +09001389 has32BitTarget := false
1390 for _, target := range targets {
1391 if target.Arch.ArchType.Multilib == "lib32" {
1392 has32BitTarget = true
1393 }
1394 }
1395 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001396 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001397 // multilib.both
1398 addDependenciesForNativeModules(ctx,
1399 ApexNativeDependencies{
1400 Native_shared_libs: a.properties.Native_shared_libs,
1401 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001402 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001403 Binaries: nil,
1404 },
1405 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001406
Jiyong Park397e55e2018-10-24 21:09:55 +09001407 // Add native modules targetting both ABIs
1408 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001409 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001410 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001411 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001412
Alex Light3d673592019-01-18 14:37:31 -08001413 isPrimaryAbi := i == 0
1414 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001415 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001416 // multilib.first
1417 addDependenciesForNativeModules(ctx,
1418 ApexNativeDependencies{
1419 Native_shared_libs: nil,
1420 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001421 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001422 Binaries: a.properties.Binaries,
1423 },
1424 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001425
1426 // Add native modules targetting the first ABI
1427 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001428 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001429 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001430 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001431 }
1432
1433 switch target.Arch.ArchType.Multilib {
1434 case "lib32":
1435 // Add native modules targetting 32-bit ABI
1436 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001437 a.properties.Multilib.Lib32,
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
1441 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001442 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001443 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001444 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001445 case "lib64":
1446 // Add native modules targetting 64-bit ABI
1447 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001448 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001449 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001450 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001451
1452 if !has32BitTarget {
1453 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001454 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001455 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001456 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001457 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001458
1459 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1460 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1461 if sanitizer == "hwaddress" {
1462 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001463 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001464 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001465 break
1466 }
1467 }
1468 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001469 }
1470
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001471 }
1472
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001473 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1474 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1475 // b/144532908
1476 archForPrebuiltEtc := config.Arches()[0]
1477 for _, arch := range config.Arches() {
1478 // Prefer 64-bit arch if there is any
1479 if arch.ArchType.Multilib == "lib64" {
1480 archForPrebuiltEtc = arch
1481 break
1482 }
1483 }
1484 ctx.AddFarVariationDependencies([]blueprint.Variation{
1485 {Mutator: "os", Variation: ctx.Os().String()},
1486 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1487 }, prebuiltTag, a.properties.Prebuilts...)
1488
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001489 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1490 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001491
Ulya Trafimovich44561882020-01-03 13:25:54 +00001492 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1493 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1494 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1495 javaLibTag, "jacocoagent")
1496 }
1497
Jiyong Park23c52b02019-02-02 13:13:47 +09001498 if String(a.properties.Key) == "" {
1499 ctx.ModuleErrorf("key is missing")
1500 return
1501 }
1502 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001503
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001504 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001505 if cert != "" {
1506 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001507 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001508
1509 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1510 if len(a.properties.Uses_sdks) > 0 {
1511 sdkRefs := []android.SdkRef{}
1512 for _, str := range a.properties.Uses_sdks {
1513 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1514 sdkRefs = append(sdkRefs, parsed)
1515 }
1516 a.BuildWithSdks(sdkRefs)
1517 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001518}
1519
Jiyong Park5d790c32019-11-15 18:40:32 +09001520func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1521 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1522 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001523 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1524 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001525}
1526
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001527func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1528 // direct deps of an APEX bundle are all part of the APEX bundle
1529 return true
1530}
1531
Colin Cross0ea8ba82019-06-06 14:33:29 -07001532func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001533 moduleName := ctx.ModuleName()
1534 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1535 // we check with the pseudo module name to see if its certificate is overridden.
1536 if a.vndkApex {
1537 moduleName = vndkApexName
1538 }
1539 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001540 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001541 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001542 }
1543 return String(a.properties.Certificate)
1544}
1545
Colin Cross41955e82019-05-29 14:40:35 -07001546func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1547 switch tag {
1548 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001549 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001550 default:
1551 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001552 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001553}
1554
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001555func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001556 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001557}
1558
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001559func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1560 return proptools.Bool(a.properties.Test_only_no_hashtree)
1561}
1562
Dario Freni98410fd2020-04-27 18:21:11 +01001563func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1564 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1565}
1566
Jiyong Park7c1dc612019-01-05 11:15:24 +09001567func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001568 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001569 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001570 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001571 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001572 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001573 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001574 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001575 }
1576}
1577
Jiyong Parkf97782b2019-02-13 20:28:58 +09001578func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1579 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1580 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1581 }
1582}
1583
Jiyong Park388ef3f2019-01-28 19:47:32 +09001584func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001585 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1586 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001587 }
1588
1589 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001590 globalSanitizerNames := []string{}
1591 if a.Host() {
1592 globalSanitizerNames = ctx.Config().SanitizeHost()
1593 } else {
1594 arches := ctx.Config().SanitizeDeviceArch()
1595 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1596 globalSanitizerNames = ctx.Config().SanitizeDevice()
1597 }
1598 }
1599 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001600}
1601
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001602var _ cc.Coverage = (*apexBundle)(nil)
1603
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001604func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001605 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001606}
1607
1608func (a *apexBundle) PreventInstall() {
1609 a.properties.PreventInstall = true
1610}
1611
1612func (a *apexBundle) HideFromMake() {
1613 a.properties.HideFromMake = true
1614}
1615
Jiyong Park956305c2020-01-09 12:32:06 +09001616func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1617 a.properties.IsCoverageVariant = coverage
1618}
1619
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001620func (a *apexBundle) EnableCoverageIfNeeded() {}
1621
Jiyong Parkf653b052019-11-18 15:39:01 +09001622// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001623func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001624 // Decide the APEX-local directory by the multilib of the library
1625 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001626 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001627 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001628 case "lib32":
1629 dirInApex = "lib"
1630 case "lib64":
1631 dirInApex = "lib64"
1632 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001633 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001634 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001635 }
Jooyung Han35155c42020-02-06 17:33:20 +09001636 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001637 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001638 // Special case for Bionic libs and other libs installed with them. This is
1639 // to prevent those libs from being included in the search path
1640 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1641 // those libs in the Runtime APEX are available via the legacy paths in
1642 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1643 // to the legacy paths and thus will be loaded into the default linker
1644 // namespace (aka "platform" namespace). If the libs are directly in
1645 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1646 // into the runtime linker namespace, which will result in double loading of
1647 // them, which isn't supported.
1648 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001649 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001650
Jiyong Parkf653b052019-11-18 15:39:01 +09001651 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001652 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001653}
1654
Jiyong Park1833cef2019-12-13 13:28:36 +09001655func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001656 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001657 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001658 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001659 }
Jooyung Han35155c42020-02-06 17:33:20 +09001660 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001661 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001662 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001663 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001664 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001665 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001666}
1667
Jiyong Park1833cef2019-12-13 13:28:36 +09001668func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001669 dirInApex := "bin"
1670 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001671 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001672}
Jiyong Park1833cef2019-12-13 13:28:36 +09001673func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001674 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001675 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1676 if err != nil {
1677 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001678 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001679 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 fileToCopy := android.PathForOutput(ctx, s)
1681 // NB: Since go binaries are static we don't need the module for anything here, which is
1682 // good since the go tool is a blueprint.Module not an android.Module like we would
1683 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001684 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001685}
1686
Jiyong Park1833cef2019-12-13 13:28:36 +09001687func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 dirInApex := filepath.Join("bin", sh.SubDir())
1689 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001690 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 af.symlinks = sh.Symlinks()
1692 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001693}
1694
Paul Duffin581bbbe2020-05-14 20:49:32 +01001695func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib java.Dependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001696 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001697 fileToCopy := lib.DexJar()
Paul Duffin581bbbe2020-05-14 20:49:32 +01001698 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001699 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1700 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001701}
1702
Jiyong Park1833cef2019-12-13 13:28:36 +09001703func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001704 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1705 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001706 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001707}
1708
atrost6e126252020-01-27 17:01:16 +00001709func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1710 dirInApex := filepath.Join("etc", config.SubDir())
1711 fileToCopy := config.CompatConfig()
1712 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1713}
1714
Jiyong Park1833cef2019-12-13 13:28:36 +09001715func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001716 android.Module
1717 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001718 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001719 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001720 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001721 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001722}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001723 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001724 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001725 appDir = "priv-app"
1726 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001727 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001728 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001729 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1730 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001731 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001732
1733 if app, ok := aapp.(interface {
1734 OverriddenManifestPackageName() string
1735 }); ok {
1736 af.overriddenPackageName = app.OverriddenManifestPackageName()
1737 }
Jiyong Park618922e2020-01-08 13:35:43 +09001738 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001739}
1740
Jiyong Park69aeba92020-04-24 21:16:36 +09001741func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1742 rroDir := "overlay"
1743 dirInApex := filepath.Join(rroDir, rro.Theme())
1744 fileToCopy := rro.OutputFile()
1745 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1746 af.certificate = rro.Certificate()
1747
1748 if a, ok := rro.(interface {
1749 OverriddenManifestPackageName() string
1750 }); ok {
1751 af.overriddenPackageName = a.OverriddenManifestPackageName()
1752 }
1753 return af
1754}
1755
Roland Levillain935639d2019-08-13 14:55:28 +01001756// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1757type flattenedApexContext struct {
1758 android.ModuleContext
1759}
1760
1761func (c *flattenedApexContext) InstallBypassMake() bool {
1762 return true
1763}
1764
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001765// Function called while walking an APEX's payload dependencies.
1766//
1767// Return true if the `to` module should be visited, false otherwise.
1768type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1769
Jiyong Park201cedd2020-02-07 17:25:49 +09001770// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001771func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001772 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001773 am, ok := child.(android.ApexModule)
1774 if !ok || !am.CanHaveApexVariants() {
1775 return false
1776 }
1777
1778 // Check for the direct dependencies that contribute to the payload
1779 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1780 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001781 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001782 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001783 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001784 return false
1785 }
1786
1787 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001788 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001789 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001790 }
1791
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001792 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001793 })
1794}
1795
Jooyung Han03b51852020-02-26 22:45:42 +09001796func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1797 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001798 intVer, err := android.ApiStrToNum(ctx, ver)
1799 if err != nil {
1800 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001801 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001802 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001803}
1804
Jiyong Park201cedd2020-02-07 17:25:49 +09001805// Ensures that the dependencies are marked as available for this APEX
1806func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1807 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1808 if ctx.Host() || a.testApex || a.vndkApex {
1809 return
1810 }
1811
Jiyong Park58d10902020-03-28 14:43:19 +09001812 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1813 // Requiring them and their transitive depencies with apex_available is not right
1814 // because they just add noise.
1815 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1816 return
1817 }
1818
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001819 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1820 if externalDep {
1821 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1822 return false
1823 }
1824
Jiyong Park201cedd2020-02-07 17:25:49 +09001825 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001826 fromName := ctx.OtherModuleName(from)
1827 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001828
1829 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1830 // do any of its dependencies.
1831 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1832 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1833 return false
1834 }
1835
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001836 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1837 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001838 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001839 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 +01001840 // Visit this module's dependencies to check and report any issues with their availability.
1841 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001842 })
1843}
1844
Jooyung Han548640b2020-04-27 12:10:30 +09001845func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1846 if proptools.Bool(a.properties.Updatable) {
1847 if String(a.properties.Min_sdk_version) == "" {
1848 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1849 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001850
1851 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001852 }
1853}
1854
Jiyong Parkaf7ed392020-05-10 15:16:24 +09001855// Ensures that a lib providing stub isn't statically linked
1856func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1857 // Practically, we only care about regular APEXes on the device.
1858 if ctx.Host() || a.testApex || a.vndkApex {
1859 return
1860 }
1861
1862 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1863 if ccm, ok := to.(*cc.Module); ok {
1864 apexName := ctx.ModuleName()
1865 fromName := ctx.OtherModuleName(from)
1866 toName := ctx.OtherModuleName(to)
1867
1868 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1869 // do any of its dependencies.
1870 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1871 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1872 return false
1873 }
1874
1875 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
1876 // It can't make the static dependencies dynamic because it can't
1877 // do the dynamic linking for itself.
1878 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1879 return false
1880 }
1881
1882 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName)
1883 if isStubLibraryFromOtherApex && !externalDep {
1884 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1885 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1886 }
1887
1888 }
1889 return true
1890 })
1891}
1892
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001893func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001894 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1895 switch a.properties.ApexType {
1896 case imageApex:
1897 if buildFlattenedAsDefault {
1898 a.suffix = imageApexSuffix
1899 } else {
1900 a.suffix = ""
1901 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001902
1903 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001904 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001905 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001906 }
1907 case zipApex:
1908 if proptools.String(a.properties.Payload_type) == "zip" {
1909 a.suffix = ""
1910 a.primaryApexType = true
1911 } else {
1912 a.suffix = zipApexSuffix
1913 }
1914 case flattenedApex:
1915 if buildFlattenedAsDefault {
1916 a.suffix = ""
1917 a.primaryApexType = true
1918 } else {
1919 a.suffix = flattenedSuffix
1920 }
Alex Light5098a612018-11-29 17:12:15 -08001921 }
1922
Roland Levillain630846d2019-06-26 12:48:34 +01001923 if len(a.properties.Tests) > 0 && !a.testApex {
1924 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1925 return
1926 }
1927
Jiyong Parkfa899442020-01-31 02:49:53 +09001928 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001929 a.checkUpdatable(ctx)
Jiyong Parkaf7ed392020-05-10 15:16:24 +09001930 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001931
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001932 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1933
Jooyung Hane1633032019-08-01 17:41:43 +09001934 // native lib dependencies
1935 var provideNativeLibs []string
1936 var requireNativeLibs []string
1937
Jooyung Han5c998b92019-06-27 11:30:33 +09001938 // Check if "uses" requirements are met with dependent apexBundles
1939 var providedNativeSharedLibs []string
1940 useVendor := proptools.Bool(a.properties.Use_vendor)
1941 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1942 if ctx.OtherModuleDependencyTag(m) != usesTag {
1943 return
1944 }
1945 otherName := ctx.OtherModuleName(m)
1946 other, ok := m.(*apexBundle)
1947 if !ok {
1948 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1949 return
1950 }
1951 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1952 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1953 return
1954 }
1955 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1956 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1957 return
1958 }
1959 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1960 })
1961
Jiyong Parkf653b052019-11-18 15:39:01 +09001962 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001963 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001964 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001965 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001966 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1967 return false
1968 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001969 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001970 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001971 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001972 case sharedLibTag, jniLibTag:
1973 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001974 if c, ok := child.(*cc.Module); ok {
1975 // bootstrap bionic libs are treated as provided by system
1976 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1977 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001978 }
Jooyung Han643adc42020-02-27 13:50:06 +09001979 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1980 fi.isJniLib = isJniLib
1981 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001982 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001983 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001984 propertyName := "native_shared_libs"
1985 if isJniLib {
1986 propertyName = "jni_libs"
1987 }
1988 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001989 }
1990 case executableTag:
1991 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001992 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001993 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001994 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001995 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001996 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001997 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001998 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001999 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002000 } else {
Alex Light778127a2019-02-27 14:19:50 -08002001 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 +09002002 }
2003 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002004 if javaLib, ok := child.(*java.Library); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01002005 af := apexFileForJavaLibrary(ctx, javaLib, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002006 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002007 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2008 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002009 filesInfo = append(filesInfo, af)
2010 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002011 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002012 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01002013 af := apexFileForJavaLibrary(ctx, sdkLib, sdkLib)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002014 if !af.Ok() {
2015 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2016 return false
2017 }
2018 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002019 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002020 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002021 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002022 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002023 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002024 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002025 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002026 return true // track transitive dependencies
2027 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002028 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002029 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002030 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002031 } else {
2032 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2033 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002034 case rroTag:
2035 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2036 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2037 } else {
2038 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2039 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002040 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002041 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002042 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002043 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2044 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002045 } else {
atrost6e126252020-01-27 17:01:16 +00002046 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002047 }
Roland Levillain630846d2019-06-26 12:48:34 +01002048 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002049 if ccTest, ok := child.(*cc.Module); ok {
2050 if ccTest.IsTestPerSrcAllTestsVariation() {
2051 // Multiple-output test module (where `test_per_src: true`).
2052 //
2053 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2054 // We do not add this variation to `filesInfo`, as it has no output;
2055 // however, we do add the other variations of this module as indirect
2056 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002057 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002058 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002059 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002060 af.class = nativeTest
2061 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002062 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002063 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002064 } else {
2065 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2066 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002067 case keyTag:
2068 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002069 a.private_key_file = key.private_key_file
2070 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002071 } else {
2072 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002073 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002074 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002075 case certificateTag:
2076 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002077 a.container_certificate_file = dep.Certificate.Pem
2078 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002079 } else {
2080 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2081 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002082 case android.PrebuiltDepTag:
2083 // If the prebuilt is force disabled, remember to delete the prebuilt file
2084 // that might have been installed in the previous builds
2085 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2086 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2087 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002088 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002089 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002090 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002091 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002092 // We cannot use a switch statement on `depTag` here as the checked
2093 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002094 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002095 if cc, ok := child.(*cc.Module); ok {
2096 if android.InList(cc.Name(), providedNativeSharedLibs) {
2097 // If we're using a shared library which is provided from other APEX,
2098 // don't include it in this APEX
2099 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002100 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002101 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002102 // If the dependency is a stubs lib, don't include it in this APEX,
2103 // but make sure that the lib is installed on the device.
2104 // In case no APEX is having the lib, the lib is installed to the system
2105 // partition.
2106 //
2107 // Always include if we are a host-apex however since those won't have any
2108 // system libraries.
Yo Chiang29555d52020-05-06 15:59:59 +08002109 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.BaseModuleName(), a.requiredDeps) {
2110 a.requiredDeps = append(a.requiredDeps, cc.BaseModuleName())
Roland Levillainf89cd092019-07-29 16:22:59 +01002111 }
Jooyung Hane1633032019-08-01 17:41:43 +09002112 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002113 // Don't track further
2114 return false
2115 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002116 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002117 af.transitiveDep = true
2118 filesInfo = append(filesInfo, af)
2119 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002120 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002121 } else if cc.IsTestPerSrcDepTag(depTag) {
2122 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002123 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002124 // Handle modules created as `test_per_src` variations of a single test module:
2125 // use the name of the generated test binary (`fileToCopy`) instead of the name
2126 // of the original test module (`depName`, shared by all `test_per_src`
2127 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002128 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002129 // these are not considered transitive dep
2130 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002131 filesInfo = append(filesInfo, af)
2132 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002133 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002134 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002135 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2136 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002137 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2138 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2139 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2140 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002141 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002142 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002143 }
2144 }
2145 }
2146 return false
2147 })
2148
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002149 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2150 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2151 // via the global boot image config.
2152 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002153 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002154 dirInApex := filepath.Join("javalib", arch.String())
2155 for _, f := range files {
2156 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002157 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002158 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002159 }
2160 }
2161 }
2162
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002163 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002164 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2165 return
2166 }
2167
Jiyong Park8fd61922018-11-08 02:50:25 +09002168 // remove duplicates in filesInfo
2169 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002170 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002171 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002172 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002173 if e, ok := encountered[dest]; !ok {
2174 encountered[dest] = f
2175 } else {
2176 // If a module is directly included and also transitively depended on
2177 // consider it as directly included.
2178 e.transitiveDep = e.transitiveDep && f.transitiveDep
2179 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002180 }
2181 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002182 var result []apexFile
2183 for _, v := range encountered {
2184 result = append(result, v)
2185 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002186 return result
2187 }
2188 filesInfo = removeDup(filesInfo)
2189
2190 // to have consistent build rules
2191 sort.Slice(filesInfo, func(i, j int) bool {
2192 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2193 })
2194
Jiyong Park8fd61922018-11-08 02:50:25 +09002195 a.installDir = android.PathForModuleInstall(ctx, "apex")
2196 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002197
Jooyung Han54aca7b2019-11-20 02:26:02 +09002198 if a.properties.ApexType != zipApex {
2199 if a.properties.File_contexts == nil {
2200 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2201 } else {
2202 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2203 if a.Platform() {
2204 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2205 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2206 }
2207 }
2208 }
2209 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2210 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2211 return
2212 }
2213 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002214 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2215 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2216 // the same library in the system partition, thus effectively sharing the same libraries
2217 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2218 // in the APEX.
2219 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2220 a.installable() &&
2221 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002222
Jiyong Park9d677202020-02-19 16:29:35 +09002223 // We don't need the optimization for updatable APEXes, as it might give false signal
2224 // to the system health when the APEXes are still bundled (b/149805758)
2225 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2226 a.linkToSystemLib = false
2227 }
2228
Jiyong Park9b964182020-02-26 18:27:19 +09002229 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2230 if ctx.Host() {
2231 a.linkToSystemLib = false
2232 }
2233
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002234 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002235 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2236
2237 a.setCertificateAndPrivateKey(ctx)
2238 if a.properties.ApexType == flattenedApex {
2239 a.buildFlattenedApex(ctx)
2240 } else {
2241 a.buildUnflattenedApex(ctx)
2242 }
2243
Jooyung Han002ab682020-01-08 01:57:58 +09002244 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002245
2246 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002247}
2248
Artur Satayev8cf899a2020-04-15 17:29:42 +01002249// Enforce that Java deps of the apex are using stable SDKs to compile
2250func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2251 // Visit direct deps only. As long as we guarantee top-level deps are using
2252 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2253 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2254 tag := ctx.OtherModuleDependencyTag(module)
2255 switch tag {
2256 case javaLibTag, androidAppTag:
2257 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2258 if err := m.CheckStableSdkVersion(); err != nil {
2259 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2260 }
2261 }
2262 }
2263 })
2264}
2265
Jooyung Han5e9013b2020-03-10 06:23:13 +09002266func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002267 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002268 moduleName = normalizeModuleName(moduleName)
2269
2270 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2271 return true
2272 }
2273
2274 key = android.AvailableToAnyApex
2275 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2276 return true
2277 }
2278
2279 return false
2280}
2281
2282func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002283 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2284 // system. Trim the prefix for the check since they are confusing
2285 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2286 if strings.HasPrefix(moduleName, "libclang_rt.") {
2287 // This module has many arch variants that depend on the product being built.
2288 // We don't want to list them all
2289 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002290 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002291 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002292}
2293
Jooyung Han344d5432019-08-23 11:17:39 +09002294func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002295 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002296 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002297 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002298 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002299 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002300 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2301 })
Alex Light5098a612018-11-29 17:12:15 -08002302 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002303 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002304 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002305 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002306 return module
2307}
Jiyong Park30ca9372019-02-07 16:27:23 +09002308
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002309func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002310 bundle := newApexBundle()
2311 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002312 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002313 return bundle
2314}
2315
Jiyong Parkfce0b422020-02-11 03:56:06 +09002316// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2317// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002318func testApexBundleFactory() android.Module {
2319 bundle := newApexBundle()
2320 bundle.testApex = true
2321 return bundle
2322}
2323
Jiyong Parkfce0b422020-02-11 03:56:06 +09002324// apex packages other modules into an APEX file which is a packaging format for system-level
2325// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002326func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002327 return newApexBundle()
2328}
2329
Jiyong Park30ca9372019-02-07 16:27:23 +09002330//
2331// Defaults
2332//
2333type Defaults struct {
2334 android.ModuleBase
2335 android.DefaultsModuleBase
2336}
2337
Jiyong Park30ca9372019-02-07 16:27:23 +09002338func defaultsFactory() android.Module {
2339 return DefaultsFactory()
2340}
2341
2342func DefaultsFactory(props ...interface{}) android.Module {
2343 module := &Defaults{}
2344
2345 module.AddProperties(props...)
2346 module.AddProperties(
2347 &apexBundleProperties{},
2348 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002349 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002350 )
2351
2352 android.InitDefaultsModule(module)
2353 return module
2354}
Jiyong Park5d790c32019-11-15 18:40:32 +09002355
2356//
2357// OverrideApex
2358//
2359type OverrideApex struct {
2360 android.ModuleBase
2361 android.OverrideModuleBase
2362}
2363
2364func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2365 // All the overrides happen in the base module.
2366}
2367
2368// override_apex is used to create an apex module based on another apex module
2369// by overriding some of its properties.
2370func overrideApexFactory() android.Module {
2371 m := &OverrideApex{}
2372 m.AddProperties(&overridableProperties{})
2373
2374 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2375 android.InitOverrideModule(m)
2376 return m
2377}