blob: 91421610e7b2c5c15bd51368f18a70342e24f651 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinc5192442020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jooyung Han03b51852020-02-26 22:45:42 +090023 "strconv"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090025 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090026
27 "android/soong/android"
28 "android/soong/cc"
29 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080030 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090031
32 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080033 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090034 "github.com/google/blueprint/proptools"
35)
36
Jooyung Han72bd2f82019-10-23 16:46:38 +090037const (
38 imageApexSuffix = ".apex"
39 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090040 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080041
Sundong Ahnabb64432019-10-22 13:58:29 +090042 imageApexType = "image"
43 zipApexType = "zip"
44 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090045)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090046
47type dependencyTag struct {
48 blueprint.BaseDependencyTag
49 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090050
51 // determines if the dependent will be part of the APEX payload
52 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090053}
54
55var (
Jiyong Park0f80c182020-01-31 02:49:53 +090056 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090057 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090058 executableTag = dependencyTag{name: "executable", payload: true}
59 javaLibTag = dependencyTag{name: "javaLib", payload: true}
60 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
61 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090062 keyTag = dependencyTag{name: "key"}
63 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090064 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090065 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000066 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000067
68 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069)
70
Paul Duffin7d74e7b2020-03-06 12:30:13 +000071// Transform the map of apex -> modules to module -> apexes.
72func invertApexWhiteList(m map[string][]string) map[string][]string {
73 r := make(map[string][]string)
74 for apex, modules := range m {
75 for _, module := range modules {
76 r[module] = append(r[module], apex)
77 }
78 }
79 return r
80}
81
82// Retrieve the while list of apexes to which the supplied module belongs.
83func WhitelistedApexAvailable(moduleName string) []string {
84 return inverseApexAvailWl[normalizeModuleName(moduleName)]
85}
86
Anton Hanssoneec79eb2020-01-10 15:12:39 +000087// This is a map from apex to modules, which overrides the
88// apex_available setting for that particular module to make
89// it available for the apex regardless of its setting.
90// TODO(b/147364041): remove this
91func makeApexAvailableWhitelist() map[string][]string {
92 // The "Module separator"s below are employed to minimize merge conflicts.
93 m := make(map[string][]string)
94 //
95 // Module separator
96 //
Jiyong Park0f80c182020-01-31 02:49:53 +090097 m["com.android.adbd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "libadbd_auth",
Jiyong Park0f80c182020-01-31 02:49:53 +090099 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "libcap",
Jiyong Park0f80c182020-01-31 02:49:53 +0900101 "libmdnssd",
102 "libminijail",
103 "libminijail_gen_constants",
104 "libminijail_gen_constants_obj",
105 "libminijail_gen_syscall",
106 "libminijail_gen_syscall_obj",
107 "libminijail_generated",
108 "libpackagelistparser",
109 "libpcre2",
110 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 }
112 //
113 // Module separator
114 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000115 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900116 "art_cmdlineparser_headers",
117 "art_disassembler_headers",
118 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900119 "bionic_libc_platform_headers",
120 "core-repackaged-icu4j",
121 "cpp-define-generator-asm-support",
122 "cpp-define-generator-definitions",
123 "crtbegin_dynamic",
124 "crtbegin_dynamic1",
125 "crtbegin_so1",
126 "crtbrand",
127 "conscrypt.module.intra.core.api.stubs",
128 "dex2oat_headers",
129 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900131 "javavm_headers",
132 "jni_platform_headers",
133 "libPlatformProperties",
134 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000135 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900136 "libandroidicuinit",
137 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000138 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900139 "libasync_safe",
Jiyong Park0f80c182020-01-31 02:49:53 +0900140 "libdexfile_all_headers",
141 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000142 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900143 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000144 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900145 "libfdlibm",
146 "libgtest_prod",
147 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000148 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900149 "libicuuc_headers",
150 "libicuuc_stubdata",
151 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000153 "liblzma",
154 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "libnativebridge-headers",
156 "libnativehelper_header_only",
157 "libnativeloader-headers",
158 "libnpt_headers",
159 "libopenjdkjvmti_headers",
160 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000163 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "libv8",
165 "libv8base",
166 "libv8gen",
167 "libv8platform",
168 "libv8sampler",
169 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000170 "libvixl",
171 "libvixld",
172 "libz",
173 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900174 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000175 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000176 m["com.android.art.debug"] = artApexContents
177 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000178 //
179 // Module separator
180 //
181 m["com.android.bluetooth.updatable"] = []string{
182 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000183 "android.hardware.bluetooth.a2dp@1.0",
184 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900185 "android.hardware.bluetooth@1.0",
186 "android.hardware.bluetooth@1.1",
187 "android.hardware.graphics.bufferqueue@1.0",
188 "android.hardware.graphics.bufferqueue@2.0",
189 "android.hardware.graphics.common@1.0",
190 "android.hardware.graphics.common@1.1",
191 "android.hardware.graphics.common@1.2",
192 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000193 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900194 "android.hidl.token@1.0",
195 "android.hidl.token@1.0-utils",
196 "avrcp-target-service",
197 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900198 "bluetooth-protos-lite",
199 "bluetooth.mapsapi",
200 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900201 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900202 "ipmemorystore-aidl-interfaces-V5-java",
203 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900204 "internal_include_headers",
205 "lib-bt-packets",
206 "lib-bt-packets-avrcp",
207 "lib-bt-packets-base",
208 "libFraunhoferAAC",
209 "libaudio-a2dp-hw-utils",
210 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900211 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000212 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900213 "libbluetooth-types",
214 "libbluetooth-types-header",
215 "libbluetooth_gd",
216 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000217 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900218 "libbt-audio-hal-interface",
219 "libbt-bta",
220 "libbt-common",
221 "libbt-hci",
222 "libbt-platform-protos-lite",
223 "libbt-protos-lite",
224 "libbt-sbc-decoder",
225 "libbt-sbc-encoder",
226 "libbt-stack",
227 "libbt-utils",
228 "libbtcore",
229 "libbtdevice",
230 "libbte",
231 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000232 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000233 "libevent",
234 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900235 "libg722codec",
236 "libgtest_prod",
237 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900238 "libmedia_headers",
239 "libmodpb64",
240 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000241 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 "libstagefright_foundation_headers",
244 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000245 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900246 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000247 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900248 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000249 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900250 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900251 "net-utils-services-common",
252 "netd_aidl_interface-unstable-java",
253 "netd_event_listener_interface-java",
254 "netlink-client",
255 "networkstack-aidl-interfaces-unstable-java",
256 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900257 "sap-api-java-static",
258 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000259 }
260 //
261 // Module separator
262 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900263 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000264 //
265 // Module separator
266 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900268 "boringssl_self_test",
Jiyong Park0f80c182020-01-31 02:49:53 +0900269 "libnativehelper_header_only",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900270 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 }
272 //
273 // Module separator
274 //
275 m["com.android.extservices"] = []string{
276 "flatbuffer_headers",
277 "liblua",
278 "libtextclassifier",
279 "libtextclassifier_hash_static",
280 "libtflite_static",
281 "libutf",
282 "libz_current",
283 "tensorflow_headers",
284 }
285 //
286 // Module separator
287 //
288 m["com.android.cronet"] = []string{
289 "cronet_impl_common_java",
290 "cronet_impl_native_java",
291 "cronet_impl_platform_java",
292 "libcronet.80.0.3986.0",
293 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900294 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 "prebuilt_libcronet.80.0.3986.0",
296 }
297 //
298 // Module separator
299 //
300 m["com.android.neuralnetworks"] = []string{
301 "android.hardware.neuralnetworks@1.0",
302 "android.hardware.neuralnetworks@1.1",
303 "android.hardware.neuralnetworks@1.2",
304 "android.hardware.neuralnetworks@1.3",
305 "android.hidl.allocator@1.0",
306 "android.hidl.memory.token@1.0",
307 "android.hidl.memory@1.0",
308 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900309 "gemmlowp_headers",
310 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900311 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900312 "libeigen",
313 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900314 "libmath",
315 "libneuralnetworks_common",
316 "libneuralnetworks_headers",
317 "libprocessgroup",
318 "libprocessgroup_headers",
319 "libprocpartition",
320 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900321 "libtextclassifier_hash",
322 "libtextclassifier_hash_headers",
323 "libtextclassifier_hash_static",
324 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900325 "philox_random",
326 "philox_random_headers",
327 "tensorflow_headers",
328 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000329 //
330 // Module separator
331 //
332 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000333 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900334 "android.hardware.cas.native@1.0",
335 "android.hardware.cas@1.0",
336 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000337 "android.hardware.configstore@1.0",
338 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000339 "android.hardware.graphics.allocator@2.0",
340 "android.hardware.graphics.allocator@3.0",
341 "android.hardware.graphics.bufferqueue@1.0",
342 "android.hardware.graphics.bufferqueue@2.0",
343 "android.hardware.graphics.common@1.0",
344 "android.hardware.graphics.common@1.1",
345 "android.hardware.graphics.common@1.2",
346 "android.hardware.graphics.mapper@2.0",
347 "android.hardware.graphics.mapper@2.1",
348 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900349 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000350 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900351 "android.hidl.allocator@1.0",
352 "android.hidl.memory.token@1.0",
353 "android.hidl.memory@1.0",
354 "android.hidl.token@1.0",
355 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900356 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900357 "gl_headers",
358 "libEGL",
359 "libEGL_blobCache",
360 "libEGL_getProcAddress",
361 "libFLAC",
362 "libFLAC-config",
363 "libFLAC-headers",
364 "libGLESv2",
365 "libaacextractor",
366 "libamrextractor",
367 "libarect",
368 "libasync_safe",
369 "libaudio_system_headers",
370 "libaudioclient",
371 "libaudioclient_headers",
372 "libaudiofoundation",
373 "libaudiofoundation_headers",
374 "libaudiomanager",
375 "libaudiopolicy",
376 "libaudioutils",
377 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900378 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900379 "libbluetooth-types-header",
380 "libbufferhub",
381 "libbufferhub_headers",
382 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900383 "libc_malloc_debug_backtrace",
384 "libcamera_client",
385 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900386 "libdexfile_external_headers",
387 "libdexfile_support",
388 "libdvr_headers",
389 "libexpat",
390 "libfifo",
391 "libflacextractor",
392 "libgrallocusage",
393 "libgraphicsenv",
394 "libgui",
395 "libgui_headers",
396 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900397 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900398 "liblzma",
399 "libmath",
400 "libmedia",
401 "libmedia_codeclist",
402 "libmedia_headers",
403 "libmedia_helper",
404 "libmedia_helper_headers",
405 "libmedia_midiiowrapper",
406 "libmedia_omx",
407 "libmediautils",
408 "libmidiextractor",
409 "libmkvextractor",
410 "libmp3extractor",
411 "libmp4extractor",
412 "libmpeg2extractor",
413 "libnativebase_headers",
414 "libnativebridge-headers",
415 "libnativebridge_lazy",
416 "libnativeloader-headers",
417 "libnativeloader_lazy",
418 "libnativewindow_headers",
419 "libnblog",
420 "liboggextractor",
421 "libpackagelistparser",
422 "libpcre2",
423 "libpdx",
424 "libpdx_default_transport",
425 "libpdx_headers",
426 "libpdx_uds",
427 "libprocessgroup",
428 "libprocessgroup_headers",
429 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900430 "libsonivox",
431 "libspeexresampler",
432 "libspeexresampler",
433 "libstagefright_esds",
434 "libstagefright_flacdec",
435 "libstagefright_flacdec",
436 "libstagefright_foundation",
437 "libstagefright_foundation_headers",
438 "libstagefright_foundation_without_imemory",
439 "libstagefright_headers",
440 "libstagefright_id3",
441 "libstagefright_metadatautils",
442 "libstagefright_mpeg2extractor",
443 "libstagefright_mpeg2support",
444 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900445 "libui",
446 "libui_headers",
447 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900448 "libvibrator",
449 "libvorbisidec",
450 "libwavextractor",
451 "libwebm",
452 "media_ndk_headers",
453 "media_plugin_headers",
454 "updatable-media",
455 }
456 //
457 // Module separator
458 //
459 m["com.android.media.swcodec"] = []string{
460 "android.frameworks.bufferhub@1.0",
461 "android.hardware.common-ndk_platform",
462 "android.hardware.configstore-utils",
463 "android.hardware.configstore@1.0",
464 "android.hardware.configstore@1.1",
465 "android.hardware.graphics.allocator@2.0",
466 "android.hardware.graphics.allocator@3.0",
467 "android.hardware.graphics.bufferqueue@1.0",
468 "android.hardware.graphics.bufferqueue@2.0",
469 "android.hardware.graphics.common-ndk_platform",
470 "android.hardware.graphics.common@1.0",
471 "android.hardware.graphics.common@1.1",
472 "android.hardware.graphics.common@1.2",
473 "android.hardware.graphics.mapper@2.0",
474 "android.hardware.graphics.mapper@2.1",
475 "android.hardware.graphics.mapper@3.0",
476 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000477 "android.hardware.media.bufferpool@2.0",
478 "android.hardware.media.c2@1.0",
479 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900480 "android.hardware.media@1.0",
481 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000482 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900483 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000484 "android.hidl.safe_union@1.0",
485 "android.hidl.token@1.0",
486 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900487 "libEGL",
488 "libFLAC",
489 "libFLAC-config",
490 "libFLAC-headers",
491 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900492 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900493 "libarect",
494 "libasync_safe",
495 "libaudio_system_headers",
496 "libaudioutils",
497 "libaudioutils",
498 "libaudioutils_fixedfft",
499 "libavcdec",
500 "libavcenc",
501 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000502 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900503 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900504 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900505 "libbluetooth-types-header",
506 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900507 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000508 "libcap",
509 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900510 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000511 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900512 "libcodec2_hidl@1.1",
513 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000514 "libcodec2_soft_aacdec",
515 "libcodec2_soft_aacenc",
516 "libcodec2_soft_amrnbdec",
517 "libcodec2_soft_amrnbenc",
518 "libcodec2_soft_amrwbdec",
519 "libcodec2_soft_amrwbenc",
520 "libcodec2_soft_av1dec_gav1",
521 "libcodec2_soft_avcdec",
522 "libcodec2_soft_avcenc",
523 "libcodec2_soft_common",
524 "libcodec2_soft_flacdec",
525 "libcodec2_soft_flacenc",
526 "libcodec2_soft_g711alawdec",
527 "libcodec2_soft_g711mlawdec",
528 "libcodec2_soft_gsmdec",
529 "libcodec2_soft_h263dec",
530 "libcodec2_soft_h263enc",
531 "libcodec2_soft_hevcdec",
532 "libcodec2_soft_hevcenc",
533 "libcodec2_soft_mp3dec",
534 "libcodec2_soft_mpeg2dec",
535 "libcodec2_soft_mpeg4dec",
536 "libcodec2_soft_mpeg4enc",
537 "libcodec2_soft_opusdec",
538 "libcodec2_soft_opusenc",
539 "libcodec2_soft_rawdec",
540 "libcodec2_soft_vorbisdec",
541 "libcodec2_soft_vp8dec",
542 "libcodec2_soft_vp8enc",
543 "libcodec2_soft_vp9dec",
544 "libcodec2_soft_vp9enc",
545 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000546 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900547 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000548 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900549 "libfmq",
550 "libgav1",
551 "libgralloctypes",
552 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000553 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900554 "libgsm",
555 "libgui_bufferqueue_static",
556 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000557 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900558 "libhardware_headers",
559 "libhevcdec",
560 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000561 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000563 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900564 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000565 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900566 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000567 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900568 "libminijail_gen_constants",
569 "libminijail_gen_constants_obj",
570 "libminijail_gen_syscall",
571 "libminijail_gen_syscall_obj",
572 "libminijail_generated",
573 "libmpeg2dec",
574 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000575 "libnativebridge_lazy",
576 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900577 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000578 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900579 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000580 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000582 "libscudo_wrapper",
583 "libsfplugin_ccodec_utils",
584 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900585 "libstagefright_amrnbdec",
586 "libstagefright_amrnbenc",
587 "libstagefright_amrwbdec",
588 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000589 "libstagefright_bufferpool@2.0.1",
590 "libstagefright_bufferqueue_helper",
591 "libstagefright_enc_common",
592 "libstagefright_flacdec",
593 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libstagefright_foundation_headers",
595 "libstagefright_headers",
596 "libstagefright_m4vh263dec",
597 "libstagefright_m4vh263enc",
598 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000599 "libsync",
600 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900601 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000602 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000603 "libvorbisidec",
604 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 "libyuv",
606 "libyuv_static",
607 "media_ndk_headers",
608 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000609 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900610 }
611 //
612 // Module separator
613 //
614 m["com.android.mediaprovider"] = []string{
615 "MediaProvider",
616 "MediaProviderGoogle",
617 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900618 "libbase_ndk",
619 "libfuse",
620 "libfuse_jni",
621 "libnativehelper_header_only",
622 }
623 //
624 // Module separator
625 //
626 m["com.android.permission"] = []string{
627 "androidx.annotation_annotation",
628 "androidx.annotation_annotation-nodeps",
629 "androidx.lifecycle_lifecycle-common",
630 "androidx.lifecycle_lifecycle-common-java8",
631 "androidx.lifecycle_lifecycle-common-java8-nodeps",
632 "androidx.lifecycle_lifecycle-common-nodeps",
633 "kotlin-annotations",
634 "kotlin-stdlib",
635 "kotlin-stdlib-jdk7",
636 "kotlin-stdlib-jdk8",
637 "kotlinx-coroutines-android",
638 "kotlinx-coroutines-android-nodeps",
639 "kotlinx-coroutines-core",
640 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900641 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000642 }
643 //
644 // Module separator
645 //
646 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900648 "libarm-optimized-routines-math",
649 "libasync_safe",
650 "libasync_safe_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900651 "libc_aeabi",
652 "libc_bionic",
653 "libc_bionic_ndk",
654 "libc_bootstrap",
655 "libc_common",
656 "libc_common_shared",
657 "libc_common_static",
658 "libc_dns",
659 "libc_dynamic_dispatch",
660 "libc_fortify",
661 "libc_freebsd",
662 "libc_freebsd_large_stack",
663 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900664 "libc_init_dynamic",
665 "libc_init_static",
666 "libc_jemalloc_wrapper",
667 "libc_netbsd",
668 "libc_nomalloc",
669 "libc_nopthread",
670 "libc_openbsd",
671 "libc_openbsd_large_stack",
672 "libc_openbsd_ndk",
673 "libc_pthread",
674 "libc_static_dispatch",
675 "libc_syscalls",
676 "libc_tzcode",
677 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900678 "libdebuggerd",
679 "libdebuggerd_common_headers",
680 "libdebuggerd_handler_core",
681 "libdebuggerd_handler_fallback",
682 "libdexfile_external_headers",
683 "libdexfile_support",
684 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900685 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900686 "libgtest_prod",
687 "libjemalloc5",
688 "liblinker_main",
689 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900690 "liblz4",
691 "liblzma",
692 "libprocessgroup_headers",
693 "libprocinfo",
694 "libpropertyinfoparser",
695 "libscudo",
696 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900697 "libsystemproperties",
698 "libtombstoned_client_static",
699 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900700 "libz",
701 "libziparchive",
702 }
703 //
704 // Module separator
705 //
706 m["com.android.resolv"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Park0f80c182020-01-31 02:49:53 +0900708 "libgtest_prod",
Jiyong Park0f80c182020-01-31 02:49:53 +0900709 "libnativehelper_header_only",
710 "libnetd_client_headers",
711 "libnetd_resolv",
712 "libnetdutils",
713 "libprocessgroup",
714 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900715 "libstatslog_resolv",
716 "libstatspush_compat",
717 "libstatssocket",
718 "libstatssocket_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900719 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900720 "netd_event_listener_interface-ndk_platform",
721 "server_configurable_flags",
722 "stats_proto",
723 }
724 //
725 // Module separator
726 //
727 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900728 "libnativehelper_compat_libc++",
729 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900730 "libcgrouprc",
731 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900732 "libprocessgroup",
733 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900734 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900735 "libvndksupport",
736 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000737 }
738 //
739 // Module separator
740 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900741 m["com.android.wifi"] = []string{
742 "PlatformProperties",
743 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900744 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900745 "android.hardware.wifi-V1.1-java",
746 "android.hardware.wifi-V1.2-java",
747 "android.hardware.wifi-V1.3-java",
748 "android.hardware.wifi-V1.4-java",
749 "android.hardware.wifi.hostapd-V1.0-java",
750 "android.hardware.wifi.hostapd-V1.1-java",
751 "android.hardware.wifi.hostapd-V1.2-java",
752 "android.hardware.wifi.supplicant-V1.0-java",
753 "android.hardware.wifi.supplicant-V1.1-java",
754 "android.hardware.wifi.supplicant-V1.2-java",
755 "android.hardware.wifi.supplicant-V1.3-java",
756 "android.hidl.base-V1.0-java",
757 "android.hidl.manager-V1.0-java",
758 "android.hidl.manager-V1.1-java",
759 "android.hidl.manager-V1.2-java",
760 "androidx.annotation_annotation",
761 "androidx.annotation_annotation-nodeps",
762 "bouncycastle-unbundled",
763 "dnsresolver_aidl_interface-V2-java",
764 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900765 "framework-wifi-pre-jarjar",
766 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900767 "ipmemorystore-aidl-interfaces-V3-java",
768 "ipmemorystore-aidl-interfaces-java",
769 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900770 "libnanohttpd",
771 "libprocessgroup",
772 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900773 "libwifi-jni",
774 "net-utils-services-common",
775 "netd_aidl_interface-V2-java",
776 "netd_aidl_interface-unstable-java",
777 "netd_event_listener_interface-java",
778 "netlink-client",
779 "networkstack-aidl-interfaces-unstable-java",
780 "networkstack-client",
781 "services.net",
782 "wifi-lite-protos",
783 "wifi-nano-protos",
784 "wifi-service-pre-jarjar",
785 "wifi-service-resources",
786 "prebuilt_androidx.annotation_annotation-nodeps",
787 }
788 //
789 // Module separator
790 //
791 m["com.android.sdkext"] = []string{
792 "fmtlib_ndk",
793 "libbase_ndk",
794 "libprotobuf-cpp-lite-ndk",
795 }
796 //
797 // Module separator
798 //
799 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900800 "libprocessgroup_headers",
801 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900802 }
803 //
804 // Module separator
805 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000806 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900807 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900808 "libclang_rt",
809 "libgcc_stripped",
810 "libprofile-clang-extras",
811 "libprofile-clang-extras_ndk",
812 "libprofile-extras",
813 "libprofile-extras_ndk",
814 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900815 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000816 return m
817}
818
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900819func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900820 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800821 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900822 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900823 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700824 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900825 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900826
Jooyung Han31c470b2019-10-18 16:26:59 +0900827 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900828 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900829
830 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
831 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
832 sort.Strings(*apexFileContextsInfos)
833 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
834 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900835}
836
Jooyung Han31c470b2019-10-18 16:26:59 +0900837func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
838 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
839 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
840}
841
Jiyong Parkd1063c12019-07-17 20:08:41 +0900842func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900843 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900844 ctx.BottomUp("apex", apexMutator).Parallel()
845 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
846 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900847}
848
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900849// Mark the direct and transitive dependencies of apex bundles so that they
850// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900851func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800852 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900853 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000854 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han5e9013b2020-03-10 06:23:13 +0900855 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han5417f772020-03-12 18:37:20 +0900856 ApexName: mctx.ModuleName(),
857 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900858 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900859 directDep = true
860 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800861 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900862 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900863 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900864
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800865 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900866 return
867 }
868
Paul Duffin923e8a52020-03-30 15:33:32 +0100869 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900870
Jiyong Parkf760cae2020-02-12 07:53:12 +0900871 mctx.VisitDirectDeps(func(child android.Module) {
872 depName := mctx.OtherModuleName(child)
873 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +0900874 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800875 android.UpdateApexDependency(apexBundles, depName, directDep)
876 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900877 }
878 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900879}
880
881// Create apex variations if a module is included in APEX(s).
882func apexMutator(mctx android.BottomUpMutatorContext) {
883 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900884 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000885 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900886 // apex bundle itself is mutated so that it and its modules have same
887 // apex variant.
888 apexBundleName := mctx.ModuleName()
889 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900890 } else if o, ok := mctx.Module().(*OverrideApex); ok {
891 apexBundleName := o.GetOverriddenModuleName()
892 if apexBundleName == "" {
893 mctx.ModuleErrorf("base property is not set")
894 return
895 }
896 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900897 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900898
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900899}
Sundong Ahne9b55722019-09-06 17:37:42 +0900900
Jooyung Han7a78a922019-10-08 21:59:58 +0900901var (
902 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
903 apexFileContextsInfosMutex sync.Mutex
904)
905
906func apexFileContextsInfos(config android.Config) *[]string {
907 return config.Once(apexFileContextsInfosKey, func() interface{} {
908 return &[]string{}
909 }).(*[]string)
910}
911
Jooyung Han54aca7b2019-11-20 02:26:02 +0900912func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900913 apexFileContextsInfosMutex.Lock()
914 defer apexFileContextsInfosMutex.Unlock()
915 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900916 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900917}
918
Sundong Ahne9b55722019-09-06 17:37:42 +0900919func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900920 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900921 var variants []string
922 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
923 case "image":
924 variants = append(variants, imageApexType, flattenedApexType)
925 case "zip":
926 variants = append(variants, zipApexType)
927 case "both":
928 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
929 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900930 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900931 return
932 }
933
934 modules := mctx.CreateLocalVariations(variants...)
935
936 for i, v := range variants {
937 switch v {
938 case imageApexType:
939 modules[i].(*apexBundle).properties.ApexType = imageApex
940 case zipApexType:
941 modules[i].(*apexBundle).properties.ApexType = zipApex
942 case flattenedApexType:
943 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900944 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900945 modules[i].(*apexBundle).MakeAsSystemExt()
946 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900947 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900948 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900949 } else if _, ok := mctx.Module().(*OverrideApex); ok {
950 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900951 }
952}
953
Jooyung Han5c998b92019-06-27 11:30:33 +0900954func apexUsesMutator(mctx android.BottomUpMutatorContext) {
955 if ab, ok := mctx.Module().(*apexBundle); ok {
956 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
957 }
958}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900959
Jooyung Handc782442019-11-01 03:14:38 +0900960var (
961 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
962)
963
964// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
965// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
966// which may cause compatibility issues. (e.g. libbinder)
967// Even though libbinder restricts its availability via 'apex_available' property and relies on
968// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
969// to avoid similar problems.
970func useVendorWhitelist(config android.Config) []string {
971 return config.Once(useVendorWhitelistKey, func() interface{} {
972 return []string{
973 // swcodec uses "vendor" variants for smaller size
974 "com.android.media.swcodec",
975 "test_com.android.media.swcodec",
976 }
977 }).([]string)
978}
979
980// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
981// called before the first call to useVendorWhitelist()
982func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
983 config.Once(useVendorWhitelistKey, func() interface{} {
984 return whitelist
985 })
986}
987
Jooyung Han01a868d2020-02-27 13:40:44 +0900988type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800989 // List of native libraries
990 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900991
Jooyung Han643adc42020-02-27 13:50:06 +0900992 // List of JNI libraries
993 Jni_libs []string
994
Alex Light9670d332019-01-29 18:07:33 -0800995 // List of native executables
996 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900997
Roland Levillain630846d2019-06-26 12:48:34 +0100998 // List of native tests
999 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001000}
Jooyung Han344d5432019-08-23 11:17:39 +09001001
Alex Light9670d332019-01-29 18:07:33 -08001002type apexMultilibProperties struct {
1003 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001004 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001005
1006 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001007 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001008
1009 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001010 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001011
1012 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001013 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001014
1015 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001016 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001017}
1018
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001019type apexBundleProperties struct {
1020 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001021 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001022 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001023
Jiyong Park40e26a22019-02-08 02:53:06 +09001024 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1025 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001026 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001027
Roland Levillain411c5842019-09-19 16:37:20 +01001028 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1029 // device (/apex/<apex_name>).
1030 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001031 Apex_name *string
1032
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001033 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001034 // For platform APEXes, this should points to a file under /system/sepolicy
1035 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1036 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001037
Jooyung Han01a868d2020-02-27 13:40:44 +09001038 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001039
1040 // List of java libraries that are embedded inside this APEX bundle
1041 Java_libs []string
1042
1043 // List of prebuilt files that are embedded inside this APEX bundle
1044 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001045
1046 // Name of the apex_key module that provides the private key to sign APEX
1047 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001048
Alex Light5098a612018-11-29 17:12:15 -08001049 // The type of APEX to build. Controls what the APEX payload is. Either
1050 // 'image', 'zip' or 'both'. Default: 'image'.
1051 Payload_type *string
1052
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001053 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1054 // or an android_app_certificate module name in the form ":module".
1055 Certificate *string
1056
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001057 // Whether this APEX is installable to one of the partitions. Default: true.
1058 Installable *bool
1059
Jiyong Parkda6eb592018-12-19 17:12:36 +09001060 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1061 // Default is false.
1062 Use_vendor *bool
1063
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001064 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1065 Ignore_system_library_special_case *bool
1066
Alex Light9670d332019-01-29 18:07:33 -08001067 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001068
Jiyong Parkf97782b2019-02-13 20:28:58 +09001069 // List of sanitizer names that this APEX is enabled for
1070 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001071
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001072 PreventInstall bool `blueprint:"mutated"`
1073
1074 HideFromMake bool `blueprint:"mutated"`
1075
Jooyung Han5c998b92019-06-27 11:30:33 +09001076 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1077 Provide_cpp_shared_libs *bool
1078
1079 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1080 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001081
1082 // A txt file containing list of files that are whitelisted to be included in this APEX.
1083 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001084
Sundong Ahnabb64432019-10-22 13:58:29 +09001085 // package format of this apex variant; could be non-flattened, flattened, or zip.
1086 // imageApex, zipApex or flattened
1087 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001088
Jiyong Parkd1063c12019-07-17 20:08:41 +09001089 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1090 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1091 // is implied. This value affects all modules included in this APEX. In other words, they are
1092 // also built with the SDKs specified here.
1093 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001094
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001095 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1096 // Should be only used in tests#.
1097 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001098
Jiyong Park956305c2020-01-09 12:32:06 +09001099 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001100
1101 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1102 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1103 // like symlinking to the system libs. Default is false.
1104 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001105
1106 // The minimum SDK version that this apex must be compatibile with.
1107 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001108}
1109
1110type apexTargetBundleProperties struct {
1111 Target struct {
1112 // Multilib properties only for android.
1113 Android struct {
1114 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001115 }
Jooyung Han344d5432019-08-23 11:17:39 +09001116
Alex Light9670d332019-01-29 18:07:33 -08001117 // Multilib properties only for host.
1118 Host struct {
1119 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001120 }
Jooyung Han344d5432019-08-23 11:17:39 +09001121
Alex Light9670d332019-01-29 18:07:33 -08001122 // Multilib properties only for host linux_bionic.
1123 Linux_bionic struct {
1124 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001125 }
Jooyung Han344d5432019-08-23 11:17:39 +09001126
Alex Light9670d332019-01-29 18:07:33 -08001127 // Multilib properties only for host linux_glibc.
1128 Linux_glibc struct {
1129 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001130 }
1131 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001132}
1133
Jiyong Park5d790c32019-11-15 18:40:32 +09001134type overridableProperties struct {
1135 // List of APKs to package inside APEX
1136 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001137
1138 // Names of modules to be overridden. Listed modules can only be other binaries
1139 // (in Make or Soong).
1140 // This does not completely prevent installation of the overridden binaries, but if both
1141 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1142 // from PRODUCT_PACKAGES.
1143 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001144
1145 // Logging Parent value
1146 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001147
1148 // Apex Container Package Name.
1149 // Override value for attribute package:name in AndroidManifest.xml
1150 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001151}
1152
Alex Light5098a612018-11-29 17:12:15 -08001153type apexPackaging int
1154
1155const (
1156 imageApex apexPackaging = iota
1157 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001158 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001159)
1160
Sundong Ahnabb64432019-10-22 13:58:29 +09001161// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001162func (a apexPackaging) suffix() string {
1163 switch a {
1164 case imageApex:
1165 return imageApexSuffix
1166 case zipApex:
1167 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001168 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001169 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001170 }
1171}
1172
1173func (a apexPackaging) name() string {
1174 switch a {
1175 case imageApex:
1176 return imageApexType
1177 case zipApex:
1178 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001179 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001180 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001181 }
1182}
1183
Jiyong Parkf653b052019-11-18 15:39:01 +09001184type apexFileClass int
1185
1186const (
1187 etc apexFileClass = iota
1188 nativeSharedLib
1189 nativeExecutable
1190 shBinary
1191 pyBinary
1192 goBinary
1193 javaSharedLib
1194 nativeTest
1195 app
1196)
1197
Jiyong Park8fd61922018-11-08 02:50:25 +09001198func (class apexFileClass) NameInMake() string {
1199 switch class {
1200 case etc:
1201 return "ETC"
1202 case nativeSharedLib:
1203 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001204 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001205 return "EXECUTABLES"
1206 case javaSharedLib:
1207 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001208 case nativeTest:
1209 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001210 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001211 // b/142537672 Why isn't this APP? We want to have full control over
1212 // the paths and file names of the apk file under the flattend APEX.
1213 // If this is set to APP, then the paths and file names are modified
1214 // by the Make build system. For example, it is installed to
1215 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1216 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1217 // appends module name (which is <apexname>.<Appname> to the path.
1218 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001219 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001220 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001221 }
1222}
1223
Jiyong Parkf653b052019-11-18 15:39:01 +09001224// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001225type apexFile struct {
1226 builtFile android.Path
1227 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001228 installDir string
1229 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001230 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001231 // list of symlinks that will be created in installDir that point to this apexFile
1232 symlinks []string
1233 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001234 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001235
1236 requiredModuleNames []string
1237 targetRequiredModuleNames []string
1238 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001239
Colin Cross503c1d02020-01-28 14:00:53 -08001240 jacocoReportClassesFile android.Path // only for javalibs and apps
1241 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001242 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001243
1244 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001245}
1246
Jiyong Park1833cef2019-12-13 13:28:36 +09001247func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1248 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001249 builtFile: builtFile,
1250 moduleName: moduleName,
1251 installDir: installDir,
1252 class: class,
1253 module: module,
1254 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001255 if module != nil {
1256 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001257 ret.requiredModuleNames = module.RequiredModuleNames()
1258 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1259 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001260 }
1261 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001262}
1263
1264func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001265 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001266}
1267
Jiyong Park7cd10e32020-01-14 09:22:18 +09001268// Path() returns path of this apex file relative to the APEX root
1269func (af *apexFile) Path() string {
1270 return filepath.Join(af.installDir, af.builtFile.Base())
1271}
1272
1273// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1274func (af *apexFile) SymlinkPaths() []string {
1275 var ret []string
1276 for _, symlink := range af.symlinks {
1277 ret = append(ret, filepath.Join(af.installDir, symlink))
1278 }
1279 return ret
1280}
1281
1282func (af *apexFile) AvailableToPlatform() bool {
1283 if af.module == nil {
1284 return false
1285 }
1286 if am, ok := af.module.(android.ApexModule); ok {
1287 return am.AvailableFor(android.AvailableToPlatform)
1288 }
1289 return false
1290}
1291
Jiyong Park678c8812020-02-07 17:25:49 +09001292type depInfo struct {
1293 to string
1294 from []string
1295 isExternal bool
1296}
1297
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001298type apexBundle struct {
1299 android.ModuleBase
1300 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001301 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001302 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001303
Jiyong Park5d790c32019-11-15 18:40:32 +09001304 properties apexBundleProperties
1305 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001306 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001307
Jooyung Hanf21c7972019-12-16 22:32:06 +09001308 // specific to apex_vndk modules
1309 vndkProperties apexVndkProperties
1310
Colin Crossa4925902018-11-16 11:36:28 -08001311 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001312 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001313 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001314
Jiyong Park03b68dd2019-07-26 23:20:40 +09001315 prebuiltFileToDelete string
1316
Jiyong Park42cca6c2019-04-01 11:15:50 +09001317 public_key_file android.Path
1318 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001319
1320 container_certificate_file android.Path
1321 container_private_key_file android.Path
1322
Jooyung Han54aca7b2019-11-20 02:26:02 +09001323 fileContexts android.Path
1324
Jiyong Park8fd61922018-11-08 02:50:25 +09001325 // list of files to be included in this apex
1326 filesInfo []apexFile
1327
Jiyong Park956305c2020-01-09 12:32:06 +09001328 // list of module names that should be installed along with this APEX
1329 requiredDeps []string
1330
Jiyong Park956305c2020-01-09 12:32:06 +09001331 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001332 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001333
Sundong Ahnabb64432019-10-22 13:58:29 +09001334 testApex bool
1335 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001336 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001337 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001338
Jooyung Han214bf372019-11-12 13:03:50 +09001339 manifestJsonOut android.WritablePath
1340 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001341
Jooyung Han002ab682020-01-08 01:57:58 +09001342 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001343 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001344 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001345 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1346 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001347
1348 // Suffix of module name in Android.mk
1349 // ".flattened", ".apex", ".zipapex", or ""
1350 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001351
1352 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001353
1354 // Whether to create symlink to the system file instead of having a file
1355 // inside the apex or not
1356 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001357
1358 // Struct holding the merged notice file paths in different formats
1359 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001360}
1361
Jiyong Park397e55e2018-10-24 21:09:55 +09001362func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001363 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001364 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001365 // Use *FarVariation* to be able to depend on modules having
1366 // conflicting variations with this module. This is required since
1367 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1368 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001369 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001370 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001371 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001372 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001373 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001374
Jooyung Han643adc42020-02-27 13:50:06 +09001375 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1376 {Mutator: "image", Variation: imageVariation},
1377 {Mutator: "link", Variation: "shared"},
1378 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1379 }...), jniLibTag, nativeModules.Jni_libs...)
1380
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001381 ctx.AddFarVariationDependencies(append(target.Variations(),
1382 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001383 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001384
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001385 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001386 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001387 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001388 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001389}
1390
Alex Light9670d332019-01-29 18:07:33 -08001391func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1392 if ctx.Os().Class == android.Device {
1393 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1394 } else {
1395 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1396 if ctx.Os().Bionic() {
1397 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1398 } else {
1399 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1400 }
1401 }
1402}
1403
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001404func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001405 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1406 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1407 }
1408
Jiyong Park397e55e2018-10-24 21:09:55 +09001409 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001410 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001411
1412 a.combineProperties(ctx)
1413
Jiyong Park397e55e2018-10-24 21:09:55 +09001414 has32BitTarget := false
1415 for _, target := range targets {
1416 if target.Arch.ArchType.Multilib == "lib32" {
1417 has32BitTarget = true
1418 }
1419 }
1420 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001421 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001422 // multilib.both
1423 addDependenciesForNativeModules(ctx,
1424 ApexNativeDependencies{
1425 Native_shared_libs: a.properties.Native_shared_libs,
1426 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001427 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001428 Binaries: nil,
1429 },
1430 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001431
Jiyong Park397e55e2018-10-24 21:09:55 +09001432 // Add native modules targetting both ABIs
1433 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001434 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001435 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001436 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001437
Alex Light3d673592019-01-18 14:37:31 -08001438 isPrimaryAbi := i == 0
1439 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001440 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001441 // multilib.first
1442 addDependenciesForNativeModules(ctx,
1443 ApexNativeDependencies{
1444 Native_shared_libs: nil,
1445 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001446 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001447 Binaries: a.properties.Binaries,
1448 },
1449 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001450
1451 // Add native modules targetting the first ABI
1452 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001453 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001454 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001455 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001456 }
1457
1458 switch target.Arch.ArchType.Multilib {
1459 case "lib32":
1460 // Add native modules targetting 32-bit ABI
1461 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001462 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001463 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001464 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001465
1466 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001467 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001468 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001469 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001470 case "lib64":
1471 // Add native modules targetting 64-bit ABI
1472 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001473 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001474 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001475 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001476
1477 if !has32BitTarget {
1478 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001479 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001480 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001481 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001482 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001483
1484 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1485 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1486 if sanitizer == "hwaddress" {
1487 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001488 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001489 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001490 break
1491 }
1492 }
1493 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001494 }
1495
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001496 }
1497
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001498 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1499 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1500 // b/144532908
1501 archForPrebuiltEtc := config.Arches()[0]
1502 for _, arch := range config.Arches() {
1503 // Prefer 64-bit arch if there is any
1504 if arch.ArchType.Multilib == "lib64" {
1505 archForPrebuiltEtc = arch
1506 break
1507 }
1508 }
1509 ctx.AddFarVariationDependencies([]blueprint.Variation{
1510 {Mutator: "os", Variation: ctx.Os().String()},
1511 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1512 }, prebuiltTag, a.properties.Prebuilts...)
1513
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001514 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1515 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001516
Ulya Trafimovich44561882020-01-03 13:25:54 +00001517 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1518 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1519 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1520 javaLibTag, "jacocoagent")
1521 }
1522
Jiyong Park23c52b02019-02-02 13:13:47 +09001523 if String(a.properties.Key) == "" {
1524 ctx.ModuleErrorf("key is missing")
1525 return
1526 }
1527 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001528
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001529 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001530 if cert != "" {
1531 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001532 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001533
1534 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1535 if len(a.properties.Uses_sdks) > 0 {
1536 sdkRefs := []android.SdkRef{}
1537 for _, str := range a.properties.Uses_sdks {
1538 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1539 sdkRefs = append(sdkRefs, parsed)
1540 }
1541 a.BuildWithSdks(sdkRefs)
1542 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001543}
1544
Jiyong Park5d790c32019-11-15 18:40:32 +09001545func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1546 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1547 androidAppTag, a.overridableProperties.Apps...)
1548}
1549
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001550func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1551 // direct deps of an APEX bundle are all part of the APEX bundle
1552 return true
1553}
1554
Colin Cross0ea8ba82019-06-06 14:33:29 -07001555func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001556 moduleName := ctx.ModuleName()
1557 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1558 // we check with the pseudo module name to see if its certificate is overridden.
1559 if a.vndkApex {
1560 moduleName = vndkApexName
1561 }
1562 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001563 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001564 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001565 }
1566 return String(a.properties.Certificate)
1567}
1568
Colin Cross41955e82019-05-29 14:40:35 -07001569func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1570 switch tag {
1571 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001572 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001573 default:
1574 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001575 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001576}
1577
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001578func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001579 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001580}
1581
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001582func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1583 return proptools.Bool(a.properties.Test_only_no_hashtree)
1584}
1585
Jiyong Park7c1dc612019-01-05 11:15:24 +09001586func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001587 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001588 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001589 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001590 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001591 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001592 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001593 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001594 }
1595}
1596
Jiyong Parkf97782b2019-02-13 20:28:58 +09001597func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1598 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1599 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1600 }
1601}
1602
Jiyong Park388ef3f2019-01-28 19:47:32 +09001603func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001604 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1605 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001606 }
1607
1608 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001609 globalSanitizerNames := []string{}
1610 if a.Host() {
1611 globalSanitizerNames = ctx.Config().SanitizeHost()
1612 } else {
1613 arches := ctx.Config().SanitizeDeviceArch()
1614 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1615 globalSanitizerNames = ctx.Config().SanitizeDevice()
1616 }
1617 }
1618 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001619}
1620
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001621func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001622 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001623}
1624
1625func (a *apexBundle) PreventInstall() {
1626 a.properties.PreventInstall = true
1627}
1628
1629func (a *apexBundle) HideFromMake() {
1630 a.properties.HideFromMake = true
1631}
1632
Jiyong Park956305c2020-01-09 12:32:06 +09001633func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1634 a.properties.IsCoverageVariant = coverage
1635}
1636
Jiyong Parkf653b052019-11-18 15:39:01 +09001637// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001638func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001639 // Decide the APEX-local directory by the multilib of the library
1640 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001641 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001642 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001643 case "lib32":
1644 dirInApex = "lib"
1645 case "lib64":
1646 dirInApex = "lib64"
1647 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001648 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001649 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001650 }
Jooyung Han35155c42020-02-06 17:33:20 +09001651 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001652 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001653 // Special case for Bionic libs and other libs installed with them. This is
1654 // to prevent those libs from being included in the search path
1655 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1656 // those libs in the Runtime APEX are available via the legacy paths in
1657 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1658 // to the legacy paths and thus will be loaded into the default linker
1659 // namespace (aka "platform" namespace). If the libs are directly in
1660 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1661 // into the runtime linker namespace, which will result in double loading of
1662 // them, which isn't supported.
1663 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001664 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001665
Jiyong Parkf653b052019-11-18 15:39:01 +09001666 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001667 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001668}
1669
Jiyong Park1833cef2019-12-13 13:28:36 +09001670func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001671 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001672 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001673 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001674 }
Jooyung Han35155c42020-02-06 17:33:20 +09001675 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001676 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001677 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001678 af.symlinks = cc.Symlinks()
1679 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001680}
1681
Jiyong Park1833cef2019-12-13 13:28:36 +09001682func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001683 dirInApex := "bin"
1684 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001685 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001686}
Jiyong Park1833cef2019-12-13 13:28:36 +09001687func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001689 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1690 if err != nil {
1691 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001692 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001693 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001694 fileToCopy := android.PathForOutput(ctx, s)
1695 // NB: Since go binaries are static we don't need the module for anything here, which is
1696 // good since the go tool is a blueprint.Module not an android.Module like we would
1697 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001698 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001699}
1700
Jiyong Park1833cef2019-12-13 13:28:36 +09001701func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001702 dirInApex := filepath.Join("bin", sh.SubDir())
1703 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001704 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001705 af.symlinks = sh.Symlinks()
1706 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001707}
1708
Jooyung Han58f26ab2019-12-18 15:34:32 +09001709// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1710type javaLibrary interface {
1711 android.Module
1712 java.Dependency
1713}
1714
1715func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001716 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001717 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001718 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1719 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1720 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001721}
1722
Jiyong Park1833cef2019-12-13 13:28:36 +09001723func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001724 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1725 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001726 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001727}
1728
atrost6e126252020-01-27 17:01:16 +00001729func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1730 dirInApex := filepath.Join("etc", config.SubDir())
1731 fileToCopy := config.CompatConfig()
1732 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1733}
1734
Jiyong Park1833cef2019-12-13 13:28:36 +09001735func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001736 android.Module
1737 Privileged() bool
1738 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001739 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001740 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001741}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001742 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001743 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001744 appDir = "priv-app"
1745 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001746 dirInApex := filepath.Join(appDir, pkgName)
1747 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001748 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1749 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001750 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001751
1752 if app, ok := aapp.(interface {
1753 OverriddenManifestPackageName() string
1754 }); ok {
1755 af.overriddenPackageName = app.OverriddenManifestPackageName()
1756 }
Jiyong Park618922e2020-01-08 13:35:43 +09001757 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001758}
1759
Roland Levillain935639d2019-08-13 14:55:28 +01001760// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1761type flattenedApexContext struct {
1762 android.ModuleContext
1763}
1764
1765func (c *flattenedApexContext) InstallBypassMake() bool {
1766 return true
1767}
1768
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001769// Function called while walking an APEX's payload dependencies.
1770//
1771// Return true if the `to` module should be visited, false otherwise.
1772type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1773
Jiyong Park201cedd2020-02-07 17:25:49 +09001774// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001775func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001776 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001777 am, ok := child.(android.ApexModule)
1778 if !ok || !am.CanHaveApexVariants() {
1779 return false
1780 }
1781
1782 // Check for the direct dependencies that contribute to the payload
1783 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1784 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001785 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001786 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001787 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001788 return false
1789 }
1790
1791 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001792 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001793 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001794 }
1795
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001796 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001797 })
1798}
1799
Jooyung Han03b51852020-02-26 22:45:42 +09001800func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1801 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1802 if ver != "current" {
1803 minSdkVersion, err := strconv.Atoi(ver)
1804 if err != nil {
1805 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1806 }
1807 return minSdkVersion
1808 }
1809 return android.FutureApiLevel
1810}
1811
Paul Duffinc5192442020-03-31 11:31:36 +01001812// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1813// a dependency tag.
1814var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1815
1816func PrettyPrintTag(tag blueprint.DependencyTag) string {
1817 // Use tag's custom String() method if available.
1818 if stringer, ok := tag.(fmt.Stringer); ok {
1819 return stringer.String()
1820 }
1821
1822 // Otherwise, get a default string representation of the tag's struct.
1823 tagString := fmt.Sprintf("%#v", tag)
1824
1825 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1826 tagString = tagCleaner.ReplaceAllString(tagString, "")
1827 return tagString
1828}
1829
Jiyong Park201cedd2020-02-07 17:25:49 +09001830// Ensures that the dependencies are marked as available for this APEX
1831func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1832 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1833 if ctx.Host() || a.testApex || a.vndkApex {
1834 return
1835 }
1836
Jiyong Park58d10902020-03-28 14:43:19 +09001837 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1838 // Requiring them and their transitive depencies with apex_available is not right
1839 // because they just add noise.
1840 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1841 return
1842 }
1843
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001844 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1845 if externalDep {
1846 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1847 return false
1848 }
1849
Jiyong Park201cedd2020-02-07 17:25:49 +09001850 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001851 fromName := ctx.OtherModuleName(from)
1852 toName := ctx.OtherModuleName(to)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001853 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1854 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001855 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001856 message := ""
Paul Duffinc5192442020-03-31 11:31:36 +01001857 tagPath := ctx.GetTagPath()
1858 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1859 walkPath := ctx.GetWalkPath()[1:]
1860 for i, m := range walkPath {
1861 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffindf915ff2020-03-30 17:58:21 +01001862 }
1863 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001864 // Visit this module's dependencies to check and report any issues with their availability.
1865 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001866 })
1867}
1868
Jiyong Park678c8812020-02-07 17:25:49 +09001869// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1870func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1871 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001872 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001873 if from.Name() == to.Name() {
1874 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001875 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1876 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001877 }
1878
1879 if info, exists := a.depInfos[to.Name()]; exists {
1880 if !android.InList(from.Name(), info.from) {
1881 info.from = append(info.from, from.Name())
1882 }
1883 info.isExternal = info.isExternal && externalDep
1884 a.depInfos[to.Name()] = info
1885 } else {
1886 a.depInfos[to.Name()] = depInfo{
1887 to: to.Name(),
1888 from: []string{from.Name()},
1889 isExternal: externalDep,
1890 }
1891 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001892
1893 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1894 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001895 })
1896}
1897
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001898func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001899 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1900 switch a.properties.ApexType {
1901 case imageApex:
1902 if buildFlattenedAsDefault {
1903 a.suffix = imageApexSuffix
1904 } else {
1905 a.suffix = ""
1906 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001907
1908 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001909 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001910 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001911 }
1912 case zipApex:
1913 if proptools.String(a.properties.Payload_type) == "zip" {
1914 a.suffix = ""
1915 a.primaryApexType = true
1916 } else {
1917 a.suffix = zipApexSuffix
1918 }
1919 case flattenedApex:
1920 if buildFlattenedAsDefault {
1921 a.suffix = ""
1922 a.primaryApexType = true
1923 } else {
1924 a.suffix = flattenedSuffix
1925 }
Alex Light5098a612018-11-29 17:12:15 -08001926 }
1927
Roland Levillain630846d2019-06-26 12:48:34 +01001928 if len(a.properties.Tests) > 0 && !a.testApex {
1929 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1930 return
1931 }
1932
Jiyong Park0f80c182020-01-31 02:49:53 +09001933 a.checkApexAvailability(ctx)
1934
Jiyong Park678c8812020-02-07 17:25:49 +09001935 a.collectDepsInfo(ctx)
1936
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001937 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1938
Jooyung Hane1633032019-08-01 17:41:43 +09001939 // native lib dependencies
1940 var provideNativeLibs []string
1941 var requireNativeLibs []string
1942
Jooyung Han5c998b92019-06-27 11:30:33 +09001943 // Check if "uses" requirements are met with dependent apexBundles
1944 var providedNativeSharedLibs []string
1945 useVendor := proptools.Bool(a.properties.Use_vendor)
1946 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1947 if ctx.OtherModuleDependencyTag(m) != usesTag {
1948 return
1949 }
1950 otherName := ctx.OtherModuleName(m)
1951 other, ok := m.(*apexBundle)
1952 if !ok {
1953 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1954 return
1955 }
1956 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1957 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1958 return
1959 }
1960 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1961 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1962 return
1963 }
1964 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1965 })
1966
Jiyong Parkf653b052019-11-18 15:39:01 +09001967 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001968 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001969 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001970 depTag := ctx.OtherModuleDependencyTag(child)
1971 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001972 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001973 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001974 case sharedLibTag, jniLibTag:
1975 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001976 if c, ok := child.(*cc.Module); ok {
1977 // bootstrap bionic libs are treated as provided by system
1978 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1979 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001980 }
Jooyung Han643adc42020-02-27 13:50:06 +09001981 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1982 fi.isJniLib = isJniLib
1983 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001984 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001985 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001986 propertyName := "native_shared_libs"
1987 if isJniLib {
1988 propertyName = "jni_libs"
1989 }
1990 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001991 }
1992 case executableTag:
1993 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001994 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001995 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001996 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001997 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001998 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001999 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002000 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002001 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002002 } else {
Alex Light778127a2019-02-27 14:19:50 -08002003 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 +09002004 }
2005 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002006 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002007 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002008 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002009 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2010 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002011 filesInfo = append(filesInfo, af)
2012 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002013 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002014 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2015 af := apexFileForJavaLibrary(ctx, sdkLib)
2016 if !af.Ok() {
2017 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2018 return false
2019 }
2020 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002021 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002022 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002023 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002024 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002025 case androidAppTag:
2026 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2027 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002028 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002029 return true // track transitive dependencies
2030 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002031 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002032 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2033 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002034 } else {
2035 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2036 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002037 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002038 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002039 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002040 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2041 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002042 } else {
atrost6e126252020-01-27 17:01:16 +00002043 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002044 }
Roland Levillain630846d2019-06-26 12:48:34 +01002045 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002046 if ccTest, ok := child.(*cc.Module); ok {
2047 if ccTest.IsTestPerSrcAllTestsVariation() {
2048 // Multiple-output test module (where `test_per_src: true`).
2049 //
2050 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2051 // We do not add this variation to `filesInfo`, as it has no output;
2052 // however, we do add the other variations of this module as indirect
2053 // dependencies (see below).
2054 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002055 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002056 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002057 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002058 af.class = nativeTest
2059 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002060 }
Roland Levillain630846d2019-06-26 12:48:34 +01002061 } else {
2062 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2063 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002064 case keyTag:
2065 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002066 a.private_key_file = key.private_key_file
2067 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002068 } else {
2069 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002070 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002071 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002072 case certificateTag:
2073 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002074 a.container_certificate_file = dep.Certificate.Pem
2075 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002076 } else {
2077 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2078 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002079 case android.PrebuiltDepTag:
2080 // If the prebuilt is force disabled, remember to delete the prebuilt file
2081 // that might have been installed in the previous builds
2082 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2083 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2084 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002085 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002086 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002087 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002088 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002089 // We cannot use a switch statement on `depTag` here as the checked
2090 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002091 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002092 if cc, ok := child.(*cc.Module); ok {
2093 if android.InList(cc.Name(), providedNativeSharedLibs) {
2094 // If we're using a shared library which is provided from other APEX,
2095 // don't include it in this APEX
2096 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002097 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002098 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002099 // If the dependency is a stubs lib, don't include it in this APEX,
2100 // but make sure that the lib is installed on the device.
2101 // In case no APEX is having the lib, the lib is installed to the system
2102 // partition.
2103 //
2104 // Always include if we are a host-apex however since those won't have any
2105 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002106 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2107 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002108 }
Jooyung Hane1633032019-08-01 17:41:43 +09002109 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002110 // Don't track further
2111 return false
2112 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002113 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002114 af.transitiveDep = true
2115 filesInfo = append(filesInfo, af)
2116 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002117 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002118 } else if cc.IsTestPerSrcDepTag(depTag) {
2119 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002120 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002121 // Handle modules created as `test_per_src` variations of a single test module:
2122 // use the name of the generated test binary (`fileToCopy`) instead of the name
2123 // of the original test module (`depName`, shared by all `test_per_src`
2124 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002125 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002126 // these are not considered transitive dep
2127 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002128 filesInfo = append(filesInfo, af)
2129 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002130 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002131 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002132 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2133 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002134 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2135 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2136 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2137 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002138 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002139 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002140 }
2141 }
2142 }
2143 return false
2144 })
2145
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002146 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2147 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2148 // via the global boot image config.
2149 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002150 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002151 dirInApex := filepath.Join("javalib", arch.String())
2152 for _, f := range files {
2153 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002154 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002155 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002156 }
2157 }
2158 }
2159
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002160 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002161 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2162 return
2163 }
2164
Jiyong Park8fd61922018-11-08 02:50:25 +09002165 // remove duplicates in filesInfo
2166 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002167 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002168 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002169 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002170 if e, ok := encountered[dest]; !ok {
2171 encountered[dest] = f
2172 } else {
2173 // If a module is directly included and also transitively depended on
2174 // consider it as directly included.
2175 e.transitiveDep = e.transitiveDep && f.transitiveDep
2176 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002177 }
2178 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002179 var result []apexFile
2180 for _, v := range encountered {
2181 result = append(result, v)
2182 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002183 return result
2184 }
2185 filesInfo = removeDup(filesInfo)
2186
2187 // to have consistent build rules
2188 sort.Slice(filesInfo, func(i, j int) bool {
2189 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2190 })
2191
Jiyong Park8fd61922018-11-08 02:50:25 +09002192 a.installDir = android.PathForModuleInstall(ctx, "apex")
2193 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002194
Jooyung Han54aca7b2019-11-20 02:26:02 +09002195 if a.properties.ApexType != zipApex {
2196 if a.properties.File_contexts == nil {
2197 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2198 } else {
2199 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2200 if a.Platform() {
2201 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2202 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2203 }
2204 }
2205 }
2206 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2207 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2208 return
2209 }
2210 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002211 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2212 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2213 // the same library in the system partition, thus effectively sharing the same libraries
2214 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2215 // in the APEX.
2216 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2217 a.installable() &&
2218 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002219
Jiyong Park9d677202020-02-19 16:29:35 +09002220 // We don't need the optimization for updatable APEXes, as it might give false signal
2221 // to the system health when the APEXes are still bundled (b/149805758)
2222 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2223 a.linkToSystemLib = false
2224 }
2225
Jiyong Park638d30e2020-02-26 18:27:19 +09002226 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2227 if ctx.Host() {
2228 a.linkToSystemLib = false
2229 }
2230
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002231 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002232 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2233
2234 a.setCertificateAndPrivateKey(ctx)
2235 if a.properties.ApexType == flattenedApex {
2236 a.buildFlattenedApex(ctx)
2237 } else {
2238 a.buildUnflattenedApex(ctx)
2239 }
2240
Jooyung Han002ab682020-01-08 01:57:58 +09002241 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002242
2243 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002244}
2245
Jooyung Han5e9013b2020-03-10 06:23:13 +09002246func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002247 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002248 moduleName = normalizeModuleName(moduleName)
2249
2250 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2251 return true
2252 }
2253
2254 key = android.AvailableToAnyApex
2255 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2256 return true
2257 }
2258
2259 return false
2260}
2261
2262func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002263 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2264 // system. Trim the prefix for the check since they are confusing
2265 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2266 if strings.HasPrefix(moduleName, "libclang_rt.") {
2267 // This module has many arch variants that depend on the product being built.
2268 // We don't want to list them all
2269 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002270 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002271 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002272}
2273
Jooyung Han344d5432019-08-23 11:17:39 +09002274func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002275 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002276 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002277 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002278 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002279 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002280 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2281 })
Alex Light5098a612018-11-29 17:12:15 -08002282 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002283 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002284 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002285 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002286 return module
2287}
Jiyong Park30ca9372019-02-07 16:27:23 +09002288
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002289func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002290 bundle := newApexBundle()
2291 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002292 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002293 return bundle
2294}
2295
Jiyong Parkfce0b422020-02-11 03:56:06 +09002296// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2297// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002298func testApexBundleFactory() android.Module {
2299 bundle := newApexBundle()
2300 bundle.testApex = true
2301 return bundle
2302}
2303
Jiyong Parkfce0b422020-02-11 03:56:06 +09002304// apex packages other modules into an APEX file which is a packaging format for system-level
2305// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002306func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002307 return newApexBundle()
2308}
2309
Jiyong Park30ca9372019-02-07 16:27:23 +09002310//
2311// Defaults
2312//
2313type Defaults struct {
2314 android.ModuleBase
2315 android.DefaultsModuleBase
2316}
2317
Jiyong Park30ca9372019-02-07 16:27:23 +09002318func defaultsFactory() android.Module {
2319 return DefaultsFactory()
2320}
2321
2322func DefaultsFactory(props ...interface{}) android.Module {
2323 module := &Defaults{}
2324
2325 module.AddProperties(props...)
2326 module.AddProperties(
2327 &apexBundleProperties{},
2328 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002329 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002330 )
2331
2332 android.InitDefaultsModule(module)
2333 return module
2334}
Jiyong Park5d790c32019-11-15 18:40:32 +09002335
2336//
2337// OverrideApex
2338//
2339type OverrideApex struct {
2340 android.ModuleBase
2341 android.OverrideModuleBase
2342}
2343
2344func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2345 // All the overrides happen in the base module.
2346}
2347
2348// override_apex is used to create an apex module based on another apex module
2349// by overriding some of its properties.
2350func overrideApexFactory() android.Module {
2351 m := &OverrideApex{}
2352 m.AddProperties(&overridableProperties{})
2353
2354 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2355 android.InitOverrideModule(m)
2356 return m
2357}