blob: 894439fdeaf3af24bd879457b5f989fa552a4685 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090048
49 // determines if the dependent will be part of the APEX payload
50 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090051}
52
53var (
Jiyong Parkfa899442020-01-31 02:49:53 +090054 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
55 executableTag = dependencyTag{name: "executable", payload: true}
56 javaLibTag = dependencyTag{name: "javaLib", payload: true}
57 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
58 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090059 keyTag = dependencyTag{name: "key"}
60 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090061 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090062 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000063 apexAvailWl = makeApexAvailableWhitelist()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090064)
65
Anton Hansson5053c292020-01-10 15:12:39 +000066// This is a map from apex to modules, which overrides the
67// apex_available setting for that particular module to make
68// it available for the apex regardless of its setting.
69// TODO(b/147364041): remove this
70func makeApexAvailableWhitelist() map[string][]string {
71 // The "Module separator"s below are employed to minimize merge conflicts.
72 m := make(map[string][]string)
73 //
74 // Module separator
75 //
Jiyong Parkfa899442020-01-31 02:49:53 +090076 m["com.android.adbd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090077 "libadbd_auth",
Jiyong Parkfa899442020-01-31 02:49:53 +090078 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +090079 "libcap",
Jiyong Parkfa899442020-01-31 02:49:53 +090080 "libmdnssd",
81 "libminijail",
82 "libminijail_gen_constants",
83 "libminijail_gen_constants_obj",
84 "libminijail_gen_syscall",
85 "libminijail_gen_syscall_obj",
86 "libminijail_generated",
87 "libpackagelistparser",
88 "libpcre2",
89 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +090090 }
91 //
92 // Module separator
93 //
Paul Duffinc23d9f62020-03-10 13:44:19 +000094 artApexContents := []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090095 "art_cmdlineparser_headers",
96 "art_disassembler_headers",
97 "art_libartbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +090098 "bionic_libc_platform_headers",
99 "core-repackaged-icu4j",
100 "cpp-define-generator-asm-support",
101 "cpp-define-generator-definitions",
102 "crtbegin_dynamic",
103 "crtbegin_dynamic1",
104 "crtbegin_so1",
105 "crtbrand",
106 "conscrypt.module.intra.core.api.stubs",
107 "dex2oat_headers",
108 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900109 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900110 "javavm_headers",
111 "jni_platform_headers",
112 "libPlatformProperties",
113 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000114 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900115 "libandroidicuinit",
116 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000117 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900118 "libasync_safe",
Jiyong Parkfa899442020-01-31 02:49:53 +0900119 "libdexfile_all_headers",
120 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000121 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900122 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000123 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900124 "libfdlibm",
125 "libgtest_prod",
126 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000127 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900128 "libicuuc_headers",
129 "libicuuc_stubdata",
130 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900131 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000132 "liblzma",
133 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900134 "libnativebridge-headers",
135 "libnativehelper_header_only",
136 "libnativeloader-headers",
137 "libnpt_headers",
138 "libopenjdkjvmti_headers",
139 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000140 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900141 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000142 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900143 "libv8",
144 "libv8base",
145 "libv8gen",
146 "libv8platform",
147 "libv8sampler",
148 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000149 "libvixl",
150 "libvixld",
151 "libz",
152 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900153 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000154 }
Paul Duffinc23d9f62020-03-10 13:44:19 +0000155 m["com.android.art.debug"] = artApexContents
156 m["com.android.art.release"] = artApexContents
Anton Hansson5053c292020-01-10 15:12:39 +0000157 //
158 // Module separator
159 //
160 m["com.android.bluetooth.updatable"] = []string{
161 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000162 "android.hardware.bluetooth.a2dp@1.0",
163 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900164 "android.hardware.bluetooth@1.0",
165 "android.hardware.bluetooth@1.1",
166 "android.hardware.graphics.bufferqueue@1.0",
167 "android.hardware.graphics.bufferqueue@2.0",
168 "android.hardware.graphics.common@1.0",
169 "android.hardware.graphics.common@1.1",
170 "android.hardware.graphics.common@1.2",
171 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000172 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900173 "android.hidl.token@1.0",
174 "android.hidl.token@1.0-utils",
175 "avrcp-target-service",
176 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900177 "bluetooth-protos-lite",
178 "bluetooth.mapsapi",
179 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900180 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900181 "ipmemorystore-aidl-interfaces-V5-java",
182 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900183 "internal_include_headers",
184 "lib-bt-packets",
185 "lib-bt-packets-avrcp",
186 "lib-bt-packets-base",
187 "libFraunhoferAAC",
188 "libaudio-a2dp-hw-utils",
189 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900190 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000191 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900192 "libbluetooth-types",
193 "libbluetooth-types-header",
194 "libbluetooth_gd",
195 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000196 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900197 "libbt-audio-hal-interface",
198 "libbt-bta",
199 "libbt-common",
200 "libbt-hci",
201 "libbt-platform-protos-lite",
202 "libbt-protos-lite",
203 "libbt-sbc-decoder",
204 "libbt-sbc-encoder",
205 "libbt-stack",
206 "libbt-utils",
207 "libbtcore",
208 "libbtdevice",
209 "libbte",
210 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000211 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000212 "libevent",
213 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900214 "libg722codec",
215 "libgtest_prod",
216 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900217 "libmedia_headers",
218 "libmodpb64",
219 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000220 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900221 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900222 "libstagefright_foundation_headers",
223 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000224 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900225 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000226 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900227 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000228 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900229 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900230 "net-utils-services-common",
231 "netd_aidl_interface-unstable-java",
232 "netd_event_listener_interface-java",
233 "netlink-client",
234 "networkstack-aidl-interfaces-unstable-java",
235 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900236 "sap-api-java-static",
237 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000238 }
239 //
240 // Module separator
241 //
242 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
243 //
244 // Module separator
245 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900246 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900247 "boringssl_self_test",
Jiyong Parkfa899442020-01-31 02:49:53 +0900248 "libnativehelper_header_only",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900249 "unsupportedappusage",
Jiyong Parkfa899442020-01-31 02:49:53 +0900250 }
Anton Hansson5053c292020-01-10 15:12:39 +0000251 //
252 // Module separator
253 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900254 m["com.android.extservices"] = []string{
255 "flatbuffer_headers",
256 "liblua",
257 "libtextclassifier",
258 "libtextclassifier_hash_static",
259 "libtflite_static",
260 "libutf",
261 "libz_current",
262 "tensorflow_headers",
263 }
264 //
265 // Module separator
266 //
267 m["com.android.cronet"] = []string{
268 "cronet_impl_common_java",
269 "cronet_impl_native_java",
270 "cronet_impl_platform_java",
271 "libcronet.80.0.3986.0",
272 "org.chromium.net.cronet",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900273 "org.chromium.net.cronet.xml",
Jiyong Parkfa899442020-01-31 02:49:53 +0900274 "prebuilt_libcronet.80.0.3986.0",
275 }
276 //
277 // Module separator
278 //
279 m["com.android.neuralnetworks"] = []string{
280 "android.hardware.neuralnetworks@1.0",
281 "android.hardware.neuralnetworks@1.1",
282 "android.hardware.neuralnetworks@1.2",
283 "android.hardware.neuralnetworks@1.3",
284 "android.hidl.allocator@1.0",
285 "android.hidl.memory.token@1.0",
286 "android.hidl.memory@1.0",
287 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900288 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900289 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900290 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900291 "libprocessgroup",
292 "libprocessgroup_headers",
293 "libprocpartition",
294 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900295 }
Anton Hansson5053c292020-01-10 15:12:39 +0000296 //
297 // Module separator
298 //
Anton Hansson5053c292020-01-10 15:12:39 +0000299 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900300 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000301 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900302 "android.hardware.cas@1.0",
303 "android.hardware.configstore-utils",
304 "android.hardware.configstore@1.0",
305 "android.hardware.configstore@1.1",
306 "android.hardware.graphics.allocator@2.0",
307 "android.hardware.graphics.allocator@3.0",
308 "android.hardware.graphics.bufferqueue@1.0",
309 "android.hardware.graphics.bufferqueue@2.0",
310 "android.hardware.graphics.common@1.0",
311 "android.hardware.graphics.common@1.1",
312 "android.hardware.graphics.common@1.2",
313 "android.hardware.graphics.mapper@2.0",
314 "android.hardware.graphics.mapper@2.1",
315 "android.hardware.graphics.mapper@3.0",
316 "android.hardware.media.omx@1.0",
317 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000318 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000319 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900320 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000321 "android.hidl.token@1.0",
322 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900323 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900324 "gl_headers",
325 "libEGL",
326 "libEGL_blobCache",
327 "libEGL_getProcAddress",
328 "libFLAC",
329 "libFLAC-config",
330 "libFLAC-headers",
331 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000332 "libaacextractor",
333 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900334 "libarect",
335 "libasync_safe",
336 "libaudio_system_headers",
337 "libaudioclient",
338 "libaudioclient_headers",
339 "libaudiofoundation",
340 "libaudiofoundation_headers",
341 "libaudiomanager",
342 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000343 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900344 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900345 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900346 "libbluetooth-types-header",
347 "libbufferhub",
348 "libbufferhub_headers",
349 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900350 "libc_malloc_debug_backtrace",
351 "libcamera_client",
352 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900353 "libdexfile_external_headers",
354 "libdexfile_support",
355 "libdvr_headers",
356 "libexpat",
357 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000358 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900359 "libgrallocusage",
360 "libgraphicsenv",
361 "libgui",
362 "libgui_headers",
363 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900364 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900365 "liblzma",
366 "libmath",
367 "libmedia",
368 "libmedia_codeclist",
369 "libmedia_headers",
370 "libmedia_helper",
371 "libmedia_helper_headers",
372 "libmedia_midiiowrapper",
373 "libmedia_omx",
374 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000375 "libmidiextractor",
376 "libmkvextractor",
377 "libmp3extractor",
378 "libmp4extractor",
379 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900380 "libnativebase_headers",
381 "libnativebridge-headers",
382 "libnativebridge_lazy",
383 "libnativeloader-headers",
384 "libnativeloader_lazy",
385 "libnativewindow_headers",
386 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000387 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900388 "libpackagelistparser",
389 "libpcre2",
390 "libpdx",
391 "libpdx_default_transport",
392 "libpdx_headers",
393 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000394 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900395 "libprocessgroup_headers",
396 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900397 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000398 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900399 "libspeexresampler",
400 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000401 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900402 "libstagefright_flacdec",
403 "libstagefright_foundation",
404 "libstagefright_foundation_headers",
405 "libstagefright_foundation_without_imemory",
406 "libstagefright_headers",
407 "libstagefright_id3",
408 "libstagefright_metadatautils",
409 "libstagefright_mpeg2extractor",
410 "libstagefright_mpeg2support",
411 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900412 "libui",
413 "libui_headers",
414 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900415 "libvibrator",
416 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000417 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900418 "libwebm",
419 "media_ndk_headers",
420 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000421 "updatable-media",
422 }
423 //
424 // Module separator
425 //
426 m["com.android.media.swcodec"] = []string{
427 "android.frameworks.bufferhub@1.0",
428 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900429 "android.hardware.configstore-utils",
430 "android.hardware.configstore@1.0",
431 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000432 "android.hardware.graphics.allocator@2.0",
433 "android.hardware.graphics.allocator@3.0",
434 "android.hardware.graphics.allocator@4.0",
435 "android.hardware.graphics.bufferqueue@1.0",
436 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900437 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000438 "android.hardware.graphics.common@1.0",
439 "android.hardware.graphics.common@1.1",
440 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000441 "android.hardware.graphics.mapper@2.0",
442 "android.hardware.graphics.mapper@2.1",
443 "android.hardware.graphics.mapper@3.0",
444 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000445 "android.hardware.media.bufferpool@2.0",
446 "android.hardware.media.c2@1.0",
447 "android.hardware.media.c2@1.1",
448 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900449 "android.hardware.media@1.0",
450 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000451 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900452 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000453 "android.hidl.safe_union@1.0",
454 "android.hidl.token@1.0",
455 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900456 "libEGL",
457 "libFLAC",
458 "libFLAC-config",
459 "libFLAC-headers",
460 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900461 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900462 "libarect",
463 "libasync_safe",
464 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000465 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900466 "libaudioutils",
467 "libaudioutils_fixedfft",
468 "libavcdec",
469 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000470 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900471 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900472 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900473 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900474 "libbluetooth-types-header",
475 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900476 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000477 "libcap",
478 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900479 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000480 "libcodec2_hidl@1.0",
481 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900482 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000483 "libcodec2_soft_aacdec",
484 "libcodec2_soft_aacenc",
485 "libcodec2_soft_amrnbdec",
486 "libcodec2_soft_amrnbenc",
487 "libcodec2_soft_amrwbdec",
488 "libcodec2_soft_amrwbenc",
489 "libcodec2_soft_av1dec_gav1",
490 "libcodec2_soft_avcdec",
491 "libcodec2_soft_avcenc",
492 "libcodec2_soft_common",
493 "libcodec2_soft_flacdec",
494 "libcodec2_soft_flacenc",
495 "libcodec2_soft_g711alawdec",
496 "libcodec2_soft_g711mlawdec",
497 "libcodec2_soft_gsmdec",
498 "libcodec2_soft_h263dec",
499 "libcodec2_soft_h263enc",
500 "libcodec2_soft_hevcdec",
501 "libcodec2_soft_hevcenc",
502 "libcodec2_soft_mp3dec",
503 "libcodec2_soft_mpeg2dec",
504 "libcodec2_soft_mpeg4dec",
505 "libcodec2_soft_mpeg4enc",
506 "libcodec2_soft_opusdec",
507 "libcodec2_soft_opusenc",
508 "libcodec2_soft_rawdec",
509 "libcodec2_soft_vorbisdec",
510 "libcodec2_soft_vp8dec",
511 "libcodec2_soft_vp8enc",
512 "libcodec2_soft_vp9dec",
513 "libcodec2_soft_vp9enc",
514 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900515 "libdexfile_support",
516 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000517 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900518 "libfmq",
519 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000520 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900521 "libgrallocusage",
522 "libgraphicsenv",
523 "libgsm",
524 "libgui_bufferqueue_static",
525 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000526 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900527 "libhardware_headers",
528 "libhevcdec",
529 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000530 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900531 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900532 "liblzma",
533 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000534 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900535 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000536 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900537 "libminijail_gen_constants",
538 "libminijail_gen_constants_obj",
539 "libminijail_gen_syscall",
540 "libminijail_gen_syscall_obj",
541 "libminijail_generated",
542 "libmpeg2dec",
543 "libnativebase_headers",
544 "libnativebridge_lazy",
545 "libnativeloader_lazy",
546 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000547 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900548 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000549 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900550 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000551 "libscudo_wrapper",
552 "libsfplugin_ccodec_utils",
553 "libspeexresampler",
554 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900555 "libstagefright_amrnbdec",
556 "libstagefright_amrnbenc",
557 "libstagefright_amrwbdec",
558 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000559 "libstagefright_bufferpool@2.0.1",
560 "libstagefright_bufferqueue_helper",
561 "libstagefright_enc_common",
562 "libstagefright_flacdec",
563 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900564 "libstagefright_foundation_headers",
565 "libstagefright_headers",
566 "libstagefright_m4vh263dec",
567 "libstagefright_m4vh263enc",
568 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000569 "libsync",
570 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900571 "libui_headers",
572 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000573 "libvorbisidec",
574 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900575 "libyuv",
576 "libyuv_static",
577 "media_ndk_headers",
578 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000579 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000580 }
581 //
582 // Module separator
583 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900584 m["com.android.mediaprovider"] = []string{
585 "MediaProvider",
586 "MediaProviderGoogle",
587 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900588 "libbase_ndk",
589 "libfuse",
590 "libfuse_jni",
591 "libnativehelper_header_only",
592 }
593 //
594 // Module separator
595 //
596 m["com.android.permission"] = []string{
597 "androidx.annotation_annotation",
598 "androidx.annotation_annotation-nodeps",
599 "androidx.lifecycle_lifecycle-common",
600 "androidx.lifecycle_lifecycle-common-java8",
601 "androidx.lifecycle_lifecycle-common-java8-nodeps",
602 "androidx.lifecycle_lifecycle-common-nodeps",
603 "kotlin-annotations",
604 "kotlin-stdlib",
605 "kotlin-stdlib-jdk7",
606 "kotlin-stdlib-jdk8",
607 "kotlinx-coroutines-android",
608 "kotlinx-coroutines-android-nodeps",
609 "kotlinx-coroutines-core",
610 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900611 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900612 "GooglePermissionController",
613 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900614 }
Anton Hansson5053c292020-01-10 15:12:39 +0000615 //
616 // Module separator
617 //
Anton Hansson5053c292020-01-10 15:12:39 +0000618 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900619 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900620 "libarm-optimized-routines-math",
621 "libasync_safe",
622 "libasync_safe_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900623 "libc_aeabi",
624 "libc_bionic",
625 "libc_bionic_ndk",
626 "libc_bootstrap",
627 "libc_common",
628 "libc_common_shared",
629 "libc_common_static",
630 "libc_dns",
631 "libc_dynamic_dispatch",
632 "libc_fortify",
633 "libc_freebsd",
634 "libc_freebsd_large_stack",
635 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900636 "libc_init_dynamic",
637 "libc_init_static",
638 "libc_jemalloc_wrapper",
639 "libc_netbsd",
640 "libc_nomalloc",
641 "libc_nopthread",
642 "libc_openbsd",
643 "libc_openbsd_large_stack",
644 "libc_openbsd_ndk",
645 "libc_pthread",
646 "libc_static_dispatch",
647 "libc_syscalls",
648 "libc_tzcode",
649 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900650 "libdebuggerd",
651 "libdebuggerd_common_headers",
652 "libdebuggerd_handler_core",
653 "libdebuggerd_handler_fallback",
654 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000655 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900656 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900657 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900658 "libgtest_prod",
659 "libjemalloc5",
660 "liblinker_main",
661 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900662 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000663 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900664 "libprocessgroup_headers",
665 "libprocinfo",
666 "libpropertyinfoparser",
667 "libscudo",
668 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900669 "libsystemproperties",
670 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000671 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900672 "libz",
673 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000674 }
675 //
676 // Module separator
677 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900678 m["com.android.resolv"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900679 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900680 "libgtest_prod",
Jiyong Parkfa899442020-01-31 02:49:53 +0900681 "libnativehelper_header_only",
682 "libnetd_client_headers",
683 "libnetd_resolv",
684 "libnetdutils",
685 "libprocessgroup",
686 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900687 "libstatslog_resolv",
688 "libstatspush_compat",
689 "libstatssocket",
690 "libstatssocket_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900691 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900692 "netd_event_listener_interface-ndk_platform",
693 "server_configurable_flags",
694 "stats_proto",
695 }
Anton Hansson5053c292020-01-10 15:12:39 +0000696 //
697 // Module separator
698 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900700 "libnativehelper_compat_libc++",
701 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900702 "libcgrouprc",
703 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900704 "libprocessgroup",
705 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900706 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900707 "libvndksupport",
708 "tethering-aidl-interfaces-java",
709 }
Anton Hansson5053c292020-01-10 15:12:39 +0000710 //
711 // Module separator
712 //
713 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900714 "PlatformProperties",
715 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900716 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900717 "android.hardware.wifi-V1.1-java",
718 "android.hardware.wifi-V1.2-java",
719 "android.hardware.wifi-V1.3-java",
720 "android.hardware.wifi-V1.4-java",
721 "android.hardware.wifi.hostapd-V1.0-java",
722 "android.hardware.wifi.hostapd-V1.1-java",
723 "android.hardware.wifi.hostapd-V1.2-java",
724 "android.hardware.wifi.supplicant-V1.0-java",
725 "android.hardware.wifi.supplicant-V1.1-java",
726 "android.hardware.wifi.supplicant-V1.2-java",
727 "android.hardware.wifi.supplicant-V1.3-java",
728 "android.hidl.base-V1.0-java",
729 "android.hidl.manager-V1.0-java",
730 "android.hidl.manager-V1.1-java",
731 "android.hidl.manager-V1.2-java",
732 "androidx.annotation_annotation",
733 "androidx.annotation_annotation-nodeps",
734 "bouncycastle-unbundled",
735 "dnsresolver_aidl_interface-V2-java",
736 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900737 "framework-wifi-pre-jarjar",
738 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900739 "ipmemorystore-aidl-interfaces-V3-java",
740 "ipmemorystore-aidl-interfaces-java",
741 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900742 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000743 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900744 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000745 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900746 "net-utils-services-common",
747 "netd_aidl_interface-V2-java",
748 "netd_aidl_interface-unstable-java",
749 "netd_event_listener_interface-java",
750 "netlink-client",
751 "networkstack-aidl-interfaces-unstable-java",
752 "networkstack-client",
753 "services.net",
754 "wifi-lite-protos",
755 "wifi-nano-protos",
756 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000757 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900758 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000759 }
760 //
761 // Module separator
762 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900763 m["com.android.sdkext"] = []string{
764 "fmtlib_ndk",
765 "libbase_ndk",
766 "libprotobuf-cpp-lite-ndk",
767 }
768 //
769 // Module separator
770 //
771 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900772 "libprocessgroup_headers",
773 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900774 }
775 //
776 // Module separator
777 //
778 m["//any"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900779 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900780 "libclang_rt",
781 "libgcc_stripped",
782 "libprofile-clang-extras",
783 "libprofile-clang-extras_ndk",
784 "libprofile-extras",
785 "libprofile-extras_ndk",
786 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900787 }
Anton Hansson5053c292020-01-10 15:12:39 +0000788 return m
789}
790
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900791func init() {
Jooyung Hane17caa62020-04-08 14:13:04 +0900792 android.AddNeverAllowRules(android.NeverAllow().
793 ModuleType("apex").
794 With("updatable", "true").
795 With("min_sdk_version", "").
796 Because("All updatable apexes should set min_sdk_version."))
797
Jiyong Parkd1063c12019-07-17 20:08:41 +0900798 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800799 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900800 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900801 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700802 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900803 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900804
Jooyung Han31c470b2019-10-18 16:26:59 +0900805 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900806 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900807
808 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
809 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
810 sort.Strings(*apexFileContextsInfos)
811 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
812 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900813}
814
Jooyung Han31c470b2019-10-18 16:26:59 +0900815func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
816 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
817 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
818}
819
Jiyong Parkd1063c12019-07-17 20:08:41 +0900820func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900821 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900822 ctx.BottomUp("apex", apexMutator).Parallel()
823 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
824 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900825}
826
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900827// Mark the direct and transitive dependencies of apex bundles so that they
828// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900829func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800830 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900831 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000832 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900833 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900834 ApexName: mctx.ModuleName(),
835 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900836 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900837 directDep = true
838 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800839 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900840 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900841 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900842
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800843 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900844 return
845 }
846
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900847 cur := mctx.Module().(interface {
848 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
849 })
850
Jiyong Parkf760cae2020-02-12 07:53:12 +0900851 mctx.VisitDirectDeps(func(child android.Module) {
852 depName := mctx.OtherModuleName(child)
853 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900854 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800855 android.UpdateApexDependency(apexBundles, depName, directDep)
856 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900857 }
858 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900859}
860
861// Create apex variations if a module is included in APEX(s).
862func apexMutator(mctx android.BottomUpMutatorContext) {
863 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900864 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000865 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900866 // apex bundle itself is mutated so that it and its modules have same
867 // apex variant.
868 apexBundleName := mctx.ModuleName()
869 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900870 } else if o, ok := mctx.Module().(*OverrideApex); ok {
871 apexBundleName := o.GetOverriddenModuleName()
872 if apexBundleName == "" {
873 mctx.ModuleErrorf("base property is not set")
874 return
875 }
876 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900878
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900879}
Sundong Ahne9b55722019-09-06 17:37:42 +0900880
Jooyung Han7a78a922019-10-08 21:59:58 +0900881var (
882 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
883 apexFileContextsInfosMutex sync.Mutex
884)
885
886func apexFileContextsInfos(config android.Config) *[]string {
887 return config.Once(apexFileContextsInfosKey, func() interface{} {
888 return &[]string{}
889 }).(*[]string)
890}
891
Jooyung Han54aca7b2019-11-20 02:26:02 +0900892func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900893 apexFileContextsInfosMutex.Lock()
894 defer apexFileContextsInfosMutex.Unlock()
895 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900896 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900897}
898
Sundong Ahne9b55722019-09-06 17:37:42 +0900899func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900900 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900901 var variants []string
902 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
903 case "image":
904 variants = append(variants, imageApexType, flattenedApexType)
905 case "zip":
906 variants = append(variants, zipApexType)
907 case "both":
908 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
909 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900910 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900911 return
912 }
913
914 modules := mctx.CreateLocalVariations(variants...)
915
916 for i, v := range variants {
917 switch v {
918 case imageApexType:
919 modules[i].(*apexBundle).properties.ApexType = imageApex
920 case zipApexType:
921 modules[i].(*apexBundle).properties.ApexType = zipApex
922 case flattenedApexType:
923 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900924 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900925 modules[i].(*apexBundle).MakeAsSystemExt()
926 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900927 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900928 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900929 } else if _, ok := mctx.Module().(*OverrideApex); ok {
930 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900931 }
932}
933
Jooyung Han5c998b92019-06-27 11:30:33 +0900934func apexUsesMutator(mctx android.BottomUpMutatorContext) {
935 if ab, ok := mctx.Module().(*apexBundle); ok {
936 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
937 }
938}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900939
Jooyung Handc782442019-11-01 03:14:38 +0900940var (
941 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
942)
943
944// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
945// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
946// which may cause compatibility issues. (e.g. libbinder)
947// Even though libbinder restricts its availability via 'apex_available' property and relies on
948// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
949// to avoid similar problems.
950func useVendorWhitelist(config android.Config) []string {
951 return config.Once(useVendorWhitelistKey, func() interface{} {
952 return []string{
953 // swcodec uses "vendor" variants for smaller size
954 "com.android.media.swcodec",
955 "test_com.android.media.swcodec",
956 }
957 }).([]string)
958}
959
960// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
961// called before the first call to useVendorWhitelist()
962func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
963 config.Once(useVendorWhitelistKey, func() interface{} {
964 return whitelist
965 })
966}
967
Alex Light9670d332019-01-29 18:07:33 -0800968type apexNativeDependencies struct {
969 // List of native libraries
970 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900971
Alex Light9670d332019-01-29 18:07:33 -0800972 // List of native executables
973 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900974
Roland Levillain630846d2019-06-26 12:48:34 +0100975 // List of native tests
976 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800977}
Jooyung Han344d5432019-08-23 11:17:39 +0900978
Alex Light9670d332019-01-29 18:07:33 -0800979type apexMultilibProperties struct {
980 // Native dependencies whose compile_multilib is "first"
981 First apexNativeDependencies
982
983 // Native dependencies whose compile_multilib is "both"
984 Both apexNativeDependencies
985
986 // Native dependencies whose compile_multilib is "prefer32"
987 Prefer32 apexNativeDependencies
988
989 // Native dependencies whose compile_multilib is "32"
990 Lib32 apexNativeDependencies
991
992 // Native dependencies whose compile_multilib is "64"
993 Lib64 apexNativeDependencies
994}
995
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900996type apexBundleProperties struct {
997 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000998 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800999 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001000
Jiyong Park40e26a22019-02-08 02:53:06 +09001001 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1002 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001003 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001004
Roland Levillain411c5842019-09-19 16:37:20 +01001005 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1006 // device (/apex/<apex_name>).
1007 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001008 Apex_name *string
1009
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001010 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001011 // For platform APEXes, this should points to a file under /system/sepolicy
1012 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1013 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001014
1015 // List of native shared libs that are embedded inside this APEX bundle
1016 Native_shared_libs []string
1017
Roland Levillain630846d2019-06-26 12:48:34 +01001018 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001019 Binaries []string
1020
1021 // List of java libraries that are embedded inside this APEX bundle
1022 Java_libs []string
1023
1024 // List of prebuilt files that are embedded inside this APEX bundle
1025 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001026
Roland Levillain630846d2019-06-26 12:48:34 +01001027 // List of tests that are embedded inside this APEX bundle
1028 Tests []string
1029
Jiyong Parkff1458f2018-10-12 21:49:38 +09001030 // Name of the apex_key module that provides the private key to sign APEX
1031 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001032
Alex Light5098a612018-11-29 17:12:15 -08001033 // The type of APEX to build. Controls what the APEX payload is. Either
1034 // 'image', 'zip' or 'both'. Default: 'image'.
1035 Payload_type *string
1036
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001037 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1038 // or an android_app_certificate module name in the form ":module".
1039 Certificate *string
1040
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001041 // Whether this APEX is installable to one of the partitions. Default: true.
1042 Installable *bool
1043
Jiyong Parkda6eb592018-12-19 17:12:36 +09001044 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1045 // Default is false.
1046 Use_vendor *bool
1047
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001048 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1049 Ignore_system_library_special_case *bool
1050
Alex Light9670d332019-01-29 18:07:33 -08001051 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001052
Jiyong Parkf97782b2019-02-13 20:28:58 +09001053 // List of sanitizer names that this APEX is enabled for
1054 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001055
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001056 PreventInstall bool `blueprint:"mutated"`
1057
1058 HideFromMake bool `blueprint:"mutated"`
1059
Jooyung Han5c998b92019-06-27 11:30:33 +09001060 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1061 Provide_cpp_shared_libs *bool
1062
1063 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1064 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001065
1066 // A txt file containing list of files that are whitelisted to be included in this APEX.
1067 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001068
Sundong Ahnabb64432019-10-22 13:58:29 +09001069 // package format of this apex variant; could be non-flattened, flattened, or zip.
1070 // imageApex, zipApex or flattened
1071 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001072
Jiyong Parkd1063c12019-07-17 20:08:41 +09001073 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1074 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1075 // is implied. This value affects all modules included in this APEX. In other words, they are
1076 // also built with the SDKs specified here.
1077 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001078
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001079 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1080 // Should be only used in tests#.
1081 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001082
Jiyong Park956305c2020-01-09 12:32:06 +09001083 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001084
1085 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1086 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1087 // like symlinking to the system libs. Default is false.
1088 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001089
1090 // The minimum SDK version that this apex must be compatible with.
1091 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001092}
1093
1094type apexTargetBundleProperties struct {
1095 Target struct {
1096 // Multilib properties only for android.
1097 Android struct {
1098 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001099 }
Jooyung Han344d5432019-08-23 11:17:39 +09001100
Alex Light9670d332019-01-29 18:07:33 -08001101 // Multilib properties only for host.
1102 Host struct {
1103 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001104 }
Jooyung Han344d5432019-08-23 11:17:39 +09001105
Alex Light9670d332019-01-29 18:07:33 -08001106 // Multilib properties only for host linux_bionic.
1107 Linux_bionic struct {
1108 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001109 }
Jooyung Han344d5432019-08-23 11:17:39 +09001110
Alex Light9670d332019-01-29 18:07:33 -08001111 // Multilib properties only for host linux_glibc.
1112 Linux_glibc struct {
1113 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001114 }
1115 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001116}
1117
Jiyong Park5d790c32019-11-15 18:40:32 +09001118type overridableProperties struct {
1119 // List of APKs to package inside APEX
1120 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001121
1122 // Names of modules to be overridden. Listed modules can only be other binaries
1123 // (in Make or Soong).
1124 // This does not completely prevent installation of the overridden binaries, but if both
1125 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1126 // from PRODUCT_PACKAGES.
1127 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001128
1129 // Logging Parent value
1130 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001131
1132 // Apex Container Package Name.
1133 // Override value for attribute package:name in AndroidManifest.xml
1134 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001135}
1136
Alex Light5098a612018-11-29 17:12:15 -08001137type apexPackaging int
1138
1139const (
1140 imageApex apexPackaging = iota
1141 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001142 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001143)
1144
Sundong Ahnabb64432019-10-22 13:58:29 +09001145// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001146func (a apexPackaging) suffix() string {
1147 switch a {
1148 case imageApex:
1149 return imageApexSuffix
1150 case zipApex:
1151 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001152 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001153 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001154 }
1155}
1156
1157func (a apexPackaging) name() string {
1158 switch a {
1159 case imageApex:
1160 return imageApexType
1161 case zipApex:
1162 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001163 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001164 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001165 }
1166}
1167
Jiyong Parkf653b052019-11-18 15:39:01 +09001168type apexFileClass int
1169
1170const (
1171 etc apexFileClass = iota
1172 nativeSharedLib
1173 nativeExecutable
1174 shBinary
1175 pyBinary
1176 goBinary
1177 javaSharedLib
1178 nativeTest
1179 app
1180)
1181
Jiyong Park8fd61922018-11-08 02:50:25 +09001182func (class apexFileClass) NameInMake() string {
1183 switch class {
1184 case etc:
1185 return "ETC"
1186 case nativeSharedLib:
1187 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001188 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001189 return "EXECUTABLES"
1190 case javaSharedLib:
1191 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001192 case nativeTest:
1193 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001194 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001195 // b/142537672 Why isn't this APP? We want to have full control over
1196 // the paths and file names of the apk file under the flattend APEX.
1197 // If this is set to APP, then the paths and file names are modified
1198 // by the Make build system. For example, it is installed to
1199 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1200 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1201 // appends module name (which is <apexname>.<Appname> to the path.
1202 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001203 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001204 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001205 }
1206}
1207
Jiyong Parkf653b052019-11-18 15:39:01 +09001208// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001209type apexFile struct {
1210 builtFile android.Path
1211 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001212 installDir string
1213 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001214 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001215 // list of symlinks that will be created in installDir that point to this apexFile
1216 symlinks []string
1217 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001218 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001219
1220 requiredModuleNames []string
1221 targetRequiredModuleNames []string
1222 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001223
Colin Cross503c1d02020-01-28 14:00:53 -08001224 jacocoReportClassesFile android.Path // only for javalibs and apps
1225 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001226 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001227}
1228
Jiyong Park1833cef2019-12-13 13:28:36 +09001229func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1230 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001231 builtFile: builtFile,
1232 moduleName: moduleName,
1233 installDir: installDir,
1234 class: class,
1235 module: module,
1236 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001237 if module != nil {
1238 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001239 ret.requiredModuleNames = module.RequiredModuleNames()
1240 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1241 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001242 }
1243 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001244}
1245
1246func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001247 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001248}
1249
Jiyong Park7cd10e32020-01-14 09:22:18 +09001250// Path() returns path of this apex file relative to the APEX root
1251func (af *apexFile) Path() string {
1252 return filepath.Join(af.installDir, af.builtFile.Base())
1253}
1254
1255// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1256func (af *apexFile) SymlinkPaths() []string {
1257 var ret []string
1258 for _, symlink := range af.symlinks {
1259 ret = append(ret, filepath.Join(af.installDir, symlink))
1260 }
1261 return ret
1262}
1263
1264func (af *apexFile) AvailableToPlatform() bool {
1265 if af.module == nil {
1266 return false
1267 }
1268 if am, ok := af.module.(android.ApexModule); ok {
1269 return am.AvailableFor(android.AvailableToPlatform)
1270 }
1271 return false
1272}
1273
Jiyong Park678c8812020-02-07 17:25:49 +09001274type depInfo struct {
1275 to string
1276 from []string
1277 isExternal bool
1278}
1279
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001280type apexBundle struct {
1281 android.ModuleBase
1282 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001283 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001284 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001285
Jiyong Park5d790c32019-11-15 18:40:32 +09001286 properties apexBundleProperties
1287 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001288 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001289
Jooyung Hanf21c7972019-12-16 22:32:06 +09001290 // specific to apex_vndk modules
1291 vndkProperties apexVndkProperties
1292
Colin Crossa4925902018-11-16 11:36:28 -08001293 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001294 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001295 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001296
Jiyong Park03b68dd2019-07-26 23:20:40 +09001297 prebuiltFileToDelete string
1298
Jiyong Park42cca6c2019-04-01 11:15:50 +09001299 public_key_file android.Path
1300 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001301
1302 container_certificate_file android.Path
1303 container_private_key_file android.Path
1304
Jooyung Han54aca7b2019-11-20 02:26:02 +09001305 fileContexts android.Path
1306
Jiyong Park8fd61922018-11-08 02:50:25 +09001307 // list of files to be included in this apex
1308 filesInfo []apexFile
1309
Jiyong Park956305c2020-01-09 12:32:06 +09001310 // list of module names that should be installed along with this APEX
1311 requiredDeps []string
1312
Jiyong Park956305c2020-01-09 12:32:06 +09001313 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001314 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001315
Sundong Ahnabb64432019-10-22 13:58:29 +09001316 testApex bool
1317 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001318 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001319 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001320
Jooyung Han214bf372019-11-12 13:03:50 +09001321 manifestJsonOut android.WritablePath
1322 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001323
Jooyung Han002ab682020-01-08 01:57:58 +09001324 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001325 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001326 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001327 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1328 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001329
1330 // Suffix of module name in Android.mk
1331 // ".flattened", ".apex", ".zipapex", or ""
1332 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001333
1334 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001335
1336 // Whether to create symlink to the system file instead of having a file
1337 // inside the apex or not
1338 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001339
1340 // Struct holding the merged notice file paths in different formats
1341 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001342}
1343
Jiyong Park397e55e2018-10-24 21:09:55 +09001344func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001345 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001346 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001347 // Use *FarVariation* to be able to depend on modules having
1348 // conflicting variations with this module. This is required since
1349 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1350 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001351 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001352 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001353 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001354 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001355 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001356
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001357 ctx.AddFarVariationDependencies(append(target.Variations(),
1358 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1359 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001360
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001361 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001362 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001363 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001364 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001365}
1366
Alex Light9670d332019-01-29 18:07:33 -08001367func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1368 if ctx.Os().Class == android.Device {
1369 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1370 } else {
1371 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1372 if ctx.Os().Bionic() {
1373 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1374 } else {
1375 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1376 }
1377 }
1378}
1379
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001380func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001381 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1382 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1383 }
1384
Jiyong Park397e55e2018-10-24 21:09:55 +09001385 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001386 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001387
1388 a.combineProperties(ctx)
1389
Jiyong Park397e55e2018-10-24 21:09:55 +09001390 has32BitTarget := false
1391 for _, target := range targets {
1392 if target.Arch.ArchType.Multilib == "lib32" {
1393 has32BitTarget = true
1394 }
1395 }
1396 for i, target := range targets {
1397 // When multilib.* is omitted for native_shared_libs, it implies
1398 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001399 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001400 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001401 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001402 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001403
Roland Levillain630846d2019-06-26 12:48:34 +01001404 // When multilib.* is omitted for tests, it implies
1405 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001406 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001407 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001408 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001409 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001410
Jiyong Park397e55e2018-10-24 21:09:55 +09001411 // Add native modules targetting both ABIs
1412 addDependenciesForNativeModules(ctx,
1413 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001414 a.properties.Multilib.Both.Binaries,
1415 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001416 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001417 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001418
Alex Light3d673592019-01-18 14:37:31 -08001419 isPrimaryAbi := i == 0
1420 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001421 // When multilib.* is omitted for binaries, it implies
1422 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001423 ctx.AddFarVariationDependencies(append(target.Variations(),
1424 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1425 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001426
1427 // Add native modules targetting the first ABI
1428 addDependenciesForNativeModules(ctx,
1429 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001430 a.properties.Multilib.First.Binaries,
1431 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001432 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001433 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001434 }
1435
1436 switch target.Arch.ArchType.Multilib {
1437 case "lib32":
1438 // Add native modules targetting 32-bit ABI
1439 addDependenciesForNativeModules(ctx,
1440 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001441 a.properties.Multilib.Lib32.Binaries,
1442 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001443 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001444 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001445
1446 addDependenciesForNativeModules(ctx,
1447 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001448 a.properties.Multilib.Prefer32.Binaries,
1449 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001450 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001451 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001452 case "lib64":
1453 // Add native modules targetting 64-bit ABI
1454 addDependenciesForNativeModules(ctx,
1455 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001456 a.properties.Multilib.Lib64.Binaries,
1457 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001458 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001459 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001460
1461 if !has32BitTarget {
1462 addDependenciesForNativeModules(ctx,
1463 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001464 a.properties.Multilib.Prefer32.Binaries,
1465 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001466 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001467 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001468 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001469
1470 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1471 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1472 if sanitizer == "hwaddress" {
1473 addDependenciesForNativeModules(ctx,
1474 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001475 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001476 break
1477 }
1478 }
1479 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001480 }
1481
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001482 }
1483
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001484 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1485 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1486 // b/144532908
1487 archForPrebuiltEtc := config.Arches()[0]
1488 for _, arch := range config.Arches() {
1489 // Prefer 64-bit arch if there is any
1490 if arch.ArchType.Multilib == "lib64" {
1491 archForPrebuiltEtc = arch
1492 break
1493 }
1494 }
1495 ctx.AddFarVariationDependencies([]blueprint.Variation{
1496 {Mutator: "os", Variation: ctx.Os().String()},
1497 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1498 }, prebuiltTag, a.properties.Prebuilts...)
1499
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001500 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1501 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001502
Ulya Trafimovich44561882020-01-03 13:25:54 +00001503 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1504 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1505 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1506 javaLibTag, "jacocoagent")
1507 }
1508
Jiyong Park23c52b02019-02-02 13:13:47 +09001509 if String(a.properties.Key) == "" {
1510 ctx.ModuleErrorf("key is missing")
1511 return
1512 }
1513 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001514
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001515 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001516 if cert != "" {
1517 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001518 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001519
1520 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1521 if len(a.properties.Uses_sdks) > 0 {
1522 sdkRefs := []android.SdkRef{}
1523 for _, str := range a.properties.Uses_sdks {
1524 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1525 sdkRefs = append(sdkRefs, parsed)
1526 }
1527 a.BuildWithSdks(sdkRefs)
1528 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001529}
1530
Jiyong Park5d790c32019-11-15 18:40:32 +09001531func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1532 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1533 androidAppTag, a.overridableProperties.Apps...)
1534}
1535
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001536func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1537 // direct deps of an APEX bundle are all part of the APEX bundle
1538 return true
1539}
1540
Colin Cross0ea8ba82019-06-06 14:33:29 -07001541func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001542 moduleName := ctx.ModuleName()
1543 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1544 // we check with the pseudo module name to see if its certificate is overridden.
1545 if a.vndkApex {
1546 moduleName = vndkApexName
1547 }
1548 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001549 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001550 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001551 }
1552 return String(a.properties.Certificate)
1553}
1554
Colin Cross41955e82019-05-29 14:40:35 -07001555func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1556 switch tag {
1557 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001558 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001559 default:
1560 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001561 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001562}
1563
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001564func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001565 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001566}
1567
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001568func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1569 return proptools.Bool(a.properties.Test_only_no_hashtree)
1570}
1571
Jiyong Park7c1dc612019-01-05 11:15:24 +09001572func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001573 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001574 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001575 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001576 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001577 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001578 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001579 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001580 }
1581}
1582
Jiyong Parkf97782b2019-02-13 20:28:58 +09001583func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1584 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1585 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1586 }
1587}
1588
Jiyong Park388ef3f2019-01-28 19:47:32 +09001589func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001590 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1591 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001592 }
1593
1594 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001595 globalSanitizerNames := []string{}
1596 if a.Host() {
1597 globalSanitizerNames = ctx.Config().SanitizeHost()
1598 } else {
1599 arches := ctx.Config().SanitizeDeviceArch()
1600 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1601 globalSanitizerNames = ctx.Config().SanitizeDevice()
1602 }
1603 }
1604 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001605}
1606
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001607func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001608 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001609}
1610
1611func (a *apexBundle) PreventInstall() {
1612 a.properties.PreventInstall = true
1613}
1614
1615func (a *apexBundle) HideFromMake() {
1616 a.properties.HideFromMake = true
1617}
1618
Jiyong Park956305c2020-01-09 12:32:06 +09001619func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1620 a.properties.IsCoverageVariant = coverage
1621}
1622
Jiyong Parkf653b052019-11-18 15:39:01 +09001623// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001624func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001625 // Decide the APEX-local directory by the multilib of the library
1626 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001627 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001628 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001629 case "lib32":
1630 dirInApex = "lib"
1631 case "lib64":
1632 dirInApex = "lib64"
1633 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001634 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001635 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001636 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001637 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001638 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001639 // Special case for Bionic libs and other libs installed with them. This is
1640 // to prevent those libs from being included in the search path
1641 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1642 // those libs in the Runtime APEX are available via the legacy paths in
1643 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1644 // to the legacy paths and thus will be loaded into the default linker
1645 // namespace (aka "platform" namespace). If the libs are directly in
1646 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1647 // into the runtime linker namespace, which will result in double loading of
1648 // them, which isn't supported.
1649 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001650 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001651
Jiyong Parkf653b052019-11-18 15:39:01 +09001652 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001653 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001654}
1655
Jiyong Park1833cef2019-12-13 13:28:36 +09001656func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001657 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001658 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001659 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001660 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001661 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001662 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001663 af.symlinks = cc.Symlinks()
1664 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001665}
1666
Jiyong Park1833cef2019-12-13 13:28:36 +09001667func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001668 dirInApex := "bin"
1669 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001670 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001671}
Jiyong Park1833cef2019-12-13 13:28:36 +09001672func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001673 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001674 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1675 if err != nil {
1676 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001677 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001678 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001679 fileToCopy := android.PathForOutput(ctx, s)
1680 // NB: Since go binaries are static we don't need the module for anything here, which is
1681 // good since the go tool is a blueprint.Module not an android.Module like we would
1682 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001683 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001684}
1685
Jiyong Park1833cef2019-12-13 13:28:36 +09001686func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001687 dirInApex := filepath.Join("bin", sh.SubDir())
1688 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001689 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001690 af.symlinks = sh.Symlinks()
1691 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001692}
1693
Jooyung Han58f26ab2019-12-18 15:34:32 +09001694// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1695type javaLibrary interface {
1696 android.Module
1697 java.Dependency
1698}
1699
1700func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001701 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001702 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001703 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1704 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1705 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001706}
1707
Jiyong Park1833cef2019-12-13 13:28:36 +09001708func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001709 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1710 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001711 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001712}
1713
atrost6e126252020-01-27 17:01:16 +00001714func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1715 dirInApex := filepath.Join("etc", config.SubDir())
1716 fileToCopy := config.CompatConfig()
1717 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1718}
1719
Jiyong Park1833cef2019-12-13 13:28:36 +09001720func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001721 android.Module
1722 Privileged() bool
1723 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001724 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001725 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001726}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001727 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001728 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001729 appDir = "priv-app"
1730 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001731 dirInApex := filepath.Join(appDir, pkgName)
1732 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001733 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1734 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001735 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001736
1737 if app, ok := aapp.(interface {
1738 OverriddenManifestPackageName() string
1739 }); ok {
1740 af.overriddenPackageName = app.OverriddenManifestPackageName()
1741 }
Jiyong Park618922e2020-01-08 13:35:43 +09001742 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001743}
1744
Roland Levillain935639d2019-08-13 14:55:28 +01001745// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1746type flattenedApexContext struct {
1747 android.ModuleContext
1748}
1749
1750func (c *flattenedApexContext) InstallBypassMake() bool {
1751 return true
1752}
1753
Jiyong Park201cedd2020-02-07 17:25:49 +09001754// Visit dependencies that contributes to the payload of this APEX
1755func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1756 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Parkfa899442020-01-31 02:49:53 +09001757 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1758 am, ok := child.(android.ApexModule)
1759 if !ok || !am.CanHaveApexVariants() {
1760 return false
1761 }
1762
1763 // Check for the direct dependencies that contribute to the payload
1764 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1765 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001766 do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001767 return true
1768 }
1769 return false
1770 }
1771
1772 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001773 if am.ApexName() != "" {
Jiyong Park201cedd2020-02-07 17:25:49 +09001774 do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001775 return true
1776 }
1777
Jiyong Park201cedd2020-02-07 17:25:49 +09001778 do(ctx, parent, am, true /* externalDep */)
1779
Jiyong Parkfa899442020-01-31 02:49:53 +09001780 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1781 return false
1782 })
1783}
1784
Jooyung Han0c4e0162020-02-26 22:45:42 +09001785func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1786 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001787 intVer, err := android.ApiStrToNum(ctx, ver)
1788 if err != nil {
1789 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001790 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001791 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001792}
1793
Jiyong Park201cedd2020-02-07 17:25:49 +09001794// Ensures that the dependencies are marked as available for this APEX
1795func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1796 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1797 if ctx.Host() || a.testApex || a.vndkApex {
1798 return
1799 }
1800
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001801 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1802 // Requiring them and their transitive depencies with apex_available is not right
1803 // because they just add noise.
1804 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1805 return
1806 }
1807
Jiyong Park201cedd2020-02-07 17:25:49 +09001808 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1809 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001810 fromName := ctx.OtherModuleName(from)
1811 toName := ctx.OtherModuleName(to)
1812 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001813 return
1814 }
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001815 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", fromName, toName)
Jiyong Park201cedd2020-02-07 17:25:49 +09001816 })
1817}
1818
Jiyong Park678c8812020-02-07 17:25:49 +09001819// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1820func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1821 a.depInfos = make(map[string]depInfo)
1822 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1823 if from.Name() == to.Name() {
1824 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
1825 return
1826 }
1827
1828 if info, exists := a.depInfos[to.Name()]; exists {
1829 if !android.InList(from.Name(), info.from) {
1830 info.from = append(info.from, from.Name())
1831 }
1832 info.isExternal = info.isExternal && externalDep
1833 a.depInfos[to.Name()] = info
1834 } else {
1835 a.depInfos[to.Name()] = depInfo{
1836 to: to.Name(),
1837 from: []string{from.Name()},
1838 isExternal: externalDep,
1839 }
1840 }
1841 })
1842}
1843
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001844func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001845 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1846 switch a.properties.ApexType {
1847 case imageApex:
1848 if buildFlattenedAsDefault {
1849 a.suffix = imageApexSuffix
1850 } else {
1851 a.suffix = ""
1852 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001853
1854 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001855 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001856 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001857 }
1858 case zipApex:
1859 if proptools.String(a.properties.Payload_type) == "zip" {
1860 a.suffix = ""
1861 a.primaryApexType = true
1862 } else {
1863 a.suffix = zipApexSuffix
1864 }
1865 case flattenedApex:
1866 if buildFlattenedAsDefault {
1867 a.suffix = ""
1868 a.primaryApexType = true
1869 } else {
1870 a.suffix = flattenedSuffix
1871 }
Alex Light5098a612018-11-29 17:12:15 -08001872 }
1873
Roland Levillain630846d2019-06-26 12:48:34 +01001874 if len(a.properties.Tests) > 0 && !a.testApex {
1875 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1876 return
1877 }
1878
Jiyong Parkfa899442020-01-31 02:49:53 +09001879 a.checkApexAvailability(ctx)
1880
Jiyong Park678c8812020-02-07 17:25:49 +09001881 a.collectDepsInfo(ctx)
1882
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001883 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1884
Jooyung Hane1633032019-08-01 17:41:43 +09001885 // native lib dependencies
1886 var provideNativeLibs []string
1887 var requireNativeLibs []string
1888
Jooyung Han5c998b92019-06-27 11:30:33 +09001889 // Check if "uses" requirements are met with dependent apexBundles
1890 var providedNativeSharedLibs []string
1891 useVendor := proptools.Bool(a.properties.Use_vendor)
1892 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1893 if ctx.OtherModuleDependencyTag(m) != usesTag {
1894 return
1895 }
1896 otherName := ctx.OtherModuleName(m)
1897 other, ok := m.(*apexBundle)
1898 if !ok {
1899 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1900 return
1901 }
1902 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1903 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1904 return
1905 }
1906 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1907 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1908 return
1909 }
1910 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1911 })
1912
Jiyong Parkf653b052019-11-18 15:39:01 +09001913 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001914 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001915 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001916 depTag := ctx.OtherModuleDependencyTag(child)
1917 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001918 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001919 switch depTag {
1920 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001921 if c, ok := child.(*cc.Module); ok {
1922 // bootstrap bionic libs are treated as provided by system
1923 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1924 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001925 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001926 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001927 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001928 } else {
1929 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001930 }
1931 case executableTag:
1932 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001933 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001934 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001935 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001936 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001937 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001938 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001939 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001940 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001941 } else {
Alex Light778127a2019-02-27 14:19:50 -08001942 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 +09001943 }
1944 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001945 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001946 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001947 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001948 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1949 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001950 filesInfo = append(filesInfo, af)
1951 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001952 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001953 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1954 af := apexFileForJavaLibrary(ctx, sdkLib)
1955 if !af.Ok() {
1956 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1957 return false
1958 }
1959 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001960 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001961 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001962 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001963 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001964 case androidAppTag:
1965 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1966 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001967 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001968 return true // track transitive dependencies
1969 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001970 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00001971 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
1972 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001973 } else {
1974 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1975 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001976 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001977 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001978 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001979 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1980 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001981 } else {
atrost6e126252020-01-27 17:01:16 +00001982 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001983 }
Roland Levillain630846d2019-06-26 12:48:34 +01001984 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001985 if ccTest, ok := child.(*cc.Module); ok {
1986 if ccTest.IsTestPerSrcAllTestsVariation() {
1987 // Multiple-output test module (where `test_per_src: true`).
1988 //
1989 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1990 // We do not add this variation to `filesInfo`, as it has no output;
1991 // however, we do add the other variations of this module as indirect
1992 // dependencies (see below).
1993 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001994 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001995 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001996 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001997 af.class = nativeTest
1998 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001999 }
Roland Levillain630846d2019-06-26 12:48:34 +01002000 } else {
2001 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2002 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002003 case keyTag:
2004 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002005 a.private_key_file = key.private_key_file
2006 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002007 } else {
2008 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002009 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002010 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002011 case certificateTag:
2012 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002013 a.container_certificate_file = dep.Certificate.Pem
2014 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002015 } else {
2016 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2017 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002018 case android.PrebuiltDepTag:
2019 // If the prebuilt is force disabled, remember to delete the prebuilt file
2020 // that might have been installed in the previous builds
2021 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2022 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2023 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002024 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002025 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002026 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002027 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002028 // We cannot use a switch statement on `depTag` here as the checked
2029 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002030 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002031 if cc, ok := child.(*cc.Module); ok {
2032 if android.InList(cc.Name(), providedNativeSharedLibs) {
2033 // If we're using a shared library which is provided from other APEX,
2034 // don't include it in this APEX
2035 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002036 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002037 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002038 // If the dependency is a stubs lib, don't include it in this APEX,
2039 // but make sure that the lib is installed on the device.
2040 // In case no APEX is having the lib, the lib is installed to the system
2041 // partition.
2042 //
2043 // Always include if we are a host-apex however since those won't have any
2044 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002045 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2046 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002047 }
Jooyung Hane1633032019-08-01 17:41:43 +09002048 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002049 // Don't track further
2050 return false
2051 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002052 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002053 af.transitiveDep = true
2054 filesInfo = append(filesInfo, af)
2055 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002056 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002057 } else if cc.IsTestPerSrcDepTag(depTag) {
2058 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002059 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002060 // Handle modules created as `test_per_src` variations of a single test module:
2061 // use the name of the generated test binary (`fileToCopy`) instead of the name
2062 // of the original test module (`depName`, shared by all `test_per_src`
2063 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002064 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002065 // these are not considered transitive dep
2066 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002067 filesInfo = append(filesInfo, af)
2068 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002069 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002070 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002071 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2072 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002073 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2074 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2075 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2076 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002077 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002078 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002079 }
2080 }
2081 }
2082 return false
2083 })
2084
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002085 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2086 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2087 // via the global boot image config.
2088 if a.artApex {
2089 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2090 dirInApex := filepath.Join("javalib", arch.String())
2091 for _, f := range files {
2092 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002093 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002094 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002095 }
2096 }
2097 }
2098
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002099 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002100 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2101 return
2102 }
2103
Jiyong Park8fd61922018-11-08 02:50:25 +09002104 // remove duplicates in filesInfo
2105 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002106 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002107 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002108 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002109 if e, ok := encountered[dest]; !ok {
2110 encountered[dest] = f
2111 } else {
2112 // If a module is directly included and also transitively depended on
2113 // consider it as directly included.
2114 e.transitiveDep = e.transitiveDep && f.transitiveDep
2115 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002116 }
2117 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002118 var result []apexFile
2119 for _, v := range encountered {
2120 result = append(result, v)
2121 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002122 return result
2123 }
2124 filesInfo = removeDup(filesInfo)
2125
2126 // to have consistent build rules
2127 sort.Slice(filesInfo, func(i, j int) bool {
2128 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2129 })
2130
Jiyong Park8fd61922018-11-08 02:50:25 +09002131 a.installDir = android.PathForModuleInstall(ctx, "apex")
2132 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002133
Jooyung Han54aca7b2019-11-20 02:26:02 +09002134 if a.properties.ApexType != zipApex {
2135 if a.properties.File_contexts == nil {
2136 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2137 } else {
2138 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2139 if a.Platform() {
2140 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2141 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2142 }
2143 }
2144 }
2145 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2146 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2147 return
2148 }
2149 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002150 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2151 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2152 // the same library in the system partition, thus effectively sharing the same libraries
2153 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2154 // in the APEX.
2155 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2156 a.installable() &&
2157 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002158
Jiyong Park9d677202020-02-19 16:29:35 +09002159 // We don't need the optimization for updatable APEXes, as it might give false signal
2160 // to the system health when the APEXes are still bundled (b/149805758)
2161 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2162 a.linkToSystemLib = false
2163 }
2164
Jiyong Park9b964182020-02-26 18:27:19 +09002165 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2166 if ctx.Host() {
2167 a.linkToSystemLib = false
2168 }
2169
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002170 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002171 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2172
2173 a.setCertificateAndPrivateKey(ctx)
2174 if a.properties.ApexType == flattenedApex {
2175 a.buildFlattenedApex(ctx)
2176 } else {
2177 a.buildUnflattenedApex(ctx)
2178 }
2179
Jooyung Han002ab682020-01-08 01:57:58 +09002180 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002181
2182 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002183}
2184
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002185func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002186 key := apex
2187 key = strings.Replace(key, "test_", "", 1)
Anton Hansson5053c292020-01-10 15:12:39 +00002188
Jiyong Parkfa899442020-01-31 02:49:53 +09002189 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2190 // system. Trim the prefix for the check since they are confusing
2191 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2192 if strings.HasPrefix(moduleName, "libclang_rt.") {
2193 // This module has many arch variants that depend on the product being built.
2194 // We don't want to list them all
2195 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002196 }
2197
2198 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2199 return true
2200 }
2201
Jiyong Parkfa899442020-01-31 02:49:53 +09002202 key = "//any"
2203 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2204 return true
2205 }
2206
Anton Hansson5053c292020-01-10 15:12:39 +00002207 return false
2208}
2209
Jooyung Han344d5432019-08-23 11:17:39 +09002210func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002211 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002212 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002213 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002214 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002215 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002216 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2217 })
Alex Light5098a612018-11-29 17:12:15 -08002218 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002219 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002220 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002221 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002222 return module
2223}
Jiyong Park30ca9372019-02-07 16:27:23 +09002224
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002225func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002226 bundle := newApexBundle()
2227 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002228 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002229 return bundle
2230}
2231
Jiyong Parkfce0b422020-02-11 03:56:06 +09002232// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2233// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002234func testApexBundleFactory() android.Module {
2235 bundle := newApexBundle()
2236 bundle.testApex = true
2237 return bundle
2238}
2239
Jiyong Parkfce0b422020-02-11 03:56:06 +09002240// apex packages other modules into an APEX file which is a packaging format for system-level
2241// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002242func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002243 return newApexBundle()
2244}
2245
Jiyong Park30ca9372019-02-07 16:27:23 +09002246//
2247// Defaults
2248//
2249type Defaults struct {
2250 android.ModuleBase
2251 android.DefaultsModuleBase
2252}
2253
Jiyong Park30ca9372019-02-07 16:27:23 +09002254func defaultsFactory() android.Module {
2255 return DefaultsFactory()
2256}
2257
2258func DefaultsFactory(props ...interface{}) android.Module {
2259 module := &Defaults{}
2260
2261 module.AddProperties(props...)
2262 module.AddProperties(
2263 &apexBundleProperties{},
2264 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002265 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002266 )
2267
2268 android.InitDefaultsModule(module)
2269 return module
2270}
Jiyong Park5d790c32019-11-15 18:40:32 +09002271
2272//
2273// OverrideApex
2274//
2275type OverrideApex struct {
2276 android.ModuleBase
2277 android.OverrideModuleBase
2278}
2279
2280func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2281 // All the overrides happen in the base module.
2282}
2283
2284// override_apex is used to create an apex module based on another apex module
2285// by overriding some of its properties.
2286func overrideApexFactory() android.Module {
2287 m := &OverrideApex{}
2288 m.AddProperties(&overridableProperties{})
2289
2290 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2291 android.InitOverrideModule(m)
2292 return m
2293}