blob: 82e2442e3c1f76c156bba015689d71037bb1b278 [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() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900809 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800810 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900811 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900812 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700813 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900814 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900815
Jooyung Han31c470b2019-10-18 16:26:59 +0900816 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900817 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900818
819 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
820 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
821 sort.Strings(*apexFileContextsInfos)
822 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
823 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900824}
825
Jooyung Han31c470b2019-10-18 16:26:59 +0900826func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
827 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
828 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
829}
830
Jiyong Parkd1063c12019-07-17 20:08:41 +0900831func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900832 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900833 ctx.BottomUp("apex", apexMutator).Parallel()
834 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
835 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900836}
837
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900838// Mark the direct and transitive dependencies of apex bundles so that they
839// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900840func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900841 if !mctx.Module().Enabled() {
842 return
843 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800844 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900845 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000846 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900847 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900848 ApexName: mctx.ModuleName(),
849 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900850 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900851 directDep = true
852 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800853 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900854 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900855 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900856
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800857 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900858 return
859 }
860
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100861 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900862
Jiyong Parkf760cae2020-02-12 07:53:12 +0900863 mctx.VisitDirectDeps(func(child android.Module) {
864 depName := mctx.OtherModuleName(child)
865 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100866 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800867 android.UpdateApexDependency(apexBundles, depName, directDep)
868 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900869 }
870 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900871}
872
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100873// If a module in an APEX depends on a module from an SDK then it needs an APEX
874// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
875func inAnySdk(module android.Module) bool {
876 if sa, ok := module.(android.SdkAware); ok {
877 return sa.IsInAnySdk()
878 }
879
880 return false
881}
882
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900883// Create apex variations if a module is included in APEX(s).
884func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900885 if !mctx.Module().Enabled() {
886 return
887 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900888 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900889 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000890 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900891 // apex bundle itself is mutated so that it and its modules have same
892 // apex variant.
893 apexBundleName := mctx.ModuleName()
894 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900895 } else if o, ok := mctx.Module().(*OverrideApex); ok {
896 apexBundleName := o.GetOverriddenModuleName()
897 if apexBundleName == "" {
898 mctx.ModuleErrorf("base property is not set")
899 return
900 }
901 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900902 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900903
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900904}
Sundong Ahne9b55722019-09-06 17:37:42 +0900905
Jooyung Han7a78a922019-10-08 21:59:58 +0900906var (
907 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
908 apexFileContextsInfosMutex sync.Mutex
909)
910
911func apexFileContextsInfos(config android.Config) *[]string {
912 return config.Once(apexFileContextsInfosKey, func() interface{} {
913 return &[]string{}
914 }).(*[]string)
915}
916
Jooyung Han54aca7b2019-11-20 02:26:02 +0900917func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900918 apexFileContextsInfosMutex.Lock()
919 defer apexFileContextsInfosMutex.Unlock()
920 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900921 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900922}
923
Sundong Ahne9b55722019-09-06 17:37:42 +0900924func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900925 if !mctx.Module().Enabled() {
926 return
927 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900928 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900929 var variants []string
930 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
931 case "image":
932 variants = append(variants, imageApexType, flattenedApexType)
933 case "zip":
934 variants = append(variants, zipApexType)
935 case "both":
936 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
937 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900938 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900939 return
940 }
941
942 modules := mctx.CreateLocalVariations(variants...)
943
944 for i, v := range variants {
945 switch v {
946 case imageApexType:
947 modules[i].(*apexBundle).properties.ApexType = imageApex
948 case zipApexType:
949 modules[i].(*apexBundle).properties.ApexType = zipApex
950 case flattenedApexType:
951 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900952 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900953 modules[i].(*apexBundle).MakeAsSystemExt()
954 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900955 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900956 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900957 } else if _, ok := mctx.Module().(*OverrideApex); ok {
958 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900959 }
960}
961
Jooyung Han5c998b92019-06-27 11:30:33 +0900962func apexUsesMutator(mctx android.BottomUpMutatorContext) {
963 if ab, ok := mctx.Module().(*apexBundle); ok {
964 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
965 }
966}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900967
Jooyung Handc782442019-11-01 03:14:38 +0900968var (
969 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
970)
971
972// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
973// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
974// which may cause compatibility issues. (e.g. libbinder)
975// Even though libbinder restricts its availability via 'apex_available' property and relies on
976// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
977// to avoid similar problems.
978func useVendorWhitelist(config android.Config) []string {
979 return config.Once(useVendorWhitelistKey, func() interface{} {
980 return []string{
981 // swcodec uses "vendor" variants for smaller size
982 "com.android.media.swcodec",
983 "test_com.android.media.swcodec",
984 }
985 }).([]string)
986}
987
988// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
989// called before the first call to useVendorWhitelist()
990func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
991 config.Once(useVendorWhitelistKey, func() interface{} {
992 return whitelist
993 })
994}
995
Alex Light9670d332019-01-29 18:07:33 -0800996type apexNativeDependencies struct {
997 // List of native libraries
998 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900999
Alex Light9670d332019-01-29 18:07:33 -08001000 // List of native executables
1001 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001002
Roland Levillain630846d2019-06-26 12:48:34 +01001003 // List of native tests
1004 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001005}
Jooyung Han344d5432019-08-23 11:17:39 +09001006
Alex Light9670d332019-01-29 18:07:33 -08001007type apexMultilibProperties struct {
1008 // Native dependencies whose compile_multilib is "first"
1009 First apexNativeDependencies
1010
1011 // Native dependencies whose compile_multilib is "both"
1012 Both apexNativeDependencies
1013
1014 // Native dependencies whose compile_multilib is "prefer32"
1015 Prefer32 apexNativeDependencies
1016
1017 // Native dependencies whose compile_multilib is "32"
1018 Lib32 apexNativeDependencies
1019
1020 // Native dependencies whose compile_multilib is "64"
1021 Lib64 apexNativeDependencies
1022}
1023
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001024type apexBundleProperties struct {
1025 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001026 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001027 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001028
Jiyong Park40e26a22019-02-08 02:53:06 +09001029 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1030 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001031 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001032
Roland Levillain411c5842019-09-19 16:37:20 +01001033 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1034 // device (/apex/<apex_name>).
1035 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001036 Apex_name *string
1037
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001038 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001039 // For platform APEXes, this should points to a file under /system/sepolicy
1040 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1041 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001042
1043 // List of native shared libs that are embedded inside this APEX bundle
1044 Native_shared_libs []string
1045
Roland Levillain630846d2019-06-26 12:48:34 +01001046 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001047 Binaries []string
1048
1049 // List of java libraries that are embedded inside this APEX bundle
1050 Java_libs []string
1051
1052 // List of prebuilt files that are embedded inside this APEX bundle
1053 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001054
Roland Levillain630846d2019-06-26 12:48:34 +01001055 // List of tests that are embedded inside this APEX bundle
1056 Tests []string
1057
Jiyong Parkff1458f2018-10-12 21:49:38 +09001058 // Name of the apex_key module that provides the private key to sign APEX
1059 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001060
Alex Light5098a612018-11-29 17:12:15 -08001061 // The type of APEX to build. Controls what the APEX payload is. Either
1062 // 'image', 'zip' or 'both'. Default: 'image'.
1063 Payload_type *string
1064
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001065 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1066 // or an android_app_certificate module name in the form ":module".
1067 Certificate *string
1068
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001069 // Whether this APEX is installable to one of the partitions. Default: true.
1070 Installable *bool
1071
Jiyong Parkda6eb592018-12-19 17:12:36 +09001072 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1073 // Default is false.
1074 Use_vendor *bool
1075
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001076 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1077 Ignore_system_library_special_case *bool
1078
Alex Light9670d332019-01-29 18:07:33 -08001079 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001080
Jiyong Parkf97782b2019-02-13 20:28:58 +09001081 // List of sanitizer names that this APEX is enabled for
1082 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001083
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001084 PreventInstall bool `blueprint:"mutated"`
1085
1086 HideFromMake bool `blueprint:"mutated"`
1087
Jooyung Han5c998b92019-06-27 11:30:33 +09001088 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1089 Provide_cpp_shared_libs *bool
1090
1091 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1092 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001093
1094 // A txt file containing list of files that are whitelisted to be included in this APEX.
1095 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001096
Sundong Ahnabb64432019-10-22 13:58:29 +09001097 // package format of this apex variant; could be non-flattened, flattened, or zip.
1098 // imageApex, zipApex or flattened
1099 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001100
Jiyong Parkd1063c12019-07-17 20:08:41 +09001101 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1102 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1103 // is implied. This value affects all modules included in this APEX. In other words, they are
1104 // also built with the SDKs specified here.
1105 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001106
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001107 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1108 // Should be only used in tests#.
1109 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001110
Jiyong Park956305c2020-01-09 12:32:06 +09001111 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001112
1113 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1114 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1115 // like symlinking to the system libs. Default is false.
1116 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001117
1118 // The minimum SDK version that this apex must be compatible with.
1119 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001120}
1121
1122type apexTargetBundleProperties struct {
1123 Target struct {
1124 // Multilib properties only for android.
1125 Android struct {
1126 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001127 }
Jooyung Han344d5432019-08-23 11:17:39 +09001128
Alex Light9670d332019-01-29 18:07:33 -08001129 // Multilib properties only for host.
1130 Host struct {
1131 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001132 }
Jooyung Han344d5432019-08-23 11:17:39 +09001133
Alex Light9670d332019-01-29 18:07:33 -08001134 // Multilib properties only for host linux_bionic.
1135 Linux_bionic struct {
1136 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001137 }
Jooyung Han344d5432019-08-23 11:17:39 +09001138
Alex Light9670d332019-01-29 18:07:33 -08001139 // Multilib properties only for host linux_glibc.
1140 Linux_glibc struct {
1141 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001142 }
1143 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001144}
1145
Jiyong Park5d790c32019-11-15 18:40:32 +09001146type overridableProperties struct {
1147 // List of APKs to package inside APEX
1148 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001149
1150 // Names of modules to be overridden. Listed modules can only be other binaries
1151 // (in Make or Soong).
1152 // This does not completely prevent installation of the overridden binaries, but if both
1153 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1154 // from PRODUCT_PACKAGES.
1155 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001156
1157 // Logging Parent value
1158 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001159
1160 // Apex Container Package Name.
1161 // Override value for attribute package:name in AndroidManifest.xml
1162 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001163}
1164
Alex Light5098a612018-11-29 17:12:15 -08001165type apexPackaging int
1166
1167const (
1168 imageApex apexPackaging = iota
1169 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001170 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001171)
1172
Sundong Ahnabb64432019-10-22 13:58:29 +09001173// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001174func (a apexPackaging) suffix() string {
1175 switch a {
1176 case imageApex:
1177 return imageApexSuffix
1178 case zipApex:
1179 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001180 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001181 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001182 }
1183}
1184
1185func (a apexPackaging) name() string {
1186 switch a {
1187 case imageApex:
1188 return imageApexType
1189 case zipApex:
1190 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001191 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001192 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001193 }
1194}
1195
Jiyong Parkf653b052019-11-18 15:39:01 +09001196type apexFileClass int
1197
1198const (
1199 etc apexFileClass = iota
1200 nativeSharedLib
1201 nativeExecutable
1202 shBinary
1203 pyBinary
1204 goBinary
1205 javaSharedLib
1206 nativeTest
1207 app
1208)
1209
Jiyong Park8fd61922018-11-08 02:50:25 +09001210func (class apexFileClass) NameInMake() string {
1211 switch class {
1212 case etc:
1213 return "ETC"
1214 case nativeSharedLib:
1215 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001216 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001217 return "EXECUTABLES"
1218 case javaSharedLib:
1219 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001220 case nativeTest:
1221 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001222 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001223 // b/142537672 Why isn't this APP? We want to have full control over
1224 // the paths and file names of the apk file under the flattend APEX.
1225 // If this is set to APP, then the paths and file names are modified
1226 // by the Make build system. For example, it is installed to
1227 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1228 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1229 // appends module name (which is <apexname>.<Appname> to the path.
1230 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001231 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001232 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001233 }
1234}
1235
Jiyong Parkf653b052019-11-18 15:39:01 +09001236// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001237type apexFile struct {
1238 builtFile android.Path
1239 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001240 installDir string
1241 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001242 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001243 // list of symlinks that will be created in installDir that point to this apexFile
1244 symlinks []string
1245 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001246 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001247
1248 requiredModuleNames []string
1249 targetRequiredModuleNames []string
1250 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001251
Colin Cross503c1d02020-01-28 14:00:53 -08001252 jacocoReportClassesFile android.Path // only for javalibs and apps
1253 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001254 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001255}
1256
Jiyong Park1833cef2019-12-13 13:28:36 +09001257func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1258 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001259 builtFile: builtFile,
1260 moduleName: moduleName,
1261 installDir: installDir,
1262 class: class,
1263 module: module,
1264 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001265 if module != nil {
1266 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001267 ret.requiredModuleNames = module.RequiredModuleNames()
1268 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1269 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001270 }
1271 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001272}
1273
1274func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001275 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001276}
1277
Jiyong Park7cd10e32020-01-14 09:22:18 +09001278// Path() returns path of this apex file relative to the APEX root
1279func (af *apexFile) Path() string {
1280 return filepath.Join(af.installDir, af.builtFile.Base())
1281}
1282
1283// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1284func (af *apexFile) SymlinkPaths() []string {
1285 var ret []string
1286 for _, symlink := range af.symlinks {
1287 ret = append(ret, filepath.Join(af.installDir, symlink))
1288 }
1289 return ret
1290}
1291
1292func (af *apexFile) AvailableToPlatform() bool {
1293 if af.module == nil {
1294 return false
1295 }
1296 if am, ok := af.module.(android.ApexModule); ok {
1297 return am.AvailableFor(android.AvailableToPlatform)
1298 }
1299 return false
1300}
1301
Jiyong Park678c8812020-02-07 17:25:49 +09001302type depInfo struct {
1303 to string
1304 from []string
1305 isExternal bool
1306}
1307
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001308type apexBundle struct {
1309 android.ModuleBase
1310 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001311 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001312 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001313
Jiyong Park5d790c32019-11-15 18:40:32 +09001314 properties apexBundleProperties
1315 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001316 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001317
Jooyung Hanf21c7972019-12-16 22:32:06 +09001318 // specific to apex_vndk modules
1319 vndkProperties apexVndkProperties
1320
Colin Crossa4925902018-11-16 11:36:28 -08001321 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001322 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001323 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001324
Jiyong Park03b68dd2019-07-26 23:20:40 +09001325 prebuiltFileToDelete string
1326
Jiyong Park42cca6c2019-04-01 11:15:50 +09001327 public_key_file android.Path
1328 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001329
1330 container_certificate_file android.Path
1331 container_private_key_file android.Path
1332
Jooyung Han54aca7b2019-11-20 02:26:02 +09001333 fileContexts android.Path
1334
Jiyong Park8fd61922018-11-08 02:50:25 +09001335 // list of files to be included in this apex
1336 filesInfo []apexFile
1337
Jiyong Park956305c2020-01-09 12:32:06 +09001338 // list of module names that should be installed along with this APEX
1339 requiredDeps []string
1340
Jiyong Park956305c2020-01-09 12:32:06 +09001341 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001342 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001343
Sundong Ahnabb64432019-10-22 13:58:29 +09001344 testApex bool
1345 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001346 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001347 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001348
Jooyung Han214bf372019-11-12 13:03:50 +09001349 manifestJsonOut android.WritablePath
1350 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001351
Jooyung Han002ab682020-01-08 01:57:58 +09001352 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001353 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001354 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001355 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1356 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001357
1358 // Suffix of module name in Android.mk
1359 // ".flattened", ".apex", ".zipapex", or ""
1360 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001361
1362 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001363
1364 // Whether to create symlink to the system file instead of having a file
1365 // inside the apex or not
1366 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001367
1368 // Struct holding the merged notice file paths in different formats
1369 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001370}
1371
Jiyong Park397e55e2018-10-24 21:09:55 +09001372func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001373 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001374 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001375 // Use *FarVariation* to be able to depend on modules having
1376 // conflicting variations with this module. This is required since
1377 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1378 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001379 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001380 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001381 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001382 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001383 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001384
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001385 ctx.AddFarVariationDependencies(append(target.Variations(),
1386 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1387 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001388
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001389 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001390 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001391 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001392 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001393}
1394
Alex Light9670d332019-01-29 18:07:33 -08001395func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1396 if ctx.Os().Class == android.Device {
1397 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1398 } else {
1399 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1400 if ctx.Os().Bionic() {
1401 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1402 } else {
1403 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1404 }
1405 }
1406}
1407
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001408func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001409 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1410 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1411 }
1412
Jiyong Park397e55e2018-10-24 21:09:55 +09001413 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001414 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001415
1416 a.combineProperties(ctx)
1417
Jiyong Park397e55e2018-10-24 21:09:55 +09001418 has32BitTarget := false
1419 for _, target := range targets {
1420 if target.Arch.ArchType.Multilib == "lib32" {
1421 has32BitTarget = true
1422 }
1423 }
1424 for i, target := range targets {
1425 // When multilib.* is omitted for native_shared_libs, it implies
1426 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001427 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001428 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001429 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001430 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001431
Roland Levillain630846d2019-06-26 12:48:34 +01001432 // When multilib.* is omitted for tests, it implies
1433 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001434 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001435 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001436 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001437 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001438
Jiyong Park397e55e2018-10-24 21:09:55 +09001439 // Add native modules targetting both ABIs
1440 addDependenciesForNativeModules(ctx,
1441 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001442 a.properties.Multilib.Both.Binaries,
1443 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001444 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001445 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001446
Alex Light3d673592019-01-18 14:37:31 -08001447 isPrimaryAbi := i == 0
1448 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001449 // When multilib.* is omitted for binaries, it implies
1450 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001451 ctx.AddFarVariationDependencies(append(target.Variations(),
1452 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1453 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001454
1455 // Add native modules targetting the first ABI
1456 addDependenciesForNativeModules(ctx,
1457 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001458 a.properties.Multilib.First.Binaries,
1459 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001460 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001461 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001462 }
1463
1464 switch target.Arch.ArchType.Multilib {
1465 case "lib32":
1466 // Add native modules targetting 32-bit ABI
1467 addDependenciesForNativeModules(ctx,
1468 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001469 a.properties.Multilib.Lib32.Binaries,
1470 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001471 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001472 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001473
1474 addDependenciesForNativeModules(ctx,
1475 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001476 a.properties.Multilib.Prefer32.Binaries,
1477 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001478 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001479 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001480 case "lib64":
1481 // Add native modules targetting 64-bit ABI
1482 addDependenciesForNativeModules(ctx,
1483 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001484 a.properties.Multilib.Lib64.Binaries,
1485 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001486 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001487 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001488
1489 if !has32BitTarget {
1490 addDependenciesForNativeModules(ctx,
1491 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001492 a.properties.Multilib.Prefer32.Binaries,
1493 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001494 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001495 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001496 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001497
1498 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1499 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1500 if sanitizer == "hwaddress" {
1501 addDependenciesForNativeModules(ctx,
1502 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001503 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001504 break
1505 }
1506 }
1507 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001508 }
1509
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001510 }
1511
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001512 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1513 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1514 // b/144532908
1515 archForPrebuiltEtc := config.Arches()[0]
1516 for _, arch := range config.Arches() {
1517 // Prefer 64-bit arch if there is any
1518 if arch.ArchType.Multilib == "lib64" {
1519 archForPrebuiltEtc = arch
1520 break
1521 }
1522 }
1523 ctx.AddFarVariationDependencies([]blueprint.Variation{
1524 {Mutator: "os", Variation: ctx.Os().String()},
1525 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1526 }, prebuiltTag, a.properties.Prebuilts...)
1527
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001528 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1529 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001530
Ulya Trafimovich44561882020-01-03 13:25:54 +00001531 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1532 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1533 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1534 javaLibTag, "jacocoagent")
1535 }
1536
Jiyong Park23c52b02019-02-02 13:13:47 +09001537 if String(a.properties.Key) == "" {
1538 ctx.ModuleErrorf("key is missing")
1539 return
1540 }
1541 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001542
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001543 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001544 if cert != "" {
1545 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001546 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001547
1548 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1549 if len(a.properties.Uses_sdks) > 0 {
1550 sdkRefs := []android.SdkRef{}
1551 for _, str := range a.properties.Uses_sdks {
1552 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1553 sdkRefs = append(sdkRefs, parsed)
1554 }
1555 a.BuildWithSdks(sdkRefs)
1556 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001557}
1558
Jiyong Park5d790c32019-11-15 18:40:32 +09001559func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1560 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1561 androidAppTag, a.overridableProperties.Apps...)
1562}
1563
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001564func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1565 // direct deps of an APEX bundle are all part of the APEX bundle
1566 return true
1567}
1568
Colin Cross0ea8ba82019-06-06 14:33:29 -07001569func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001570 moduleName := ctx.ModuleName()
1571 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1572 // we check with the pseudo module name to see if its certificate is overridden.
1573 if a.vndkApex {
1574 moduleName = vndkApexName
1575 }
1576 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001577 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001578 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001579 }
1580 return String(a.properties.Certificate)
1581}
1582
Colin Cross41955e82019-05-29 14:40:35 -07001583func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1584 switch tag {
1585 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001586 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001587 default:
1588 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001589 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001590}
1591
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001592func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001593 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001594}
1595
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001596func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1597 return proptools.Bool(a.properties.Test_only_no_hashtree)
1598}
1599
Jiyong Park7c1dc612019-01-05 11:15:24 +09001600func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001601 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001602 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001603 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001604 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001605 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001606 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001607 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001608 }
1609}
1610
Jiyong Parkf97782b2019-02-13 20:28:58 +09001611func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1612 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1613 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1614 }
1615}
1616
Jiyong Park388ef3f2019-01-28 19:47:32 +09001617func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001618 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1619 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001620 }
1621
1622 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001623 globalSanitizerNames := []string{}
1624 if a.Host() {
1625 globalSanitizerNames = ctx.Config().SanitizeHost()
1626 } else {
1627 arches := ctx.Config().SanitizeDeviceArch()
1628 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1629 globalSanitizerNames = ctx.Config().SanitizeDevice()
1630 }
1631 }
1632 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001633}
1634
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001635func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001636 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001637}
1638
1639func (a *apexBundle) PreventInstall() {
1640 a.properties.PreventInstall = true
1641}
1642
1643func (a *apexBundle) HideFromMake() {
1644 a.properties.HideFromMake = true
1645}
1646
Jiyong Park956305c2020-01-09 12:32:06 +09001647func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1648 a.properties.IsCoverageVariant = coverage
1649}
1650
Jiyong Parkf653b052019-11-18 15:39:01 +09001651// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001652func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001653 // Decide the APEX-local directory by the multilib of the library
1654 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001655 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001656 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001657 case "lib32":
1658 dirInApex = "lib"
1659 case "lib64":
1660 dirInApex = "lib64"
1661 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001662 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001663 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001664 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001665 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001666 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001667 // Special case for Bionic libs and other libs installed with them. This is
1668 // to prevent those libs from being included in the search path
1669 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1670 // those libs in the Runtime APEX are available via the legacy paths in
1671 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1672 // to the legacy paths and thus will be loaded into the default linker
1673 // namespace (aka "platform" namespace). If the libs are directly in
1674 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1675 // into the runtime linker namespace, which will result in double loading of
1676 // them, which isn't supported.
1677 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001678 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001679
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001681 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001682}
1683
Jiyong Park1833cef2019-12-13 13:28:36 +09001684func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001685 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001686 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001687 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001688 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001689 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001690 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 af.symlinks = cc.Symlinks()
1692 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001693}
1694
Jiyong Park1833cef2019-12-13 13:28:36 +09001695func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001696 dirInApex := "bin"
1697 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001698 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001699}
Jiyong Park1833cef2019-12-13 13:28:36 +09001700func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001701 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001702 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1703 if err != nil {
1704 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001705 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001706 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001707 fileToCopy := android.PathForOutput(ctx, s)
1708 // NB: Since go binaries are static we don't need the module for anything here, which is
1709 // good since the go tool is a blueprint.Module not an android.Module like we would
1710 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001711 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001712}
1713
Jiyong Park1833cef2019-12-13 13:28:36 +09001714func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001715 dirInApex := filepath.Join("bin", sh.SubDir())
1716 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001717 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001718 af.symlinks = sh.Symlinks()
1719 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001720}
1721
Jooyung Han58f26ab2019-12-18 15:34:32 +09001722// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1723type javaLibrary interface {
1724 android.Module
1725 java.Dependency
1726}
1727
1728func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001729 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001730 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001731 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1732 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1733 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001734}
1735
Jiyong Park1833cef2019-12-13 13:28:36 +09001736func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001737 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1738 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001739 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001740}
1741
atrost6e126252020-01-27 17:01:16 +00001742func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1743 dirInApex := filepath.Join("etc", config.SubDir())
1744 fileToCopy := config.CompatConfig()
1745 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1746}
1747
Jiyong Park1833cef2019-12-13 13:28:36 +09001748func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001749 android.Module
1750 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001751 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001752 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001753 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001754 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001755}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001756 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001757 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001758 appDir = "priv-app"
1759 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001760 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001761 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001762 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1763 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001764 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001765
1766 if app, ok := aapp.(interface {
1767 OverriddenManifestPackageName() string
1768 }); ok {
1769 af.overriddenPackageName = app.OverriddenManifestPackageName()
1770 }
Jiyong Park618922e2020-01-08 13:35:43 +09001771 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001772}
1773
Roland Levillain935639d2019-08-13 14:55:28 +01001774// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1775type flattenedApexContext struct {
1776 android.ModuleContext
1777}
1778
1779func (c *flattenedApexContext) InstallBypassMake() bool {
1780 return true
1781}
1782
Paul Duffin133608f2020-03-30 15:54:08 +01001783// Function called while walking an APEX's payload dependencies.
1784//
1785// Return true if the `to` module should be visited, false otherwise.
1786type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1787
Jiyong Park201cedd2020-02-07 17:25:49 +09001788// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001789func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001790 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001791 am, ok := child.(android.ApexModule)
1792 if !ok || !am.CanHaveApexVariants() {
1793 return false
1794 }
1795
1796 // Check for the direct dependencies that contribute to the payload
1797 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1798 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001799 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001800 }
Paul Duffin133608f2020-03-30 15:54:08 +01001801 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001802 return false
1803 }
1804
1805 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001806 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001807 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001808 }
1809
Paul Duffin133608f2020-03-30 15:54:08 +01001810 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001811 })
1812}
1813
Jooyung Han0c4e0162020-02-26 22:45:42 +09001814func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1815 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001816 intVer, err := android.ApiStrToNum(ctx, ver)
1817 if err != nil {
1818 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001819 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001820 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001821}
1822
Paul Duffinf0207962020-03-31 11:31:36 +01001823// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1824// a dependency tag.
1825var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1826
1827func PrettyPrintTag(tag blueprint.DependencyTag) string {
1828 // Use tag's custom String() method if available.
1829 if stringer, ok := tag.(fmt.Stringer); ok {
1830 return stringer.String()
1831 }
1832
1833 // Otherwise, get a default string representation of the tag's struct.
1834 tagString := fmt.Sprintf("%#v", tag)
1835
1836 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1837 tagString = tagCleaner.ReplaceAllString(tagString, "")
1838 return tagString
1839}
1840
Jiyong Park201cedd2020-02-07 17:25:49 +09001841// Ensures that the dependencies are marked as available for this APEX
1842func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1843 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1844 if ctx.Host() || a.testApex || a.vndkApex {
1845 return
1846 }
1847
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001848 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1849 // Requiring them and their transitive depencies with apex_available is not right
1850 // because they just add noise.
1851 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1852 return
1853 }
1854
Paul Duffin133608f2020-03-30 15:54:08 +01001855 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1856 if externalDep {
1857 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1858 return false
1859 }
1860
Jiyong Park201cedd2020-02-07 17:25:49 +09001861 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001862 fromName := ctx.OtherModuleName(from)
1863 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001864
1865 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1866 // do any of its dependencies.
1867 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1868 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1869 return false
1870 }
1871
Paul Duffin133608f2020-03-30 15:54:08 +01001872 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1873 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001874 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001875 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001876 tagPath := ctx.GetTagPath()
1877 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1878 walkPath := ctx.GetWalkPath()[1:]
1879 for i, m := range walkPath {
1880 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001881 }
1882 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 +01001883 // Visit this module's dependencies to check and report any issues with their availability.
1884 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001885 })
1886}
1887
Jiyong Park678c8812020-02-07 17:25:49 +09001888// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1889func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1890 a.depInfos = make(map[string]depInfo)
Paul Duffin133608f2020-03-30 15:54:08 +01001891 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001892 if from.Name() == to.Name() {
1893 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffin133608f2020-03-30 15:54:08 +01001894 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1895 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001896 }
1897
1898 if info, exists := a.depInfos[to.Name()]; exists {
1899 if !android.InList(from.Name(), info.from) {
1900 info.from = append(info.from, from.Name())
1901 }
1902 info.isExternal = info.isExternal && externalDep
1903 a.depInfos[to.Name()] = info
1904 } else {
1905 a.depInfos[to.Name()] = depInfo{
1906 to: to.Name(),
1907 from: []string{from.Name()},
1908 isExternal: externalDep,
1909 }
1910 }
Paul Duffin133608f2020-03-30 15:54:08 +01001911
1912 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1913 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001914 })
1915}
1916
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001917func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001918 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1919 switch a.properties.ApexType {
1920 case imageApex:
1921 if buildFlattenedAsDefault {
1922 a.suffix = imageApexSuffix
1923 } else {
1924 a.suffix = ""
1925 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001926
1927 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001928 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001929 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001930 }
1931 case zipApex:
1932 if proptools.String(a.properties.Payload_type) == "zip" {
1933 a.suffix = ""
1934 a.primaryApexType = true
1935 } else {
1936 a.suffix = zipApexSuffix
1937 }
1938 case flattenedApex:
1939 if buildFlattenedAsDefault {
1940 a.suffix = ""
1941 a.primaryApexType = true
1942 } else {
1943 a.suffix = flattenedSuffix
1944 }
Alex Light5098a612018-11-29 17:12:15 -08001945 }
1946
Roland Levillain630846d2019-06-26 12:48:34 +01001947 if len(a.properties.Tests) > 0 && !a.testApex {
1948 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1949 return
1950 }
1951
Jiyong Parkfa899442020-01-31 02:49:53 +09001952 a.checkApexAvailability(ctx)
1953
Jiyong Park678c8812020-02-07 17:25:49 +09001954 a.collectDepsInfo(ctx)
1955
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001956 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1957
Jooyung Hane1633032019-08-01 17:41:43 +09001958 // native lib dependencies
1959 var provideNativeLibs []string
1960 var requireNativeLibs []string
1961
Jooyung Han5c998b92019-06-27 11:30:33 +09001962 // Check if "uses" requirements are met with dependent apexBundles
1963 var providedNativeSharedLibs []string
1964 useVendor := proptools.Bool(a.properties.Use_vendor)
1965 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1966 if ctx.OtherModuleDependencyTag(m) != usesTag {
1967 return
1968 }
1969 otherName := ctx.OtherModuleName(m)
1970 other, ok := m.(*apexBundle)
1971 if !ok {
1972 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1973 return
1974 }
1975 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1976 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1977 return
1978 }
1979 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1980 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1981 return
1982 }
1983 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1984 })
1985
Jiyong Parkf653b052019-11-18 15:39:01 +09001986 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001987 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001988 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001989 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01001990 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1991 return false
1992 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001993 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001994 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001995 switch depTag {
1996 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001997 if c, ok := child.(*cc.Module); ok {
1998 // bootstrap bionic libs are treated as provided by system
1999 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2000 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002001 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002002 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002003 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002004 } else {
2005 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002006 }
2007 case executableTag:
2008 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002009 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002010 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002011 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002012 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002013 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002014 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002015 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002016 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002017 } else {
Alex Light778127a2019-02-27 14:19:50 -08002018 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 +09002019 }
2020 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002021 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002022 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002023 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002024 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2025 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002026 filesInfo = append(filesInfo, af)
2027 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002028 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002029 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2030 af := apexFileForJavaLibrary(ctx, sdkLib)
2031 if !af.Ok() {
2032 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2033 return false
2034 }
2035 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002036 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002037 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002038 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002039 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002040 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002041 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002042 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002043 return true // track transitive dependencies
2044 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002045 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002046 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002047 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002048 } else {
2049 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2050 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002051 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002052 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002053 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002054 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2055 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002056 } else {
atrost6e126252020-01-27 17:01:16 +00002057 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002058 }
Roland Levillain630846d2019-06-26 12:48:34 +01002059 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002060 if ccTest, ok := child.(*cc.Module); ok {
2061 if ccTest.IsTestPerSrcAllTestsVariation() {
2062 // Multiple-output test module (where `test_per_src: true`).
2063 //
2064 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2065 // We do not add this variation to `filesInfo`, as it has no output;
2066 // however, we do add the other variations of this module as indirect
2067 // dependencies (see below).
2068 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002069 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002070 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002071 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002072 af.class = nativeTest
2073 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002074 }
Roland Levillain630846d2019-06-26 12:48:34 +01002075 } else {
2076 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2077 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002078 case keyTag:
2079 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002080 a.private_key_file = key.private_key_file
2081 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002082 } else {
2083 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002084 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002085 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002086 case certificateTag:
2087 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002088 a.container_certificate_file = dep.Certificate.Pem
2089 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002090 } else {
2091 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2092 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002093 case android.PrebuiltDepTag:
2094 // If the prebuilt is force disabled, remember to delete the prebuilt file
2095 // that might have been installed in the previous builds
2096 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2097 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2098 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002099 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002100 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002101 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002102 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002103 // We cannot use a switch statement on `depTag` here as the checked
2104 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002105 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002106 if cc, ok := child.(*cc.Module); ok {
2107 if android.InList(cc.Name(), providedNativeSharedLibs) {
2108 // If we're using a shared library which is provided from other APEX,
2109 // don't include it in this APEX
2110 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002111 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002112 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002113 // If the dependency is a stubs lib, don't include it in this APEX,
2114 // but make sure that the lib is installed on the device.
2115 // In case no APEX is having the lib, the lib is installed to the system
2116 // partition.
2117 //
2118 // Always include if we are a host-apex however since those won't have any
2119 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002120 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2121 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002122 }
Jooyung Hane1633032019-08-01 17:41:43 +09002123 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002124 // Don't track further
2125 return false
2126 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002127 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002128 af.transitiveDep = true
2129 filesInfo = append(filesInfo, af)
2130 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002131 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002132 } else if cc.IsTestPerSrcDepTag(depTag) {
2133 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002134 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002135 // Handle modules created as `test_per_src` variations of a single test module:
2136 // use the name of the generated test binary (`fileToCopy`) instead of the name
2137 // of the original test module (`depName`, shared by all `test_per_src`
2138 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002139 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002140 // these are not considered transitive dep
2141 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002142 filesInfo = append(filesInfo, af)
2143 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002144 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002145 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002146 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2147 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002148 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2149 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2150 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2151 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002152 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002153 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002154 }
2155 }
2156 }
2157 return false
2158 })
2159
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002160 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2161 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2162 // via the global boot image config.
2163 if a.artApex {
2164 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2165 dirInApex := filepath.Join("javalib", arch.String())
2166 for _, f := range files {
2167 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002168 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002169 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002170 }
2171 }
2172 }
2173
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002174 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002175 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2176 return
2177 }
2178
Jiyong Park8fd61922018-11-08 02:50:25 +09002179 // remove duplicates in filesInfo
2180 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002181 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002182 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002183 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002184 if e, ok := encountered[dest]; !ok {
2185 encountered[dest] = f
2186 } else {
2187 // If a module is directly included and also transitively depended on
2188 // consider it as directly included.
2189 e.transitiveDep = e.transitiveDep && f.transitiveDep
2190 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002191 }
2192 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002193 var result []apexFile
2194 for _, v := range encountered {
2195 result = append(result, v)
2196 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002197 return result
2198 }
2199 filesInfo = removeDup(filesInfo)
2200
2201 // to have consistent build rules
2202 sort.Slice(filesInfo, func(i, j int) bool {
2203 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2204 })
2205
Jiyong Park8fd61922018-11-08 02:50:25 +09002206 a.installDir = android.PathForModuleInstall(ctx, "apex")
2207 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002208
Jooyung Han54aca7b2019-11-20 02:26:02 +09002209 if a.properties.ApexType != zipApex {
2210 if a.properties.File_contexts == nil {
2211 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2212 } else {
2213 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2214 if a.Platform() {
2215 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2216 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2217 }
2218 }
2219 }
2220 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2221 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2222 return
2223 }
2224 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002225 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2226 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2227 // the same library in the system partition, thus effectively sharing the same libraries
2228 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2229 // in the APEX.
2230 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2231 a.installable() &&
2232 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002233
Jiyong Park9d677202020-02-19 16:29:35 +09002234 // We don't need the optimization for updatable APEXes, as it might give false signal
2235 // to the system health when the APEXes are still bundled (b/149805758)
2236 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2237 a.linkToSystemLib = false
2238 }
2239
Jiyong Park9b964182020-02-26 18:27:19 +09002240 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2241 if ctx.Host() {
2242 a.linkToSystemLib = false
2243 }
2244
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002245 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002246 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2247
2248 a.setCertificateAndPrivateKey(ctx)
2249 if a.properties.ApexType == flattenedApex {
2250 a.buildFlattenedApex(ctx)
2251 } else {
2252 a.buildUnflattenedApex(ctx)
2253 }
2254
Jooyung Han002ab682020-01-08 01:57:58 +09002255 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002256
2257 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002258}
2259
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002260func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002261 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002262 moduleName = normalizeModuleName(moduleName)
2263
2264 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2265 return true
2266 }
2267
2268 key = android.AvailableToAnyApex
2269 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2270 return true
2271 }
2272
2273 return false
2274}
2275
2276func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002277 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2278 // system. Trim the prefix for the check since they are confusing
2279 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2280 if strings.HasPrefix(moduleName, "libclang_rt.") {
2281 // This module has many arch variants that depend on the product being built.
2282 // We don't want to list them all
2283 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002284 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002285 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002286}
2287
Jooyung Han344d5432019-08-23 11:17:39 +09002288func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002289 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002290 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002291 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002292 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002293 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002294 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2295 })
Alex Light5098a612018-11-29 17:12:15 -08002296 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002297 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002298 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002299 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002300 return module
2301}
Jiyong Park30ca9372019-02-07 16:27:23 +09002302
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002303func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002304 bundle := newApexBundle()
2305 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002306 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002307 return bundle
2308}
2309
Jiyong Parkfce0b422020-02-11 03:56:06 +09002310// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2311// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002312func testApexBundleFactory() android.Module {
2313 bundle := newApexBundle()
2314 bundle.testApex = true
2315 return bundle
2316}
2317
Jiyong Parkfce0b422020-02-11 03:56:06 +09002318// apex packages other modules into an APEX file which is a packaging format for system-level
2319// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002320func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002321 return newApexBundle()
2322}
2323
Jiyong Park30ca9372019-02-07 16:27:23 +09002324//
2325// Defaults
2326//
2327type Defaults struct {
2328 android.ModuleBase
2329 android.DefaultsModuleBase
2330}
2331
Jiyong Park30ca9372019-02-07 16:27:23 +09002332func defaultsFactory() android.Module {
2333 return DefaultsFactory()
2334}
2335
2336func DefaultsFactory(props ...interface{}) android.Module {
2337 module := &Defaults{}
2338
2339 module.AddProperties(props...)
2340 module.AddProperties(
2341 &apexBundleProperties{},
2342 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002343 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002344 )
2345
2346 android.InitDefaultsModule(module)
2347 return module
2348}
Jiyong Park5d790c32019-11-15 18:40:32 +09002349
2350//
2351// OverrideApex
2352//
2353type OverrideApex struct {
2354 android.ModuleBase
2355 android.OverrideModuleBase
2356}
2357
2358func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2359 // All the overrides happen in the base module.
2360}
2361
2362// override_apex is used to create an apex module based on another apex module
2363// by overriding some of its properties.
2364func overrideApexFactory() android.Module {
2365 m := &OverrideApex{}
2366 m.AddProperties(&overridableProperties{})
2367
2368 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2369 android.InitOverrideModule(m)
2370 return m
2371}