blob: 16027e1da5c8146b58dc1f5812889a1caaa87673 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinf0207962020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Parkfa899442020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
56 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000064 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin404db3f2020-03-06 12:30:13 +000065
66 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067)
68
Paul Duffin404db3f2020-03-06 12:30:13 +000069// Transform the map of apex -> modules to module -> apexes.
70func invertApexWhiteList(m map[string][]string) map[string][]string {
71 r := make(map[string][]string)
72 for apex, modules := range m {
73 for _, module := range modules {
74 r[module] = append(r[module], apex)
75 }
76 }
77 return r
78}
79
80// Retrieve the while list of apexes to which the supplied module belongs.
81func WhitelistedApexAvailable(moduleName string) []string {
82 return inverseApexAvailWl[normalizeModuleName(moduleName)]
83}
84
Anton Hansson5053c292020-01-10 15:12:39 +000085// This is a map from apex to modules, which overrides the
86// apex_available setting for that particular module to make
87// it available for the apex regardless of its setting.
88// TODO(b/147364041): remove this
89func makeApexAvailableWhitelist() map[string][]string {
90 // The "Module separator"s below are employed to minimize merge conflicts.
91 m := make(map[string][]string)
92 //
93 // Module separator
94 //
Jiyong Parkfa899442020-01-31 02:49:53 +090095 m["com.android.adbd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090096 "libadbd_auth",
Jiyong Parkfa899442020-01-31 02:49:53 +090097 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +090098 "libcap",
Jiyong Parkfa899442020-01-31 02:49:53 +090099 "libmdnssd",
100 "libminijail",
101 "libminijail_gen_constants",
102 "libminijail_gen_constants_obj",
103 "libminijail_gen_syscall",
104 "libminijail_gen_syscall_obj",
105 "libminijail_generated",
106 "libpackagelistparser",
107 "libpcre2",
108 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900109 }
110 //
111 // Module separator
112 //
Paul Duffinc23d9f62020-03-10 13:44:19 +0000113 artApexContents := []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900114 "art_cmdlineparser_headers",
115 "art_disassembler_headers",
116 "art_libartbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900117 "bionic_libc_platform_headers",
118 "core-repackaged-icu4j",
119 "cpp-define-generator-asm-support",
120 "cpp-define-generator-definitions",
121 "crtbegin_dynamic",
122 "crtbegin_dynamic1",
123 "crtbegin_so1",
124 "crtbrand",
Jiyong Parkfa899442020-01-31 02:49:53 +0900125 "dex2oat_headers",
126 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900127 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900128 "javavm_headers",
129 "jni_platform_headers",
130 "libPlatformProperties",
131 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000132 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900133 "libandroidicuinit",
134 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000135 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900136 "libasync_safe",
Jiyong Parkfa899442020-01-31 02:49:53 +0900137 "libdexfile_all_headers",
138 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000139 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900140 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000141 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900142 "libfdlibm",
143 "libgtest_prod",
144 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000145 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900146 "libicuuc_headers",
147 "libicuuc_stubdata",
148 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900149 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000150 "liblzma",
151 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900152 "libnativebridge-headers",
153 "libnativehelper_header_only",
154 "libnativeloader-headers",
155 "libnpt_headers",
156 "libopenjdkjvmti_headers",
157 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000158 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900159 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000160 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900161 "libv8",
162 "libv8base",
163 "libv8gen",
164 "libv8platform",
165 "libv8sampler",
166 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000167 "libvixl",
168 "libvixld",
169 "libz",
170 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000172 }
Paul Duffinc23d9f62020-03-10 13:44:19 +0000173 m["com.android.art.debug"] = artApexContents
174 m["com.android.art.release"] = artApexContents
Anton Hansson5053c292020-01-10 15:12:39 +0000175 //
176 // Module separator
177 //
178 m["com.android.bluetooth.updatable"] = []string{
179 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000180 "android.hardware.bluetooth.a2dp@1.0",
181 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900182 "android.hardware.bluetooth@1.0",
183 "android.hardware.bluetooth@1.1",
184 "android.hardware.graphics.bufferqueue@1.0",
185 "android.hardware.graphics.bufferqueue@2.0",
186 "android.hardware.graphics.common@1.0",
187 "android.hardware.graphics.common@1.1",
188 "android.hardware.graphics.common@1.2",
189 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000190 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900191 "android.hidl.token@1.0",
192 "android.hidl.token@1.0-utils",
193 "avrcp-target-service",
194 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 "bluetooth-protos-lite",
196 "bluetooth.mapsapi",
197 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900198 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900199 "ipmemorystore-aidl-interfaces-V5-java",
200 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900201 "internal_include_headers",
202 "lib-bt-packets",
203 "lib-bt-packets-avrcp",
204 "lib-bt-packets-base",
205 "libFraunhoferAAC",
206 "libaudio-a2dp-hw-utils",
207 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900208 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000209 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900210 "libbluetooth-types",
211 "libbluetooth-types-header",
212 "libbluetooth_gd",
213 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000214 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libbt-audio-hal-interface",
216 "libbt-bta",
217 "libbt-common",
218 "libbt-hci",
219 "libbt-platform-protos-lite",
220 "libbt-protos-lite",
221 "libbt-sbc-decoder",
222 "libbt-sbc-encoder",
223 "libbt-stack",
224 "libbt-utils",
225 "libbtcore",
226 "libbtdevice",
227 "libbte",
228 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000229 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000230 "libevent",
231 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900232 "libg722codec",
233 "libgtest_prod",
234 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900235 "libmedia_headers",
236 "libmodpb64",
237 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000238 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900239 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900240 "libstagefright_foundation_headers",
241 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000242 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900243 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000244 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900245 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000246 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900247 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900248 "net-utils-services-common",
249 "netd_aidl_interface-unstable-java",
250 "netd_event_listener_interface-java",
251 "netlink-client",
252 "networkstack-aidl-interfaces-unstable-java",
253 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900254 "sap-api-java-static",
255 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000256 }
257 //
258 // Module separator
259 //
260 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
261 //
262 // Module separator
263 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900264 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900265 "boringssl_self_test",
Jiyong Parkfa899442020-01-31 02:49:53 +0900266 "libnativehelper_header_only",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900267 "unsupportedappusage",
Jiyong Parkfa899442020-01-31 02:49:53 +0900268 }
Anton Hansson5053c292020-01-10 15:12:39 +0000269 //
270 // Module separator
271 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900272 m["com.android.extservices"] = []string{
273 "flatbuffer_headers",
274 "liblua",
275 "libtextclassifier",
276 "libtextclassifier_hash_static",
277 "libtflite_static",
278 "libutf",
279 "libz_current",
280 "tensorflow_headers",
281 }
282 //
283 // Module separator
284 //
285 m["com.android.cronet"] = []string{
286 "cronet_impl_common_java",
287 "cronet_impl_native_java",
288 "cronet_impl_platform_java",
289 "libcronet.80.0.3986.0",
290 "org.chromium.net.cronet",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900291 "org.chromium.net.cronet.xml",
Jiyong Parkfa899442020-01-31 02:49:53 +0900292 "prebuilt_libcronet.80.0.3986.0",
293 }
294 //
295 // Module separator
296 //
297 m["com.android.neuralnetworks"] = []string{
298 "android.hardware.neuralnetworks@1.0",
299 "android.hardware.neuralnetworks@1.1",
300 "android.hardware.neuralnetworks@1.2",
301 "android.hardware.neuralnetworks@1.3",
302 "android.hidl.allocator@1.0",
303 "android.hidl.memory.token@1.0",
304 "android.hidl.memory@1.0",
305 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900306 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900307 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900308 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900309 "libprocessgroup",
310 "libprocessgroup_headers",
311 "libprocpartition",
312 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900313 }
Anton Hansson5053c292020-01-10 15:12:39 +0000314 //
315 // Module separator
316 //
Anton Hansson5053c292020-01-10 15:12:39 +0000317 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900318 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000319 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900320 "android.hardware.cas@1.0",
321 "android.hardware.configstore-utils",
322 "android.hardware.configstore@1.0",
323 "android.hardware.configstore@1.1",
324 "android.hardware.graphics.allocator@2.0",
325 "android.hardware.graphics.allocator@3.0",
326 "android.hardware.graphics.bufferqueue@1.0",
327 "android.hardware.graphics.bufferqueue@2.0",
328 "android.hardware.graphics.common@1.0",
329 "android.hardware.graphics.common@1.1",
330 "android.hardware.graphics.common@1.2",
331 "android.hardware.graphics.mapper@2.0",
332 "android.hardware.graphics.mapper@2.1",
333 "android.hardware.graphics.mapper@3.0",
334 "android.hardware.media.omx@1.0",
335 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000336 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000337 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900338 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000339 "android.hidl.token@1.0",
340 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900341 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900342 "gl_headers",
343 "libEGL",
344 "libEGL_blobCache",
345 "libEGL_getProcAddress",
346 "libFLAC",
347 "libFLAC-config",
348 "libFLAC-headers",
349 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000350 "libaacextractor",
351 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900352 "libarect",
353 "libasync_safe",
354 "libaudio_system_headers",
355 "libaudioclient",
356 "libaudioclient_headers",
357 "libaudiofoundation",
358 "libaudiofoundation_headers",
359 "libaudiomanager",
360 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000361 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900362 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900363 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900364 "libbluetooth-types-header",
365 "libbufferhub",
366 "libbufferhub_headers",
367 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900368 "libc_malloc_debug_backtrace",
369 "libcamera_client",
370 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900371 "libdexfile_external_headers",
372 "libdexfile_support",
373 "libdvr_headers",
374 "libexpat",
375 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000376 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900377 "libgrallocusage",
378 "libgraphicsenv",
379 "libgui",
380 "libgui_headers",
381 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900382 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900383 "liblzma",
384 "libmath",
385 "libmedia",
386 "libmedia_codeclist",
387 "libmedia_headers",
388 "libmedia_helper",
389 "libmedia_helper_headers",
390 "libmedia_midiiowrapper",
391 "libmedia_omx",
392 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000393 "libmidiextractor",
394 "libmkvextractor",
395 "libmp3extractor",
396 "libmp4extractor",
397 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900398 "libnativebase_headers",
399 "libnativebridge-headers",
400 "libnativebridge_lazy",
401 "libnativeloader-headers",
402 "libnativeloader_lazy",
403 "libnativewindow_headers",
404 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000405 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900406 "libpackagelistparser",
407 "libpcre2",
408 "libpdx",
409 "libpdx_default_transport",
410 "libpdx_headers",
411 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000412 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900413 "libprocessgroup_headers",
414 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000415 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900416 "libspeexresampler",
417 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000418 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900419 "libstagefright_flacdec",
420 "libstagefright_foundation",
421 "libstagefright_foundation_headers",
422 "libstagefright_foundation_without_imemory",
423 "libstagefright_headers",
424 "libstagefright_id3",
425 "libstagefright_metadatautils",
426 "libstagefright_mpeg2extractor",
427 "libstagefright_mpeg2support",
428 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900429 "libui",
430 "libui_headers",
431 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900432 "libvibrator",
433 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000434 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900435 "libwebm",
436 "media_ndk_headers",
437 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000438 "updatable-media",
439 }
440 //
441 // Module separator
442 //
443 m["com.android.media.swcodec"] = []string{
444 "android.frameworks.bufferhub@1.0",
445 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900446 "android.hardware.configstore-utils",
447 "android.hardware.configstore@1.0",
448 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000449 "android.hardware.graphics.allocator@2.0",
450 "android.hardware.graphics.allocator@3.0",
451 "android.hardware.graphics.allocator@4.0",
452 "android.hardware.graphics.bufferqueue@1.0",
453 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900454 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000455 "android.hardware.graphics.common@1.0",
456 "android.hardware.graphics.common@1.1",
457 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000458 "android.hardware.graphics.mapper@2.0",
459 "android.hardware.graphics.mapper@2.1",
460 "android.hardware.graphics.mapper@3.0",
461 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000462 "android.hardware.media.bufferpool@2.0",
463 "android.hardware.media.c2@1.0",
464 "android.hardware.media.c2@1.1",
465 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900466 "android.hardware.media@1.0",
467 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000468 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900469 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000470 "android.hidl.safe_union@1.0",
471 "android.hidl.token@1.0",
472 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900473 "libEGL",
474 "libFLAC",
475 "libFLAC-config",
476 "libFLAC-headers",
477 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900478 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900479 "libarect",
480 "libasync_safe",
481 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000482 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900483 "libaudioutils",
484 "libaudioutils_fixedfft",
485 "libavcdec",
486 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000487 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900488 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900489 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900490 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900491 "libbluetooth-types-header",
492 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900493 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000494 "libcap",
495 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900496 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000497 "libcodec2_hidl@1.0",
498 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900499 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000500 "libcodec2_soft_aacdec",
501 "libcodec2_soft_aacenc",
502 "libcodec2_soft_amrnbdec",
503 "libcodec2_soft_amrnbenc",
504 "libcodec2_soft_amrwbdec",
505 "libcodec2_soft_amrwbenc",
506 "libcodec2_soft_av1dec_gav1",
507 "libcodec2_soft_avcdec",
508 "libcodec2_soft_avcenc",
509 "libcodec2_soft_common",
510 "libcodec2_soft_flacdec",
511 "libcodec2_soft_flacenc",
512 "libcodec2_soft_g711alawdec",
513 "libcodec2_soft_g711mlawdec",
514 "libcodec2_soft_gsmdec",
515 "libcodec2_soft_h263dec",
516 "libcodec2_soft_h263enc",
517 "libcodec2_soft_hevcdec",
518 "libcodec2_soft_hevcenc",
519 "libcodec2_soft_mp3dec",
520 "libcodec2_soft_mpeg2dec",
521 "libcodec2_soft_mpeg4dec",
522 "libcodec2_soft_mpeg4enc",
523 "libcodec2_soft_opusdec",
524 "libcodec2_soft_opusenc",
525 "libcodec2_soft_rawdec",
526 "libcodec2_soft_vorbisdec",
527 "libcodec2_soft_vp8dec",
528 "libcodec2_soft_vp8enc",
529 "libcodec2_soft_vp9dec",
530 "libcodec2_soft_vp9enc",
531 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900532 "libdexfile_support",
533 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000534 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900535 "libfmq",
536 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000537 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900538 "libgrallocusage",
539 "libgraphicsenv",
540 "libgsm",
541 "libgui_bufferqueue_static",
542 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000543 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900544 "libhardware_headers",
545 "libhevcdec",
546 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000547 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900548 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900549 "liblzma",
550 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000551 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900552 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000553 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900554 "libminijail_gen_constants",
555 "libminijail_gen_constants_obj",
556 "libminijail_gen_syscall",
557 "libminijail_gen_syscall_obj",
558 "libminijail_generated",
559 "libmpeg2dec",
560 "libnativebase_headers",
561 "libnativebridge_lazy",
562 "libnativeloader_lazy",
563 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000564 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900565 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000566 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900567 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000568 "libscudo_wrapper",
569 "libsfplugin_ccodec_utils",
570 "libspeexresampler",
571 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900572 "libstagefright_amrnbdec",
573 "libstagefright_amrnbenc",
574 "libstagefright_amrwbdec",
575 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000576 "libstagefright_bufferpool@2.0.1",
577 "libstagefright_bufferqueue_helper",
578 "libstagefright_enc_common",
579 "libstagefright_flacdec",
580 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900581 "libstagefright_foundation_headers",
582 "libstagefright_headers",
583 "libstagefright_m4vh263dec",
584 "libstagefright_m4vh263enc",
585 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000586 "libsync",
587 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900588 "libui_headers",
589 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000590 "libvorbisidec",
591 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900592 "libyuv",
593 "libyuv_static",
594 "media_ndk_headers",
595 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000596 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000597 }
598 //
599 // Module separator
600 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900601 m["com.android.mediaprovider"] = []string{
602 "MediaProvider",
603 "MediaProviderGoogle",
604 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900605 "libbase_ndk",
606 "libfuse",
607 "libfuse_jni",
608 "libnativehelper_header_only",
609 }
610 //
611 // Module separator
612 //
613 m["com.android.permission"] = []string{
614 "androidx.annotation_annotation",
615 "androidx.annotation_annotation-nodeps",
616 "androidx.lifecycle_lifecycle-common",
617 "androidx.lifecycle_lifecycle-common-java8",
618 "androidx.lifecycle_lifecycle-common-java8-nodeps",
619 "androidx.lifecycle_lifecycle-common-nodeps",
620 "kotlin-annotations",
621 "kotlin-stdlib",
622 "kotlin-stdlib-jdk7",
623 "kotlin-stdlib-jdk8",
624 "kotlinx-coroutines-android",
625 "kotlinx-coroutines-android-nodeps",
626 "kotlinx-coroutines-core",
627 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900628 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900629 "GooglePermissionController",
630 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900631 }
Anton Hansson5053c292020-01-10 15:12:39 +0000632 //
633 // Module separator
634 //
Anton Hansson5053c292020-01-10 15:12:39 +0000635 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900636 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "libarm-optimized-routines-math",
638 "libasync_safe",
639 "libasync_safe_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900640 "libc_aeabi",
641 "libc_bionic",
642 "libc_bionic_ndk",
643 "libc_bootstrap",
644 "libc_common",
645 "libc_common_shared",
646 "libc_common_static",
647 "libc_dns",
648 "libc_dynamic_dispatch",
649 "libc_fortify",
650 "libc_freebsd",
651 "libc_freebsd_large_stack",
652 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900653 "libc_init_dynamic",
654 "libc_init_static",
655 "libc_jemalloc_wrapper",
656 "libc_netbsd",
657 "libc_nomalloc",
658 "libc_nopthread",
659 "libc_openbsd",
660 "libc_openbsd_large_stack",
661 "libc_openbsd_ndk",
662 "libc_pthread",
663 "libc_static_dispatch",
664 "libc_syscalls",
665 "libc_tzcode",
666 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900667 "libdebuggerd",
668 "libdebuggerd_common_headers",
669 "libdebuggerd_handler_core",
670 "libdebuggerd_handler_fallback",
671 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000672 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900673 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900674 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900675 "libgtest_prod",
676 "libjemalloc5",
677 "liblinker_main",
678 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900679 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000680 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900681 "libprocessgroup_headers",
682 "libprocinfo",
683 "libpropertyinfoparser",
684 "libscudo",
685 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900686 "libsystemproperties",
687 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000688 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900689 "libz",
690 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000691 }
692 //
693 // Module separator
694 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900695 m["com.android.resolv"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900696 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 "libgtest_prod",
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 "libnativehelper_header_only",
699 "libnetd_client_headers",
700 "libnetd_resolv",
701 "libnetdutils",
702 "libprocessgroup",
703 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900704 "libstatslog_resolv",
705 "libstatspush_compat",
706 "libstatssocket",
707 "libstatssocket_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900708 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900709 "netd_event_listener_interface-ndk_platform",
710 "server_configurable_flags",
711 "stats_proto",
712 }
Anton Hansson5053c292020-01-10 15:12:39 +0000713 //
714 // Module separator
715 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900716 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900717 "libnativehelper_compat_libc++",
718 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900719 "libcgrouprc",
720 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900721 "libprocessgroup",
722 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900723 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900724 "libvndksupport",
725 "tethering-aidl-interfaces-java",
726 }
Anton Hansson5053c292020-01-10 15:12:39 +0000727 //
728 // Module separator
729 //
730 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900731 "PlatformProperties",
732 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900733 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900734 "android.hardware.wifi-V1.1-java",
735 "android.hardware.wifi-V1.2-java",
736 "android.hardware.wifi-V1.3-java",
737 "android.hardware.wifi-V1.4-java",
738 "android.hardware.wifi.hostapd-V1.0-java",
739 "android.hardware.wifi.hostapd-V1.1-java",
740 "android.hardware.wifi.hostapd-V1.2-java",
741 "android.hardware.wifi.supplicant-V1.0-java",
742 "android.hardware.wifi.supplicant-V1.1-java",
743 "android.hardware.wifi.supplicant-V1.2-java",
744 "android.hardware.wifi.supplicant-V1.3-java",
745 "android.hidl.base-V1.0-java",
746 "android.hidl.manager-V1.0-java",
747 "android.hidl.manager-V1.1-java",
748 "android.hidl.manager-V1.2-java",
749 "androidx.annotation_annotation",
750 "androidx.annotation_annotation-nodeps",
751 "bouncycastle-unbundled",
752 "dnsresolver_aidl_interface-V2-java",
753 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900754 "framework-wifi-pre-jarjar",
755 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900756 "ipmemorystore-aidl-interfaces-V3-java",
757 "ipmemorystore-aidl-interfaces-java",
758 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900759 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000760 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900761 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000762 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900763 "net-utils-services-common",
764 "netd_aidl_interface-V2-java",
765 "netd_aidl_interface-unstable-java",
766 "netd_event_listener_interface-java",
767 "netlink-client",
768 "networkstack-aidl-interfaces-unstable-java",
769 "networkstack-client",
770 "services.net",
771 "wifi-lite-protos",
772 "wifi-nano-protos",
773 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000774 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900775 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000776 }
777 //
778 // Module separator
779 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900780 m["com.android.sdkext"] = []string{
781 "fmtlib_ndk",
782 "libbase_ndk",
783 "libprotobuf-cpp-lite-ndk",
784 }
785 //
786 // Module separator
787 //
788 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900789 "libprocessgroup_headers",
790 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900791 }
792 //
793 // Module separator
794 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000795 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900796 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900797 "libclang_rt",
798 "libgcc_stripped",
799 "libprofile-clang-extras",
800 "libprofile-clang-extras_ndk",
801 "libprofile-extras",
802 "libprofile-extras_ndk",
803 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900804 }
Anton Hansson5053c292020-01-10 15:12:39 +0000805 return m
806}
807
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900808func init() {
Jooyung Hane17caa62020-04-08 14:13:04 +0900809 android.AddNeverAllowRules(android.NeverAllow().
810 ModuleType("apex").
811 With("updatable", "true").
812 With("min_sdk_version", "").
813 Because("All updatable apexes should set min_sdk_version."))
814
Jiyong Parkd1063c12019-07-17 20:08:41 +0900815 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800816 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900817 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900818 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700819 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900820 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900821
Jooyung Han31c470b2019-10-18 16:26:59 +0900822 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900823 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900824
825 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
826 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
827 sort.Strings(*apexFileContextsInfos)
828 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
829 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900830}
831
Jooyung Han31c470b2019-10-18 16:26:59 +0900832func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
833 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
834 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
835}
836
Jiyong Parkd1063c12019-07-17 20:08:41 +0900837func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900838 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900839 ctx.BottomUp("apex", apexMutator).Parallel()
840 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
841 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900842 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900843}
844
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900845// Mark the direct and transitive dependencies of apex bundles so that they
846// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900847func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900848 if !mctx.Module().Enabled() {
849 return
850 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800851 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900852 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000853 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900854 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900855 ApexName: mctx.ModuleName(),
856 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900857 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900858 directDep = true
859 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800860 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900861 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900863
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800864 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900865 return
866 }
867
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100868 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900869
Jiyong Parkf760cae2020-02-12 07:53:12 +0900870 mctx.VisitDirectDeps(func(child android.Module) {
871 depName := mctx.OtherModuleName(child)
872 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100873 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800874 android.UpdateApexDependency(apexBundles, depName, directDep)
875 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900876 }
877 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900878}
879
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900880// mark if a module cannot be available to platform. A module cannot be available
881// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
882// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
883func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
884 // Host and recovery are not considered as platform
885 if mctx.Host() || mctx.Module().InstallInRecovery() {
886 return
887 }
888
889 if am, ok := mctx.Module().(android.ApexModule); ok {
890 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
891
892 // In a rare case when a lib is marked as available only to an apex
893 // but the apex doesn't exist. This can happen in a partial manifest branch
894 // like master-art. Currently, libstatssocket in the stats APEX is causing
895 // this problem.
896 // Include the lib in platform because the module SDK that ought to provide
897 // it doesn't exist, so it would otherwise be left out completely.
898 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
899 // this check for libraries provided by SDKs.
900 if !availableToPlatform && !android.InAnyApex(am.Name()) {
901 availableToPlatform = true
902 }
903
904 // If any of the dep is not available to platform, this module is also considered
905 // as being not available to platform even if it has "//apex_available:platform"
906 mctx.VisitDirectDeps(func(child android.Module) {
907 if !am.DepIsInSameApex(mctx, child) {
908 // if the dependency crosses apex boundary, don't consider it
909 return
910 }
911 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
912 availableToPlatform = false
913 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
914 }
915 })
916
917 // Exception 1: stub libraries and native bridge libraries are always available to platform
918 if cc, ok := mctx.Module().(*cc.Module); ok &&
919 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
920 availableToPlatform = true
921 }
922
923 // Exception 2: bootstrap bionic libraries are also always available to platform
924 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
925 availableToPlatform = true
926 }
927
928 if !availableToPlatform {
929 am.SetNotAvailableForPlatform()
930 }
931 }
932}
933
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100934// If a module in an APEX depends on a module from an SDK then it needs an APEX
935// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
936func inAnySdk(module android.Module) bool {
937 if sa, ok := module.(android.SdkAware); ok {
938 return sa.IsInAnySdk()
939 }
940
941 return false
942}
943
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900944// Create apex variations if a module is included in APEX(s).
945func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900946 if !mctx.Module().Enabled() {
947 return
948 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900949 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900950 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000951 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900952 // apex bundle itself is mutated so that it and its modules have same
953 // apex variant.
954 apexBundleName := mctx.ModuleName()
955 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900956 } else if o, ok := mctx.Module().(*OverrideApex); ok {
957 apexBundleName := o.GetOverriddenModuleName()
958 if apexBundleName == "" {
959 mctx.ModuleErrorf("base property is not set")
960 return
961 }
962 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900963 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900964
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900965}
Sundong Ahne9b55722019-09-06 17:37:42 +0900966
Jooyung Han7a78a922019-10-08 21:59:58 +0900967var (
968 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
969 apexFileContextsInfosMutex sync.Mutex
970)
971
972func apexFileContextsInfos(config android.Config) *[]string {
973 return config.Once(apexFileContextsInfosKey, func() interface{} {
974 return &[]string{}
975 }).(*[]string)
976}
977
Jooyung Han54aca7b2019-11-20 02:26:02 +0900978func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900979 apexFileContextsInfosMutex.Lock()
980 defer apexFileContextsInfosMutex.Unlock()
981 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900982 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900983}
984
Sundong Ahne9b55722019-09-06 17:37:42 +0900985func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900986 if !mctx.Module().Enabled() {
987 return
988 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900989 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900990 var variants []string
991 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
992 case "image":
993 variants = append(variants, imageApexType, flattenedApexType)
994 case "zip":
995 variants = append(variants, zipApexType)
996 case "both":
997 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
998 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900999 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001000 return
1001 }
1002
1003 modules := mctx.CreateLocalVariations(variants...)
1004
1005 for i, v := range variants {
1006 switch v {
1007 case imageApexType:
1008 modules[i].(*apexBundle).properties.ApexType = imageApex
1009 case zipApexType:
1010 modules[i].(*apexBundle).properties.ApexType = zipApex
1011 case flattenedApexType:
1012 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001013 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001014 modules[i].(*apexBundle).MakeAsSystemExt()
1015 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001016 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001017 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001018 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1019 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001020 }
1021}
1022
Jooyung Han5c998b92019-06-27 11:30:33 +09001023func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1024 if ab, ok := mctx.Module().(*apexBundle); ok {
1025 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1026 }
1027}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001028
Jooyung Handc782442019-11-01 03:14:38 +09001029var (
1030 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1031)
1032
1033// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1034// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1035// which may cause compatibility issues. (e.g. libbinder)
1036// Even though libbinder restricts its availability via 'apex_available' property and relies on
1037// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1038// to avoid similar problems.
1039func useVendorWhitelist(config android.Config) []string {
1040 return config.Once(useVendorWhitelistKey, func() interface{} {
1041 return []string{
1042 // swcodec uses "vendor" variants for smaller size
1043 "com.android.media.swcodec",
1044 "test_com.android.media.swcodec",
1045 }
1046 }).([]string)
1047}
1048
1049// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1050// called before the first call to useVendorWhitelist()
1051func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1052 config.Once(useVendorWhitelistKey, func() interface{} {
1053 return whitelist
1054 })
1055}
1056
Alex Light9670d332019-01-29 18:07:33 -08001057type apexNativeDependencies struct {
1058 // List of native libraries
1059 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001060
Alex Light9670d332019-01-29 18:07:33 -08001061 // List of native executables
1062 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001063
Roland Levillain630846d2019-06-26 12:48:34 +01001064 // List of native tests
1065 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001066}
Jooyung Han344d5432019-08-23 11:17:39 +09001067
Alex Light9670d332019-01-29 18:07:33 -08001068type apexMultilibProperties struct {
1069 // Native dependencies whose compile_multilib is "first"
1070 First apexNativeDependencies
1071
1072 // Native dependencies whose compile_multilib is "both"
1073 Both apexNativeDependencies
1074
1075 // Native dependencies whose compile_multilib is "prefer32"
1076 Prefer32 apexNativeDependencies
1077
1078 // Native dependencies whose compile_multilib is "32"
1079 Lib32 apexNativeDependencies
1080
1081 // Native dependencies whose compile_multilib is "64"
1082 Lib64 apexNativeDependencies
1083}
1084
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001085type apexBundleProperties struct {
1086 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001087 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001088 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001089
Jiyong Park40e26a22019-02-08 02:53:06 +09001090 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1091 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001092 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001093
Roland Levillain411c5842019-09-19 16:37:20 +01001094 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1095 // device (/apex/<apex_name>).
1096 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001097 Apex_name *string
1098
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001099 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001100 // For platform APEXes, this should points to a file under /system/sepolicy
1101 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1102 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001103
1104 // List of native shared libs that are embedded inside this APEX bundle
1105 Native_shared_libs []string
1106
Roland Levillain630846d2019-06-26 12:48:34 +01001107 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001108 Binaries []string
1109
1110 // List of java libraries that are embedded inside this APEX bundle
1111 Java_libs []string
1112
1113 // List of prebuilt files that are embedded inside this APEX bundle
1114 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001115
Roland Levillain630846d2019-06-26 12:48:34 +01001116 // List of tests that are embedded inside this APEX bundle
1117 Tests []string
1118
Jiyong Parkff1458f2018-10-12 21:49:38 +09001119 // Name of the apex_key module that provides the private key to sign APEX
1120 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001121
Alex Light5098a612018-11-29 17:12:15 -08001122 // The type of APEX to build. Controls what the APEX payload is. Either
1123 // 'image', 'zip' or 'both'. Default: 'image'.
1124 Payload_type *string
1125
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001126 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1127 // or an android_app_certificate module name in the form ":module".
1128 Certificate *string
1129
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001130 // Whether this APEX is installable to one of the partitions. Default: true.
1131 Installable *bool
1132
Jiyong Parkda6eb592018-12-19 17:12:36 +09001133 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1134 // Default is false.
1135 Use_vendor *bool
1136
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001137 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1138 Ignore_system_library_special_case *bool
1139
Alex Light9670d332019-01-29 18:07:33 -08001140 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001141
Jiyong Parkf97782b2019-02-13 20:28:58 +09001142 // List of sanitizer names that this APEX is enabled for
1143 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001144
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001145 PreventInstall bool `blueprint:"mutated"`
1146
1147 HideFromMake bool `blueprint:"mutated"`
1148
Jooyung Han5c998b92019-06-27 11:30:33 +09001149 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1150 Provide_cpp_shared_libs *bool
1151
1152 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1153 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001154
1155 // A txt file containing list of files that are whitelisted to be included in this APEX.
1156 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001157
Sundong Ahnabb64432019-10-22 13:58:29 +09001158 // package format of this apex variant; could be non-flattened, flattened, or zip.
1159 // imageApex, zipApex or flattened
1160 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001161
Jiyong Parkd1063c12019-07-17 20:08:41 +09001162 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1163 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1164 // is implied. This value affects all modules included in this APEX. In other words, they are
1165 // also built with the SDKs specified here.
1166 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001167
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001168 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1169 // Should be only used in tests#.
1170 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001171
Jiyong Park956305c2020-01-09 12:32:06 +09001172 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001173
1174 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1175 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1176 // like symlinking to the system libs. Default is false.
1177 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001178
1179 // The minimum SDK version that this apex must be compatible with.
1180 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001181}
1182
1183type apexTargetBundleProperties struct {
1184 Target struct {
1185 // Multilib properties only for android.
1186 Android struct {
1187 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001188 }
Jooyung Han344d5432019-08-23 11:17:39 +09001189
Alex Light9670d332019-01-29 18:07:33 -08001190 // Multilib properties only for host.
1191 Host struct {
1192 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001193 }
Jooyung Han344d5432019-08-23 11:17:39 +09001194
Alex Light9670d332019-01-29 18:07:33 -08001195 // Multilib properties only for host linux_bionic.
1196 Linux_bionic struct {
1197 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001198 }
Jooyung Han344d5432019-08-23 11:17:39 +09001199
Alex Light9670d332019-01-29 18:07:33 -08001200 // Multilib properties only for host linux_glibc.
1201 Linux_glibc struct {
1202 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001203 }
1204 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001205}
1206
Jiyong Park5d790c32019-11-15 18:40:32 +09001207type overridableProperties struct {
1208 // List of APKs to package inside APEX
1209 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001210
1211 // Names of modules to be overridden. Listed modules can only be other binaries
1212 // (in Make or Soong).
1213 // This does not completely prevent installation of the overridden binaries, but if both
1214 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1215 // from PRODUCT_PACKAGES.
1216 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001217
1218 // Logging Parent value
1219 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001220
1221 // Apex Container Package Name.
1222 // Override value for attribute package:name in AndroidManifest.xml
1223 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001224}
1225
Alex Light5098a612018-11-29 17:12:15 -08001226type apexPackaging int
1227
1228const (
1229 imageApex apexPackaging = iota
1230 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001231 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001232)
1233
Sundong Ahnabb64432019-10-22 13:58:29 +09001234// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001235func (a apexPackaging) suffix() string {
1236 switch a {
1237 case imageApex:
1238 return imageApexSuffix
1239 case zipApex:
1240 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001241 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001242 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001243 }
1244}
1245
1246func (a apexPackaging) name() string {
1247 switch a {
1248 case imageApex:
1249 return imageApexType
1250 case zipApex:
1251 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001252 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001253 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001254 }
1255}
1256
Jiyong Parkf653b052019-11-18 15:39:01 +09001257type apexFileClass int
1258
1259const (
1260 etc apexFileClass = iota
1261 nativeSharedLib
1262 nativeExecutable
1263 shBinary
1264 pyBinary
1265 goBinary
1266 javaSharedLib
1267 nativeTest
1268 app
1269)
1270
Jiyong Park8fd61922018-11-08 02:50:25 +09001271func (class apexFileClass) NameInMake() string {
1272 switch class {
1273 case etc:
1274 return "ETC"
1275 case nativeSharedLib:
1276 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001277 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001278 return "EXECUTABLES"
1279 case javaSharedLib:
1280 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001281 case nativeTest:
1282 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001283 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001284 // b/142537672 Why isn't this APP? We want to have full control over
1285 // the paths and file names of the apk file under the flattend APEX.
1286 // If this is set to APP, then the paths and file names are modified
1287 // by the Make build system. For example, it is installed to
1288 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1289 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1290 // appends module name (which is <apexname>.<Appname> to the path.
1291 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001292 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001293 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001294 }
1295}
1296
Jiyong Parkf653b052019-11-18 15:39:01 +09001297// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001298type apexFile struct {
1299 builtFile android.Path
1300 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001301 installDir string
1302 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001303 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001304 // list of symlinks that will be created in installDir that point to this apexFile
1305 symlinks []string
1306 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001307 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001308
1309 requiredModuleNames []string
1310 targetRequiredModuleNames []string
1311 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001312
Colin Cross503c1d02020-01-28 14:00:53 -08001313 jacocoReportClassesFile android.Path // only for javalibs and apps
1314 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001315 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001316}
1317
Jiyong Park1833cef2019-12-13 13:28:36 +09001318func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1319 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001320 builtFile: builtFile,
1321 moduleName: moduleName,
1322 installDir: installDir,
1323 class: class,
1324 module: module,
1325 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001326 if module != nil {
1327 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001328 ret.requiredModuleNames = module.RequiredModuleNames()
1329 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1330 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001331 }
1332 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001333}
1334
1335func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001336 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001337}
1338
Jiyong Park7cd10e32020-01-14 09:22:18 +09001339// Path() returns path of this apex file relative to the APEX root
1340func (af *apexFile) Path() string {
1341 return filepath.Join(af.installDir, af.builtFile.Base())
1342}
1343
1344// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1345func (af *apexFile) SymlinkPaths() []string {
1346 var ret []string
1347 for _, symlink := range af.symlinks {
1348 ret = append(ret, filepath.Join(af.installDir, symlink))
1349 }
1350 return ret
1351}
1352
1353func (af *apexFile) AvailableToPlatform() bool {
1354 if af.module == nil {
1355 return false
1356 }
1357 if am, ok := af.module.(android.ApexModule); ok {
1358 return am.AvailableFor(android.AvailableToPlatform)
1359 }
1360 return false
1361}
1362
Jiyong Park678c8812020-02-07 17:25:49 +09001363type depInfo struct {
1364 to string
1365 from []string
1366 isExternal bool
1367}
1368
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001369type apexBundle struct {
1370 android.ModuleBase
1371 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001372 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001373 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001374
Jiyong Park5d790c32019-11-15 18:40:32 +09001375 properties apexBundleProperties
1376 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001377 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001378
Jooyung Hanf21c7972019-12-16 22:32:06 +09001379 // specific to apex_vndk modules
1380 vndkProperties apexVndkProperties
1381
Colin Crossa4925902018-11-16 11:36:28 -08001382 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001383 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001384 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001385
Jiyong Park03b68dd2019-07-26 23:20:40 +09001386 prebuiltFileToDelete string
1387
Jiyong Park42cca6c2019-04-01 11:15:50 +09001388 public_key_file android.Path
1389 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001390
1391 container_certificate_file android.Path
1392 container_private_key_file android.Path
1393
Jooyung Han54aca7b2019-11-20 02:26:02 +09001394 fileContexts android.Path
1395
Jiyong Park8fd61922018-11-08 02:50:25 +09001396 // list of files to be included in this apex
1397 filesInfo []apexFile
1398
Jiyong Park956305c2020-01-09 12:32:06 +09001399 // list of module names that should be installed along with this APEX
1400 requiredDeps []string
1401
Jiyong Park956305c2020-01-09 12:32:06 +09001402 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001403 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001404
Sundong Ahnabb64432019-10-22 13:58:29 +09001405 testApex bool
1406 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001407 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001408 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001409
Jooyung Han214bf372019-11-12 13:03:50 +09001410 manifestJsonOut android.WritablePath
1411 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001412
Jooyung Han002ab682020-01-08 01:57:58 +09001413 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001414 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001415 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001416 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1417 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001418
1419 // Suffix of module name in Android.mk
1420 // ".flattened", ".apex", ".zipapex", or ""
1421 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001422
1423 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001424
1425 // Whether to create symlink to the system file instead of having a file
1426 // inside the apex or not
1427 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001428
1429 // Struct holding the merged notice file paths in different formats
1430 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001431}
1432
Jiyong Park397e55e2018-10-24 21:09:55 +09001433func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001434 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001435 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001436 // Use *FarVariation* to be able to depend on modules having
1437 // conflicting variations with this module. This is required since
1438 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1439 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001440 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001441 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001442 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001443 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001444 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001445
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001446 ctx.AddFarVariationDependencies(append(target.Variations(),
1447 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1448 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001449
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001450 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001451 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001452 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001453 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001454}
1455
Alex Light9670d332019-01-29 18:07:33 -08001456func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1457 if ctx.Os().Class == android.Device {
1458 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1459 } else {
1460 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1461 if ctx.Os().Bionic() {
1462 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1463 } else {
1464 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1465 }
1466 }
1467}
1468
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001469func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001470 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1471 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1472 }
1473
Jiyong Park397e55e2018-10-24 21:09:55 +09001474 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001475 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001476
1477 a.combineProperties(ctx)
1478
Jiyong Park397e55e2018-10-24 21:09:55 +09001479 has32BitTarget := false
1480 for _, target := range targets {
1481 if target.Arch.ArchType.Multilib == "lib32" {
1482 has32BitTarget = true
1483 }
1484 }
1485 for i, target := range targets {
1486 // When multilib.* is omitted for native_shared_libs, it implies
1487 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001488 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001489 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001490 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001491 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001492
Roland Levillain630846d2019-06-26 12:48:34 +01001493 // When multilib.* is omitted for tests, it implies
1494 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001495 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001496 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001497 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001498 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001499
Jiyong Park397e55e2018-10-24 21:09:55 +09001500 // Add native modules targetting both ABIs
1501 addDependenciesForNativeModules(ctx,
1502 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001503 a.properties.Multilib.Both.Binaries,
1504 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001505 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001506 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001507
Alex Light3d673592019-01-18 14:37:31 -08001508 isPrimaryAbi := i == 0
1509 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001510 // When multilib.* is omitted for binaries, it implies
1511 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001512 ctx.AddFarVariationDependencies(append(target.Variations(),
1513 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1514 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001515
1516 // Add native modules targetting the first ABI
1517 addDependenciesForNativeModules(ctx,
1518 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001519 a.properties.Multilib.First.Binaries,
1520 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001521 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001522 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001523 }
1524
1525 switch target.Arch.ArchType.Multilib {
1526 case "lib32":
1527 // Add native modules targetting 32-bit ABI
1528 addDependenciesForNativeModules(ctx,
1529 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001530 a.properties.Multilib.Lib32.Binaries,
1531 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001532 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001533 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001534
1535 addDependenciesForNativeModules(ctx,
1536 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001537 a.properties.Multilib.Prefer32.Binaries,
1538 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001539 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001540 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001541 case "lib64":
1542 // Add native modules targetting 64-bit ABI
1543 addDependenciesForNativeModules(ctx,
1544 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001545 a.properties.Multilib.Lib64.Binaries,
1546 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001547 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001548 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001549
1550 if !has32BitTarget {
1551 addDependenciesForNativeModules(ctx,
1552 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001553 a.properties.Multilib.Prefer32.Binaries,
1554 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001555 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001556 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001557 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001558
1559 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1560 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1561 if sanitizer == "hwaddress" {
1562 addDependenciesForNativeModules(ctx,
1563 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001564 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001565 break
1566 }
1567 }
1568 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001569 }
1570
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001571 }
1572
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001573 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1574 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1575 // b/144532908
1576 archForPrebuiltEtc := config.Arches()[0]
1577 for _, arch := range config.Arches() {
1578 // Prefer 64-bit arch if there is any
1579 if arch.ArchType.Multilib == "lib64" {
1580 archForPrebuiltEtc = arch
1581 break
1582 }
1583 }
1584 ctx.AddFarVariationDependencies([]blueprint.Variation{
1585 {Mutator: "os", Variation: ctx.Os().String()},
1586 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1587 }, prebuiltTag, a.properties.Prebuilts...)
1588
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001589 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1590 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001591
Ulya Trafimovich44561882020-01-03 13:25:54 +00001592 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1593 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1594 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1595 javaLibTag, "jacocoagent")
1596 }
1597
Jiyong Park23c52b02019-02-02 13:13:47 +09001598 if String(a.properties.Key) == "" {
1599 ctx.ModuleErrorf("key is missing")
1600 return
1601 }
1602 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001603
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001604 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001605 if cert != "" {
1606 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001607 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001608
1609 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1610 if len(a.properties.Uses_sdks) > 0 {
1611 sdkRefs := []android.SdkRef{}
1612 for _, str := range a.properties.Uses_sdks {
1613 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1614 sdkRefs = append(sdkRefs, parsed)
1615 }
1616 a.BuildWithSdks(sdkRefs)
1617 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001618}
1619
Jiyong Park5d790c32019-11-15 18:40:32 +09001620func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1621 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1622 androidAppTag, a.overridableProperties.Apps...)
1623}
1624
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001625func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1626 // direct deps of an APEX bundle are all part of the APEX bundle
1627 return true
1628}
1629
Colin Cross0ea8ba82019-06-06 14:33:29 -07001630func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001631 moduleName := ctx.ModuleName()
1632 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1633 // we check with the pseudo module name to see if its certificate is overridden.
1634 if a.vndkApex {
1635 moduleName = vndkApexName
1636 }
1637 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001638 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001639 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001640 }
1641 return String(a.properties.Certificate)
1642}
1643
Colin Cross41955e82019-05-29 14:40:35 -07001644func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1645 switch tag {
1646 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001647 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001648 default:
1649 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001650 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001651}
1652
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001653func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001654 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001655}
1656
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001657func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1658 return proptools.Bool(a.properties.Test_only_no_hashtree)
1659}
1660
Jiyong Park7c1dc612019-01-05 11:15:24 +09001661func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001662 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001663 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001664 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001665 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001666 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001667 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001668 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001669 }
1670}
1671
Jiyong Parkf97782b2019-02-13 20:28:58 +09001672func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1673 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1674 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1675 }
1676}
1677
Jiyong Park388ef3f2019-01-28 19:47:32 +09001678func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001679 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1680 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001681 }
1682
1683 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001684 globalSanitizerNames := []string{}
1685 if a.Host() {
1686 globalSanitizerNames = ctx.Config().SanitizeHost()
1687 } else {
1688 arches := ctx.Config().SanitizeDeviceArch()
1689 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1690 globalSanitizerNames = ctx.Config().SanitizeDevice()
1691 }
1692 }
1693 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001694}
1695
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001696func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001697 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001698}
1699
1700func (a *apexBundle) PreventInstall() {
1701 a.properties.PreventInstall = true
1702}
1703
1704func (a *apexBundle) HideFromMake() {
1705 a.properties.HideFromMake = true
1706}
1707
Jiyong Park956305c2020-01-09 12:32:06 +09001708func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1709 a.properties.IsCoverageVariant = coverage
1710}
1711
Jiyong Parkf653b052019-11-18 15:39:01 +09001712// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001713func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001714 // Decide the APEX-local directory by the multilib of the library
1715 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001716 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001717 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001718 case "lib32":
1719 dirInApex = "lib"
1720 case "lib64":
1721 dirInApex = "lib64"
1722 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001723 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001724 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001725 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001726 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001727 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001728 // Special case for Bionic libs and other libs installed with them. This is
1729 // to prevent those libs from being included in the search path
1730 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1731 // those libs in the Runtime APEX are available via the legacy paths in
1732 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1733 // to the legacy paths and thus will be loaded into the default linker
1734 // namespace (aka "platform" namespace). If the libs are directly in
1735 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1736 // into the runtime linker namespace, which will result in double loading of
1737 // them, which isn't supported.
1738 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001739 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001740
Jiyong Parkf653b052019-11-18 15:39:01 +09001741 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001742 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001743}
1744
Jiyong Park1833cef2019-12-13 13:28:36 +09001745func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001746 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001747 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001748 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001749 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001750 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001751 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001752 af.symlinks = cc.Symlinks()
1753 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001754}
1755
Jiyong Park1833cef2019-12-13 13:28:36 +09001756func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001757 dirInApex := "bin"
1758 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001759 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001760}
Jiyong Park1833cef2019-12-13 13:28:36 +09001761func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001762 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001763 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1764 if err != nil {
1765 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001766 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001767 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001768 fileToCopy := android.PathForOutput(ctx, s)
1769 // NB: Since go binaries are static we don't need the module for anything here, which is
1770 // good since the go tool is a blueprint.Module not an android.Module like we would
1771 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001772 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001773}
1774
Jiyong Park1833cef2019-12-13 13:28:36 +09001775func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001776 dirInApex := filepath.Join("bin", sh.SubDir())
1777 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001778 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001779 af.symlinks = sh.Symlinks()
1780 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001781}
1782
Jooyung Han58f26ab2019-12-18 15:34:32 +09001783// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1784type javaLibrary interface {
1785 android.Module
1786 java.Dependency
1787}
1788
1789func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001790 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001791 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001792 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1793 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1794 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001795}
1796
Jiyong Park1833cef2019-12-13 13:28:36 +09001797func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001798 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1799 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001800 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001801}
1802
atrost6e126252020-01-27 17:01:16 +00001803func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1804 dirInApex := filepath.Join("etc", config.SubDir())
1805 fileToCopy := config.CompatConfig()
1806 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1807}
1808
Jiyong Park1833cef2019-12-13 13:28:36 +09001809func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001810 android.Module
1811 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001812 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001813 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001814 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001815 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001816}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001817 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001818 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001819 appDir = "priv-app"
1820 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001821 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001822 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001823 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1824 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001825 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001826
1827 if app, ok := aapp.(interface {
1828 OverriddenManifestPackageName() string
1829 }); ok {
1830 af.overriddenPackageName = app.OverriddenManifestPackageName()
1831 }
Jiyong Park618922e2020-01-08 13:35:43 +09001832 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001833}
1834
Roland Levillain935639d2019-08-13 14:55:28 +01001835// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1836type flattenedApexContext struct {
1837 android.ModuleContext
1838}
1839
1840func (c *flattenedApexContext) InstallBypassMake() bool {
1841 return true
1842}
1843
Paul Duffin133608f2020-03-30 15:54:08 +01001844// Function called while walking an APEX's payload dependencies.
1845//
1846// Return true if the `to` module should be visited, false otherwise.
1847type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1848
Jiyong Park201cedd2020-02-07 17:25:49 +09001849// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001850func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001851 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001852 am, ok := child.(android.ApexModule)
1853 if !ok || !am.CanHaveApexVariants() {
1854 return false
1855 }
1856
1857 // Check for the direct dependencies that contribute to the payload
1858 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1859 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001860 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001861 }
Paul Duffin133608f2020-03-30 15:54:08 +01001862 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001863 return false
1864 }
1865
1866 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001867 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001868 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001869 }
1870
Paul Duffin133608f2020-03-30 15:54:08 +01001871 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001872 })
1873}
1874
Jooyung Han0c4e0162020-02-26 22:45:42 +09001875func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1876 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001877 intVer, err := android.ApiStrToNum(ctx, ver)
1878 if err != nil {
1879 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001880 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001881 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001882}
1883
Paul Duffinf0207962020-03-31 11:31:36 +01001884// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1885// a dependency tag.
1886var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1887
1888func PrettyPrintTag(tag blueprint.DependencyTag) string {
1889 // Use tag's custom String() method if available.
1890 if stringer, ok := tag.(fmt.Stringer); ok {
1891 return stringer.String()
1892 }
1893
1894 // Otherwise, get a default string representation of the tag's struct.
1895 tagString := fmt.Sprintf("%#v", tag)
1896
1897 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1898 tagString = tagCleaner.ReplaceAllString(tagString, "")
1899 return tagString
1900}
1901
Jiyong Park201cedd2020-02-07 17:25:49 +09001902// Ensures that the dependencies are marked as available for this APEX
1903func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1904 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1905 if ctx.Host() || a.testApex || a.vndkApex {
1906 return
1907 }
1908
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001909 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1910 // Requiring them and their transitive depencies with apex_available is not right
1911 // because they just add noise.
1912 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1913 return
1914 }
1915
Paul Duffin133608f2020-03-30 15:54:08 +01001916 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1917 if externalDep {
1918 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1919 return false
1920 }
1921
Jiyong Park201cedd2020-02-07 17:25:49 +09001922 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001923 fromName := ctx.OtherModuleName(from)
1924 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001925
1926 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1927 // do any of its dependencies.
1928 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1929 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1930 return false
1931 }
1932
Paul Duffin133608f2020-03-30 15:54:08 +01001933 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1934 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001935 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001936 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001937 tagPath := ctx.GetTagPath()
1938 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1939 walkPath := ctx.GetWalkPath()[1:]
1940 for i, m := range walkPath {
1941 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001942 }
1943 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffin133608f2020-03-30 15:54:08 +01001944 // Visit this module's dependencies to check and report any issues with their availability.
1945 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001946 })
1947}
1948
Jiyong Park678c8812020-02-07 17:25:49 +09001949// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1950func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1951 a.depInfos = make(map[string]depInfo)
Paul Duffin133608f2020-03-30 15:54:08 +01001952 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001953 if from.Name() == to.Name() {
1954 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffin133608f2020-03-30 15:54:08 +01001955 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1956 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001957 }
1958
1959 if info, exists := a.depInfos[to.Name()]; exists {
1960 if !android.InList(from.Name(), info.from) {
1961 info.from = append(info.from, from.Name())
1962 }
1963 info.isExternal = info.isExternal && externalDep
1964 a.depInfos[to.Name()] = info
1965 } else {
1966 a.depInfos[to.Name()] = depInfo{
1967 to: to.Name(),
1968 from: []string{from.Name()},
1969 isExternal: externalDep,
1970 }
1971 }
Paul Duffin133608f2020-03-30 15:54:08 +01001972
1973 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1974 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001975 })
1976}
1977
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001978func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001979 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1980 switch a.properties.ApexType {
1981 case imageApex:
1982 if buildFlattenedAsDefault {
1983 a.suffix = imageApexSuffix
1984 } else {
1985 a.suffix = ""
1986 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001987
1988 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001989 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001990 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001991 }
1992 case zipApex:
1993 if proptools.String(a.properties.Payload_type) == "zip" {
1994 a.suffix = ""
1995 a.primaryApexType = true
1996 } else {
1997 a.suffix = zipApexSuffix
1998 }
1999 case flattenedApex:
2000 if buildFlattenedAsDefault {
2001 a.suffix = ""
2002 a.primaryApexType = true
2003 } else {
2004 a.suffix = flattenedSuffix
2005 }
Alex Light5098a612018-11-29 17:12:15 -08002006 }
2007
Roland Levillain630846d2019-06-26 12:48:34 +01002008 if len(a.properties.Tests) > 0 && !a.testApex {
2009 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2010 return
2011 }
2012
Jiyong Parkfa899442020-01-31 02:49:53 +09002013 a.checkApexAvailability(ctx)
2014
Jiyong Park678c8812020-02-07 17:25:49 +09002015 a.collectDepsInfo(ctx)
2016
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002017 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2018
Jooyung Hane1633032019-08-01 17:41:43 +09002019 // native lib dependencies
2020 var provideNativeLibs []string
2021 var requireNativeLibs []string
2022
Jooyung Han5c998b92019-06-27 11:30:33 +09002023 // Check if "uses" requirements are met with dependent apexBundles
2024 var providedNativeSharedLibs []string
2025 useVendor := proptools.Bool(a.properties.Use_vendor)
2026 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2027 if ctx.OtherModuleDependencyTag(m) != usesTag {
2028 return
2029 }
2030 otherName := ctx.OtherModuleName(m)
2031 other, ok := m.(*apexBundle)
2032 if !ok {
2033 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2034 return
2035 }
2036 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2037 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2038 return
2039 }
2040 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2041 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2042 return
2043 }
2044 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2045 })
2046
Jiyong Parkf653b052019-11-18 15:39:01 +09002047 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002048 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002049 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002050 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01002051 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2052 return false
2053 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002054 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002055 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002056 switch depTag {
2057 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002058 if c, ok := child.(*cc.Module); ok {
2059 // bootstrap bionic libs are treated as provided by system
2060 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2061 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002062 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002063 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002064 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002065 } else {
2066 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002067 }
2068 case executableTag:
2069 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002070 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002071 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002072 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002073 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002074 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002075 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002076 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002077 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002078 } else {
Alex Light778127a2019-02-27 14:19:50 -08002079 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 +09002080 }
2081 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002082 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002083 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002084 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002085 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2086 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002087 filesInfo = append(filesInfo, af)
2088 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002089 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002090 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2091 af := apexFileForJavaLibrary(ctx, sdkLib)
2092 if !af.Ok() {
2093 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2094 return false
2095 }
2096 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002097 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002098 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002099 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002100 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002101 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002102 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002103 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002104 return true // track transitive dependencies
2105 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002106 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002107 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002108 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002109 } else {
2110 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2111 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002112 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002113 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002114 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002115 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2116 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002117 } else {
atrost6e126252020-01-27 17:01:16 +00002118 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002119 }
Roland Levillain630846d2019-06-26 12:48:34 +01002120 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002121 if ccTest, ok := child.(*cc.Module); ok {
2122 if ccTest.IsTestPerSrcAllTestsVariation() {
2123 // Multiple-output test module (where `test_per_src: true`).
2124 //
2125 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2126 // We do not add this variation to `filesInfo`, as it has no output;
2127 // however, we do add the other variations of this module as indirect
2128 // dependencies (see below).
2129 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002130 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002131 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002132 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002133 af.class = nativeTest
2134 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002135 }
Roland Levillain630846d2019-06-26 12:48:34 +01002136 } else {
2137 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2138 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002139 case keyTag:
2140 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002141 a.private_key_file = key.private_key_file
2142 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002143 } else {
2144 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002145 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002146 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002147 case certificateTag:
2148 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002149 a.container_certificate_file = dep.Certificate.Pem
2150 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002151 } else {
2152 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2153 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002154 case android.PrebuiltDepTag:
2155 // If the prebuilt is force disabled, remember to delete the prebuilt file
2156 // that might have been installed in the previous builds
2157 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2158 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2159 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002160 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002161 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002162 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002163 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002164 // We cannot use a switch statement on `depTag` here as the checked
2165 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002166 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002167 if cc, ok := child.(*cc.Module); ok {
2168 if android.InList(cc.Name(), providedNativeSharedLibs) {
2169 // If we're using a shared library which is provided from other APEX,
2170 // don't include it in this APEX
2171 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002172 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002173 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002174 // If the dependency is a stubs lib, don't include it in this APEX,
2175 // but make sure that the lib is installed on the device.
2176 // In case no APEX is having the lib, the lib is installed to the system
2177 // partition.
2178 //
2179 // Always include if we are a host-apex however since those won't have any
2180 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002181 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2182 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002183 }
Jooyung Hane1633032019-08-01 17:41:43 +09002184 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002185 // Don't track further
2186 return false
2187 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002188 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002189 af.transitiveDep = true
2190 filesInfo = append(filesInfo, af)
2191 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002192 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002193 } else if cc.IsTestPerSrcDepTag(depTag) {
2194 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002195 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002196 // Handle modules created as `test_per_src` variations of a single test module:
2197 // use the name of the generated test binary (`fileToCopy`) instead of the name
2198 // of the original test module (`depName`, shared by all `test_per_src`
2199 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002200 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002201 // these are not considered transitive dep
2202 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002203 filesInfo = append(filesInfo, af)
2204 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002205 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002206 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002207 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2208 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002209 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2210 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2211 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2212 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002213 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002214 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002215 }
2216 }
2217 }
2218 return false
2219 })
2220
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002221 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2222 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2223 // via the global boot image config.
2224 if a.artApex {
2225 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2226 dirInApex := filepath.Join("javalib", arch.String())
2227 for _, f := range files {
2228 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002229 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002230 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002231 }
2232 }
2233 }
2234
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002235 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002236 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2237 return
2238 }
2239
Jiyong Park8fd61922018-11-08 02:50:25 +09002240 // remove duplicates in filesInfo
2241 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002242 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002243 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002244 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002245 if e, ok := encountered[dest]; !ok {
2246 encountered[dest] = f
2247 } else {
2248 // If a module is directly included and also transitively depended on
2249 // consider it as directly included.
2250 e.transitiveDep = e.transitiveDep && f.transitiveDep
2251 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002252 }
2253 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002254 var result []apexFile
2255 for _, v := range encountered {
2256 result = append(result, v)
2257 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002258 return result
2259 }
2260 filesInfo = removeDup(filesInfo)
2261
2262 // to have consistent build rules
2263 sort.Slice(filesInfo, func(i, j int) bool {
2264 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2265 })
2266
Jiyong Park8fd61922018-11-08 02:50:25 +09002267 a.installDir = android.PathForModuleInstall(ctx, "apex")
2268 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002269
Jooyung Han54aca7b2019-11-20 02:26:02 +09002270 if a.properties.ApexType != zipApex {
2271 if a.properties.File_contexts == nil {
2272 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2273 } else {
2274 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2275 if a.Platform() {
2276 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2277 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2278 }
2279 }
2280 }
2281 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2282 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2283 return
2284 }
2285 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002286 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2287 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2288 // the same library in the system partition, thus effectively sharing the same libraries
2289 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2290 // in the APEX.
2291 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2292 a.installable() &&
2293 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002294
Jiyong Park9d677202020-02-19 16:29:35 +09002295 // We don't need the optimization for updatable APEXes, as it might give false signal
2296 // to the system health when the APEXes are still bundled (b/149805758)
2297 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2298 a.linkToSystemLib = false
2299 }
2300
Jiyong Park9b964182020-02-26 18:27:19 +09002301 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2302 if ctx.Host() {
2303 a.linkToSystemLib = false
2304 }
2305
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002306 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002307 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2308
2309 a.setCertificateAndPrivateKey(ctx)
2310 if a.properties.ApexType == flattenedApex {
2311 a.buildFlattenedApex(ctx)
2312 } else {
2313 a.buildUnflattenedApex(ctx)
2314 }
2315
Jooyung Han002ab682020-01-08 01:57:58 +09002316 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002317
2318 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002319}
2320
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002321func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002322 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002323 moduleName = normalizeModuleName(moduleName)
2324
2325 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2326 return true
2327 }
2328
2329 key = android.AvailableToAnyApex
2330 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2331 return true
2332 }
2333
2334 return false
2335}
2336
2337func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002338 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2339 // system. Trim the prefix for the check since they are confusing
2340 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2341 if strings.HasPrefix(moduleName, "libclang_rt.") {
2342 // This module has many arch variants that depend on the product being built.
2343 // We don't want to list them all
2344 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002345 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002346 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002347}
2348
Jooyung Han344d5432019-08-23 11:17:39 +09002349func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002350 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002351 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002352 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002353 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002354 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002355 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2356 })
Alex Light5098a612018-11-29 17:12:15 -08002357 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002358 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002359 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002360 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002361 return module
2362}
Jiyong Park30ca9372019-02-07 16:27:23 +09002363
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002364func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002365 bundle := newApexBundle()
2366 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002367 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002368 return bundle
2369}
2370
Jiyong Parkfce0b422020-02-11 03:56:06 +09002371// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2372// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002373func testApexBundleFactory() android.Module {
2374 bundle := newApexBundle()
2375 bundle.testApex = true
2376 return bundle
2377}
2378
Jiyong Parkfce0b422020-02-11 03:56:06 +09002379// apex packages other modules into an APEX file which is a packaging format for system-level
2380// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002381func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002382 return newApexBundle()
2383}
2384
Jiyong Park30ca9372019-02-07 16:27:23 +09002385//
2386// Defaults
2387//
2388type Defaults struct {
2389 android.ModuleBase
2390 android.DefaultsModuleBase
2391}
2392
Jiyong Park30ca9372019-02-07 16:27:23 +09002393func defaultsFactory() android.Module {
2394 return DefaultsFactory()
2395}
2396
2397func DefaultsFactory(props ...interface{}) android.Module {
2398 module := &Defaults{}
2399
2400 module.AddProperties(props...)
2401 module.AddProperties(
2402 &apexBundleProperties{},
2403 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002404 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002405 )
2406
2407 android.InitDefaultsModule(module)
2408 return module
2409}
Jiyong Park5d790c32019-11-15 18:40:32 +09002410
2411//
2412// OverrideApex
2413//
2414type OverrideApex struct {
2415 android.ModuleBase
2416 android.OverrideModuleBase
2417}
2418
2419func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2420 // All the overrides happen in the base module.
2421}
2422
2423// override_apex is used to create an apex module based on another apex module
2424// by overriding some of its properties.
2425func overrideApexFactory() android.Module {
2426 m := &OverrideApex{}
2427 m.AddProperties(&overridableProperties{})
2428
2429 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2430 android.InitOverrideModule(m)
2431 return m
2432}