blob: a40a7539dd63fdd24dcd06378bc82417afca2e01 [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",
125 "conscrypt.module.intra.core.api.stubs",
126 "dex2oat_headers",
127 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900128 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900129 "javavm_headers",
130 "jni_platform_headers",
131 "libPlatformProperties",
132 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000133 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900134 "libandroidicuinit",
135 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000136 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900137 "libasync_safe",
Jiyong Parkfa899442020-01-31 02:49:53 +0900138 "libdexfile_all_headers",
139 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000140 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900141 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000142 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900143 "libfdlibm",
144 "libgtest_prod",
145 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000146 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900147 "libicuuc_headers",
148 "libicuuc_stubdata",
149 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900150 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000151 "liblzma",
152 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900153 "libnativebridge-headers",
154 "libnativehelper_header_only",
155 "libnativeloader-headers",
156 "libnpt_headers",
157 "libopenjdkjvmti_headers",
158 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000159 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900160 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000161 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900162 "libv8",
163 "libv8base",
164 "libv8gen",
165 "libv8platform",
166 "libv8sampler",
167 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000168 "libvixl",
169 "libvixld",
170 "libz",
171 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900172 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000173 }
Paul Duffinc23d9f62020-03-10 13:44:19 +0000174 m["com.android.art.debug"] = artApexContents
175 m["com.android.art.release"] = artApexContents
Anton Hansson5053c292020-01-10 15:12:39 +0000176 //
177 // Module separator
178 //
179 m["com.android.bluetooth.updatable"] = []string{
180 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000181 "android.hardware.bluetooth.a2dp@1.0",
182 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900183 "android.hardware.bluetooth@1.0",
184 "android.hardware.bluetooth@1.1",
185 "android.hardware.graphics.bufferqueue@1.0",
186 "android.hardware.graphics.bufferqueue@2.0",
187 "android.hardware.graphics.common@1.0",
188 "android.hardware.graphics.common@1.1",
189 "android.hardware.graphics.common@1.2",
190 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000191 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900192 "android.hidl.token@1.0",
193 "android.hidl.token@1.0-utils",
194 "avrcp-target-service",
195 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900196 "bluetooth-protos-lite",
197 "bluetooth.mapsapi",
198 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900199 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900200 "ipmemorystore-aidl-interfaces-V5-java",
201 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900202 "internal_include_headers",
203 "lib-bt-packets",
204 "lib-bt-packets-avrcp",
205 "lib-bt-packets-base",
206 "libFraunhoferAAC",
207 "libaudio-a2dp-hw-utils",
208 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900209 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000210 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900211 "libbluetooth-types",
212 "libbluetooth-types-header",
213 "libbluetooth_gd",
214 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000215 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900216 "libbt-audio-hal-interface",
217 "libbt-bta",
218 "libbt-common",
219 "libbt-hci",
220 "libbt-platform-protos-lite",
221 "libbt-protos-lite",
222 "libbt-sbc-decoder",
223 "libbt-sbc-encoder",
224 "libbt-stack",
225 "libbt-utils",
226 "libbtcore",
227 "libbtdevice",
228 "libbte",
229 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000230 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000231 "libevent",
232 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900233 "libg722codec",
234 "libgtest_prod",
235 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900236 "libmedia_headers",
237 "libmodpb64",
238 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000239 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900240 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900241 "libstagefright_foundation_headers",
242 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000243 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900244 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000245 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900246 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000247 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900248 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900249 "net-utils-services-common",
250 "netd_aidl_interface-unstable-java",
251 "netd_event_listener_interface-java",
252 "netlink-client",
253 "networkstack-aidl-interfaces-unstable-java",
254 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900255 "sap-api-java-static",
256 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000257 }
258 //
259 // Module separator
260 //
261 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
262 //
263 // Module separator
264 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900265 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900266 "boringssl_self_test",
Jiyong Parkfa899442020-01-31 02:49:53 +0900267 "libnativehelper_header_only",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900268 "unsupportedappusage",
Jiyong Parkfa899442020-01-31 02:49:53 +0900269 }
Anton Hansson5053c292020-01-10 15:12:39 +0000270 //
271 // Module separator
272 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900273 m["com.android.extservices"] = []string{
274 "flatbuffer_headers",
275 "liblua",
276 "libtextclassifier",
277 "libtextclassifier_hash_static",
278 "libtflite_static",
279 "libutf",
280 "libz_current",
281 "tensorflow_headers",
282 }
283 //
284 // Module separator
285 //
286 m["com.android.cronet"] = []string{
287 "cronet_impl_common_java",
288 "cronet_impl_native_java",
289 "cronet_impl_platform_java",
290 "libcronet.80.0.3986.0",
291 "org.chromium.net.cronet",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900292 "org.chromium.net.cronet.xml",
Jiyong Parkfa899442020-01-31 02:49:53 +0900293 "prebuilt_libcronet.80.0.3986.0",
294 }
295 //
296 // Module separator
297 //
298 m["com.android.neuralnetworks"] = []string{
299 "android.hardware.neuralnetworks@1.0",
300 "android.hardware.neuralnetworks@1.1",
301 "android.hardware.neuralnetworks@1.2",
302 "android.hardware.neuralnetworks@1.3",
303 "android.hidl.allocator@1.0",
304 "android.hidl.memory.token@1.0",
305 "android.hidl.memory@1.0",
306 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900307 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900308 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900309 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900310 "libprocessgroup",
311 "libprocessgroup_headers",
312 "libprocpartition",
313 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900314 }
Anton Hansson5053c292020-01-10 15:12:39 +0000315 //
316 // Module separator
317 //
Anton Hansson5053c292020-01-10 15:12:39 +0000318 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900319 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000320 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900321 "android.hardware.cas@1.0",
322 "android.hardware.configstore-utils",
323 "android.hardware.configstore@1.0",
324 "android.hardware.configstore@1.1",
325 "android.hardware.graphics.allocator@2.0",
326 "android.hardware.graphics.allocator@3.0",
327 "android.hardware.graphics.bufferqueue@1.0",
328 "android.hardware.graphics.bufferqueue@2.0",
329 "android.hardware.graphics.common@1.0",
330 "android.hardware.graphics.common@1.1",
331 "android.hardware.graphics.common@1.2",
332 "android.hardware.graphics.mapper@2.0",
333 "android.hardware.graphics.mapper@2.1",
334 "android.hardware.graphics.mapper@3.0",
335 "android.hardware.media.omx@1.0",
336 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000337 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000338 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900339 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000340 "android.hidl.token@1.0",
341 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900342 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900343 "gl_headers",
344 "libEGL",
345 "libEGL_blobCache",
346 "libEGL_getProcAddress",
347 "libFLAC",
348 "libFLAC-config",
349 "libFLAC-headers",
350 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000351 "libaacextractor",
352 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900353 "libarect",
354 "libasync_safe",
355 "libaudio_system_headers",
356 "libaudioclient",
357 "libaudioclient_headers",
358 "libaudiofoundation",
359 "libaudiofoundation_headers",
360 "libaudiomanager",
361 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000362 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900363 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900364 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900365 "libbluetooth-types-header",
366 "libbufferhub",
367 "libbufferhub_headers",
368 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900369 "libc_malloc_debug_backtrace",
370 "libcamera_client",
371 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900372 "libdexfile_external_headers",
373 "libdexfile_support",
374 "libdvr_headers",
375 "libexpat",
376 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000377 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900378 "libgrallocusage",
379 "libgraphicsenv",
380 "libgui",
381 "libgui_headers",
382 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900383 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900384 "liblzma",
385 "libmath",
386 "libmedia",
387 "libmedia_codeclist",
388 "libmedia_headers",
389 "libmedia_helper",
390 "libmedia_helper_headers",
391 "libmedia_midiiowrapper",
392 "libmedia_omx",
393 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000394 "libmidiextractor",
395 "libmkvextractor",
396 "libmp3extractor",
397 "libmp4extractor",
398 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900399 "libnativebase_headers",
400 "libnativebridge-headers",
401 "libnativebridge_lazy",
402 "libnativeloader-headers",
403 "libnativeloader_lazy",
404 "libnativewindow_headers",
405 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000406 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900407 "libpackagelistparser",
408 "libpcre2",
409 "libpdx",
410 "libpdx_default_transport",
411 "libpdx_headers",
412 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000413 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900414 "libprocessgroup_headers",
415 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900416 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000417 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900418 "libspeexresampler",
419 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000420 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900421 "libstagefright_flacdec",
422 "libstagefright_foundation",
423 "libstagefright_foundation_headers",
424 "libstagefright_foundation_without_imemory",
425 "libstagefright_headers",
426 "libstagefright_id3",
427 "libstagefright_metadatautils",
428 "libstagefright_mpeg2extractor",
429 "libstagefright_mpeg2support",
430 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900431 "libui",
432 "libui_headers",
433 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900434 "libvibrator",
435 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000436 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900437 "libwebm",
438 "media_ndk_headers",
439 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000440 "updatable-media",
441 }
442 //
443 // Module separator
444 //
445 m["com.android.media.swcodec"] = []string{
446 "android.frameworks.bufferhub@1.0",
447 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900448 "android.hardware.configstore-utils",
449 "android.hardware.configstore@1.0",
450 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000451 "android.hardware.graphics.allocator@2.0",
452 "android.hardware.graphics.allocator@3.0",
453 "android.hardware.graphics.allocator@4.0",
454 "android.hardware.graphics.bufferqueue@1.0",
455 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900456 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000457 "android.hardware.graphics.common@1.0",
458 "android.hardware.graphics.common@1.1",
459 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000460 "android.hardware.graphics.mapper@2.0",
461 "android.hardware.graphics.mapper@2.1",
462 "android.hardware.graphics.mapper@3.0",
463 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000464 "android.hardware.media.bufferpool@2.0",
465 "android.hardware.media.c2@1.0",
466 "android.hardware.media.c2@1.1",
467 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900468 "android.hardware.media@1.0",
469 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000470 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900471 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000472 "android.hidl.safe_union@1.0",
473 "android.hidl.token@1.0",
474 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900475 "libEGL",
476 "libFLAC",
477 "libFLAC-config",
478 "libFLAC-headers",
479 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900480 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900481 "libarect",
482 "libasync_safe",
483 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000484 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900485 "libaudioutils",
486 "libaudioutils_fixedfft",
487 "libavcdec",
488 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000489 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900490 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900491 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900492 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900493 "libbluetooth-types-header",
494 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900495 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000496 "libcap",
497 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900498 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000499 "libcodec2_hidl@1.0",
500 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900501 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000502 "libcodec2_soft_aacdec",
503 "libcodec2_soft_aacenc",
504 "libcodec2_soft_amrnbdec",
505 "libcodec2_soft_amrnbenc",
506 "libcodec2_soft_amrwbdec",
507 "libcodec2_soft_amrwbenc",
508 "libcodec2_soft_av1dec_gav1",
509 "libcodec2_soft_avcdec",
510 "libcodec2_soft_avcenc",
511 "libcodec2_soft_common",
512 "libcodec2_soft_flacdec",
513 "libcodec2_soft_flacenc",
514 "libcodec2_soft_g711alawdec",
515 "libcodec2_soft_g711mlawdec",
516 "libcodec2_soft_gsmdec",
517 "libcodec2_soft_h263dec",
518 "libcodec2_soft_h263enc",
519 "libcodec2_soft_hevcdec",
520 "libcodec2_soft_hevcenc",
521 "libcodec2_soft_mp3dec",
522 "libcodec2_soft_mpeg2dec",
523 "libcodec2_soft_mpeg4dec",
524 "libcodec2_soft_mpeg4enc",
525 "libcodec2_soft_opusdec",
526 "libcodec2_soft_opusenc",
527 "libcodec2_soft_rawdec",
528 "libcodec2_soft_vorbisdec",
529 "libcodec2_soft_vp8dec",
530 "libcodec2_soft_vp8enc",
531 "libcodec2_soft_vp9dec",
532 "libcodec2_soft_vp9enc",
533 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900534 "libdexfile_support",
535 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000536 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900537 "libfmq",
538 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000539 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900540 "libgrallocusage",
541 "libgraphicsenv",
542 "libgsm",
543 "libgui_bufferqueue_static",
544 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000545 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900546 "libhardware_headers",
547 "libhevcdec",
548 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000549 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900550 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900551 "liblzma",
552 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000553 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900554 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000555 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900556 "libminijail_gen_constants",
557 "libminijail_gen_constants_obj",
558 "libminijail_gen_syscall",
559 "libminijail_gen_syscall_obj",
560 "libminijail_generated",
561 "libmpeg2dec",
562 "libnativebase_headers",
563 "libnativebridge_lazy",
564 "libnativeloader_lazy",
565 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000566 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900567 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000568 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900569 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000570 "libscudo_wrapper",
571 "libsfplugin_ccodec_utils",
572 "libspeexresampler",
573 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900574 "libstagefright_amrnbdec",
575 "libstagefright_amrnbenc",
576 "libstagefright_amrwbdec",
577 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000578 "libstagefright_bufferpool@2.0.1",
579 "libstagefright_bufferqueue_helper",
580 "libstagefright_enc_common",
581 "libstagefright_flacdec",
582 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900583 "libstagefright_foundation_headers",
584 "libstagefright_headers",
585 "libstagefright_m4vh263dec",
586 "libstagefright_m4vh263enc",
587 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000588 "libsync",
589 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900590 "libui_headers",
591 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000592 "libvorbisidec",
593 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900594 "libyuv",
595 "libyuv_static",
596 "media_ndk_headers",
597 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000598 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000599 }
600 //
601 // Module separator
602 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900603 m["com.android.mediaprovider"] = []string{
604 "MediaProvider",
605 "MediaProviderGoogle",
606 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900607 "libbase_ndk",
608 "libfuse",
609 "libfuse_jni",
610 "libnativehelper_header_only",
611 }
612 //
613 // Module separator
614 //
615 m["com.android.permission"] = []string{
616 "androidx.annotation_annotation",
617 "androidx.annotation_annotation-nodeps",
618 "androidx.lifecycle_lifecycle-common",
619 "androidx.lifecycle_lifecycle-common-java8",
620 "androidx.lifecycle_lifecycle-common-java8-nodeps",
621 "androidx.lifecycle_lifecycle-common-nodeps",
622 "kotlin-annotations",
623 "kotlin-stdlib",
624 "kotlin-stdlib-jdk7",
625 "kotlin-stdlib-jdk8",
626 "kotlinx-coroutines-android",
627 "kotlinx-coroutines-android-nodeps",
628 "kotlinx-coroutines-core",
629 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900630 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900631 "GooglePermissionController",
632 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900633 }
Anton Hansson5053c292020-01-10 15:12:39 +0000634 //
635 // Module separator
636 //
Anton Hansson5053c292020-01-10 15:12:39 +0000637 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900638 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900639 "libarm-optimized-routines-math",
640 "libasync_safe",
641 "libasync_safe_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900642 "libc_aeabi",
643 "libc_bionic",
644 "libc_bionic_ndk",
645 "libc_bootstrap",
646 "libc_common",
647 "libc_common_shared",
648 "libc_common_static",
649 "libc_dns",
650 "libc_dynamic_dispatch",
651 "libc_fortify",
652 "libc_freebsd",
653 "libc_freebsd_large_stack",
654 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900655 "libc_init_dynamic",
656 "libc_init_static",
657 "libc_jemalloc_wrapper",
658 "libc_netbsd",
659 "libc_nomalloc",
660 "libc_nopthread",
661 "libc_openbsd",
662 "libc_openbsd_large_stack",
663 "libc_openbsd_ndk",
664 "libc_pthread",
665 "libc_static_dispatch",
666 "libc_syscalls",
667 "libc_tzcode",
668 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900669 "libdebuggerd",
670 "libdebuggerd_common_headers",
671 "libdebuggerd_handler_core",
672 "libdebuggerd_handler_fallback",
673 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000674 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900675 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900676 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900677 "libgtest_prod",
678 "libjemalloc5",
679 "liblinker_main",
680 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900681 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000682 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900683 "libprocessgroup_headers",
684 "libprocinfo",
685 "libpropertyinfoparser",
686 "libscudo",
687 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900688 "libsystemproperties",
689 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000690 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900691 "libz",
692 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000693 }
694 //
695 // Module separator
696 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 m["com.android.resolv"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 "libgtest_prod",
Jiyong Parkfa899442020-01-31 02:49:53 +0900700 "libnativehelper_header_only",
701 "libnetd_client_headers",
702 "libnetd_resolv",
703 "libnetdutils",
704 "libprocessgroup",
705 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900706 "libstatslog_resolv",
707 "libstatspush_compat",
708 "libstatssocket",
709 "libstatssocket_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900710 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900711 "netd_event_listener_interface-ndk_platform",
712 "server_configurable_flags",
713 "stats_proto",
714 }
Anton Hansson5053c292020-01-10 15:12:39 +0000715 //
716 // Module separator
717 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900718 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900719 "libnativehelper_compat_libc++",
720 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900721 "libcgrouprc",
722 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900723 "libprocessgroup",
724 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900725 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900726 "libvndksupport",
727 "tethering-aidl-interfaces-java",
728 }
Anton Hansson5053c292020-01-10 15:12:39 +0000729 //
730 // Module separator
731 //
732 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900733 "PlatformProperties",
734 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900735 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900736 "android.hardware.wifi-V1.1-java",
737 "android.hardware.wifi-V1.2-java",
738 "android.hardware.wifi-V1.3-java",
739 "android.hardware.wifi-V1.4-java",
740 "android.hardware.wifi.hostapd-V1.0-java",
741 "android.hardware.wifi.hostapd-V1.1-java",
742 "android.hardware.wifi.hostapd-V1.2-java",
743 "android.hardware.wifi.supplicant-V1.0-java",
744 "android.hardware.wifi.supplicant-V1.1-java",
745 "android.hardware.wifi.supplicant-V1.2-java",
746 "android.hardware.wifi.supplicant-V1.3-java",
747 "android.hidl.base-V1.0-java",
748 "android.hidl.manager-V1.0-java",
749 "android.hidl.manager-V1.1-java",
750 "android.hidl.manager-V1.2-java",
751 "androidx.annotation_annotation",
752 "androidx.annotation_annotation-nodeps",
753 "bouncycastle-unbundled",
754 "dnsresolver_aidl_interface-V2-java",
755 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900756 "framework-wifi-pre-jarjar",
757 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900758 "ipmemorystore-aidl-interfaces-V3-java",
759 "ipmemorystore-aidl-interfaces-java",
760 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900761 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000762 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900763 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000764 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900765 "net-utils-services-common",
766 "netd_aidl_interface-V2-java",
767 "netd_aidl_interface-unstable-java",
768 "netd_event_listener_interface-java",
769 "netlink-client",
770 "networkstack-aidl-interfaces-unstable-java",
771 "networkstack-client",
772 "services.net",
773 "wifi-lite-protos",
774 "wifi-nano-protos",
775 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000776 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900777 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000778 }
779 //
780 // Module separator
781 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900782 m["com.android.sdkext"] = []string{
783 "fmtlib_ndk",
784 "libbase_ndk",
785 "libprotobuf-cpp-lite-ndk",
786 }
787 //
788 // Module separator
789 //
790 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900791 "libprocessgroup_headers",
792 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900793 }
794 //
795 // Module separator
796 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000797 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900798 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900799 "libclang_rt",
800 "libgcc_stripped",
801 "libprofile-clang-extras",
802 "libprofile-clang-extras_ndk",
803 "libprofile-extras",
804 "libprofile-extras_ndk",
805 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900806 }
Anton Hansson5053c292020-01-10 15:12:39 +0000807 return m
808}
809
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900810func init() {
Jooyung Hane17caa62020-04-08 14:13:04 +0900811 android.AddNeverAllowRules(android.NeverAllow().
812 ModuleType("apex").
813 With("updatable", "true").
814 With("min_sdk_version", "").
815 Because("All updatable apexes should set min_sdk_version."))
816
Jiyong Parkd1063c12019-07-17 20:08:41 +0900817 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800818 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900819 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900820 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700821 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900822 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900823
Jooyung Han31c470b2019-10-18 16:26:59 +0900824 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900825 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900826
827 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
828 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
829 sort.Strings(*apexFileContextsInfos)
830 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
831 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900832}
833
Jooyung Han31c470b2019-10-18 16:26:59 +0900834func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
835 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
836 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
837}
838
Jiyong Parkd1063c12019-07-17 20:08:41 +0900839func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900840 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900841 ctx.BottomUp("apex", apexMutator).Parallel()
842 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
843 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900844}
845
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900846// Mark the direct and transitive dependencies of apex bundles so that they
847// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900848func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800849 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900850 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000851 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900852 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900853 ApexName: mctx.ModuleName(),
854 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900855 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900856 directDep = true
857 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800858 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900859 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900860 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900861
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800862 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900863 return
864 }
865
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100866 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900867
Jiyong Parkf760cae2020-02-12 07:53:12 +0900868 mctx.VisitDirectDeps(func(child android.Module) {
869 depName := mctx.OtherModuleName(child)
870 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900871 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800872 android.UpdateApexDependency(apexBundles, depName, directDep)
873 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900874 }
875 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900876}
877
878// Create apex variations if a module is included in APEX(s).
879func apexMutator(mctx android.BottomUpMutatorContext) {
880 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900881 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000882 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900883 // apex bundle itself is mutated so that it and its modules have same
884 // apex variant.
885 apexBundleName := mctx.ModuleName()
886 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900887 } else if o, ok := mctx.Module().(*OverrideApex); ok {
888 apexBundleName := o.GetOverriddenModuleName()
889 if apexBundleName == "" {
890 mctx.ModuleErrorf("base property is not set")
891 return
892 }
893 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900894 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900895
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900896}
Sundong Ahne9b55722019-09-06 17:37:42 +0900897
Jooyung Han7a78a922019-10-08 21:59:58 +0900898var (
899 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
900 apexFileContextsInfosMutex sync.Mutex
901)
902
903func apexFileContextsInfos(config android.Config) *[]string {
904 return config.Once(apexFileContextsInfosKey, func() interface{} {
905 return &[]string{}
906 }).(*[]string)
907}
908
Jooyung Han54aca7b2019-11-20 02:26:02 +0900909func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900910 apexFileContextsInfosMutex.Lock()
911 defer apexFileContextsInfosMutex.Unlock()
912 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900913 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900914}
915
Sundong Ahne9b55722019-09-06 17:37:42 +0900916func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900917 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900918 var variants []string
919 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
920 case "image":
921 variants = append(variants, imageApexType, flattenedApexType)
922 case "zip":
923 variants = append(variants, zipApexType)
924 case "both":
925 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
926 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900927 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900928 return
929 }
930
931 modules := mctx.CreateLocalVariations(variants...)
932
933 for i, v := range variants {
934 switch v {
935 case imageApexType:
936 modules[i].(*apexBundle).properties.ApexType = imageApex
937 case zipApexType:
938 modules[i].(*apexBundle).properties.ApexType = zipApex
939 case flattenedApexType:
940 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900941 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900942 modules[i].(*apexBundle).MakeAsSystemExt()
943 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900944 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900945 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900946 } else if _, ok := mctx.Module().(*OverrideApex); ok {
947 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900948 }
949}
950
Jooyung Han5c998b92019-06-27 11:30:33 +0900951func apexUsesMutator(mctx android.BottomUpMutatorContext) {
952 if ab, ok := mctx.Module().(*apexBundle); ok {
953 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
954 }
955}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900956
Jooyung Handc782442019-11-01 03:14:38 +0900957var (
958 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
959)
960
961// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
962// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
963// which may cause compatibility issues. (e.g. libbinder)
964// Even though libbinder restricts its availability via 'apex_available' property and relies on
965// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
966// to avoid similar problems.
967func useVendorWhitelist(config android.Config) []string {
968 return config.Once(useVendorWhitelistKey, func() interface{} {
969 return []string{
970 // swcodec uses "vendor" variants for smaller size
971 "com.android.media.swcodec",
972 "test_com.android.media.swcodec",
973 }
974 }).([]string)
975}
976
977// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
978// called before the first call to useVendorWhitelist()
979func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
980 config.Once(useVendorWhitelistKey, func() interface{} {
981 return whitelist
982 })
983}
984
Alex Light9670d332019-01-29 18:07:33 -0800985type apexNativeDependencies struct {
986 // List of native libraries
987 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900988
Alex Light9670d332019-01-29 18:07:33 -0800989 // List of native executables
990 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900991
Roland Levillain630846d2019-06-26 12:48:34 +0100992 // List of native tests
993 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800994}
Jooyung Han344d5432019-08-23 11:17:39 +0900995
Alex Light9670d332019-01-29 18:07:33 -0800996type apexMultilibProperties struct {
997 // Native dependencies whose compile_multilib is "first"
998 First apexNativeDependencies
999
1000 // Native dependencies whose compile_multilib is "both"
1001 Both apexNativeDependencies
1002
1003 // Native dependencies whose compile_multilib is "prefer32"
1004 Prefer32 apexNativeDependencies
1005
1006 // Native dependencies whose compile_multilib is "32"
1007 Lib32 apexNativeDependencies
1008
1009 // Native dependencies whose compile_multilib is "64"
1010 Lib64 apexNativeDependencies
1011}
1012
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001013type apexBundleProperties struct {
1014 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001015 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001016 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001017
Jiyong Park40e26a22019-02-08 02:53:06 +09001018 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1019 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001020 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001021
Roland Levillain411c5842019-09-19 16:37:20 +01001022 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1023 // device (/apex/<apex_name>).
1024 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001025 Apex_name *string
1026
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001027 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001028 // For platform APEXes, this should points to a file under /system/sepolicy
1029 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1030 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001031
1032 // List of native shared libs that are embedded inside this APEX bundle
1033 Native_shared_libs []string
1034
Roland Levillain630846d2019-06-26 12:48:34 +01001035 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001036 Binaries []string
1037
1038 // List of java libraries that are embedded inside this APEX bundle
1039 Java_libs []string
1040
1041 // List of prebuilt files that are embedded inside this APEX bundle
1042 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001043
Roland Levillain630846d2019-06-26 12:48:34 +01001044 // List of tests that are embedded inside this APEX bundle
1045 Tests []string
1046
Jiyong Parkff1458f2018-10-12 21:49:38 +09001047 // Name of the apex_key module that provides the private key to sign APEX
1048 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001049
Alex Light5098a612018-11-29 17:12:15 -08001050 // The type of APEX to build. Controls what the APEX payload is. Either
1051 // 'image', 'zip' or 'both'. Default: 'image'.
1052 Payload_type *string
1053
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001054 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1055 // or an android_app_certificate module name in the form ":module".
1056 Certificate *string
1057
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001058 // Whether this APEX is installable to one of the partitions. Default: true.
1059 Installable *bool
1060
Jiyong Parkda6eb592018-12-19 17:12:36 +09001061 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1062 // Default is false.
1063 Use_vendor *bool
1064
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001065 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1066 Ignore_system_library_special_case *bool
1067
Alex Light9670d332019-01-29 18:07:33 -08001068 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001069
Jiyong Parkf97782b2019-02-13 20:28:58 +09001070 // List of sanitizer names that this APEX is enabled for
1071 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001072
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001073 PreventInstall bool `blueprint:"mutated"`
1074
1075 HideFromMake bool `blueprint:"mutated"`
1076
Jooyung Han5c998b92019-06-27 11:30:33 +09001077 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1078 Provide_cpp_shared_libs *bool
1079
1080 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1081 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001082
1083 // A txt file containing list of files that are whitelisted to be included in this APEX.
1084 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001085
Sundong Ahnabb64432019-10-22 13:58:29 +09001086 // package format of this apex variant; could be non-flattened, flattened, or zip.
1087 // imageApex, zipApex or flattened
1088 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001089
Jiyong Parkd1063c12019-07-17 20:08:41 +09001090 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1091 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1092 // is implied. This value affects all modules included in this APEX. In other words, they are
1093 // also built with the SDKs specified here.
1094 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001095
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001096 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1097 // Should be only used in tests#.
1098 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001099
Jiyong Park956305c2020-01-09 12:32:06 +09001100 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001101
1102 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1103 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1104 // like symlinking to the system libs. Default is false.
1105 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001106
1107 // The minimum SDK version that this apex must be compatible with.
1108 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001109}
1110
1111type apexTargetBundleProperties struct {
1112 Target struct {
1113 // Multilib properties only for android.
1114 Android struct {
1115 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001116 }
Jooyung Han344d5432019-08-23 11:17:39 +09001117
Alex Light9670d332019-01-29 18:07:33 -08001118 // Multilib properties only for host.
1119 Host struct {
1120 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001121 }
Jooyung Han344d5432019-08-23 11:17:39 +09001122
Alex Light9670d332019-01-29 18:07:33 -08001123 // Multilib properties only for host linux_bionic.
1124 Linux_bionic struct {
1125 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001126 }
Jooyung Han344d5432019-08-23 11:17:39 +09001127
Alex Light9670d332019-01-29 18:07:33 -08001128 // Multilib properties only for host linux_glibc.
1129 Linux_glibc struct {
1130 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001131 }
1132 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001133}
1134
Jiyong Park5d790c32019-11-15 18:40:32 +09001135type overridableProperties struct {
1136 // List of APKs to package inside APEX
1137 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001138
1139 // Names of modules to be overridden. Listed modules can only be other binaries
1140 // (in Make or Soong).
1141 // This does not completely prevent installation of the overridden binaries, but if both
1142 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1143 // from PRODUCT_PACKAGES.
1144 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001145
1146 // Logging Parent value
1147 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001148
1149 // Apex Container Package Name.
1150 // Override value for attribute package:name in AndroidManifest.xml
1151 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001152}
1153
Alex Light5098a612018-11-29 17:12:15 -08001154type apexPackaging int
1155
1156const (
1157 imageApex apexPackaging = iota
1158 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001159 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001160)
1161
Sundong Ahnabb64432019-10-22 13:58:29 +09001162// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001163func (a apexPackaging) suffix() string {
1164 switch a {
1165 case imageApex:
1166 return imageApexSuffix
1167 case zipApex:
1168 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001169 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001170 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001171 }
1172}
1173
1174func (a apexPackaging) name() string {
1175 switch a {
1176 case imageApex:
1177 return imageApexType
1178 case zipApex:
1179 return zipApexType
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
Jiyong Parkf653b052019-11-18 15:39:01 +09001185type apexFileClass int
1186
1187const (
1188 etc apexFileClass = iota
1189 nativeSharedLib
1190 nativeExecutable
1191 shBinary
1192 pyBinary
1193 goBinary
1194 javaSharedLib
1195 nativeTest
1196 app
1197)
1198
Jiyong Park8fd61922018-11-08 02:50:25 +09001199func (class apexFileClass) NameInMake() string {
1200 switch class {
1201 case etc:
1202 return "ETC"
1203 case nativeSharedLib:
1204 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001205 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001206 return "EXECUTABLES"
1207 case javaSharedLib:
1208 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001209 case nativeTest:
1210 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001211 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001212 // b/142537672 Why isn't this APP? We want to have full control over
1213 // the paths and file names of the apk file under the flattend APEX.
1214 // If this is set to APP, then the paths and file names are modified
1215 // by the Make build system. For example, it is installed to
1216 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1217 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1218 // appends module name (which is <apexname>.<Appname> to the path.
1219 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001220 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001221 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001222 }
1223}
1224
Jiyong Parkf653b052019-11-18 15:39:01 +09001225// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001226type apexFile struct {
1227 builtFile android.Path
1228 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001229 installDir string
1230 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001231 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001232 // list of symlinks that will be created in installDir that point to this apexFile
1233 symlinks []string
1234 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001235 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001236
1237 requiredModuleNames []string
1238 targetRequiredModuleNames []string
1239 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001240
Colin Cross503c1d02020-01-28 14:00:53 -08001241 jacocoReportClassesFile android.Path // only for javalibs and apps
1242 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001243 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001244}
1245
Jiyong Park1833cef2019-12-13 13:28:36 +09001246func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1247 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001248 builtFile: builtFile,
1249 moduleName: moduleName,
1250 installDir: installDir,
1251 class: class,
1252 module: module,
1253 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001254 if module != nil {
1255 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001256 ret.requiredModuleNames = module.RequiredModuleNames()
1257 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1258 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001259 }
1260 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001261}
1262
1263func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001264 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001265}
1266
Jiyong Park7cd10e32020-01-14 09:22:18 +09001267// Path() returns path of this apex file relative to the APEX root
1268func (af *apexFile) Path() string {
1269 return filepath.Join(af.installDir, af.builtFile.Base())
1270}
1271
1272// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1273func (af *apexFile) SymlinkPaths() []string {
1274 var ret []string
1275 for _, symlink := range af.symlinks {
1276 ret = append(ret, filepath.Join(af.installDir, symlink))
1277 }
1278 return ret
1279}
1280
1281func (af *apexFile) AvailableToPlatform() bool {
1282 if af.module == nil {
1283 return false
1284 }
1285 if am, ok := af.module.(android.ApexModule); ok {
1286 return am.AvailableFor(android.AvailableToPlatform)
1287 }
1288 return false
1289}
1290
Jiyong Park678c8812020-02-07 17:25:49 +09001291type depInfo struct {
1292 to string
1293 from []string
1294 isExternal bool
1295}
1296
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001297type apexBundle struct {
1298 android.ModuleBase
1299 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001300 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001301 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001302
Jiyong Park5d790c32019-11-15 18:40:32 +09001303 properties apexBundleProperties
1304 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001305 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001306
Jooyung Hanf21c7972019-12-16 22:32:06 +09001307 // specific to apex_vndk modules
1308 vndkProperties apexVndkProperties
1309
Colin Crossa4925902018-11-16 11:36:28 -08001310 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001311 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001312 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001313
Jiyong Park03b68dd2019-07-26 23:20:40 +09001314 prebuiltFileToDelete string
1315
Jiyong Park42cca6c2019-04-01 11:15:50 +09001316 public_key_file android.Path
1317 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001318
1319 container_certificate_file android.Path
1320 container_private_key_file android.Path
1321
Jooyung Han54aca7b2019-11-20 02:26:02 +09001322 fileContexts android.Path
1323
Jiyong Park8fd61922018-11-08 02:50:25 +09001324 // list of files to be included in this apex
1325 filesInfo []apexFile
1326
Jiyong Park956305c2020-01-09 12:32:06 +09001327 // list of module names that should be installed along with this APEX
1328 requiredDeps []string
1329
Jiyong Park956305c2020-01-09 12:32:06 +09001330 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001331 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001332
Sundong Ahnabb64432019-10-22 13:58:29 +09001333 testApex bool
1334 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001335 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001336 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001337
Jooyung Han214bf372019-11-12 13:03:50 +09001338 manifestJsonOut android.WritablePath
1339 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001340
Jooyung Han002ab682020-01-08 01:57:58 +09001341 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001342 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001343 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001344 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1345 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001346
1347 // Suffix of module name in Android.mk
1348 // ".flattened", ".apex", ".zipapex", or ""
1349 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001350
1351 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001352
1353 // Whether to create symlink to the system file instead of having a file
1354 // inside the apex or not
1355 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001356
1357 // Struct holding the merged notice file paths in different formats
1358 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001359}
1360
Jiyong Park397e55e2018-10-24 21:09:55 +09001361func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001362 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001363 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001364 // Use *FarVariation* to be able to depend on modules having
1365 // conflicting variations with this module. This is required since
1366 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1367 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001368 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001369 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001370 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001371 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001372 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001373
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001374 ctx.AddFarVariationDependencies(append(target.Variations(),
1375 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1376 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001377
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001378 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001379 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001380 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001381 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001382}
1383
Alex Light9670d332019-01-29 18:07:33 -08001384func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1385 if ctx.Os().Class == android.Device {
1386 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1387 } else {
1388 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1389 if ctx.Os().Bionic() {
1390 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1391 } else {
1392 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1393 }
1394 }
1395}
1396
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001397func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001398 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1399 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1400 }
1401
Jiyong Park397e55e2018-10-24 21:09:55 +09001402 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001403 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001404
1405 a.combineProperties(ctx)
1406
Jiyong Park397e55e2018-10-24 21:09:55 +09001407 has32BitTarget := false
1408 for _, target := range targets {
1409 if target.Arch.ArchType.Multilib == "lib32" {
1410 has32BitTarget = true
1411 }
1412 }
1413 for i, target := range targets {
1414 // When multilib.* is omitted for native_shared_libs, it implies
1415 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001416 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001417 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001418 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001419 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001420
Roland Levillain630846d2019-06-26 12:48:34 +01001421 // When multilib.* is omitted for tests, it implies
1422 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001423 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001424 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001425 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001426 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001427
Jiyong Park397e55e2018-10-24 21:09:55 +09001428 // Add native modules targetting both ABIs
1429 addDependenciesForNativeModules(ctx,
1430 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001431 a.properties.Multilib.Both.Binaries,
1432 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001433 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001434 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001435
Alex Light3d673592019-01-18 14:37:31 -08001436 isPrimaryAbi := i == 0
1437 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001438 // When multilib.* is omitted for binaries, it implies
1439 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001440 ctx.AddFarVariationDependencies(append(target.Variations(),
1441 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1442 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001443
1444 // Add native modules targetting the first ABI
1445 addDependenciesForNativeModules(ctx,
1446 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001447 a.properties.Multilib.First.Binaries,
1448 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001449 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001450 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001451 }
1452
1453 switch target.Arch.ArchType.Multilib {
1454 case "lib32":
1455 // Add native modules targetting 32-bit ABI
1456 addDependenciesForNativeModules(ctx,
1457 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001458 a.properties.Multilib.Lib32.Binaries,
1459 a.properties.Multilib.Lib32.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 addDependenciesForNativeModules(ctx,
1464 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001465 a.properties.Multilib.Prefer32.Binaries,
1466 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001467 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001468 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001469 case "lib64":
1470 // Add native modules targetting 64-bit ABI
1471 addDependenciesForNativeModules(ctx,
1472 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001473 a.properties.Multilib.Lib64.Binaries,
1474 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001475 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001476 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001477
1478 if !has32BitTarget {
1479 addDependenciesForNativeModules(ctx,
1480 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001481 a.properties.Multilib.Prefer32.Binaries,
1482 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001483 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001484 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001485 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001486
1487 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1488 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1489 if sanitizer == "hwaddress" {
1490 addDependenciesForNativeModules(ctx,
1491 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001492 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001493 break
1494 }
1495 }
1496 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001497 }
1498
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001499 }
1500
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001501 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1502 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1503 // b/144532908
1504 archForPrebuiltEtc := config.Arches()[0]
1505 for _, arch := range config.Arches() {
1506 // Prefer 64-bit arch if there is any
1507 if arch.ArchType.Multilib == "lib64" {
1508 archForPrebuiltEtc = arch
1509 break
1510 }
1511 }
1512 ctx.AddFarVariationDependencies([]blueprint.Variation{
1513 {Mutator: "os", Variation: ctx.Os().String()},
1514 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1515 }, prebuiltTag, a.properties.Prebuilts...)
1516
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001517 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1518 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001519
Ulya Trafimovich44561882020-01-03 13:25:54 +00001520 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1521 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1522 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1523 javaLibTag, "jacocoagent")
1524 }
1525
Jiyong Park23c52b02019-02-02 13:13:47 +09001526 if String(a.properties.Key) == "" {
1527 ctx.ModuleErrorf("key is missing")
1528 return
1529 }
1530 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001531
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001532 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001533 if cert != "" {
1534 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001535 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001536
1537 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1538 if len(a.properties.Uses_sdks) > 0 {
1539 sdkRefs := []android.SdkRef{}
1540 for _, str := range a.properties.Uses_sdks {
1541 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1542 sdkRefs = append(sdkRefs, parsed)
1543 }
1544 a.BuildWithSdks(sdkRefs)
1545 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001546}
1547
Jiyong Park5d790c32019-11-15 18:40:32 +09001548func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1549 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1550 androidAppTag, a.overridableProperties.Apps...)
1551}
1552
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001553func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1554 // direct deps of an APEX bundle are all part of the APEX bundle
1555 return true
1556}
1557
Colin Cross0ea8ba82019-06-06 14:33:29 -07001558func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001559 moduleName := ctx.ModuleName()
1560 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1561 // we check with the pseudo module name to see if its certificate is overridden.
1562 if a.vndkApex {
1563 moduleName = vndkApexName
1564 }
1565 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001566 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001567 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001568 }
1569 return String(a.properties.Certificate)
1570}
1571
Colin Cross41955e82019-05-29 14:40:35 -07001572func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1573 switch tag {
1574 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001575 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001576 default:
1577 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001578 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001579}
1580
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001581func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001582 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001583}
1584
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001585func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1586 return proptools.Bool(a.properties.Test_only_no_hashtree)
1587}
1588
Jiyong Park7c1dc612019-01-05 11:15:24 +09001589func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001590 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001591 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001592 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001593 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001594 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001595 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001596 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001597 }
1598}
1599
Jiyong Parkf97782b2019-02-13 20:28:58 +09001600func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1601 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1602 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1603 }
1604}
1605
Jiyong Park388ef3f2019-01-28 19:47:32 +09001606func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001607 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1608 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001609 }
1610
1611 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001612 globalSanitizerNames := []string{}
1613 if a.Host() {
1614 globalSanitizerNames = ctx.Config().SanitizeHost()
1615 } else {
1616 arches := ctx.Config().SanitizeDeviceArch()
1617 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1618 globalSanitizerNames = ctx.Config().SanitizeDevice()
1619 }
1620 }
1621 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001622}
1623
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001624func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001625 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001626}
1627
1628func (a *apexBundle) PreventInstall() {
1629 a.properties.PreventInstall = true
1630}
1631
1632func (a *apexBundle) HideFromMake() {
1633 a.properties.HideFromMake = true
1634}
1635
Jiyong Park956305c2020-01-09 12:32:06 +09001636func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1637 a.properties.IsCoverageVariant = coverage
1638}
1639
Jiyong Parkf653b052019-11-18 15:39:01 +09001640// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001641func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001642 // Decide the APEX-local directory by the multilib of the library
1643 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001644 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001645 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001646 case "lib32":
1647 dirInApex = "lib"
1648 case "lib64":
1649 dirInApex = "lib64"
1650 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001651 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001652 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001653 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001654 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001655 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001656 // Special case for Bionic libs and other libs installed with them. This is
1657 // to prevent those libs from being included in the search path
1658 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1659 // those libs in the Runtime APEX are available via the legacy paths in
1660 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1661 // to the legacy paths and thus will be loaded into the default linker
1662 // namespace (aka "platform" namespace). If the libs are directly in
1663 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1664 // into the runtime linker namespace, which will result in double loading of
1665 // them, which isn't supported.
1666 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001667 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001668
Jiyong Parkf653b052019-11-18 15:39:01 +09001669 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001670 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001671}
1672
Jiyong Park1833cef2019-12-13 13:28:36 +09001673func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001674 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001675 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001676 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001677 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001678 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001679 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 af.symlinks = cc.Symlinks()
1681 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001682}
1683
Jiyong Park1833cef2019-12-13 13:28:36 +09001684func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001685 dirInApex := "bin"
1686 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001687 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001688}
Jiyong Park1833cef2019-12-13 13:28:36 +09001689func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001690 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001691 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1692 if err != nil {
1693 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001694 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001695 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001696 fileToCopy := android.PathForOutput(ctx, s)
1697 // NB: Since go binaries are static we don't need the module for anything here, which is
1698 // good since the go tool is a blueprint.Module not an android.Module like we would
1699 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001700 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001701}
1702
Jiyong Park1833cef2019-12-13 13:28:36 +09001703func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001704 dirInApex := filepath.Join("bin", sh.SubDir())
1705 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001706 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001707 af.symlinks = sh.Symlinks()
1708 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001709}
1710
Jooyung Han58f26ab2019-12-18 15:34:32 +09001711// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1712type javaLibrary interface {
1713 android.Module
1714 java.Dependency
1715}
1716
1717func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001718 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001719 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001720 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1721 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1722 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001723}
1724
Jiyong Park1833cef2019-12-13 13:28:36 +09001725func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001726 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1727 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001728 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001729}
1730
atrost6e126252020-01-27 17:01:16 +00001731func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1732 dirInApex := filepath.Join("etc", config.SubDir())
1733 fileToCopy := config.CompatConfig()
1734 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1735}
1736
Jiyong Park1833cef2019-12-13 13:28:36 +09001737func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001738 android.Module
1739 Privileged() bool
1740 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001741 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001742 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001743}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001744 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001745 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001746 appDir = "priv-app"
1747 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001748 dirInApex := filepath.Join(appDir, pkgName)
1749 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001750 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1751 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001752 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001753
1754 if app, ok := aapp.(interface {
1755 OverriddenManifestPackageName() string
1756 }); ok {
1757 af.overriddenPackageName = app.OverriddenManifestPackageName()
1758 }
Jiyong Park618922e2020-01-08 13:35:43 +09001759 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001760}
1761
Roland Levillain935639d2019-08-13 14:55:28 +01001762// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1763type flattenedApexContext struct {
1764 android.ModuleContext
1765}
1766
1767func (c *flattenedApexContext) InstallBypassMake() bool {
1768 return true
1769}
1770
Paul Duffin133608f2020-03-30 15:54:08 +01001771// Function called while walking an APEX's payload dependencies.
1772//
1773// Return true if the `to` module should be visited, false otherwise.
1774type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1775
Jiyong Park201cedd2020-02-07 17:25:49 +09001776// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001777func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001778 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001779 am, ok := child.(android.ApexModule)
1780 if !ok || !am.CanHaveApexVariants() {
1781 return false
1782 }
1783
1784 // Check for the direct dependencies that contribute to the payload
1785 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1786 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001787 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001788 }
Paul Duffin133608f2020-03-30 15:54:08 +01001789 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001790 return false
1791 }
1792
1793 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001794 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001795 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001796 }
1797
Paul Duffin133608f2020-03-30 15:54:08 +01001798 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001799 })
1800}
1801
Jooyung Han0c4e0162020-02-26 22:45:42 +09001802func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1803 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001804 intVer, err := android.ApiStrToNum(ctx, ver)
1805 if err != nil {
1806 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001807 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001808 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001809}
1810
Paul Duffinf0207962020-03-31 11:31:36 +01001811// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1812// a dependency tag.
1813var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1814
1815func PrettyPrintTag(tag blueprint.DependencyTag) string {
1816 // Use tag's custom String() method if available.
1817 if stringer, ok := tag.(fmt.Stringer); ok {
1818 return stringer.String()
1819 }
1820
1821 // Otherwise, get a default string representation of the tag's struct.
1822 tagString := fmt.Sprintf("%#v", tag)
1823
1824 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1825 tagString = tagCleaner.ReplaceAllString(tagString, "")
1826 return tagString
1827}
1828
Jiyong Park201cedd2020-02-07 17:25:49 +09001829// Ensures that the dependencies are marked as available for this APEX
1830func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1831 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1832 if ctx.Host() || a.testApex || a.vndkApex {
1833 return
1834 }
1835
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001836 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1837 // Requiring them and their transitive depencies with apex_available is not right
1838 // because they just add noise.
1839 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1840 return
1841 }
1842
Paul Duffin133608f2020-03-30 15:54:08 +01001843 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1844 if externalDep {
1845 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1846 return false
1847 }
1848
Jiyong Park201cedd2020-02-07 17:25:49 +09001849 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001850 fromName := ctx.OtherModuleName(from)
1851 toName := ctx.OtherModuleName(to)
Paul Duffin133608f2020-03-30 15:54:08 +01001852 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1853 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001854 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001855 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001856 tagPath := ctx.GetTagPath()
1857 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1858 walkPath := ctx.GetWalkPath()[1:]
1859 for i, m := range walkPath {
1860 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001861 }
1862 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 +01001863 // Visit this module's dependencies to check and report any issues with their availability.
1864 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001865 })
1866}
1867
Jiyong Park678c8812020-02-07 17:25:49 +09001868// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1869func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1870 a.depInfos = make(map[string]depInfo)
Paul Duffin133608f2020-03-30 15:54:08 +01001871 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001872 if from.Name() == to.Name() {
1873 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffin133608f2020-03-30 15:54:08 +01001874 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1875 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001876 }
1877
1878 if info, exists := a.depInfos[to.Name()]; exists {
1879 if !android.InList(from.Name(), info.from) {
1880 info.from = append(info.from, from.Name())
1881 }
1882 info.isExternal = info.isExternal && externalDep
1883 a.depInfos[to.Name()] = info
1884 } else {
1885 a.depInfos[to.Name()] = depInfo{
1886 to: to.Name(),
1887 from: []string{from.Name()},
1888 isExternal: externalDep,
1889 }
1890 }
Paul Duffin133608f2020-03-30 15:54:08 +01001891
1892 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1893 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001894 })
1895}
1896
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001897func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001898 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1899 switch a.properties.ApexType {
1900 case imageApex:
1901 if buildFlattenedAsDefault {
1902 a.suffix = imageApexSuffix
1903 } else {
1904 a.suffix = ""
1905 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001906
1907 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001908 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001909 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001910 }
1911 case zipApex:
1912 if proptools.String(a.properties.Payload_type) == "zip" {
1913 a.suffix = ""
1914 a.primaryApexType = true
1915 } else {
1916 a.suffix = zipApexSuffix
1917 }
1918 case flattenedApex:
1919 if buildFlattenedAsDefault {
1920 a.suffix = ""
1921 a.primaryApexType = true
1922 } else {
1923 a.suffix = flattenedSuffix
1924 }
Alex Light5098a612018-11-29 17:12:15 -08001925 }
1926
Roland Levillain630846d2019-06-26 12:48:34 +01001927 if len(a.properties.Tests) > 0 && !a.testApex {
1928 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1929 return
1930 }
1931
Jiyong Parkfa899442020-01-31 02:49:53 +09001932 a.checkApexAvailability(ctx)
1933
Jiyong Park678c8812020-02-07 17:25:49 +09001934 a.collectDepsInfo(ctx)
1935
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001936 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1937
Jooyung Hane1633032019-08-01 17:41:43 +09001938 // native lib dependencies
1939 var provideNativeLibs []string
1940 var requireNativeLibs []string
1941
Jooyung Han5c998b92019-06-27 11:30:33 +09001942 // Check if "uses" requirements are met with dependent apexBundles
1943 var providedNativeSharedLibs []string
1944 useVendor := proptools.Bool(a.properties.Use_vendor)
1945 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1946 if ctx.OtherModuleDependencyTag(m) != usesTag {
1947 return
1948 }
1949 otherName := ctx.OtherModuleName(m)
1950 other, ok := m.(*apexBundle)
1951 if !ok {
1952 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1953 return
1954 }
1955 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1956 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1957 return
1958 }
1959 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1960 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1961 return
1962 }
1963 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1964 })
1965
Jiyong Parkf653b052019-11-18 15:39:01 +09001966 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001967 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001968 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001969 depTag := ctx.OtherModuleDependencyTag(child)
1970 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001971 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001972 switch depTag {
1973 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001974 if c, ok := child.(*cc.Module); ok {
1975 // bootstrap bionic libs are treated as provided by system
1976 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1977 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001978 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001979 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001980 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001981 } else {
1982 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001983 }
1984 case executableTag:
1985 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001986 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001987 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001988 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001989 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001990 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001991 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001992 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001993 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001994 } else {
Alex Light778127a2019-02-27 14:19:50 -08001995 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 +09001996 }
1997 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001998 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001999 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002000 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002001 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2002 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002003 filesInfo = append(filesInfo, af)
2004 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002005 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002006 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2007 af := apexFileForJavaLibrary(ctx, sdkLib)
2008 if !af.Ok() {
2009 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2010 return false
2011 }
2012 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002013 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002014 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002015 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002016 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002017 case androidAppTag:
2018 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2019 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002020 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002021 return true // track transitive dependencies
2022 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002023 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002024 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2025 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002026 } else {
2027 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2028 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002029 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002030 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002031 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002032 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2033 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002034 } else {
atrost6e126252020-01-27 17:01:16 +00002035 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002036 }
Roland Levillain630846d2019-06-26 12:48:34 +01002037 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002038 if ccTest, ok := child.(*cc.Module); ok {
2039 if ccTest.IsTestPerSrcAllTestsVariation() {
2040 // Multiple-output test module (where `test_per_src: true`).
2041 //
2042 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2043 // We do not add this variation to `filesInfo`, as it has no output;
2044 // however, we do add the other variations of this module as indirect
2045 // dependencies (see below).
2046 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002047 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002048 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002049 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002050 af.class = nativeTest
2051 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002052 }
Roland Levillain630846d2019-06-26 12:48:34 +01002053 } else {
2054 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2055 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002056 case keyTag:
2057 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002058 a.private_key_file = key.private_key_file
2059 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002060 } else {
2061 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002062 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002063 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002064 case certificateTag:
2065 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002066 a.container_certificate_file = dep.Certificate.Pem
2067 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002068 } else {
2069 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2070 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002071 case android.PrebuiltDepTag:
2072 // If the prebuilt is force disabled, remember to delete the prebuilt file
2073 // that might have been installed in the previous builds
2074 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2075 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2076 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002077 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002078 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002079 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002080 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002081 // We cannot use a switch statement on `depTag` here as the checked
2082 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002083 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002084 if cc, ok := child.(*cc.Module); ok {
2085 if android.InList(cc.Name(), providedNativeSharedLibs) {
2086 // If we're using a shared library which is provided from other APEX,
2087 // don't include it in this APEX
2088 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002089 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002090 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002091 // If the dependency is a stubs lib, don't include it in this APEX,
2092 // but make sure that the lib is installed on the device.
2093 // In case no APEX is having the lib, the lib is installed to the system
2094 // partition.
2095 //
2096 // Always include if we are a host-apex however since those won't have any
2097 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002098 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2099 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002100 }
Jooyung Hane1633032019-08-01 17:41:43 +09002101 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002102 // Don't track further
2103 return false
2104 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002105 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002106 af.transitiveDep = true
2107 filesInfo = append(filesInfo, af)
2108 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002109 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002110 } else if cc.IsTestPerSrcDepTag(depTag) {
2111 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002112 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002113 // Handle modules created as `test_per_src` variations of a single test module:
2114 // use the name of the generated test binary (`fileToCopy`) instead of the name
2115 // of the original test module (`depName`, shared by all `test_per_src`
2116 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002117 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002118 // these are not considered transitive dep
2119 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002120 filesInfo = append(filesInfo, af)
2121 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002122 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002123 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002124 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2125 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002126 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2127 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2128 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2129 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002130 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002131 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002132 }
2133 }
2134 }
2135 return false
2136 })
2137
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002138 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2139 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2140 // via the global boot image config.
2141 if a.artApex {
2142 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2143 dirInApex := filepath.Join("javalib", arch.String())
2144 for _, f := range files {
2145 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002146 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002147 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002148 }
2149 }
2150 }
2151
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002152 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002153 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2154 return
2155 }
2156
Jiyong Park8fd61922018-11-08 02:50:25 +09002157 // remove duplicates in filesInfo
2158 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002159 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002160 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002161 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002162 if e, ok := encountered[dest]; !ok {
2163 encountered[dest] = f
2164 } else {
2165 // If a module is directly included and also transitively depended on
2166 // consider it as directly included.
2167 e.transitiveDep = e.transitiveDep && f.transitiveDep
2168 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002169 }
2170 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002171 var result []apexFile
2172 for _, v := range encountered {
2173 result = append(result, v)
2174 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002175 return result
2176 }
2177 filesInfo = removeDup(filesInfo)
2178
2179 // to have consistent build rules
2180 sort.Slice(filesInfo, func(i, j int) bool {
2181 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2182 })
2183
Jiyong Park8fd61922018-11-08 02:50:25 +09002184 a.installDir = android.PathForModuleInstall(ctx, "apex")
2185 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002186
Jooyung Han54aca7b2019-11-20 02:26:02 +09002187 if a.properties.ApexType != zipApex {
2188 if a.properties.File_contexts == nil {
2189 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2190 } else {
2191 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2192 if a.Platform() {
2193 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2194 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2195 }
2196 }
2197 }
2198 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2199 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2200 return
2201 }
2202 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002203 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2204 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2205 // the same library in the system partition, thus effectively sharing the same libraries
2206 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2207 // in the APEX.
2208 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2209 a.installable() &&
2210 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002211
Jiyong Park9d677202020-02-19 16:29:35 +09002212 // We don't need the optimization for updatable APEXes, as it might give false signal
2213 // to the system health when the APEXes are still bundled (b/149805758)
2214 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2215 a.linkToSystemLib = false
2216 }
2217
Jiyong Park9b964182020-02-26 18:27:19 +09002218 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2219 if ctx.Host() {
2220 a.linkToSystemLib = false
2221 }
2222
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002223 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002224 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2225
2226 a.setCertificateAndPrivateKey(ctx)
2227 if a.properties.ApexType == flattenedApex {
2228 a.buildFlattenedApex(ctx)
2229 } else {
2230 a.buildUnflattenedApex(ctx)
2231 }
2232
Jooyung Han002ab682020-01-08 01:57:58 +09002233 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002234
2235 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002236}
2237
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002238func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002239 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002240 moduleName = normalizeModuleName(moduleName)
2241
2242 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2243 return true
2244 }
2245
2246 key = android.AvailableToAnyApex
2247 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2248 return true
2249 }
2250
2251 return false
2252}
2253
2254func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002255 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2256 // system. Trim the prefix for the check since they are confusing
2257 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2258 if strings.HasPrefix(moduleName, "libclang_rt.") {
2259 // This module has many arch variants that depend on the product being built.
2260 // We don't want to list them all
2261 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002262 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002263 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002264}
2265
Jooyung Han344d5432019-08-23 11:17:39 +09002266func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002267 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002268 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002269 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002270 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002271 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002272 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2273 })
Alex Light5098a612018-11-29 17:12:15 -08002274 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002275 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002276 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002277 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002278 return module
2279}
Jiyong Park30ca9372019-02-07 16:27:23 +09002280
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002281func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002282 bundle := newApexBundle()
2283 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002284 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002285 return bundle
2286}
2287
Jiyong Parkfce0b422020-02-11 03:56:06 +09002288// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2289// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002290func testApexBundleFactory() android.Module {
2291 bundle := newApexBundle()
2292 bundle.testApex = true
2293 return bundle
2294}
2295
Jiyong Parkfce0b422020-02-11 03:56:06 +09002296// apex packages other modules into an APEX file which is a packaging format for system-level
2297// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002298func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002299 return newApexBundle()
2300}
2301
Jiyong Park30ca9372019-02-07 16:27:23 +09002302//
2303// Defaults
2304//
2305type Defaults struct {
2306 android.ModuleBase
2307 android.DefaultsModuleBase
2308}
2309
Jiyong Park30ca9372019-02-07 16:27:23 +09002310func defaultsFactory() android.Module {
2311 return DefaultsFactory()
2312}
2313
2314func DefaultsFactory(props ...interface{}) android.Module {
2315 module := &Defaults{}
2316
2317 module.AddProperties(props...)
2318 module.AddProperties(
2319 &apexBundleProperties{},
2320 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002321 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002322 )
2323
2324 android.InitDefaultsModule(module)
2325 return module
2326}
Jiyong Park5d790c32019-11-15 18:40:32 +09002327
2328//
2329// OverrideApex
2330//
2331type OverrideApex struct {
2332 android.ModuleBase
2333 android.OverrideModuleBase
2334}
2335
2336func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2337 // All the overrides happen in the base module.
2338}
2339
2340// override_apex is used to create an apex module based on another apex module
2341// by overriding some of its properties.
2342func overrideApexFactory() android.Module {
2343 m := &OverrideApex{}
2344 m.AddProperties(&overridableProperties{})
2345
2346 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2347 android.InitOverrideModule(m)
2348 return m
2349}