blob: 98a7e8c6a60953088e1f7667239a16fd22a22aaa [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinf0207962020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Parkfa899442020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
56 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000064 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin404db3f2020-03-06 12:30:13 +000065
66 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067)
68
Paul Duffin404db3f2020-03-06 12:30:13 +000069// Transform the map of apex -> modules to module -> apexes.
70func invertApexWhiteList(m map[string][]string) map[string][]string {
71 r := make(map[string][]string)
72 for apex, modules := range m {
73 for _, module := range modules {
74 r[module] = append(r[module], apex)
75 }
76 }
77 return r
78}
79
80// Retrieve the while list of apexes to which the supplied module belongs.
81func WhitelistedApexAvailable(moduleName string) []string {
82 return inverseApexAvailWl[normalizeModuleName(moduleName)]
83}
84
Anton Hansson5053c292020-01-10 15:12:39 +000085// This is a map from apex to modules, which overrides the
86// apex_available setting for that particular module to make
87// it available for the apex regardless of its setting.
88// TODO(b/147364041): remove this
89func makeApexAvailableWhitelist() map[string][]string {
90 // The "Module separator"s below are employed to minimize merge conflicts.
91 m := make(map[string][]string)
92 //
93 // Module separator
94 //
Jiyong Parkfa899442020-01-31 02:49:53 +090095 m["com.android.adbd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090096 "libadbd_auth",
Jiyong Parkfa899442020-01-31 02:49:53 +090097 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +090098 "libcap",
Jiyong Parkfa899442020-01-31 02:49:53 +090099 "libmdnssd",
100 "libminijail",
101 "libminijail_gen_constants",
102 "libminijail_gen_constants_obj",
103 "libminijail_gen_syscall",
104 "libminijail_gen_syscall_obj",
105 "libminijail_generated",
106 "libpackagelistparser",
107 "libpcre2",
108 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900109 }
110 //
111 // Module separator
112 //
Paul Duffinc23d9f62020-03-10 13:44:19 +0000113 artApexContents := []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900114 "art_cmdlineparser_headers",
115 "art_disassembler_headers",
116 "art_libartbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900117 "bionic_libc_platform_headers",
118 "core-repackaged-icu4j",
119 "cpp-define-generator-asm-support",
120 "cpp-define-generator-definitions",
121 "crtbegin_dynamic",
122 "crtbegin_dynamic1",
123 "crtbegin_so1",
124 "crtbrand",
Jiyong Parkfa899442020-01-31 02:49:53 +0900125 "dex2oat_headers",
126 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900127 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900128 "javavm_headers",
129 "jni_platform_headers",
130 "libPlatformProperties",
131 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000132 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900133 "libandroidicuinit",
134 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000135 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900136 "libasync_safe",
Jiyong Parkfa899442020-01-31 02:49:53 +0900137 "libdexfile_all_headers",
138 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000139 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900140 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000141 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900142 "libfdlibm",
143 "libgtest_prod",
144 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000145 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900146 "libicuuc_headers",
147 "libicuuc_stubdata",
148 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900149 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000150 "liblzma",
151 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900152 "libnativebridge-headers",
153 "libnativehelper_header_only",
154 "libnativeloader-headers",
155 "libnpt_headers",
156 "libopenjdkjvmti_headers",
157 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000158 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900159 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000160 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900161 "libv8",
162 "libv8base",
163 "libv8gen",
164 "libv8platform",
165 "libv8sampler",
166 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000167 "libvixl",
168 "libvixld",
169 "libz",
170 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000172 }
Paul Duffinc23d9f62020-03-10 13:44:19 +0000173 m["com.android.art.debug"] = artApexContents
174 m["com.android.art.release"] = artApexContents
Anton Hansson5053c292020-01-10 15:12:39 +0000175 //
176 // Module separator
177 //
178 m["com.android.bluetooth.updatable"] = []string{
179 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000180 "android.hardware.bluetooth.a2dp@1.0",
181 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900182 "android.hardware.bluetooth@1.0",
183 "android.hardware.bluetooth@1.1",
184 "android.hardware.graphics.bufferqueue@1.0",
185 "android.hardware.graphics.bufferqueue@2.0",
186 "android.hardware.graphics.common@1.0",
187 "android.hardware.graphics.common@1.1",
188 "android.hardware.graphics.common@1.2",
189 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000190 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900191 "android.hidl.token@1.0",
192 "android.hidl.token@1.0-utils",
193 "avrcp-target-service",
194 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 "bluetooth-protos-lite",
196 "bluetooth.mapsapi",
197 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900198 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900199 "ipmemorystore-aidl-interfaces-V5-java",
200 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900201 "internal_include_headers",
202 "lib-bt-packets",
203 "lib-bt-packets-avrcp",
204 "lib-bt-packets-base",
205 "libFraunhoferAAC",
206 "libaudio-a2dp-hw-utils",
207 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900208 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000209 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900210 "libbluetooth-types",
211 "libbluetooth-types-header",
212 "libbluetooth_gd",
213 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000214 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libbt-audio-hal-interface",
216 "libbt-bta",
217 "libbt-common",
218 "libbt-hci",
219 "libbt-platform-protos-lite",
220 "libbt-protos-lite",
221 "libbt-sbc-decoder",
222 "libbt-sbc-encoder",
223 "libbt-stack",
224 "libbt-utils",
225 "libbtcore",
226 "libbtdevice",
227 "libbte",
228 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000229 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000230 "libevent",
231 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900232 "libg722codec",
233 "libgtest_prod",
234 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900235 "libmedia_headers",
236 "libmodpb64",
237 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000238 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900239 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900240 "libstagefright_foundation_headers",
241 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000242 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900243 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000244 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900245 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000246 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900247 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900248 "net-utils-services-common",
249 "netd_aidl_interface-unstable-java",
250 "netd_event_listener_interface-java",
251 "netlink-client",
252 "networkstack-aidl-interfaces-unstable-java",
253 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900254 "sap-api-java-static",
255 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000256 }
257 //
258 // Module separator
259 //
260 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
261 //
262 // Module separator
263 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900264 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900265 "boringssl_self_test",
Jiyong Parkfa899442020-01-31 02:49:53 +0900266 "libnativehelper_header_only",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900267 "unsupportedappusage",
Jiyong Parkfa899442020-01-31 02:49:53 +0900268 }
Anton Hansson5053c292020-01-10 15:12:39 +0000269 //
270 // Module separator
271 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900272 m["com.android.extservices"] = []string{
273 "flatbuffer_headers",
274 "liblua",
275 "libtextclassifier",
276 "libtextclassifier_hash_static",
277 "libtflite_static",
278 "libutf",
279 "libz_current",
280 "tensorflow_headers",
281 }
282 //
283 // Module separator
284 //
285 m["com.android.cronet"] = []string{
286 "cronet_impl_common_java",
287 "cronet_impl_native_java",
288 "cronet_impl_platform_java",
289 "libcronet.80.0.3986.0",
290 "org.chromium.net.cronet",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900291 "org.chromium.net.cronet.xml",
Jiyong Parkfa899442020-01-31 02:49:53 +0900292 "prebuilt_libcronet.80.0.3986.0",
293 }
294 //
295 // Module separator
296 //
297 m["com.android.neuralnetworks"] = []string{
298 "android.hardware.neuralnetworks@1.0",
299 "android.hardware.neuralnetworks@1.1",
300 "android.hardware.neuralnetworks@1.2",
301 "android.hardware.neuralnetworks@1.3",
302 "android.hidl.allocator@1.0",
303 "android.hidl.memory.token@1.0",
304 "android.hidl.memory@1.0",
305 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900306 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900307 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900308 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900309 "libprocessgroup",
310 "libprocessgroup_headers",
311 "libprocpartition",
312 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900313 }
Anton Hansson5053c292020-01-10 15:12:39 +0000314 //
315 // Module separator
316 //
Anton Hansson5053c292020-01-10 15:12:39 +0000317 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900318 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000319 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900320 "android.hardware.cas@1.0",
321 "android.hardware.configstore-utils",
322 "android.hardware.configstore@1.0",
323 "android.hardware.configstore@1.1",
324 "android.hardware.graphics.allocator@2.0",
325 "android.hardware.graphics.allocator@3.0",
326 "android.hardware.graphics.bufferqueue@1.0",
327 "android.hardware.graphics.bufferqueue@2.0",
328 "android.hardware.graphics.common@1.0",
329 "android.hardware.graphics.common@1.1",
330 "android.hardware.graphics.common@1.2",
331 "android.hardware.graphics.mapper@2.0",
332 "android.hardware.graphics.mapper@2.1",
333 "android.hardware.graphics.mapper@3.0",
334 "android.hardware.media.omx@1.0",
335 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000336 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000337 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900338 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000339 "android.hidl.token@1.0",
340 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900341 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900342 "gl_headers",
343 "libEGL",
344 "libEGL_blobCache",
345 "libEGL_getProcAddress",
346 "libFLAC",
347 "libFLAC-config",
348 "libFLAC-headers",
349 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000350 "libaacextractor",
351 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900352 "libarect",
353 "libasync_safe",
354 "libaudio_system_headers",
355 "libaudioclient",
356 "libaudioclient_headers",
357 "libaudiofoundation",
358 "libaudiofoundation_headers",
359 "libaudiomanager",
360 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000361 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900362 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900363 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900364 "libbluetooth-types-header",
365 "libbufferhub",
366 "libbufferhub_headers",
367 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900368 "libc_malloc_debug_backtrace",
369 "libcamera_client",
370 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900371 "libdexfile_external_headers",
372 "libdexfile_support",
373 "libdvr_headers",
374 "libexpat",
375 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000376 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900377 "libgrallocusage",
378 "libgraphicsenv",
379 "libgui",
380 "libgui_headers",
381 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900382 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900383 "liblzma",
384 "libmath",
385 "libmedia",
386 "libmedia_codeclist",
387 "libmedia_headers",
388 "libmedia_helper",
389 "libmedia_helper_headers",
390 "libmedia_midiiowrapper",
391 "libmedia_omx",
392 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000393 "libmidiextractor",
394 "libmkvextractor",
395 "libmp3extractor",
396 "libmp4extractor",
397 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900398 "libnativebase_headers",
399 "libnativebridge-headers",
400 "libnativebridge_lazy",
401 "libnativeloader-headers",
402 "libnativeloader_lazy",
403 "libnativewindow_headers",
404 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000405 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900406 "libpackagelistparser",
407 "libpcre2",
408 "libpdx",
409 "libpdx_default_transport",
410 "libpdx_headers",
411 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000412 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900413 "libprocessgroup_headers",
414 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900415 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000416 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900417 "libspeexresampler",
418 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000419 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900420 "libstagefright_flacdec",
421 "libstagefright_foundation",
422 "libstagefright_foundation_headers",
423 "libstagefright_foundation_without_imemory",
424 "libstagefright_headers",
425 "libstagefright_id3",
426 "libstagefright_metadatautils",
427 "libstagefright_mpeg2extractor",
428 "libstagefright_mpeg2support",
429 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900430 "libui",
431 "libui_headers",
432 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900433 "libvibrator",
434 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000435 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libwebm",
437 "media_ndk_headers",
438 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000439 "updatable-media",
440 }
441 //
442 // Module separator
443 //
444 m["com.android.media.swcodec"] = []string{
445 "android.frameworks.bufferhub@1.0",
446 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900447 "android.hardware.configstore-utils",
448 "android.hardware.configstore@1.0",
449 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000450 "android.hardware.graphics.allocator@2.0",
451 "android.hardware.graphics.allocator@3.0",
452 "android.hardware.graphics.allocator@4.0",
453 "android.hardware.graphics.bufferqueue@1.0",
454 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900455 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000456 "android.hardware.graphics.common@1.0",
457 "android.hardware.graphics.common@1.1",
458 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000459 "android.hardware.graphics.mapper@2.0",
460 "android.hardware.graphics.mapper@2.1",
461 "android.hardware.graphics.mapper@3.0",
462 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000463 "android.hardware.media.bufferpool@2.0",
464 "android.hardware.media.c2@1.0",
465 "android.hardware.media.c2@1.1",
466 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900467 "android.hardware.media@1.0",
468 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000469 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900470 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000471 "android.hidl.safe_union@1.0",
472 "android.hidl.token@1.0",
473 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900474 "libEGL",
475 "libFLAC",
476 "libFLAC-config",
477 "libFLAC-headers",
478 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900479 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900480 "libarect",
481 "libasync_safe",
482 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000483 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900484 "libaudioutils",
485 "libaudioutils_fixedfft",
486 "libavcdec",
487 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000488 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900489 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900490 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900491 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900492 "libbluetooth-types-header",
493 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900494 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000495 "libcap",
496 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900497 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000498 "libcodec2_hidl@1.0",
499 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900500 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000501 "libcodec2_soft_aacdec",
502 "libcodec2_soft_aacenc",
503 "libcodec2_soft_amrnbdec",
504 "libcodec2_soft_amrnbenc",
505 "libcodec2_soft_amrwbdec",
506 "libcodec2_soft_amrwbenc",
507 "libcodec2_soft_av1dec_gav1",
508 "libcodec2_soft_avcdec",
509 "libcodec2_soft_avcenc",
510 "libcodec2_soft_common",
511 "libcodec2_soft_flacdec",
512 "libcodec2_soft_flacenc",
513 "libcodec2_soft_g711alawdec",
514 "libcodec2_soft_g711mlawdec",
515 "libcodec2_soft_gsmdec",
516 "libcodec2_soft_h263dec",
517 "libcodec2_soft_h263enc",
518 "libcodec2_soft_hevcdec",
519 "libcodec2_soft_hevcenc",
520 "libcodec2_soft_mp3dec",
521 "libcodec2_soft_mpeg2dec",
522 "libcodec2_soft_mpeg4dec",
523 "libcodec2_soft_mpeg4enc",
524 "libcodec2_soft_opusdec",
525 "libcodec2_soft_opusenc",
526 "libcodec2_soft_rawdec",
527 "libcodec2_soft_vorbisdec",
528 "libcodec2_soft_vp8dec",
529 "libcodec2_soft_vp8enc",
530 "libcodec2_soft_vp9dec",
531 "libcodec2_soft_vp9enc",
532 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900533 "libdexfile_support",
534 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000535 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900536 "libfmq",
537 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000538 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900539 "libgrallocusage",
540 "libgraphicsenv",
541 "libgsm",
542 "libgui_bufferqueue_static",
543 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000544 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900545 "libhardware_headers",
546 "libhevcdec",
547 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000548 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900549 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900550 "liblzma",
551 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000552 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900553 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000554 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900555 "libminijail_gen_constants",
556 "libminijail_gen_constants_obj",
557 "libminijail_gen_syscall",
558 "libminijail_gen_syscall_obj",
559 "libminijail_generated",
560 "libmpeg2dec",
561 "libnativebase_headers",
562 "libnativebridge_lazy",
563 "libnativeloader_lazy",
564 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000565 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900566 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000567 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900568 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000569 "libscudo_wrapper",
570 "libsfplugin_ccodec_utils",
571 "libspeexresampler",
572 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "libstagefright_amrnbdec",
574 "libstagefright_amrnbenc",
575 "libstagefright_amrwbdec",
576 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000577 "libstagefright_bufferpool@2.0.1",
578 "libstagefright_bufferqueue_helper",
579 "libstagefright_enc_common",
580 "libstagefright_flacdec",
581 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900582 "libstagefright_foundation_headers",
583 "libstagefright_headers",
584 "libstagefright_m4vh263dec",
585 "libstagefright_m4vh263enc",
586 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000587 "libsync",
588 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900589 "libui_headers",
590 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000591 "libvorbisidec",
592 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900593 "libyuv",
594 "libyuv_static",
595 "media_ndk_headers",
596 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000597 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000598 }
599 //
600 // Module separator
601 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900602 m["com.android.mediaprovider"] = []string{
603 "MediaProvider",
604 "MediaProviderGoogle",
605 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900606 "libbase_ndk",
607 "libfuse",
608 "libfuse_jni",
609 "libnativehelper_header_only",
610 }
611 //
612 // Module separator
613 //
614 m["com.android.permission"] = []string{
615 "androidx.annotation_annotation",
616 "androidx.annotation_annotation-nodeps",
617 "androidx.lifecycle_lifecycle-common",
618 "androidx.lifecycle_lifecycle-common-java8",
619 "androidx.lifecycle_lifecycle-common-java8-nodeps",
620 "androidx.lifecycle_lifecycle-common-nodeps",
621 "kotlin-annotations",
622 "kotlin-stdlib",
623 "kotlin-stdlib-jdk7",
624 "kotlin-stdlib-jdk8",
625 "kotlinx-coroutines-android",
626 "kotlinx-coroutines-android-nodeps",
627 "kotlinx-coroutines-core",
628 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900629 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900630 "GooglePermissionController",
631 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900632 }
Anton Hansson5053c292020-01-10 15:12:39 +0000633 //
634 // Module separator
635 //
Anton Hansson5053c292020-01-10 15:12:39 +0000636 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900638 "libarm-optimized-routines-math",
639 "libasync_safe",
640 "libasync_safe_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900641 "libc_aeabi",
642 "libc_bionic",
643 "libc_bionic_ndk",
644 "libc_bootstrap",
645 "libc_common",
646 "libc_common_shared",
647 "libc_common_static",
648 "libc_dns",
649 "libc_dynamic_dispatch",
650 "libc_fortify",
651 "libc_freebsd",
652 "libc_freebsd_large_stack",
653 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900654 "libc_init_dynamic",
655 "libc_init_static",
656 "libc_jemalloc_wrapper",
657 "libc_netbsd",
658 "libc_nomalloc",
659 "libc_nopthread",
660 "libc_openbsd",
661 "libc_openbsd_large_stack",
662 "libc_openbsd_ndk",
663 "libc_pthread",
664 "libc_static_dispatch",
665 "libc_syscalls",
666 "libc_tzcode",
667 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900668 "libdebuggerd",
669 "libdebuggerd_common_headers",
670 "libdebuggerd_handler_core",
671 "libdebuggerd_handler_fallback",
672 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000673 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900674 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900675 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900676 "libgtest_prod",
677 "libjemalloc5",
678 "liblinker_main",
679 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900680 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000681 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900682 "libprocessgroup_headers",
683 "libprocinfo",
684 "libpropertyinfoparser",
685 "libscudo",
686 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900687 "libsystemproperties",
688 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000689 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900690 "libz",
691 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000692 }
693 //
694 // Module separator
695 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900696 m["com.android.resolv"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 "libgtest_prod",
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 "libnativehelper_header_only",
700 "libnetd_client_headers",
701 "libnetd_resolv",
702 "libnetdutils",
703 "libprocessgroup",
704 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900705 "libstatslog_resolv",
706 "libstatspush_compat",
707 "libstatssocket",
708 "libstatssocket_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900709 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900710 "netd_event_listener_interface-ndk_platform",
711 "server_configurable_flags",
712 "stats_proto",
713 }
Anton Hansson5053c292020-01-10 15:12:39 +0000714 //
715 // Module separator
716 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900717 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900718 "libnativehelper_compat_libc++",
719 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900720 "libcgrouprc",
721 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900722 "libprocessgroup",
723 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900724 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900725 "libvndksupport",
726 "tethering-aidl-interfaces-java",
727 }
Anton Hansson5053c292020-01-10 15:12:39 +0000728 //
729 // Module separator
730 //
731 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900732 "PlatformProperties",
733 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900734 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900735 "android.hardware.wifi-V1.1-java",
736 "android.hardware.wifi-V1.2-java",
737 "android.hardware.wifi-V1.3-java",
738 "android.hardware.wifi-V1.4-java",
739 "android.hardware.wifi.hostapd-V1.0-java",
740 "android.hardware.wifi.hostapd-V1.1-java",
741 "android.hardware.wifi.hostapd-V1.2-java",
742 "android.hardware.wifi.supplicant-V1.0-java",
743 "android.hardware.wifi.supplicant-V1.1-java",
744 "android.hardware.wifi.supplicant-V1.2-java",
745 "android.hardware.wifi.supplicant-V1.3-java",
746 "android.hidl.base-V1.0-java",
747 "android.hidl.manager-V1.0-java",
748 "android.hidl.manager-V1.1-java",
749 "android.hidl.manager-V1.2-java",
750 "androidx.annotation_annotation",
751 "androidx.annotation_annotation-nodeps",
752 "bouncycastle-unbundled",
753 "dnsresolver_aidl_interface-V2-java",
754 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900755 "framework-wifi-pre-jarjar",
756 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900757 "ipmemorystore-aidl-interfaces-V3-java",
758 "ipmemorystore-aidl-interfaces-java",
759 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900760 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000761 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900762 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000763 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900764 "net-utils-services-common",
765 "netd_aidl_interface-V2-java",
766 "netd_aidl_interface-unstable-java",
767 "netd_event_listener_interface-java",
768 "netlink-client",
769 "networkstack-aidl-interfaces-unstable-java",
770 "networkstack-client",
771 "services.net",
772 "wifi-lite-protos",
773 "wifi-nano-protos",
774 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000775 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900776 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000777 }
778 //
779 // Module separator
780 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900781 m["com.android.sdkext"] = []string{
782 "fmtlib_ndk",
783 "libbase_ndk",
784 "libprotobuf-cpp-lite-ndk",
785 }
786 //
787 // Module separator
788 //
789 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900790 "libprocessgroup_headers",
791 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900792 }
793 //
794 // Module separator
795 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000796 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900797 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900798 "libclang_rt",
799 "libgcc_stripped",
800 "libprofile-clang-extras",
801 "libprofile-clang-extras_ndk",
802 "libprofile-extras",
803 "libprofile-extras_ndk",
804 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900805 }
Anton Hansson5053c292020-01-10 15:12:39 +0000806 return m
807}
808
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900809func init() {
Jooyung Hane17caa62020-04-08 14:13:04 +0900810 android.AddNeverAllowRules(android.NeverAllow().
811 ModuleType("apex").
812 With("updatable", "true").
813 With("min_sdk_version", "").
814 Because("All updatable apexes should set min_sdk_version."))
815
Jiyong Parkd1063c12019-07-17 20:08:41 +0900816 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800817 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900818 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900819 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700820 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900821 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900822
Jooyung Han31c470b2019-10-18 16:26:59 +0900823 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900824 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900825
826 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
827 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
828 sort.Strings(*apexFileContextsInfos)
829 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
830 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900831}
832
Jooyung Han31c470b2019-10-18 16:26:59 +0900833func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
834 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
835 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
836}
837
Jiyong Parkd1063c12019-07-17 20:08:41 +0900838func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900839 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900840 ctx.BottomUp("apex", apexMutator).Parallel()
841 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
842 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900843}
844
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900845// Mark the direct and transitive dependencies of apex bundles so that they
846// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900847func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900848 if !mctx.Module().Enabled() {
849 return
850 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800851 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900852 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000853 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900854 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900855 ApexName: mctx.ModuleName(),
856 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900857 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900858 directDep = true
859 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800860 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900861 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900863
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800864 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900865 return
866 }
867
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100868 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900869
Jiyong Parkf760cae2020-02-12 07:53:12 +0900870 mctx.VisitDirectDeps(func(child android.Module) {
871 depName := mctx.OtherModuleName(child)
872 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100873 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800874 android.UpdateApexDependency(apexBundles, depName, directDep)
875 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900876 }
877 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900878}
879
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100880// If a module in an APEX depends on a module from an SDK then it needs an APEX
881// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
882func inAnySdk(module android.Module) bool {
883 if sa, ok := module.(android.SdkAware); ok {
884 return sa.IsInAnySdk()
885 }
886
887 return false
888}
889
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900890// Create apex variations if a module is included in APEX(s).
891func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900892 if !mctx.Module().Enabled() {
893 return
894 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900895 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900896 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000897 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900898 // apex bundle itself is mutated so that it and its modules have same
899 // apex variant.
900 apexBundleName := mctx.ModuleName()
901 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900902 } else if o, ok := mctx.Module().(*OverrideApex); ok {
903 apexBundleName := o.GetOverriddenModuleName()
904 if apexBundleName == "" {
905 mctx.ModuleErrorf("base property is not set")
906 return
907 }
908 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900909 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900910
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900911}
Sundong Ahne9b55722019-09-06 17:37:42 +0900912
Jooyung Han7a78a922019-10-08 21:59:58 +0900913var (
914 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
915 apexFileContextsInfosMutex sync.Mutex
916)
917
918func apexFileContextsInfos(config android.Config) *[]string {
919 return config.Once(apexFileContextsInfosKey, func() interface{} {
920 return &[]string{}
921 }).(*[]string)
922}
923
Jooyung Han54aca7b2019-11-20 02:26:02 +0900924func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900925 apexFileContextsInfosMutex.Lock()
926 defer apexFileContextsInfosMutex.Unlock()
927 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900928 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900929}
930
Sundong Ahne9b55722019-09-06 17:37:42 +0900931func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900932 if !mctx.Module().Enabled() {
933 return
934 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900935 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900936 var variants []string
937 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
938 case "image":
939 variants = append(variants, imageApexType, flattenedApexType)
940 case "zip":
941 variants = append(variants, zipApexType)
942 case "both":
943 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
944 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900945 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900946 return
947 }
948
949 modules := mctx.CreateLocalVariations(variants...)
950
951 for i, v := range variants {
952 switch v {
953 case imageApexType:
954 modules[i].(*apexBundle).properties.ApexType = imageApex
955 case zipApexType:
956 modules[i].(*apexBundle).properties.ApexType = zipApex
957 case flattenedApexType:
958 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900959 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900960 modules[i].(*apexBundle).MakeAsSystemExt()
961 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900962 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900963 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900964 } else if _, ok := mctx.Module().(*OverrideApex); ok {
965 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900966 }
967}
968
Jooyung Han5c998b92019-06-27 11:30:33 +0900969func apexUsesMutator(mctx android.BottomUpMutatorContext) {
970 if ab, ok := mctx.Module().(*apexBundle); ok {
971 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
972 }
973}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900974
Jooyung Handc782442019-11-01 03:14:38 +0900975var (
976 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
977)
978
979// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
980// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
981// which may cause compatibility issues. (e.g. libbinder)
982// Even though libbinder restricts its availability via 'apex_available' property and relies on
983// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
984// to avoid similar problems.
985func useVendorWhitelist(config android.Config) []string {
986 return config.Once(useVendorWhitelistKey, func() interface{} {
987 return []string{
988 // swcodec uses "vendor" variants for smaller size
989 "com.android.media.swcodec",
990 "test_com.android.media.swcodec",
991 }
992 }).([]string)
993}
994
995// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
996// called before the first call to useVendorWhitelist()
997func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
998 config.Once(useVendorWhitelistKey, func() interface{} {
999 return whitelist
1000 })
1001}
1002
Alex Light9670d332019-01-29 18:07:33 -08001003type apexNativeDependencies struct {
1004 // List of native libraries
1005 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001006
Alex Light9670d332019-01-29 18:07:33 -08001007 // List of native executables
1008 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001009
Roland Levillain630846d2019-06-26 12:48:34 +01001010 // List of native tests
1011 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001012}
Jooyung Han344d5432019-08-23 11:17:39 +09001013
Alex Light9670d332019-01-29 18:07:33 -08001014type apexMultilibProperties struct {
1015 // Native dependencies whose compile_multilib is "first"
1016 First apexNativeDependencies
1017
1018 // Native dependencies whose compile_multilib is "both"
1019 Both apexNativeDependencies
1020
1021 // Native dependencies whose compile_multilib is "prefer32"
1022 Prefer32 apexNativeDependencies
1023
1024 // Native dependencies whose compile_multilib is "32"
1025 Lib32 apexNativeDependencies
1026
1027 // Native dependencies whose compile_multilib is "64"
1028 Lib64 apexNativeDependencies
1029}
1030
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001031type apexBundleProperties struct {
1032 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001033 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001034 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001035
Jiyong Park40e26a22019-02-08 02:53:06 +09001036 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1037 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001038 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001039
Roland Levillain411c5842019-09-19 16:37:20 +01001040 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1041 // device (/apex/<apex_name>).
1042 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001043 Apex_name *string
1044
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001045 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001046 // For platform APEXes, this should points to a file under /system/sepolicy
1047 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1048 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001049
1050 // List of native shared libs that are embedded inside this APEX bundle
1051 Native_shared_libs []string
1052
Roland Levillain630846d2019-06-26 12:48:34 +01001053 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054 Binaries []string
1055
1056 // List of java libraries that are embedded inside this APEX bundle
1057 Java_libs []string
1058
1059 // List of prebuilt files that are embedded inside this APEX bundle
1060 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001061
Roland Levillain630846d2019-06-26 12:48:34 +01001062 // List of tests that are embedded inside this APEX bundle
1063 Tests []string
1064
Jiyong Parkff1458f2018-10-12 21:49:38 +09001065 // Name of the apex_key module that provides the private key to sign APEX
1066 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001067
Alex Light5098a612018-11-29 17:12:15 -08001068 // The type of APEX to build. Controls what the APEX payload is. Either
1069 // 'image', 'zip' or 'both'. Default: 'image'.
1070 Payload_type *string
1071
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001072 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1073 // or an android_app_certificate module name in the form ":module".
1074 Certificate *string
1075
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001076 // Whether this APEX is installable to one of the partitions. Default: true.
1077 Installable *bool
1078
Jiyong Parkda6eb592018-12-19 17:12:36 +09001079 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1080 // Default is false.
1081 Use_vendor *bool
1082
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001083 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1084 Ignore_system_library_special_case *bool
1085
Alex Light9670d332019-01-29 18:07:33 -08001086 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001087
Jiyong Parkf97782b2019-02-13 20:28:58 +09001088 // List of sanitizer names that this APEX is enabled for
1089 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001090
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001091 PreventInstall bool `blueprint:"mutated"`
1092
1093 HideFromMake bool `blueprint:"mutated"`
1094
Jooyung Han5c998b92019-06-27 11:30:33 +09001095 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1096 Provide_cpp_shared_libs *bool
1097
1098 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1099 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001100
1101 // A txt file containing list of files that are whitelisted to be included in this APEX.
1102 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001103
Sundong Ahnabb64432019-10-22 13:58:29 +09001104 // package format of this apex variant; could be non-flattened, flattened, or zip.
1105 // imageApex, zipApex or flattened
1106 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001107
Jiyong Parkd1063c12019-07-17 20:08:41 +09001108 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1109 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1110 // is implied. This value affects all modules included in this APEX. In other words, they are
1111 // also built with the SDKs specified here.
1112 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001113
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001114 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1115 // Should be only used in tests#.
1116 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001117
Jiyong Park956305c2020-01-09 12:32:06 +09001118 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001119
1120 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1121 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1122 // like symlinking to the system libs. Default is false.
1123 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001124
1125 // The minimum SDK version that this apex must be compatible with.
1126 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001127}
1128
1129type apexTargetBundleProperties struct {
1130 Target struct {
1131 // Multilib properties only for android.
1132 Android struct {
1133 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001134 }
Jooyung Han344d5432019-08-23 11:17:39 +09001135
Alex Light9670d332019-01-29 18:07:33 -08001136 // Multilib properties only for host.
1137 Host struct {
1138 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001139 }
Jooyung Han344d5432019-08-23 11:17:39 +09001140
Alex Light9670d332019-01-29 18:07:33 -08001141 // Multilib properties only for host linux_bionic.
1142 Linux_bionic struct {
1143 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001144 }
Jooyung Han344d5432019-08-23 11:17:39 +09001145
Alex Light9670d332019-01-29 18:07:33 -08001146 // Multilib properties only for host linux_glibc.
1147 Linux_glibc struct {
1148 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001149 }
1150 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001151}
1152
Jiyong Park5d790c32019-11-15 18:40:32 +09001153type overridableProperties struct {
1154 // List of APKs to package inside APEX
1155 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001156
1157 // Names of modules to be overridden. Listed modules can only be other binaries
1158 // (in Make or Soong).
1159 // This does not completely prevent installation of the overridden binaries, but if both
1160 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1161 // from PRODUCT_PACKAGES.
1162 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001163
1164 // Logging Parent value
1165 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001166
1167 // Apex Container Package Name.
1168 // Override value for attribute package:name in AndroidManifest.xml
1169 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001170}
1171
Alex Light5098a612018-11-29 17:12:15 -08001172type apexPackaging int
1173
1174const (
1175 imageApex apexPackaging = iota
1176 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001177 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001178)
1179
Sundong Ahnabb64432019-10-22 13:58:29 +09001180// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001181func (a apexPackaging) suffix() string {
1182 switch a {
1183 case imageApex:
1184 return imageApexSuffix
1185 case zipApex:
1186 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001187 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001188 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001189 }
1190}
1191
1192func (a apexPackaging) name() string {
1193 switch a {
1194 case imageApex:
1195 return imageApexType
1196 case zipApex:
1197 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001198 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001199 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001200 }
1201}
1202
Jiyong Parkf653b052019-11-18 15:39:01 +09001203type apexFileClass int
1204
1205const (
1206 etc apexFileClass = iota
1207 nativeSharedLib
1208 nativeExecutable
1209 shBinary
1210 pyBinary
1211 goBinary
1212 javaSharedLib
1213 nativeTest
1214 app
1215)
1216
Jiyong Park8fd61922018-11-08 02:50:25 +09001217func (class apexFileClass) NameInMake() string {
1218 switch class {
1219 case etc:
1220 return "ETC"
1221 case nativeSharedLib:
1222 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001223 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001224 return "EXECUTABLES"
1225 case javaSharedLib:
1226 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001227 case nativeTest:
1228 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001229 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001230 // b/142537672 Why isn't this APP? We want to have full control over
1231 // the paths and file names of the apk file under the flattend APEX.
1232 // If this is set to APP, then the paths and file names are modified
1233 // by the Make build system. For example, it is installed to
1234 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1235 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1236 // appends module name (which is <apexname>.<Appname> to the path.
1237 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001238 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001239 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001240 }
1241}
1242
Jiyong Parkf653b052019-11-18 15:39:01 +09001243// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001244type apexFile struct {
1245 builtFile android.Path
1246 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001247 installDir string
1248 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001249 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001250 // list of symlinks that will be created in installDir that point to this apexFile
1251 symlinks []string
1252 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001253 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001254
1255 requiredModuleNames []string
1256 targetRequiredModuleNames []string
1257 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001258
Colin Cross503c1d02020-01-28 14:00:53 -08001259 jacocoReportClassesFile android.Path // only for javalibs and apps
1260 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001261 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001262}
1263
Jiyong Park1833cef2019-12-13 13:28:36 +09001264func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1265 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001266 builtFile: builtFile,
1267 moduleName: moduleName,
1268 installDir: installDir,
1269 class: class,
1270 module: module,
1271 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001272 if module != nil {
1273 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001274 ret.requiredModuleNames = module.RequiredModuleNames()
1275 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1276 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001277 }
1278 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001279}
1280
1281func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001282 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001283}
1284
Jiyong Park7cd10e32020-01-14 09:22:18 +09001285// Path() returns path of this apex file relative to the APEX root
1286func (af *apexFile) Path() string {
1287 return filepath.Join(af.installDir, af.builtFile.Base())
1288}
1289
1290// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1291func (af *apexFile) SymlinkPaths() []string {
1292 var ret []string
1293 for _, symlink := range af.symlinks {
1294 ret = append(ret, filepath.Join(af.installDir, symlink))
1295 }
1296 return ret
1297}
1298
1299func (af *apexFile) AvailableToPlatform() bool {
1300 if af.module == nil {
1301 return false
1302 }
1303 if am, ok := af.module.(android.ApexModule); ok {
1304 return am.AvailableFor(android.AvailableToPlatform)
1305 }
1306 return false
1307}
1308
Jiyong Park678c8812020-02-07 17:25:49 +09001309type depInfo struct {
1310 to string
1311 from []string
1312 isExternal bool
1313}
1314
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001315type apexBundle struct {
1316 android.ModuleBase
1317 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001318 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001319 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001320
Jiyong Park5d790c32019-11-15 18:40:32 +09001321 properties apexBundleProperties
1322 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001323 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001324
Jooyung Hanf21c7972019-12-16 22:32:06 +09001325 // specific to apex_vndk modules
1326 vndkProperties apexVndkProperties
1327
Colin Crossa4925902018-11-16 11:36:28 -08001328 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001329 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001330 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001331
Jiyong Park03b68dd2019-07-26 23:20:40 +09001332 prebuiltFileToDelete string
1333
Jiyong Park42cca6c2019-04-01 11:15:50 +09001334 public_key_file android.Path
1335 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001336
1337 container_certificate_file android.Path
1338 container_private_key_file android.Path
1339
Jooyung Han54aca7b2019-11-20 02:26:02 +09001340 fileContexts android.Path
1341
Jiyong Park8fd61922018-11-08 02:50:25 +09001342 // list of files to be included in this apex
1343 filesInfo []apexFile
1344
Jiyong Park956305c2020-01-09 12:32:06 +09001345 // list of module names that should be installed along with this APEX
1346 requiredDeps []string
1347
Jiyong Park956305c2020-01-09 12:32:06 +09001348 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001349 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001350
Sundong Ahnabb64432019-10-22 13:58:29 +09001351 testApex bool
1352 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001353 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001354 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001355
Jooyung Han214bf372019-11-12 13:03:50 +09001356 manifestJsonOut android.WritablePath
1357 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001358
Jooyung Han002ab682020-01-08 01:57:58 +09001359 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001360 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001361 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001362 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1363 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001364
1365 // Suffix of module name in Android.mk
1366 // ".flattened", ".apex", ".zipapex", or ""
1367 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001368
1369 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001370
1371 // Whether to create symlink to the system file instead of having a file
1372 // inside the apex or not
1373 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001374
1375 // Struct holding the merged notice file paths in different formats
1376 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001377}
1378
Jiyong Park397e55e2018-10-24 21:09:55 +09001379func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001380 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001381 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001382 // Use *FarVariation* to be able to depend on modules having
1383 // conflicting variations with this module. This is required since
1384 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1385 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001386 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001387 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001388 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001389 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001390 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001391
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001392 ctx.AddFarVariationDependencies(append(target.Variations(),
1393 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1394 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001395
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001396 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001397 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001398 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001399 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001400}
1401
Alex Light9670d332019-01-29 18:07:33 -08001402func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1403 if ctx.Os().Class == android.Device {
1404 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1405 } else {
1406 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1407 if ctx.Os().Bionic() {
1408 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1409 } else {
1410 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1411 }
1412 }
1413}
1414
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001415func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001416 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1417 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1418 }
1419
Jiyong Park397e55e2018-10-24 21:09:55 +09001420 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001421 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001422
1423 a.combineProperties(ctx)
1424
Jiyong Park397e55e2018-10-24 21:09:55 +09001425 has32BitTarget := false
1426 for _, target := range targets {
1427 if target.Arch.ArchType.Multilib == "lib32" {
1428 has32BitTarget = true
1429 }
1430 }
1431 for i, target := range targets {
1432 // When multilib.* is omitted for native_shared_libs, it implies
1433 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001434 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001435 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001436 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001437 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001438
Roland Levillain630846d2019-06-26 12:48:34 +01001439 // When multilib.* is omitted for tests, it implies
1440 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001441 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001442 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001443 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001444 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001445
Jiyong Park397e55e2018-10-24 21:09:55 +09001446 // Add native modules targetting both ABIs
1447 addDependenciesForNativeModules(ctx,
1448 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001449 a.properties.Multilib.Both.Binaries,
1450 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001451 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001452 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001453
Alex Light3d673592019-01-18 14:37:31 -08001454 isPrimaryAbi := i == 0
1455 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001456 // When multilib.* is omitted for binaries, it implies
1457 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001458 ctx.AddFarVariationDependencies(append(target.Variations(),
1459 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1460 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001461
1462 // Add native modules targetting the first ABI
1463 addDependenciesForNativeModules(ctx,
1464 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001465 a.properties.Multilib.First.Binaries,
1466 a.properties.Multilib.First.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 }
1470
1471 switch target.Arch.ArchType.Multilib {
1472 case "lib32":
1473 // Add native modules targetting 32-bit ABI
1474 addDependenciesForNativeModules(ctx,
1475 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001476 a.properties.Multilib.Lib32.Binaries,
1477 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001478 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001479 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001480
1481 addDependenciesForNativeModules(ctx,
1482 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001483 a.properties.Multilib.Prefer32.Binaries,
1484 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001485 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001486 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001487 case "lib64":
1488 // Add native modules targetting 64-bit ABI
1489 addDependenciesForNativeModules(ctx,
1490 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001491 a.properties.Multilib.Lib64.Binaries,
1492 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001493 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001494 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001495
1496 if !has32BitTarget {
1497 addDependenciesForNativeModules(ctx,
1498 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001499 a.properties.Multilib.Prefer32.Binaries,
1500 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001501 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001502 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001503 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001504
1505 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1506 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1507 if sanitizer == "hwaddress" {
1508 addDependenciesForNativeModules(ctx,
1509 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001510 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001511 break
1512 }
1513 }
1514 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001515 }
1516
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001517 }
1518
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001519 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1520 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1521 // b/144532908
1522 archForPrebuiltEtc := config.Arches()[0]
1523 for _, arch := range config.Arches() {
1524 // Prefer 64-bit arch if there is any
1525 if arch.ArchType.Multilib == "lib64" {
1526 archForPrebuiltEtc = arch
1527 break
1528 }
1529 }
1530 ctx.AddFarVariationDependencies([]blueprint.Variation{
1531 {Mutator: "os", Variation: ctx.Os().String()},
1532 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1533 }, prebuiltTag, a.properties.Prebuilts...)
1534
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001535 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1536 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001537
Ulya Trafimovich44561882020-01-03 13:25:54 +00001538 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1539 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1540 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1541 javaLibTag, "jacocoagent")
1542 }
1543
Jiyong Park23c52b02019-02-02 13:13:47 +09001544 if String(a.properties.Key) == "" {
1545 ctx.ModuleErrorf("key is missing")
1546 return
1547 }
1548 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001549
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001550 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001551 if cert != "" {
1552 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001553 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001554
1555 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1556 if len(a.properties.Uses_sdks) > 0 {
1557 sdkRefs := []android.SdkRef{}
1558 for _, str := range a.properties.Uses_sdks {
1559 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1560 sdkRefs = append(sdkRefs, parsed)
1561 }
1562 a.BuildWithSdks(sdkRefs)
1563 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001564}
1565
Jiyong Park5d790c32019-11-15 18:40:32 +09001566func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1567 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1568 androidAppTag, a.overridableProperties.Apps...)
1569}
1570
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001571func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1572 // direct deps of an APEX bundle are all part of the APEX bundle
1573 return true
1574}
1575
Colin Cross0ea8ba82019-06-06 14:33:29 -07001576func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001577 moduleName := ctx.ModuleName()
1578 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1579 // we check with the pseudo module name to see if its certificate is overridden.
1580 if a.vndkApex {
1581 moduleName = vndkApexName
1582 }
1583 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001584 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001585 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001586 }
1587 return String(a.properties.Certificate)
1588}
1589
Colin Cross41955e82019-05-29 14:40:35 -07001590func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1591 switch tag {
1592 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001593 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001594 default:
1595 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001596 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001597}
1598
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001599func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001600 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001601}
1602
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001603func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1604 return proptools.Bool(a.properties.Test_only_no_hashtree)
1605}
1606
Jiyong Park7c1dc612019-01-05 11:15:24 +09001607func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001608 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001609 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001610 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001611 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001612 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001613 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001614 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001615 }
1616}
1617
Jiyong Parkf97782b2019-02-13 20:28:58 +09001618func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1619 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1620 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1621 }
1622}
1623
Jiyong Park388ef3f2019-01-28 19:47:32 +09001624func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001625 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1626 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001627 }
1628
1629 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001630 globalSanitizerNames := []string{}
1631 if a.Host() {
1632 globalSanitizerNames = ctx.Config().SanitizeHost()
1633 } else {
1634 arches := ctx.Config().SanitizeDeviceArch()
1635 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1636 globalSanitizerNames = ctx.Config().SanitizeDevice()
1637 }
1638 }
1639 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001640}
1641
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001642func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001643 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001644}
1645
1646func (a *apexBundle) PreventInstall() {
1647 a.properties.PreventInstall = true
1648}
1649
1650func (a *apexBundle) HideFromMake() {
1651 a.properties.HideFromMake = true
1652}
1653
Jiyong Park956305c2020-01-09 12:32:06 +09001654func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1655 a.properties.IsCoverageVariant = coverage
1656}
1657
Jiyong Parkf653b052019-11-18 15:39:01 +09001658// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001659func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001660 // Decide the APEX-local directory by the multilib of the library
1661 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001662 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001663 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001664 case "lib32":
1665 dirInApex = "lib"
1666 case "lib64":
1667 dirInApex = "lib64"
1668 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001669 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001670 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001671 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001672 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001673 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001674 // Special case for Bionic libs and other libs installed with them. This is
1675 // to prevent those libs from being included in the search path
1676 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1677 // those libs in the Runtime APEX are available via the legacy paths in
1678 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1679 // to the legacy paths and thus will be loaded into the default linker
1680 // namespace (aka "platform" namespace). If the libs are directly in
1681 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1682 // into the runtime linker namespace, which will result in double loading of
1683 // them, which isn't supported.
1684 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001685 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001686
Jiyong Parkf653b052019-11-18 15:39:01 +09001687 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001688 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001689}
1690
Jiyong Park1833cef2019-12-13 13:28:36 +09001691func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001692 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001693 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001694 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001695 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001696 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001697 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001698 af.symlinks = cc.Symlinks()
1699 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001700}
1701
Jiyong Park1833cef2019-12-13 13:28:36 +09001702func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001703 dirInApex := "bin"
1704 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001705 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001706}
Jiyong Park1833cef2019-12-13 13:28:36 +09001707func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001708 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001709 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1710 if err != nil {
1711 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001712 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001713 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001714 fileToCopy := android.PathForOutput(ctx, s)
1715 // NB: Since go binaries are static we don't need the module for anything here, which is
1716 // good since the go tool is a blueprint.Module not an android.Module like we would
1717 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001718 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001719}
1720
Jiyong Park1833cef2019-12-13 13:28:36 +09001721func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001722 dirInApex := filepath.Join("bin", sh.SubDir())
1723 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001724 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001725 af.symlinks = sh.Symlinks()
1726 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001727}
1728
Jooyung Han58f26ab2019-12-18 15:34:32 +09001729// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1730type javaLibrary interface {
1731 android.Module
1732 java.Dependency
1733}
1734
1735func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001736 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001737 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001738 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1739 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1740 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001741}
1742
Jiyong Park1833cef2019-12-13 13:28:36 +09001743func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001744 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1745 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001746 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001747}
1748
atrost6e126252020-01-27 17:01:16 +00001749func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1750 dirInApex := filepath.Join("etc", config.SubDir())
1751 fileToCopy := config.CompatConfig()
1752 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1753}
1754
Jiyong Park1833cef2019-12-13 13:28:36 +09001755func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001756 android.Module
1757 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001758 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001759 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001760 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001761 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001762}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001763 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001764 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001765 appDir = "priv-app"
1766 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001767 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001768 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001769 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1770 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001771 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001772
1773 if app, ok := aapp.(interface {
1774 OverriddenManifestPackageName() string
1775 }); ok {
1776 af.overriddenPackageName = app.OverriddenManifestPackageName()
1777 }
Jiyong Park618922e2020-01-08 13:35:43 +09001778 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001779}
1780
Roland Levillain935639d2019-08-13 14:55:28 +01001781// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1782type flattenedApexContext struct {
1783 android.ModuleContext
1784}
1785
1786func (c *flattenedApexContext) InstallBypassMake() bool {
1787 return true
1788}
1789
Paul Duffin133608f2020-03-30 15:54:08 +01001790// Function called while walking an APEX's payload dependencies.
1791//
1792// Return true if the `to` module should be visited, false otherwise.
1793type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1794
Jiyong Park201cedd2020-02-07 17:25:49 +09001795// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001796func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001797 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001798 am, ok := child.(android.ApexModule)
1799 if !ok || !am.CanHaveApexVariants() {
1800 return false
1801 }
1802
1803 // Check for the direct dependencies that contribute to the payload
1804 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1805 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001806 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001807 }
Paul Duffin133608f2020-03-30 15:54:08 +01001808 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001809 return false
1810 }
1811
1812 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001813 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001814 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001815 }
1816
Paul Duffin133608f2020-03-30 15:54:08 +01001817 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001818 })
1819}
1820
Jooyung Han0c4e0162020-02-26 22:45:42 +09001821func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1822 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001823 intVer, err := android.ApiStrToNum(ctx, ver)
1824 if err != nil {
1825 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001826 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001827 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001828}
1829
Paul Duffinf0207962020-03-31 11:31:36 +01001830// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1831// a dependency tag.
1832var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1833
1834func PrettyPrintTag(tag blueprint.DependencyTag) string {
1835 // Use tag's custom String() method if available.
1836 if stringer, ok := tag.(fmt.Stringer); ok {
1837 return stringer.String()
1838 }
1839
1840 // Otherwise, get a default string representation of the tag's struct.
1841 tagString := fmt.Sprintf("%#v", tag)
1842
1843 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1844 tagString = tagCleaner.ReplaceAllString(tagString, "")
1845 return tagString
1846}
1847
Jiyong Park201cedd2020-02-07 17:25:49 +09001848// Ensures that the dependencies are marked as available for this APEX
1849func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1850 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1851 if ctx.Host() || a.testApex || a.vndkApex {
1852 return
1853 }
1854
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001855 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1856 // Requiring them and their transitive depencies with apex_available is not right
1857 // because they just add noise.
1858 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1859 return
1860 }
1861
Paul Duffin133608f2020-03-30 15:54:08 +01001862 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1863 if externalDep {
1864 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1865 return false
1866 }
1867
Jiyong Park201cedd2020-02-07 17:25:49 +09001868 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001869 fromName := ctx.OtherModuleName(from)
1870 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001871
1872 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1873 // do any of its dependencies.
1874 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1875 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1876 return false
1877 }
1878
Paul Duffin133608f2020-03-30 15:54:08 +01001879 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1880 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001881 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001882 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001883 tagPath := ctx.GetTagPath()
1884 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1885 walkPath := ctx.GetWalkPath()[1:]
1886 for i, m := range walkPath {
1887 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001888 }
1889 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 +01001890 // Visit this module's dependencies to check and report any issues with their availability.
1891 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001892 })
1893}
1894
Jiyong Park678c8812020-02-07 17:25:49 +09001895// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1896func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1897 a.depInfos = make(map[string]depInfo)
Paul Duffin133608f2020-03-30 15:54:08 +01001898 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001899 if from.Name() == to.Name() {
1900 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffin133608f2020-03-30 15:54:08 +01001901 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1902 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001903 }
1904
1905 if info, exists := a.depInfos[to.Name()]; exists {
1906 if !android.InList(from.Name(), info.from) {
1907 info.from = append(info.from, from.Name())
1908 }
1909 info.isExternal = info.isExternal && externalDep
1910 a.depInfos[to.Name()] = info
1911 } else {
1912 a.depInfos[to.Name()] = depInfo{
1913 to: to.Name(),
1914 from: []string{from.Name()},
1915 isExternal: externalDep,
1916 }
1917 }
Paul Duffin133608f2020-03-30 15:54:08 +01001918
1919 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1920 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001921 })
1922}
1923
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001924func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001925 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1926 switch a.properties.ApexType {
1927 case imageApex:
1928 if buildFlattenedAsDefault {
1929 a.suffix = imageApexSuffix
1930 } else {
1931 a.suffix = ""
1932 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001933
1934 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001935 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001936 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001937 }
1938 case zipApex:
1939 if proptools.String(a.properties.Payload_type) == "zip" {
1940 a.suffix = ""
1941 a.primaryApexType = true
1942 } else {
1943 a.suffix = zipApexSuffix
1944 }
1945 case flattenedApex:
1946 if buildFlattenedAsDefault {
1947 a.suffix = ""
1948 a.primaryApexType = true
1949 } else {
1950 a.suffix = flattenedSuffix
1951 }
Alex Light5098a612018-11-29 17:12:15 -08001952 }
1953
Roland Levillain630846d2019-06-26 12:48:34 +01001954 if len(a.properties.Tests) > 0 && !a.testApex {
1955 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1956 return
1957 }
1958
Jiyong Parkfa899442020-01-31 02:49:53 +09001959 a.checkApexAvailability(ctx)
1960
Jiyong Park678c8812020-02-07 17:25:49 +09001961 a.collectDepsInfo(ctx)
1962
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001963 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1964
Jooyung Hane1633032019-08-01 17:41:43 +09001965 // native lib dependencies
1966 var provideNativeLibs []string
1967 var requireNativeLibs []string
1968
Jooyung Han5c998b92019-06-27 11:30:33 +09001969 // Check if "uses" requirements are met with dependent apexBundles
1970 var providedNativeSharedLibs []string
1971 useVendor := proptools.Bool(a.properties.Use_vendor)
1972 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1973 if ctx.OtherModuleDependencyTag(m) != usesTag {
1974 return
1975 }
1976 otherName := ctx.OtherModuleName(m)
1977 other, ok := m.(*apexBundle)
1978 if !ok {
1979 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1980 return
1981 }
1982 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1983 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1984 return
1985 }
1986 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1987 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1988 return
1989 }
1990 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1991 })
1992
Jiyong Parkf653b052019-11-18 15:39:01 +09001993 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001994 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001995 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001996 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01001997 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1998 return false
1999 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002000 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002001 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002002 switch depTag {
2003 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002004 if c, ok := child.(*cc.Module); ok {
2005 // bootstrap bionic libs are treated as provided by system
2006 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2007 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002008 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002009 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002010 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002011 } else {
2012 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002013 }
2014 case executableTag:
2015 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002016 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002017 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002018 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002019 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002020 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002021 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002022 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002023 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002024 } else {
Alex Light778127a2019-02-27 14:19:50 -08002025 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 +09002026 }
2027 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002028 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002029 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002030 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002031 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2032 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002033 filesInfo = append(filesInfo, af)
2034 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002035 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002036 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2037 af := apexFileForJavaLibrary(ctx, sdkLib)
2038 if !af.Ok() {
2039 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2040 return false
2041 }
2042 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002043 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002044 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002045 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002046 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002047 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002048 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002049 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002050 return true // track transitive dependencies
2051 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002052 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002053 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002054 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002055 } else {
2056 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2057 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002058 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002059 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002060 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002061 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2062 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002063 } else {
atrost6e126252020-01-27 17:01:16 +00002064 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002065 }
Roland Levillain630846d2019-06-26 12:48:34 +01002066 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002067 if ccTest, ok := child.(*cc.Module); ok {
2068 if ccTest.IsTestPerSrcAllTestsVariation() {
2069 // Multiple-output test module (where `test_per_src: true`).
2070 //
2071 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2072 // We do not add this variation to `filesInfo`, as it has no output;
2073 // however, we do add the other variations of this module as indirect
2074 // dependencies (see below).
2075 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002076 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002077 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002078 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002079 af.class = nativeTest
2080 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002081 }
Roland Levillain630846d2019-06-26 12:48:34 +01002082 } else {
2083 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2084 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002085 case keyTag:
2086 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002087 a.private_key_file = key.private_key_file
2088 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002089 } else {
2090 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002091 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002092 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002093 case certificateTag:
2094 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002095 a.container_certificate_file = dep.Certificate.Pem
2096 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002097 } else {
2098 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2099 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002100 case android.PrebuiltDepTag:
2101 // If the prebuilt is force disabled, remember to delete the prebuilt file
2102 // that might have been installed in the previous builds
2103 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2104 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2105 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002106 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002107 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002108 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002109 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002110 // We cannot use a switch statement on `depTag` here as the checked
2111 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002112 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002113 if cc, ok := child.(*cc.Module); ok {
2114 if android.InList(cc.Name(), providedNativeSharedLibs) {
2115 // If we're using a shared library which is provided from other APEX,
2116 // don't include it in this APEX
2117 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002118 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002119 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002120 // If the dependency is a stubs lib, don't include it in this APEX,
2121 // but make sure that the lib is installed on the device.
2122 // In case no APEX is having the lib, the lib is installed to the system
2123 // partition.
2124 //
2125 // Always include if we are a host-apex however since those won't have any
2126 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002127 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2128 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002129 }
Jooyung Hane1633032019-08-01 17:41:43 +09002130 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002131 // Don't track further
2132 return false
2133 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002134 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002135 af.transitiveDep = true
2136 filesInfo = append(filesInfo, af)
2137 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002138 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002139 } else if cc.IsTestPerSrcDepTag(depTag) {
2140 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002141 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002142 // Handle modules created as `test_per_src` variations of a single test module:
2143 // use the name of the generated test binary (`fileToCopy`) instead of the name
2144 // of the original test module (`depName`, shared by all `test_per_src`
2145 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002146 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002147 // these are not considered transitive dep
2148 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002149 filesInfo = append(filesInfo, af)
2150 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002151 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002152 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002153 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2154 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002155 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2156 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2157 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2158 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002159 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002160 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002161 }
2162 }
2163 }
2164 return false
2165 })
2166
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002167 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2168 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2169 // via the global boot image config.
2170 if a.artApex {
2171 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2172 dirInApex := filepath.Join("javalib", arch.String())
2173 for _, f := range files {
2174 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002175 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002176 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002177 }
2178 }
2179 }
2180
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002181 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002182 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2183 return
2184 }
2185
Jiyong Park8fd61922018-11-08 02:50:25 +09002186 // remove duplicates in filesInfo
2187 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002188 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002189 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002190 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002191 if e, ok := encountered[dest]; !ok {
2192 encountered[dest] = f
2193 } else {
2194 // If a module is directly included and also transitively depended on
2195 // consider it as directly included.
2196 e.transitiveDep = e.transitiveDep && f.transitiveDep
2197 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002198 }
2199 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002200 var result []apexFile
2201 for _, v := range encountered {
2202 result = append(result, v)
2203 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002204 return result
2205 }
2206 filesInfo = removeDup(filesInfo)
2207
2208 // to have consistent build rules
2209 sort.Slice(filesInfo, func(i, j int) bool {
2210 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2211 })
2212
Jiyong Park8fd61922018-11-08 02:50:25 +09002213 a.installDir = android.PathForModuleInstall(ctx, "apex")
2214 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002215
Jooyung Han54aca7b2019-11-20 02:26:02 +09002216 if a.properties.ApexType != zipApex {
2217 if a.properties.File_contexts == nil {
2218 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2219 } else {
2220 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2221 if a.Platform() {
2222 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2223 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2224 }
2225 }
2226 }
2227 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2228 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2229 return
2230 }
2231 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002232 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2233 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2234 // the same library in the system partition, thus effectively sharing the same libraries
2235 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2236 // in the APEX.
2237 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2238 a.installable() &&
2239 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002240
Jiyong Park9d677202020-02-19 16:29:35 +09002241 // We don't need the optimization for updatable APEXes, as it might give false signal
2242 // to the system health when the APEXes are still bundled (b/149805758)
2243 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2244 a.linkToSystemLib = false
2245 }
2246
Jiyong Park9b964182020-02-26 18:27:19 +09002247 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2248 if ctx.Host() {
2249 a.linkToSystemLib = false
2250 }
2251
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002252 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002253 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2254
2255 a.setCertificateAndPrivateKey(ctx)
2256 if a.properties.ApexType == flattenedApex {
2257 a.buildFlattenedApex(ctx)
2258 } else {
2259 a.buildUnflattenedApex(ctx)
2260 }
2261
Jooyung Han002ab682020-01-08 01:57:58 +09002262 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002263
2264 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002265}
2266
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002267func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002268 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002269 moduleName = normalizeModuleName(moduleName)
2270
2271 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2272 return true
2273 }
2274
2275 key = android.AvailableToAnyApex
2276 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2277 return true
2278 }
2279
2280 return false
2281}
2282
2283func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002284 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2285 // system. Trim the prefix for the check since they are confusing
2286 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2287 if strings.HasPrefix(moduleName, "libclang_rt.") {
2288 // This module has many arch variants that depend on the product being built.
2289 // We don't want to list them all
2290 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002291 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002292 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002293}
2294
Jooyung Han344d5432019-08-23 11:17:39 +09002295func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002296 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002297 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002298 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002299 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002300 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002301 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2302 })
Alex Light5098a612018-11-29 17:12:15 -08002303 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002304 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002305 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002306 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002307 return module
2308}
Jiyong Park30ca9372019-02-07 16:27:23 +09002309
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002310func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002311 bundle := newApexBundle()
2312 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002313 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002314 return bundle
2315}
2316
Jiyong Parkfce0b422020-02-11 03:56:06 +09002317// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2318// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002319func testApexBundleFactory() android.Module {
2320 bundle := newApexBundle()
2321 bundle.testApex = true
2322 return bundle
2323}
2324
Jiyong Parkfce0b422020-02-11 03:56:06 +09002325// apex packages other modules into an APEX file which is a packaging format for system-level
2326// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002327func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002328 return newApexBundle()
2329}
2330
Jiyong Park30ca9372019-02-07 16:27:23 +09002331//
2332// Defaults
2333//
2334type Defaults struct {
2335 android.ModuleBase
2336 android.DefaultsModuleBase
2337}
2338
Jiyong Park30ca9372019-02-07 16:27:23 +09002339func defaultsFactory() android.Module {
2340 return DefaultsFactory()
2341}
2342
2343func DefaultsFactory(props ...interface{}) android.Module {
2344 module := &Defaults{}
2345
2346 module.AddProperties(props...)
2347 module.AddProperties(
2348 &apexBundleProperties{},
2349 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002350 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002351 )
2352
2353 android.InitDefaultsModule(module)
2354 return module
2355}
Jiyong Park5d790c32019-11-15 18:40:32 +09002356
2357//
2358// OverrideApex
2359//
2360type OverrideApex struct {
2361 android.ModuleBase
2362 android.OverrideModuleBase
2363}
2364
2365func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2366 // All the overrides happen in the base module.
2367}
2368
2369// override_apex is used to create an apex module based on another apex module
2370// by overriding some of its properties.
2371func overrideApexFactory() android.Module {
2372 m := &OverrideApex{}
2373 m.AddProperties(&overridableProperties{})
2374
2375 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2376 android.InitOverrideModule(m)
2377 return m
2378}