blob: b1137b846ca2bf6c04f9d1c53c7c9b5243c50937 [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 //
Jooyung Han040ff3d2020-05-19 15:47:01 +0900247 m["com.android.extservices"] = []string{
248 "error_prone_annotations",
249 "ExtServices-core",
250 "ExtServices",
251 "libtextclassifier-java",
252 "libz_current",
253 "textclassifier-statsd",
254 "TextClassifierNotificationLibNoManifest",
255 "TextClassifierServiceLibNoManifest",
256 }
257 //
258 // Module separator
259 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900260 m["com.android.neuralnetworks"] = []string{
261 "android.hardware.neuralnetworks@1.0",
262 "android.hardware.neuralnetworks@1.1",
263 "android.hardware.neuralnetworks@1.2",
264 "android.hardware.neuralnetworks@1.3",
265 "android.hidl.allocator@1.0",
266 "android.hidl.memory.token@1.0",
267 "android.hidl.memory@1.0",
268 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900269 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900270 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900271 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900272 "libprocpartition",
273 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900274 }
Anton Hansson5053c292020-01-10 15:12:39 +0000275 //
276 // Module separator
277 //
Anton Hansson5053c292020-01-10 15:12:39 +0000278 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900279 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000280 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900281 "android.hardware.cas@1.0",
282 "android.hardware.configstore-utils",
283 "android.hardware.configstore@1.0",
284 "android.hardware.configstore@1.1",
285 "android.hardware.graphics.allocator@2.0",
286 "android.hardware.graphics.allocator@3.0",
287 "android.hardware.graphics.bufferqueue@1.0",
288 "android.hardware.graphics.bufferqueue@2.0",
289 "android.hardware.graphics.common@1.0",
290 "android.hardware.graphics.common@1.1",
291 "android.hardware.graphics.common@1.2",
292 "android.hardware.graphics.mapper@2.0",
293 "android.hardware.graphics.mapper@2.1",
294 "android.hardware.graphics.mapper@3.0",
295 "android.hardware.media.omx@1.0",
296 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000297 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000298 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900299 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000300 "android.hidl.token@1.0",
301 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900302 "bionic_libc_platform_headers",
Jooyung Han040ff3d2020-05-19 15:47:01 +0900303 "exoplayer2-extractor",
304 "exoplayer2-extractor-annotation-stubs",
Jiyong Parkfa899442020-01-31 02:49:53 +0900305 "gl_headers",
Jooyung Han040ff3d2020-05-19 15:47:01 +0900306 "jsr305",
Jiyong Parkfa899442020-01-31 02:49:53 +0900307 "libEGL",
308 "libEGL_blobCache",
309 "libEGL_getProcAddress",
310 "libFLAC",
311 "libFLAC-config",
312 "libFLAC-headers",
313 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000314 "libaacextractor",
315 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900316 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900317 "libaudio_system_headers",
318 "libaudioclient",
319 "libaudioclient_headers",
320 "libaudiofoundation",
321 "libaudiofoundation_headers",
322 "libaudiomanager",
323 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000324 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900325 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900326 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900327 "libbluetooth-types-header",
328 "libbufferhub",
329 "libbufferhub_headers",
330 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900331 "libc_malloc_debug_backtrace",
332 "libcamera_client",
333 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900334 "libdexfile_external_headers",
335 "libdexfile_support",
336 "libdvr_headers",
337 "libexpat",
338 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000339 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900340 "libgrallocusage",
341 "libgraphicsenv",
342 "libgui",
343 "libgui_headers",
344 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900345 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900346 "liblzma",
347 "libmath",
348 "libmedia",
349 "libmedia_codeclist",
350 "libmedia_headers",
351 "libmedia_helper",
352 "libmedia_helper_headers",
353 "libmedia_midiiowrapper",
354 "libmedia_omx",
355 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000356 "libmidiextractor",
357 "libmkvextractor",
358 "libmp3extractor",
359 "libmp4extractor",
360 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900361 "libnativebase_headers",
362 "libnativebridge-headers",
363 "libnativebridge_lazy",
364 "libnativeloader-headers",
365 "libnativeloader_lazy",
366 "libnativewindow_headers",
367 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000368 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900369 "libpackagelistparser",
Jiyong Parkfa899442020-01-31 02:49:53 +0900370 "libpdx",
371 "libpdx_default_transport",
372 "libpdx_headers",
373 "libpdx_uds",
Jiyong Parkfa899442020-01-31 02:49:53 +0900374 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000375 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900376 "libspeexresampler",
377 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000378 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900379 "libstagefright_flacdec",
380 "libstagefright_foundation",
381 "libstagefright_foundation_headers",
382 "libstagefright_foundation_without_imemory",
383 "libstagefright_headers",
384 "libstagefright_id3",
385 "libstagefright_metadatautils",
386 "libstagefright_mpeg2extractor",
387 "libstagefright_mpeg2support",
388 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900389 "libui",
390 "libui_headers",
391 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900392 "libvibrator",
393 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000394 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900395 "libwebm",
396 "media_ndk_headers",
397 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000398 "updatable-media",
399 }
400 //
401 // Module separator
402 //
403 m["com.android.media.swcodec"] = []string{
404 "android.frameworks.bufferhub@1.0",
405 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900406 "android.hardware.configstore-utils",
407 "android.hardware.configstore@1.0",
408 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000409 "android.hardware.graphics.allocator@2.0",
410 "android.hardware.graphics.allocator@3.0",
411 "android.hardware.graphics.allocator@4.0",
412 "android.hardware.graphics.bufferqueue@1.0",
413 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900414 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000415 "android.hardware.graphics.common@1.0",
416 "android.hardware.graphics.common@1.1",
417 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000418 "android.hardware.graphics.mapper@2.0",
419 "android.hardware.graphics.mapper@2.1",
420 "android.hardware.graphics.mapper@3.0",
421 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000422 "android.hardware.media.bufferpool@2.0",
423 "android.hardware.media.c2@1.0",
424 "android.hardware.media.c2@1.1",
425 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900426 "android.hardware.media@1.0",
427 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000428 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900429 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000430 "android.hidl.safe_union@1.0",
431 "android.hidl.token@1.0",
432 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900433 "libEGL",
434 "libFLAC",
435 "libFLAC-config",
436 "libFLAC-headers",
437 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900438 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900439 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900440 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000441 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900442 "libaudioutils",
443 "libaudioutils_fixedfft",
444 "libavcdec",
445 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000446 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900447 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900448 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900449 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900450 "libbluetooth-types-header",
451 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900452 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000453 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900454 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000455 "libcodec2_hidl@1.0",
456 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900457 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000458 "libcodec2_soft_aacdec",
459 "libcodec2_soft_aacenc",
460 "libcodec2_soft_amrnbdec",
461 "libcodec2_soft_amrnbenc",
462 "libcodec2_soft_amrwbdec",
463 "libcodec2_soft_amrwbenc",
464 "libcodec2_soft_av1dec_gav1",
465 "libcodec2_soft_avcdec",
466 "libcodec2_soft_avcenc",
467 "libcodec2_soft_common",
468 "libcodec2_soft_flacdec",
469 "libcodec2_soft_flacenc",
470 "libcodec2_soft_g711alawdec",
471 "libcodec2_soft_g711mlawdec",
472 "libcodec2_soft_gsmdec",
473 "libcodec2_soft_h263dec",
474 "libcodec2_soft_h263enc",
475 "libcodec2_soft_hevcdec",
476 "libcodec2_soft_hevcenc",
477 "libcodec2_soft_mp3dec",
478 "libcodec2_soft_mpeg2dec",
479 "libcodec2_soft_mpeg4dec",
480 "libcodec2_soft_mpeg4enc",
481 "libcodec2_soft_opusdec",
482 "libcodec2_soft_opusenc",
483 "libcodec2_soft_rawdec",
484 "libcodec2_soft_vorbisdec",
485 "libcodec2_soft_vp8dec",
486 "libcodec2_soft_vp8enc",
487 "libcodec2_soft_vp9dec",
488 "libcodec2_soft_vp9enc",
489 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900490 "libdexfile_support",
491 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000492 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900493 "libfmq",
494 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000495 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900496 "libgrallocusage",
497 "libgraphicsenv",
498 "libgsm",
499 "libgui_bufferqueue_static",
500 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000501 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900502 "libhardware_headers",
503 "libhevcdec",
504 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000505 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900506 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900507 "liblzma",
508 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000509 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900510 "libmedia_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900511 "libmpeg2dec",
512 "libnativebase_headers",
513 "libnativebridge_lazy",
514 "libnativeloader_lazy",
515 "libnativewindow_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900516 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000517 "libscudo_wrapper",
518 "libsfplugin_ccodec_utils",
519 "libspeexresampler",
520 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900521 "libstagefright_amrnbdec",
522 "libstagefright_amrnbenc",
523 "libstagefright_amrwbdec",
524 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000525 "libstagefright_bufferpool@2.0.1",
526 "libstagefright_bufferqueue_helper",
527 "libstagefright_enc_common",
528 "libstagefright_flacdec",
529 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900530 "libstagefright_foundation_headers",
531 "libstagefright_headers",
532 "libstagefright_m4vh263dec",
533 "libstagefright_m4vh263enc",
534 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000535 "libsync",
536 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900537 "libui_headers",
538 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000539 "libvorbisidec",
540 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900541 "libyuv",
542 "libyuv_static",
543 "media_ndk_headers",
544 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000545 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000546 }
547 //
548 // Module separator
549 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900550 m["com.android.mediaprovider"] = []string{
551 "MediaProvider",
552 "MediaProviderGoogle",
553 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900554 "libbase_ndk",
555 "libfuse",
556 "libfuse_jni",
557 "libnativehelper_header_only",
558 }
559 //
560 // Module separator
561 //
562 m["com.android.permission"] = []string{
Jooyung Han040ff3d2020-05-19 15:47:01 +0900563 "car-ui-lib",
564 "iconloader",
Jiyong Parkfa899442020-01-31 02:49:53 +0900565 "kotlin-annotations",
566 "kotlin-stdlib",
567 "kotlin-stdlib-jdk7",
568 "kotlin-stdlib-jdk8",
569 "kotlinx-coroutines-android",
570 "kotlinx-coroutines-android-nodeps",
571 "kotlinx-coroutines-core",
572 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900574 "GooglePermissionController",
575 "PermissionController",
Jooyung Han040ff3d2020-05-19 15:47:01 +0900576 "SettingsLibActionBarShadow",
577 "SettingsLibAppPreference",
578 "SettingsLibBarChartPreference",
579 "SettingsLibLayoutPreference",
580 "SettingsLibProgressBar",
581 "SettingsLibSearchWidget",
582 "SettingsLibSettingsTheme",
583 "SettingsLibRestrictedLockUtils",
584 "SettingsLibHelpUtils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900585 }
Anton Hansson5053c292020-01-10 15:12:39 +0000586 //
587 // Module separator
588 //
Anton Hansson5053c292020-01-10 15:12:39 +0000589 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900590 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900591 "libarm-optimized-routines-math",
Jiyong Parkfa899442020-01-31 02:49:53 +0900592 "libc_aeabi",
593 "libc_bionic",
594 "libc_bionic_ndk",
595 "libc_bootstrap",
596 "libc_common",
597 "libc_common_shared",
598 "libc_common_static",
599 "libc_dns",
600 "libc_dynamic_dispatch",
601 "libc_fortify",
602 "libc_freebsd",
603 "libc_freebsd_large_stack",
604 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900605 "libc_init_dynamic",
606 "libc_init_static",
607 "libc_jemalloc_wrapper",
608 "libc_netbsd",
609 "libc_nomalloc",
610 "libc_nopthread",
611 "libc_openbsd",
612 "libc_openbsd_large_stack",
613 "libc_openbsd_ndk",
614 "libc_pthread",
615 "libc_static_dispatch",
616 "libc_syscalls",
617 "libc_tzcode",
618 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900619 "libdebuggerd",
620 "libdebuggerd_common_headers",
621 "libdebuggerd_handler_core",
622 "libdebuggerd_handler_fallback",
623 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000624 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900625 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900626 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900627 "libjemalloc5",
628 "liblinker_main",
629 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900630 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000631 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900632 "libprocinfo",
633 "libpropertyinfoparser",
634 "libscudo",
635 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900636 "libsystemproperties",
637 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000638 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900639 "libz",
640 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000641 }
642 //
643 // Module separator
644 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900645 m["com.android.tethering"] = []string{
Jooyung Han040ff3d2020-05-19 15:47:01 +0900646 "android.hardware.tetheroffload.config-V1.0-java",
647 "android.hardware.tetheroffload.control-V1.0-java",
648 "android.hidl.base-V1.0-java",
649 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900650 "libcgrouprc",
651 "libcgrouprc_format",
Jooyung Han040ff3d2020-05-19 15:47:01 +0900652 "libnativehelper_compat_libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900653 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900654 "libvndksupport",
Jooyung Han040ff3d2020-05-19 15:47:01 +0900655 "net-utils-framework-common",
656 "netd_aidl_interface-V3-java",
657 "netlink-client",
658 "networkstack-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900659 "tethering-aidl-interfaces-java",
Jooyung Han040ff3d2020-05-19 15:47:01 +0900660 "TetheringApiCurrentLib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900661 }
Anton Hansson5053c292020-01-10 15:12:39 +0000662 //
663 // Module separator
664 //
665 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900666 "PlatformProperties",
667 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900668 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900669 "android.hardware.wifi-V1.1-java",
670 "android.hardware.wifi-V1.2-java",
671 "android.hardware.wifi-V1.3-java",
672 "android.hardware.wifi-V1.4-java",
673 "android.hardware.wifi.hostapd-V1.0-java",
674 "android.hardware.wifi.hostapd-V1.1-java",
675 "android.hardware.wifi.hostapd-V1.2-java",
676 "android.hardware.wifi.supplicant-V1.0-java",
677 "android.hardware.wifi.supplicant-V1.1-java",
678 "android.hardware.wifi.supplicant-V1.2-java",
679 "android.hardware.wifi.supplicant-V1.3-java",
680 "android.hidl.base-V1.0-java",
681 "android.hidl.manager-V1.0-java",
682 "android.hidl.manager-V1.1-java",
683 "android.hidl.manager-V1.2-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900684 "bouncycastle-unbundled",
685 "dnsresolver_aidl_interface-V2-java",
686 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900687 "framework-wifi-pre-jarjar",
688 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900689 "ipmemorystore-aidl-interfaces-V3-java",
690 "ipmemorystore-aidl-interfaces-java",
691 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900692 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000693 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900694 "net-utils-services-common",
695 "netd_aidl_interface-V2-java",
696 "netd_aidl_interface-unstable-java",
697 "netd_event_listener_interface-java",
698 "netlink-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 "networkstack-client",
700 "services.net",
701 "wifi-lite-protos",
702 "wifi-nano-protos",
703 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000704 "wifi-service-resources",
705 }
706 //
707 // Module separator
708 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900709 m["com.android.sdkext"] = []string{
710 "fmtlib_ndk",
711 "libbase_ndk",
712 "libprotobuf-cpp-lite-ndk",
713 }
714 //
715 // Module separator
716 //
717 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900718 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900719 }
720 //
721 // Module separator
722 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000723 m[android.AvailableToAnyApex] = []string{
Jooyung Han040ff3d2020-05-19 15:47:01 +0900724 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
725 "androidx",
726 "androidx-constraintlayout_constraintlayout",
727 "androidx-constraintlayout_constraintlayout-nodeps",
728 "androidx-constraintlayout_constraintlayout-solver",
729 "androidx-constraintlayout_constraintlayout-solver-nodeps",
730 "com.google.android.material_material",
731 "com.google.android.material_material-nodeps",
732
Jiyong Parkfa899442020-01-31 02:49:53 +0900733 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900734 "libclang_rt",
735 "libgcc_stripped",
736 "libprofile-clang-extras",
737 "libprofile-clang-extras_ndk",
738 "libprofile-extras",
739 "libprofile-extras_ndk",
740 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900741 }
Anton Hansson5053c292020-01-10 15:12:39 +0000742 return m
743}
744
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900745func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900746 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800747 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900748 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900749 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700750 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900751 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700752 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900753
Jooyung Han31c470b2019-10-18 16:26:59 +0900754 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900755 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900756
757 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
758 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
759 sort.Strings(*apexFileContextsInfos)
760 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
761 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900762}
763
Jooyung Han31c470b2019-10-18 16:26:59 +0900764func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
765 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
766 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
767}
768
Jiyong Parkd1063c12019-07-17 20:08:41 +0900769func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900770 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900771 ctx.BottomUp("apex", apexMutator).Parallel()
772 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
773 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900774 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900775}
776
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900777// Mark the direct and transitive dependencies of apex bundles so that they
778// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900779func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900780 if !mctx.Module().Enabled() {
781 return
782 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800783 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900784 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000785 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900786 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900787 ApexName: mctx.ModuleName(),
788 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100789 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900790 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900791 directDep = true
792 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800793 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900794 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900795 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900796
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800797 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900798 return
799 }
800
Paul Duffin923e8a52020-03-30 15:33:32 +0100801 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900802
Jiyong Parkf760cae2020-02-12 07:53:12 +0900803 mctx.VisitDirectDeps(func(child android.Module) {
804 depName := mctx.OtherModuleName(child)
805 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100806 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800807 android.UpdateApexDependency(apexBundles, depName, directDep)
808 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900809 }
810 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900811}
812
Jiyong Park89e850a2020-04-07 16:37:39 +0900813// mark if a module cannot be available to platform. A module cannot be available
814// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
815// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
816func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
817 // Host and recovery are not considered as platform
818 if mctx.Host() || mctx.Module().InstallInRecovery() {
819 return
820 }
821
822 if am, ok := mctx.Module().(android.ApexModule); ok {
823 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
824
825 // In a rare case when a lib is marked as available only to an apex
826 // but the apex doesn't exist. This can happen in a partial manifest branch
827 // like master-art. Currently, libstatssocket in the stats APEX is causing
828 // this problem.
829 // Include the lib in platform because the module SDK that ought to provide
830 // it doesn't exist, so it would otherwise be left out completely.
831 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
832 // this check for libraries provided by SDKs.
833 if !availableToPlatform && !android.InAnyApex(am.Name()) {
834 availableToPlatform = true
835 }
836
837 // If any of the dep is not available to platform, this module is also considered
838 // as being not available to platform even if it has "//apex_available:platform"
839 mctx.VisitDirectDeps(func(child android.Module) {
840 if !am.DepIsInSameApex(mctx, child) {
841 // if the dependency crosses apex boundary, don't consider it
842 return
843 }
844 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
845 availableToPlatform = false
846 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
847 }
848 })
849
850 // Exception 1: stub libraries and native bridge libraries are always available to platform
851 if cc, ok := mctx.Module().(*cc.Module); ok &&
852 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
853 availableToPlatform = true
854 }
855
856 // Exception 2: bootstrap bionic libraries are also always available to platform
857 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
858 availableToPlatform = true
859 }
860
861 if !availableToPlatform {
862 am.SetNotAvailableForPlatform()
863 }
864 }
865}
866
Paul Duffin65347702020-03-31 15:23:40 +0100867// If a module in an APEX depends on a module from an SDK then it needs an APEX
868// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
869func inAnySdk(module android.Module) bool {
870 if sa, ok := module.(android.SdkAware); ok {
871 return sa.IsInAnySdk()
872 }
873
874 return false
875}
876
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877// Create apex variations if a module is included in APEX(s).
878func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900879 if !mctx.Module().Enabled() {
880 return
881 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900882 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900883 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000884 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900885 // apex bundle itself is mutated so that it and its modules have same
886 // apex variant.
887 apexBundleName := mctx.ModuleName()
888 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900889 } else if o, ok := mctx.Module().(*OverrideApex); ok {
890 apexBundleName := o.GetOverriddenModuleName()
891 if apexBundleName == "" {
892 mctx.ModuleErrorf("base property is not set")
893 return
894 }
895 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900896 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900897
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900898}
Sundong Ahne9b55722019-09-06 17:37:42 +0900899
Jooyung Han7a78a922019-10-08 21:59:58 +0900900var (
901 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
902 apexFileContextsInfosMutex sync.Mutex
903)
904
905func apexFileContextsInfos(config android.Config) *[]string {
906 return config.Once(apexFileContextsInfosKey, func() interface{} {
907 return &[]string{}
908 }).(*[]string)
909}
910
Jooyung Han54aca7b2019-11-20 02:26:02 +0900911func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900912 apexFileContextsInfosMutex.Lock()
913 defer apexFileContextsInfosMutex.Unlock()
914 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900915 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900916}
917
Sundong Ahne9b55722019-09-06 17:37:42 +0900918func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900919 if !mctx.Module().Enabled() {
920 return
921 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900922 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900923 var variants []string
924 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
925 case "image":
926 variants = append(variants, imageApexType, flattenedApexType)
927 case "zip":
928 variants = append(variants, zipApexType)
929 case "both":
930 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
931 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900932 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900933 return
934 }
935
936 modules := mctx.CreateLocalVariations(variants...)
937
938 for i, v := range variants {
939 switch v {
940 case imageApexType:
941 modules[i].(*apexBundle).properties.ApexType = imageApex
942 case zipApexType:
943 modules[i].(*apexBundle).properties.ApexType = zipApex
944 case flattenedApexType:
945 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900946 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900947 modules[i].(*apexBundle).MakeAsSystemExt()
948 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900949 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900950 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900951 } else if _, ok := mctx.Module().(*OverrideApex); ok {
952 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900953 }
954}
955
Jooyung Han5c998b92019-06-27 11:30:33 +0900956func apexUsesMutator(mctx android.BottomUpMutatorContext) {
957 if ab, ok := mctx.Module().(*apexBundle); ok {
958 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
959 }
960}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900961
Jooyung Handc782442019-11-01 03:14:38 +0900962var (
963 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
964)
965
966// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
967// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
968// which may cause compatibility issues. (e.g. libbinder)
969// Even though libbinder restricts its availability via 'apex_available' property and relies on
970// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
971// to avoid similar problems.
972func useVendorWhitelist(config android.Config) []string {
973 return config.Once(useVendorWhitelistKey, func() interface{} {
974 return []string{
975 // swcodec uses "vendor" variants for smaller size
976 "com.android.media.swcodec",
977 "test_com.android.media.swcodec",
978 }
979 }).([]string)
980}
981
982// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
983// called before the first call to useVendorWhitelist()
984func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
985 config.Once(useVendorWhitelistKey, func() interface{} {
986 return whitelist
987 })
988}
989
Jooyung Han01a868d2020-02-27 13:40:44 +0900990type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800991 // List of native libraries
992 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900993
Jooyung Han643adc42020-02-27 13:50:06 +0900994 // List of JNI libraries
995 Jni_libs []string
996
Alex Light9670d332019-01-29 18:07:33 -0800997 // List of native executables
998 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900999
Roland Levillain630846d2019-06-26 12:48:34 +01001000 // List of native tests
1001 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001002}
Jooyung Han344d5432019-08-23 11:17:39 +09001003
Alex Light9670d332019-01-29 18:07:33 -08001004type apexMultilibProperties struct {
1005 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001006 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001007
1008 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001009 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001010
1011 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001012 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001013
1014 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001015 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001016
1017 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001018 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001019}
1020
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001021type apexBundleProperties struct {
1022 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001023 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001024 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001025
Jiyong Park40e26a22019-02-08 02:53:06 +09001026 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1027 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001028 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001029
Roland Levillain411c5842019-09-19 16:37:20 +01001030 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1031 // device (/apex/<apex_name>).
1032 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001033 Apex_name *string
1034
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001035 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001036 // For platform APEXes, this should points to a file under /system/sepolicy
1037 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1038 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001039
Jooyung Han01a868d2020-02-27 13:40:44 +09001040 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001041
1042 // List of java libraries that are embedded inside this APEX bundle
1043 Java_libs []string
1044
1045 // List of prebuilt files that are embedded inside this APEX bundle
1046 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001047
1048 // Name of the apex_key module that provides the private key to sign APEX
1049 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001050
Alex Light5098a612018-11-29 17:12:15 -08001051 // The type of APEX to build. Controls what the APEX payload is. Either
1052 // 'image', 'zip' or 'both'. Default: 'image'.
1053 Payload_type *string
1054
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001055 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1056 // or an android_app_certificate module name in the form ":module".
1057 Certificate *string
1058
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001059 // Whether this APEX is installable to one of the partitions. Default: true.
1060 Installable *bool
1061
Jiyong Parkda6eb592018-12-19 17:12:36 +09001062 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1063 // Default is false.
1064 Use_vendor *bool
1065
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001066 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1067 Ignore_system_library_special_case *bool
1068
Alex Light9670d332019-01-29 18:07:33 -08001069 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001070
Jiyong Parkf97782b2019-02-13 20:28:58 +09001071 // List of sanitizer names that this APEX is enabled for
1072 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001073
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001074 PreventInstall bool `blueprint:"mutated"`
1075
1076 HideFromMake bool `blueprint:"mutated"`
1077
Jooyung Han5c998b92019-06-27 11:30:33 +09001078 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1079 Provide_cpp_shared_libs *bool
1080
1081 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1082 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001083
1084 // A txt file containing list of files that are whitelisted to be included in this APEX.
1085 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001086
Sundong Ahnabb64432019-10-22 13:58:29 +09001087 // package format of this apex variant; could be non-flattened, flattened, or zip.
1088 // imageApex, zipApex or flattened
1089 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001090
Jiyong Parkd1063c12019-07-17 20:08:41 +09001091 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1092 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1093 // is implied. This value affects all modules included in this APEX. In other words, they are
1094 // also built with the SDKs specified here.
1095 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001096
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001097 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1098 // Should be only used in tests#.
1099 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001100
Dario Freni98410fd2020-04-27 18:21:11 +01001101 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1102 // Should be only used in tests#.
1103 Test_only_unsigned_payload *bool
1104
Jiyong Park956305c2020-01-09 12:32:06 +09001105 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001106
1107 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001108 // rules for making sure that the APEX is truly updatable.
1109 // - To be updatable, min_sdk_version should be set as well
1110 // This will also disable the size optimizations like symlinking to the system libs.
1111 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001112 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001113
1114 // The minimum SDK version that this apex must be compatibile with.
1115 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001116}
1117
1118type apexTargetBundleProperties struct {
1119 Target struct {
1120 // Multilib properties only for android.
1121 Android struct {
1122 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001123 }
Jooyung Han344d5432019-08-23 11:17:39 +09001124
Alex Light9670d332019-01-29 18:07:33 -08001125 // Multilib properties only for host.
1126 Host struct {
1127 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001128 }
Jooyung Han344d5432019-08-23 11:17:39 +09001129
Alex Light9670d332019-01-29 18:07:33 -08001130 // Multilib properties only for host linux_bionic.
1131 Linux_bionic struct {
1132 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001133 }
Jooyung Han344d5432019-08-23 11:17:39 +09001134
Alex Light9670d332019-01-29 18:07:33 -08001135 // Multilib properties only for host linux_glibc.
1136 Linux_glibc struct {
1137 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001138 }
1139 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001140}
1141
Jiyong Park5d790c32019-11-15 18:40:32 +09001142type overridableProperties struct {
1143 // List of APKs to package inside APEX
1144 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001145
Jiyong Park69aeba92020-04-24 21:16:36 +09001146 // List of runtime resource overlays (RROs) inside APEX
1147 Rros []string
1148
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001149 // Names of modules to be overridden. Listed modules can only be other binaries
1150 // (in Make or Soong).
1151 // This does not completely prevent installation of the overridden binaries, but if both
1152 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1153 // from PRODUCT_PACKAGES.
1154 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001155
1156 // Logging Parent value
1157 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001158
1159 // Apex Container Package Name.
1160 // Override value for attribute package:name in AndroidManifest.xml
1161 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001162}
1163
Alex Light5098a612018-11-29 17:12:15 -08001164type apexPackaging int
1165
1166const (
1167 imageApex apexPackaging = iota
1168 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001169 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001170)
1171
Sundong Ahnabb64432019-10-22 13:58:29 +09001172// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001173func (a apexPackaging) suffix() string {
1174 switch a {
1175 case imageApex:
1176 return imageApexSuffix
1177 case zipApex:
1178 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001179 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001180 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001181 }
1182}
1183
1184func (a apexPackaging) name() string {
1185 switch a {
1186 case imageApex:
1187 return imageApexType
1188 case zipApex:
1189 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001190 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001191 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001192 }
1193}
1194
Jiyong Parkf653b052019-11-18 15:39:01 +09001195type apexFileClass int
1196
1197const (
1198 etc apexFileClass = iota
1199 nativeSharedLib
1200 nativeExecutable
1201 shBinary
1202 pyBinary
1203 goBinary
1204 javaSharedLib
1205 nativeTest
1206 app
1207)
1208
Jiyong Park8fd61922018-11-08 02:50:25 +09001209func (class apexFileClass) NameInMake() string {
1210 switch class {
1211 case etc:
1212 return "ETC"
1213 case nativeSharedLib:
1214 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001215 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001216 return "EXECUTABLES"
1217 case javaSharedLib:
1218 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001219 case nativeTest:
1220 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001221 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001222 // b/142537672 Why isn't this APP? We want to have full control over
1223 // the paths and file names of the apk file under the flattend APEX.
1224 // If this is set to APP, then the paths and file names are modified
1225 // by the Make build system. For example, it is installed to
1226 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1227 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1228 // appends module name (which is <apexname>.<Appname> to the path.
1229 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001230 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001231 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001232 }
1233}
1234
Jiyong Parkf653b052019-11-18 15:39:01 +09001235// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001236type apexFile struct {
1237 builtFile android.Path
1238 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001239 installDir string
1240 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001241 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001242 // list of symlinks that will be created in installDir that point to this apexFile
1243 symlinks []string
Liz Kammer1c14a212020-05-12 15:26:55 -07001244 dataPaths android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001245 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001246 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001247
1248 requiredModuleNames []string
1249 targetRequiredModuleNames []string
1250 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001251
Colin Cross503c1d02020-01-28 14:00:53 -08001252 jacocoReportClassesFile android.Path // only for javalibs and apps
1253 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001254 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001255
1256 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001257}
1258
Jiyong Park1833cef2019-12-13 13:28:36 +09001259func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1260 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001261 builtFile: builtFile,
1262 moduleName: moduleName,
1263 installDir: installDir,
1264 class: class,
1265 module: module,
1266 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001267 if module != nil {
1268 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001269 ret.requiredModuleNames = module.RequiredModuleNames()
1270 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1271 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001272 }
1273 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001274}
1275
1276func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001277 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001278}
1279
Liz Kammer1c14a212020-05-12 15:26:55 -07001280func (af *apexFile) apexRelativePath(path string) string {
1281 return filepath.Join(af.installDir, path)
1282}
1283
Jiyong Park7cd10e32020-01-14 09:22:18 +09001284// Path() returns path of this apex file relative to the APEX root
1285func (af *apexFile) Path() string {
Liz Kammer1c14a212020-05-12 15:26:55 -07001286 return af.apexRelativePath(af.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001287}
1288
1289// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1290func (af *apexFile) SymlinkPaths() []string {
1291 var ret []string
1292 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001293 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001294 }
1295 return ret
1296}
1297
1298func (af *apexFile) AvailableToPlatform() bool {
1299 if af.module == nil {
1300 return false
1301 }
1302 if am, ok := af.module.(android.ApexModule); ok {
1303 return am.AvailableFor(android.AvailableToPlatform)
1304 }
1305 return false
1306}
1307
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001308type apexBundle struct {
1309 android.ModuleBase
1310 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001311 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001312 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001313
Jiyong Park5d790c32019-11-15 18:40:32 +09001314 properties apexBundleProperties
1315 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001316 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001317
Jooyung Hanf21c7972019-12-16 22:32:06 +09001318 // specific to apex_vndk modules
1319 vndkProperties apexVndkProperties
1320
Colin Crossa4925902018-11-16 11:36:28 -08001321 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001322 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001323 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001324
Jiyong Park03b68dd2019-07-26 23:20:40 +09001325 prebuiltFileToDelete string
1326
Jiyong Park42cca6c2019-04-01 11:15:50 +09001327 public_key_file android.Path
1328 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001329
1330 container_certificate_file android.Path
1331 container_private_key_file android.Path
1332
Jooyung Han54aca7b2019-11-20 02:26:02 +09001333 fileContexts android.Path
1334
Jiyong Park8fd61922018-11-08 02:50:25 +09001335 // list of files to be included in this apex
1336 filesInfo []apexFile
1337
Jiyong Park956305c2020-01-09 12:32:06 +09001338 // list of module names that should be installed along with this APEX
1339 requiredDeps []string
1340
Jiyong Park956305c2020-01-09 12:32:06 +09001341 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001342 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001343
Sundong Ahnabb64432019-10-22 13:58:29 +09001344 testApex bool
1345 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001346 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001347 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001348
Jooyung Han214bf372019-11-12 13:03:50 +09001349 manifestJsonOut android.WritablePath
1350 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001351
Jooyung Han002ab682020-01-08 01:57:58 +09001352 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001353 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001354 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001355 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1356 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001357
1358 // Suffix of module name in Android.mk
1359 // ".flattened", ".apex", ".zipapex", or ""
1360 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001361
1362 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001363
1364 // Whether to create symlink to the system file instead of having a file
1365 // inside the apex or not
1366 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001367
1368 // Struct holding the merged notice file paths in different formats
1369 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001370}
1371
Jiyong Park397e55e2018-10-24 21:09:55 +09001372func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001373 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001374 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001375 // Use *FarVariation* to be able to depend on modules having
1376 // conflicting variations with this module. This is required since
1377 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1378 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001379 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001380 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001381 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001382 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001383 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001384
Jooyung Han643adc42020-02-27 13:50:06 +09001385 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1386 {Mutator: "image", Variation: imageVariation},
1387 {Mutator: "link", Variation: "shared"},
1388 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1389 }...), jniLibTag, nativeModules.Jni_libs...)
1390
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001391 ctx.AddFarVariationDependencies(append(target.Variations(),
1392 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001393 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001394
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001395 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001396 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001397 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001398 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001399}
1400
Alex Light9670d332019-01-29 18:07:33 -08001401func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1402 if ctx.Os().Class == android.Device {
1403 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1404 } else {
1405 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1406 if ctx.Os().Bionic() {
1407 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1408 } else {
1409 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1410 }
1411 }
1412}
1413
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001414func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001415 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1416 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1417 }
1418
Jiyong Park397e55e2018-10-24 21:09:55 +09001419 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001420 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001421
1422 a.combineProperties(ctx)
1423
Jiyong Park397e55e2018-10-24 21:09:55 +09001424 has32BitTarget := false
1425 for _, target := range targets {
1426 if target.Arch.ArchType.Multilib == "lib32" {
1427 has32BitTarget = true
1428 }
1429 }
1430 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001431 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001432 // multilib.both
1433 addDependenciesForNativeModules(ctx,
1434 ApexNativeDependencies{
1435 Native_shared_libs: a.properties.Native_shared_libs,
1436 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001437 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001438 Binaries: nil,
1439 },
1440 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001441
Jiyong Park397e55e2018-10-24 21:09:55 +09001442 // Add native modules targetting both ABIs
1443 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001444 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001445 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001446 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001447
Alex Light3d673592019-01-18 14:37:31 -08001448 isPrimaryAbi := i == 0
1449 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001450 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001451 // multilib.first
1452 addDependenciesForNativeModules(ctx,
1453 ApexNativeDependencies{
1454 Native_shared_libs: nil,
1455 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001456 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001457 Binaries: a.properties.Binaries,
1458 },
1459 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001460
1461 // Add native modules targetting the first ABI
1462 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001463 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001464 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001465 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001466 }
1467
1468 switch target.Arch.ArchType.Multilib {
1469 case "lib32":
1470 // Add native modules targetting 32-bit ABI
1471 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001472 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001473 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001474 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001475
1476 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001477 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001478 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001479 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001480 case "lib64":
1481 // Add native modules targetting 64-bit ABI
1482 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001483 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001484 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001485 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001486
1487 if !has32BitTarget {
1488 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001489 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001490 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001491 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001492 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001493
1494 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1495 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1496 if sanitizer == "hwaddress" {
1497 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001498 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001499 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001500 break
1501 }
1502 }
1503 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001504 }
1505
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001506 }
1507
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001508 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1509 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1510 // b/144532908
1511 archForPrebuiltEtc := config.Arches()[0]
1512 for _, arch := range config.Arches() {
1513 // Prefer 64-bit arch if there is any
1514 if arch.ArchType.Multilib == "lib64" {
1515 archForPrebuiltEtc = arch
1516 break
1517 }
1518 }
1519 ctx.AddFarVariationDependencies([]blueprint.Variation{
1520 {Mutator: "os", Variation: ctx.Os().String()},
1521 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1522 }, prebuiltTag, a.properties.Prebuilts...)
1523
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001524 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1525 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001526
Ulya Trafimovich44561882020-01-03 13:25:54 +00001527 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1528 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1529 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1530 javaLibTag, "jacocoagent")
1531 }
1532
Jiyong Park23c52b02019-02-02 13:13:47 +09001533 if String(a.properties.Key) == "" {
1534 ctx.ModuleErrorf("key is missing")
1535 return
1536 }
1537 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001538
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001539 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001540 if cert != "" {
1541 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001542 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001543
1544 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1545 if len(a.properties.Uses_sdks) > 0 {
1546 sdkRefs := []android.SdkRef{}
1547 for _, str := range a.properties.Uses_sdks {
1548 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1549 sdkRefs = append(sdkRefs, parsed)
1550 }
1551 a.BuildWithSdks(sdkRefs)
1552 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001553}
1554
Jiyong Park5d790c32019-11-15 18:40:32 +09001555func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1556 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1557 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001558 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1559 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001560}
1561
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001562func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1563 // direct deps of an APEX bundle are all part of the APEX bundle
1564 return true
1565}
1566
Colin Cross0ea8ba82019-06-06 14:33:29 -07001567func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001568 moduleName := ctx.ModuleName()
1569 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1570 // we check with the pseudo module name to see if its certificate is overridden.
1571 if a.vndkApex {
1572 moduleName = vndkApexName
1573 }
1574 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001575 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001576 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001577 }
1578 return String(a.properties.Certificate)
1579}
1580
Colin Cross41955e82019-05-29 14:40:35 -07001581func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1582 switch tag {
1583 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001584 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001585 default:
1586 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001587 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001588}
1589
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001590func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001591 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001592}
1593
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001594func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1595 return proptools.Bool(a.properties.Test_only_no_hashtree)
1596}
1597
Dario Freni98410fd2020-04-27 18:21:11 +01001598func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1599 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1600}
1601
Jiyong Park7c1dc612019-01-05 11:15:24 +09001602func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001603 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001604 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001605 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001606 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001607 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001608 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001609 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001610 }
1611}
1612
Jiyong Parkf97782b2019-02-13 20:28:58 +09001613func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1614 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1615 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1616 }
1617}
1618
Jiyong Park388ef3f2019-01-28 19:47:32 +09001619func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001620 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1621 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001622 }
1623
1624 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001625 globalSanitizerNames := []string{}
1626 if a.Host() {
1627 globalSanitizerNames = ctx.Config().SanitizeHost()
1628 } else {
1629 arches := ctx.Config().SanitizeDeviceArch()
1630 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1631 globalSanitizerNames = ctx.Config().SanitizeDevice()
1632 }
1633 }
1634 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001635}
1636
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001637var _ cc.Coverage = (*apexBundle)(nil)
1638
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001639func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001640 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001641}
1642
1643func (a *apexBundle) PreventInstall() {
1644 a.properties.PreventInstall = true
1645}
1646
1647func (a *apexBundle) HideFromMake() {
1648 a.properties.HideFromMake = true
1649}
1650
Jiyong Park956305c2020-01-09 12:32:06 +09001651func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1652 a.properties.IsCoverageVariant = coverage
1653}
1654
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001655func (a *apexBundle) EnableCoverageIfNeeded() {}
1656
Jiyong Parkf653b052019-11-18 15:39:01 +09001657// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001658func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001659 // Decide the APEX-local directory by the multilib of the library
1660 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001661 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001662 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001663 case "lib32":
1664 dirInApex = "lib"
1665 case "lib64":
1666 dirInApex = "lib64"
1667 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001668 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001669 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001670 }
Jooyung Han35155c42020-02-06 17:33:20 +09001671 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001672 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001673 // Special case for Bionic libs and other libs installed with them. This is
1674 // to prevent those libs from being included in the search path
1675 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1676 // those libs in the Runtime APEX are available via the legacy paths in
1677 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1678 // to the legacy paths and thus will be loaded into the default linker
1679 // namespace (aka "platform" namespace). If the libs are directly in
1680 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1681 // into the runtime linker namespace, which will result in double loading of
1682 // them, which isn't supported.
1683 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001684 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001685
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001687 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001688}
1689
Jiyong Park1833cef2019-12-13 13:28:36 +09001690func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001691 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001692 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001693 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001694 }
Jooyung Han35155c42020-02-06 17:33:20 +09001695 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001696 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001697 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001698 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001699 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001700 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001701}
1702
Jiyong Park1833cef2019-12-13 13:28:36 +09001703func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001704 dirInApex := "bin"
1705 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001706 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001707}
Jiyong Park1833cef2019-12-13 13:28:36 +09001708func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001709 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001710 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1711 if err != nil {
1712 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001713 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001714 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001715 fileToCopy := android.PathForOutput(ctx, s)
1716 // NB: Since go binaries are static we don't need the module for anything here, which is
1717 // good since the go tool is a blueprint.Module not an android.Module like we would
1718 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001719 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001720}
1721
Jiyong Park1833cef2019-12-13 13:28:36 +09001722func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001723 dirInApex := filepath.Join("bin", sh.SubDir())
1724 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001725 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001726 af.symlinks = sh.Symlinks()
1727 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001728}
1729
Paul Duffin581bbbe2020-05-14 20:49:32 +01001730func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib java.Dependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001731 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001732 fileToCopy := lib.DexJar()
Paul Duffin581bbbe2020-05-14 20:49:32 +01001733 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001734 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1735 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001736}
1737
Jiyong Park1833cef2019-12-13 13:28:36 +09001738func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001739 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1740 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001741 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001742}
1743
atrost6e126252020-01-27 17:01:16 +00001744func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1745 dirInApex := filepath.Join("etc", config.SubDir())
1746 fileToCopy := config.CompatConfig()
1747 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1748}
1749
Jiyong Park1833cef2019-12-13 13:28:36 +09001750func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001751 android.Module
1752 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001753 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001754 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001755 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001756 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001757}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001758 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001759 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001760 appDir = "priv-app"
1761 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001762 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001763 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001764 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1765 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001766 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001767
1768 if app, ok := aapp.(interface {
1769 OverriddenManifestPackageName() string
1770 }); ok {
1771 af.overriddenPackageName = app.OverriddenManifestPackageName()
1772 }
Jiyong Park618922e2020-01-08 13:35:43 +09001773 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001774}
1775
Jiyong Park69aeba92020-04-24 21:16:36 +09001776func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1777 rroDir := "overlay"
1778 dirInApex := filepath.Join(rroDir, rro.Theme())
1779 fileToCopy := rro.OutputFile()
1780 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1781 af.certificate = rro.Certificate()
1782
1783 if a, ok := rro.(interface {
1784 OverriddenManifestPackageName() string
1785 }); ok {
1786 af.overriddenPackageName = a.OverriddenManifestPackageName()
1787 }
1788 return af
1789}
1790
Roland Levillain935639d2019-08-13 14:55:28 +01001791// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1792type flattenedApexContext struct {
1793 android.ModuleContext
1794}
1795
1796func (c *flattenedApexContext) InstallBypassMake() bool {
1797 return true
1798}
1799
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001800// Function called while walking an APEX's payload dependencies.
1801//
1802// Return true if the `to` module should be visited, false otherwise.
1803type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1804
Jiyong Park201cedd2020-02-07 17:25:49 +09001805// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001806func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001807 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001808 am, ok := child.(android.ApexModule)
1809 if !ok || !am.CanHaveApexVariants() {
1810 return false
1811 }
1812
1813 // Check for the direct dependencies that contribute to the payload
1814 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1815 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001816 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001817 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001818 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001819 return false
1820 }
1821
1822 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001823 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001824 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001825 }
1826
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001827 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001828 })
1829}
1830
Jooyung Han03b51852020-02-26 22:45:42 +09001831func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1832 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001833 intVer, err := android.ApiStrToNum(ctx, ver)
1834 if err != nil {
1835 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001836 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001837 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001838}
1839
Jiyong Park201cedd2020-02-07 17:25:49 +09001840// Ensures that the dependencies are marked as available for this APEX
1841func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1842 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1843 if ctx.Host() || a.testApex || a.vndkApex {
1844 return
1845 }
1846
Jiyong Park58d10902020-03-28 14:43:19 +09001847 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1848 // Requiring them and their transitive depencies with apex_available is not right
1849 // because they just add noise.
1850 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1851 return
1852 }
1853
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001854 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1855 if externalDep {
1856 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1857 return false
1858 }
1859
Jiyong Park201cedd2020-02-07 17:25:49 +09001860 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001861 fromName := ctx.OtherModuleName(from)
1862 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001863
1864 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1865 // do any of its dependencies.
1866 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1867 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1868 return false
1869 }
1870
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001871 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1872 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001873 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001874 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 +01001875 // Visit this module's dependencies to check and report any issues with their availability.
1876 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001877 })
1878}
1879
Jooyung Han548640b2020-04-27 12:10:30 +09001880func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1881 if proptools.Bool(a.properties.Updatable) {
1882 if String(a.properties.Min_sdk_version) == "" {
1883 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1884 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001885
1886 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001887 }
1888}
1889
Jiyong Parkaf7ed392020-05-10 15:16:24 +09001890// Ensures that a lib providing stub isn't statically linked
1891func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1892 // Practically, we only care about regular APEXes on the device.
1893 if ctx.Host() || a.testApex || a.vndkApex {
1894 return
1895 }
1896
1897 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1898 if ccm, ok := to.(*cc.Module); ok {
1899 apexName := ctx.ModuleName()
1900 fromName := ctx.OtherModuleName(from)
1901 toName := ctx.OtherModuleName(to)
1902
1903 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1904 // do any of its dependencies.
1905 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1906 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1907 return false
1908 }
1909
1910 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
1911 // It can't make the static dependencies dynamic because it can't
1912 // do the dynamic linking for itself.
1913 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1914 return false
1915 }
1916
1917 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName)
1918 if isStubLibraryFromOtherApex && !externalDep {
1919 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1920 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1921 }
1922
1923 }
1924 return true
1925 })
1926}
1927
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001928func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001929 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1930 switch a.properties.ApexType {
1931 case imageApex:
1932 if buildFlattenedAsDefault {
1933 a.suffix = imageApexSuffix
1934 } else {
1935 a.suffix = ""
1936 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001937
1938 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001939 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001940 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001941 }
1942 case zipApex:
1943 if proptools.String(a.properties.Payload_type) == "zip" {
1944 a.suffix = ""
1945 a.primaryApexType = true
1946 } else {
1947 a.suffix = zipApexSuffix
1948 }
1949 case flattenedApex:
1950 if buildFlattenedAsDefault {
1951 a.suffix = ""
1952 a.primaryApexType = true
1953 } else {
1954 a.suffix = flattenedSuffix
1955 }
Alex Light5098a612018-11-29 17:12:15 -08001956 }
1957
Roland Levillain630846d2019-06-26 12:48:34 +01001958 if len(a.properties.Tests) > 0 && !a.testApex {
1959 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1960 return
1961 }
1962
Jiyong Parkfa899442020-01-31 02:49:53 +09001963 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001964 a.checkUpdatable(ctx)
Jiyong Parkaf7ed392020-05-10 15:16:24 +09001965 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001966
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001967 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1968
Jooyung Hane1633032019-08-01 17:41:43 +09001969 // native lib dependencies
1970 var provideNativeLibs []string
1971 var requireNativeLibs []string
1972
Jooyung Han5c998b92019-06-27 11:30:33 +09001973 // Check if "uses" requirements are met with dependent apexBundles
1974 var providedNativeSharedLibs []string
1975 useVendor := proptools.Bool(a.properties.Use_vendor)
1976 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1977 if ctx.OtherModuleDependencyTag(m) != usesTag {
1978 return
1979 }
1980 otherName := ctx.OtherModuleName(m)
1981 other, ok := m.(*apexBundle)
1982 if !ok {
1983 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1984 return
1985 }
1986 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1987 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1988 return
1989 }
1990 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1991 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1992 return
1993 }
1994 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1995 })
1996
Jiyong Parkf653b052019-11-18 15:39:01 +09001997 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001998 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001999 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002000 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002001 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2002 return false
2003 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002004 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002005 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002006 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002007 case sharedLibTag, jniLibTag:
2008 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002009 if c, ok := child.(*cc.Module); ok {
2010 // bootstrap bionic libs are treated as provided by system
2011 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2012 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002013 }
Jooyung Han643adc42020-02-27 13:50:06 +09002014 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2015 fi.isJniLib = isJniLib
2016 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002017 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002018 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002019 propertyName := "native_shared_libs"
2020 if isJniLib {
2021 propertyName = "jni_libs"
2022 }
2023 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002024 }
2025 case executableTag:
2026 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002027 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002028 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002029 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002030 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002031 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002032 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002033 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002034 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002035 } else {
Alex Light778127a2019-02-27 14:19:50 -08002036 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 +09002037 }
2038 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002039 if javaLib, ok := child.(*java.Library); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01002040 af := apexFileForJavaLibrary(ctx, javaLib, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002041 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002042 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2043 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002044 filesInfo = append(filesInfo, af)
2045 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002046 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002047 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01002048 af := apexFileForJavaLibrary(ctx, sdkLib, sdkLib)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002049 if !af.Ok() {
2050 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2051 return false
2052 }
2053 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002054 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002055 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002056 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002057 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002058 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002059 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002060 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002061 return true // track transitive dependencies
2062 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002063 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002064 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002065 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002066 } else {
2067 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2068 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002069 case rroTag:
2070 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2071 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2072 } else {
2073 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2074 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002075 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002076 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002077 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002078 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2079 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002080 } else {
atrost6e126252020-01-27 17:01:16 +00002081 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002082 }
Roland Levillain630846d2019-06-26 12:48:34 +01002083 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002084 if ccTest, ok := child.(*cc.Module); ok {
2085 if ccTest.IsTestPerSrcAllTestsVariation() {
2086 // Multiple-output test module (where `test_per_src: true`).
2087 //
2088 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2089 // We do not add this variation to `filesInfo`, as it has no output;
2090 // however, we do add the other variations of this module as indirect
2091 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002092 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002093 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002094 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002095 af.class = nativeTest
2096 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002097 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002098 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002099 } else {
2100 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2101 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002102 case keyTag:
2103 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002104 a.private_key_file = key.private_key_file
2105 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002106 } else {
2107 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002108 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002109 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002110 case certificateTag:
2111 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002112 a.container_certificate_file = dep.Certificate.Pem
2113 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002114 } else {
2115 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2116 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002117 case android.PrebuiltDepTag:
2118 // If the prebuilt is force disabled, remember to delete the prebuilt file
2119 // that might have been installed in the previous builds
2120 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2121 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2122 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002123 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002124 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002125 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002126 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002127 // We cannot use a switch statement on `depTag` here as the checked
2128 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002129 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002130 if cc, ok := child.(*cc.Module); ok {
2131 if android.InList(cc.Name(), providedNativeSharedLibs) {
2132 // If we're using a shared library which is provided from other APEX,
2133 // don't include it in this APEX
2134 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002135 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002136 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002137 // If the dependency is a stubs lib, don't include it in this APEX,
2138 // but make sure that the lib is installed on the device.
2139 // In case no APEX is having the lib, the lib is installed to the system
2140 // partition.
2141 //
2142 // Always include if we are a host-apex however since those won't have any
2143 // system libraries.
Yo Chiang29555d52020-05-06 15:59:59 +08002144 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.BaseModuleName(), a.requiredDeps) {
2145 a.requiredDeps = append(a.requiredDeps, cc.BaseModuleName())
Roland Levillainf89cd092019-07-29 16:22:59 +01002146 }
Jooyung Hane1633032019-08-01 17:41:43 +09002147 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002148 // Don't track further
2149 return false
2150 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002151 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002152 af.transitiveDep = true
2153 filesInfo = append(filesInfo, af)
2154 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002155 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002156 } else if cc.IsTestPerSrcDepTag(depTag) {
2157 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002158 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002159 // Handle modules created as `test_per_src` variations of a single test module:
2160 // use the name of the generated test binary (`fileToCopy`) instead of the name
2161 // of the original test module (`depName`, shared by all `test_per_src`
2162 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002163 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002164 // these are not considered transitive dep
2165 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002166 filesInfo = append(filesInfo, af)
2167 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002168 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002169 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002170 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2171 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002172 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2173 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2174 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2175 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002176 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002177 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002178 }
2179 }
2180 }
2181 return false
2182 })
2183
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002184 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2185 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2186 // via the global boot image config.
2187 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002188 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002189 dirInApex := filepath.Join("javalib", arch.String())
2190 for _, f := range files {
2191 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002192 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002193 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002194 }
2195 }
2196 }
2197
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002198 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002199 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2200 return
2201 }
2202
Jiyong Park8fd61922018-11-08 02:50:25 +09002203 // remove duplicates in filesInfo
2204 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002205 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002206 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002207 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002208 if e, ok := encountered[dest]; !ok {
2209 encountered[dest] = f
2210 } else {
2211 // If a module is directly included and also transitively depended on
2212 // consider it as directly included.
2213 e.transitiveDep = e.transitiveDep && f.transitiveDep
2214 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002215 }
2216 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002217 var result []apexFile
2218 for _, v := range encountered {
2219 result = append(result, v)
2220 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002221 return result
2222 }
2223 filesInfo = removeDup(filesInfo)
2224
2225 // to have consistent build rules
2226 sort.Slice(filesInfo, func(i, j int) bool {
2227 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2228 })
2229
Jiyong Park8fd61922018-11-08 02:50:25 +09002230 a.installDir = android.PathForModuleInstall(ctx, "apex")
2231 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002232
Jooyung Han54aca7b2019-11-20 02:26:02 +09002233 if a.properties.ApexType != zipApex {
2234 if a.properties.File_contexts == nil {
2235 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2236 } else {
2237 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2238 if a.Platform() {
2239 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2240 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2241 }
2242 }
2243 }
2244 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2245 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2246 return
2247 }
2248 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002249 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2250 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2251 // the same library in the system partition, thus effectively sharing the same libraries
2252 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2253 // in the APEX.
2254 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2255 a.installable() &&
2256 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002257
Jiyong Park9d677202020-02-19 16:29:35 +09002258 // We don't need the optimization for updatable APEXes, as it might give false signal
2259 // to the system health when the APEXes are still bundled (b/149805758)
2260 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2261 a.linkToSystemLib = false
2262 }
2263
Jiyong Park9b964182020-02-26 18:27:19 +09002264 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2265 if ctx.Host() {
2266 a.linkToSystemLib = false
2267 }
2268
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002269 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002270 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2271
2272 a.setCertificateAndPrivateKey(ctx)
2273 if a.properties.ApexType == flattenedApex {
2274 a.buildFlattenedApex(ctx)
2275 } else {
2276 a.buildUnflattenedApex(ctx)
2277 }
2278
Jooyung Han002ab682020-01-08 01:57:58 +09002279 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002280
2281 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002282}
2283
Artur Satayev8cf899a2020-04-15 17:29:42 +01002284// Enforce that Java deps of the apex are using stable SDKs to compile
2285func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2286 // Visit direct deps only. As long as we guarantee top-level deps are using
2287 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2288 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2289 tag := ctx.OtherModuleDependencyTag(module)
2290 switch tag {
2291 case javaLibTag, androidAppTag:
2292 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2293 if err := m.CheckStableSdkVersion(); err != nil {
2294 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2295 }
2296 }
2297 }
2298 })
2299}
2300
Jooyung Han5e9013b2020-03-10 06:23:13 +09002301func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002302 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002303 moduleName = normalizeModuleName(moduleName)
2304
2305 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2306 return true
2307 }
2308
2309 key = android.AvailableToAnyApex
2310 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2311 return true
2312 }
2313
2314 return false
2315}
2316
2317func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002318 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2319 // system. Trim the prefix for the check since they are confusing
2320 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2321 if strings.HasPrefix(moduleName, "libclang_rt.") {
2322 // This module has many arch variants that depend on the product being built.
2323 // We don't want to list them all
2324 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002325 }
Jooyung Han040ff3d2020-05-19 15:47:01 +09002326 if strings.HasPrefix(moduleName, "androidx.") {
2327 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2328 moduleName = "androidx"
2329 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002330 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002331}
2332
Jooyung Han344d5432019-08-23 11:17:39 +09002333func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002334 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002335 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002336 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002337 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002338 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002339 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2340 })
Alex Light5098a612018-11-29 17:12:15 -08002341 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002342 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002343 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002344 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002345 return module
2346}
Jiyong Park30ca9372019-02-07 16:27:23 +09002347
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002348func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002349 bundle := newApexBundle()
2350 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002351 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002352 return bundle
2353}
2354
Jiyong Parkfce0b422020-02-11 03:56:06 +09002355// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2356// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002357func testApexBundleFactory() android.Module {
2358 bundle := newApexBundle()
2359 bundle.testApex = true
2360 return bundle
2361}
2362
Jiyong Parkfce0b422020-02-11 03:56:06 +09002363// apex packages other modules into an APEX file which is a packaging format for system-level
2364// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002365func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002366 return newApexBundle()
2367}
2368
Jiyong Park30ca9372019-02-07 16:27:23 +09002369//
2370// Defaults
2371//
2372type Defaults struct {
2373 android.ModuleBase
2374 android.DefaultsModuleBase
2375}
2376
Jiyong Park30ca9372019-02-07 16:27:23 +09002377func defaultsFactory() android.Module {
2378 return DefaultsFactory()
2379}
2380
2381func DefaultsFactory(props ...interface{}) android.Module {
2382 module := &Defaults{}
2383
2384 module.AddProperties(props...)
2385 module.AddProperties(
2386 &apexBundleProperties{},
2387 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002388 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002389 )
2390
2391 android.InitDefaultsModule(module)
2392 return module
2393}
Jiyong Park5d790c32019-11-15 18:40:32 +09002394
2395//
2396// OverrideApex
2397//
2398type OverrideApex struct {
2399 android.ModuleBase
2400 android.OverrideModuleBase
2401}
2402
2403func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2404 // All the overrides happen in the base module.
2405}
2406
2407// override_apex is used to create an apex module based on another apex module
2408// by overriding some of its properties.
2409func overrideApexFactory() android.Module {
2410 m := &OverrideApex{}
2411 m.AddProperties(&overridableProperties{})
2412
2413 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2414 android.InitOverrideModule(m)
2415 return m
2416}