blob: 8e9bd04494571b14a8b1844d996a104af5fc9d49 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jooyung Han03b51852020-02-26 22:45:42 +090022 "strconv"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Jiyong Park0f80c182020-01-31 02:49:53 +090096 m["com.android.adbd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090097 "libadbd_auth",
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +090099 "libcap",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "libmdnssd",
101 "libminijail",
102 "libminijail_gen_constants",
103 "libminijail_gen_constants_obj",
104 "libminijail_gen_syscall",
105 "libminijail_gen_syscall_obj",
106 "libminijail_generated",
107 "libpackagelistparser",
108 "libpcre2",
109 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900110 }
111 //
112 // Module separator
113 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000114 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900115 "art_cmdlineparser_headers",
116 "art_disassembler_headers",
117 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900118 "bionic_libc_platform_headers",
119 "core-repackaged-icu4j",
120 "cpp-define-generator-asm-support",
121 "cpp-define-generator-definitions",
122 "crtbegin_dynamic",
123 "crtbegin_dynamic1",
124 "crtbegin_so1",
125 "crtbrand",
126 "conscrypt.module.intra.core.api.stubs",
127 "dex2oat_headers",
128 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900129 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "javavm_headers",
131 "jni_platform_headers",
132 "libPlatformProperties",
133 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000134 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900135 "libandroidicuinit",
136 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000137 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900138 "libasync_safe",
Jiyong Park0f80c182020-01-31 02:49:53 +0900139 "libdexfile_all_headers",
140 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000141 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900142 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000143 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900144 "libfdlibm",
145 "libgtest_prod",
146 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000147 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900148 "libicuuc_headers",
149 "libicuuc_stubdata",
150 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900151 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000152 "liblzma",
153 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900154 "libnativebridge-headers",
155 "libnativehelper_header_only",
156 "libnativeloader-headers",
157 "libnpt_headers",
158 "libopenjdkjvmti_headers",
159 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000160 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900161 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000162 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900163 "libv8",
164 "libv8base",
165 "libv8gen",
166 "libv8platform",
167 "libv8sampler",
168 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000169 "libvixl",
170 "libvixld",
171 "libz",
172 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900173 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000174 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000175 m["com.android.art.debug"] = artApexContents
176 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 //
178 // Module separator
179 //
180 m["com.android.bluetooth.updatable"] = []string{
181 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000182 "android.hardware.bluetooth.a2dp@1.0",
183 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900184 "android.hardware.bluetooth@1.0",
185 "android.hardware.bluetooth@1.1",
186 "android.hardware.graphics.bufferqueue@1.0",
187 "android.hardware.graphics.bufferqueue@2.0",
188 "android.hardware.graphics.common@1.0",
189 "android.hardware.graphics.common@1.1",
190 "android.hardware.graphics.common@1.2",
191 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000192 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900193 "android.hidl.token@1.0",
194 "android.hidl.token@1.0-utils",
195 "avrcp-target-service",
196 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900197 "bluetooth-protos-lite",
198 "bluetooth.mapsapi",
199 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900200 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900201 "ipmemorystore-aidl-interfaces-V5-java",
202 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900203 "internal_include_headers",
204 "lib-bt-packets",
205 "lib-bt-packets-avrcp",
206 "lib-bt-packets-base",
207 "libFraunhoferAAC",
208 "libaudio-a2dp-hw-utils",
209 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900210 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000211 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900212 "libbluetooth-types",
213 "libbluetooth-types-header",
214 "libbluetooth_gd",
215 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000216 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900217 "libbt-audio-hal-interface",
218 "libbt-bta",
219 "libbt-common",
220 "libbt-hci",
221 "libbt-platform-protos-lite",
222 "libbt-protos-lite",
223 "libbt-sbc-decoder",
224 "libbt-sbc-encoder",
225 "libbt-stack",
226 "libbt-utils",
227 "libbtcore",
228 "libbtdevice",
229 "libbte",
230 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000231 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000232 "libevent",
233 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900234 "libg722codec",
235 "libgtest_prod",
236 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900237 "libmedia_headers",
238 "libmodpb64",
239 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000240 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libstagefright_foundation_headers",
243 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000244 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900245 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000246 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900247 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000248 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900249 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900250 "net-utils-services-common",
251 "netd_aidl_interface-unstable-java",
252 "netd_event_listener_interface-java",
253 "netlink-client",
254 "networkstack-aidl-interfaces-unstable-java",
255 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900256 "sap-api-java-static",
257 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000258 }
259 //
260 // Module separator
261 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900262 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000263 //
264 // Module separator
265 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900266 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 "boringssl_self_test",
Jiyong Park0f80c182020-01-31 02:49:53 +0900268 "libnativehelper_header_only",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900269 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900270 }
271 //
272 // Module separator
273 //
274 m["com.android.extservices"] = []string{
275 "flatbuffer_headers",
276 "liblua",
277 "libtextclassifier",
278 "libtextclassifier_hash_static",
279 "libtflite_static",
280 "libutf",
281 "libz_current",
282 "tensorflow_headers",
283 }
284 //
285 // Module separator
286 //
287 m["com.android.cronet"] = []string{
288 "cronet_impl_common_java",
289 "cronet_impl_native_java",
290 "cronet_impl_platform_java",
291 "libcronet.80.0.3986.0",
292 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900293 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900294 "prebuilt_libcronet.80.0.3986.0",
295 }
296 //
297 // Module separator
298 //
299 m["com.android.neuralnetworks"] = []string{
300 "android.hardware.neuralnetworks@1.0",
301 "android.hardware.neuralnetworks@1.1",
302 "android.hardware.neuralnetworks@1.2",
303 "android.hardware.neuralnetworks@1.3",
304 "android.hidl.allocator@1.0",
305 "android.hidl.memory.token@1.0",
306 "android.hidl.memory@1.0",
307 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900308 "gemmlowp_headers",
309 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900310 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900311 "libeigen",
312 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900313 "libmath",
314 "libneuralnetworks_common",
315 "libneuralnetworks_headers",
316 "libprocessgroup",
317 "libprocessgroup_headers",
318 "libprocpartition",
319 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900320 "libtextclassifier_hash",
321 "libtextclassifier_hash_headers",
322 "libtextclassifier_hash_static",
323 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900324 "philox_random",
325 "philox_random_headers",
326 "tensorflow_headers",
327 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000328 //
329 // Module separator
330 //
331 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000332 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900333 "android.hardware.cas.native@1.0",
334 "android.hardware.cas@1.0",
335 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000336 "android.hardware.configstore@1.0",
337 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000338 "android.hardware.graphics.allocator@2.0",
339 "android.hardware.graphics.allocator@3.0",
340 "android.hardware.graphics.bufferqueue@1.0",
341 "android.hardware.graphics.bufferqueue@2.0",
342 "android.hardware.graphics.common@1.0",
343 "android.hardware.graphics.common@1.1",
344 "android.hardware.graphics.common@1.2",
345 "android.hardware.graphics.mapper@2.0",
346 "android.hardware.graphics.mapper@2.1",
347 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900348 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000349 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900350 "android.hidl.allocator@1.0",
351 "android.hidl.memory.token@1.0",
352 "android.hidl.memory@1.0",
353 "android.hidl.token@1.0",
354 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900355 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900356 "gl_headers",
357 "libEGL",
358 "libEGL_blobCache",
359 "libEGL_getProcAddress",
360 "libFLAC",
361 "libFLAC-config",
362 "libFLAC-headers",
363 "libGLESv2",
364 "libaacextractor",
365 "libamrextractor",
366 "libarect",
367 "libasync_safe",
368 "libaudio_system_headers",
369 "libaudioclient",
370 "libaudioclient_headers",
371 "libaudiofoundation",
372 "libaudiofoundation_headers",
373 "libaudiomanager",
374 "libaudiopolicy",
375 "libaudioutils",
376 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900377 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900378 "libbluetooth-types-header",
379 "libbufferhub",
380 "libbufferhub_headers",
381 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900382 "libc_malloc_debug_backtrace",
383 "libcamera_client",
384 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900385 "libdexfile_external_headers",
386 "libdexfile_support",
387 "libdvr_headers",
388 "libexpat",
389 "libfifo",
390 "libflacextractor",
391 "libgrallocusage",
392 "libgraphicsenv",
393 "libgui",
394 "libgui_headers",
395 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900396 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900397 "liblzma",
398 "libmath",
399 "libmedia",
400 "libmedia_codeclist",
401 "libmedia_headers",
402 "libmedia_helper",
403 "libmedia_helper_headers",
404 "libmedia_midiiowrapper",
405 "libmedia_omx",
406 "libmediautils",
407 "libmidiextractor",
408 "libmkvextractor",
409 "libmp3extractor",
410 "libmp4extractor",
411 "libmpeg2extractor",
412 "libnativebase_headers",
413 "libnativebridge-headers",
414 "libnativebridge_lazy",
415 "libnativeloader-headers",
416 "libnativeloader_lazy",
417 "libnativewindow_headers",
418 "libnblog",
419 "liboggextractor",
420 "libpackagelistparser",
421 "libpcre2",
422 "libpdx",
423 "libpdx_default_transport",
424 "libpdx_headers",
425 "libpdx_uds",
426 "libprocessgroup",
427 "libprocessgroup_headers",
428 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900429 "libsonivox",
430 "libspeexresampler",
431 "libspeexresampler",
432 "libstagefright_esds",
433 "libstagefright_flacdec",
434 "libstagefright_flacdec",
435 "libstagefright_foundation",
436 "libstagefright_foundation_headers",
437 "libstagefright_foundation_without_imemory",
438 "libstagefright_headers",
439 "libstagefright_id3",
440 "libstagefright_metadatautils",
441 "libstagefright_mpeg2extractor",
442 "libstagefright_mpeg2support",
443 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900444 "libui",
445 "libui_headers",
446 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900447 "libvibrator",
448 "libvorbisidec",
449 "libwavextractor",
450 "libwebm",
451 "media_ndk_headers",
452 "media_plugin_headers",
453 "updatable-media",
454 }
455 //
456 // Module separator
457 //
458 m["com.android.media.swcodec"] = []string{
459 "android.frameworks.bufferhub@1.0",
460 "android.hardware.common-ndk_platform",
461 "android.hardware.configstore-utils",
462 "android.hardware.configstore@1.0",
463 "android.hardware.configstore@1.1",
464 "android.hardware.graphics.allocator@2.0",
465 "android.hardware.graphics.allocator@3.0",
466 "android.hardware.graphics.bufferqueue@1.0",
467 "android.hardware.graphics.bufferqueue@2.0",
468 "android.hardware.graphics.common-ndk_platform",
469 "android.hardware.graphics.common@1.0",
470 "android.hardware.graphics.common@1.1",
471 "android.hardware.graphics.common@1.2",
472 "android.hardware.graphics.mapper@2.0",
473 "android.hardware.graphics.mapper@2.1",
474 "android.hardware.graphics.mapper@3.0",
475 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000476 "android.hardware.media.bufferpool@2.0",
477 "android.hardware.media.c2@1.0",
478 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900479 "android.hardware.media@1.0",
480 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000481 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900482 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000483 "android.hidl.safe_union@1.0",
484 "android.hidl.token@1.0",
485 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900486 "libEGL",
487 "libFLAC",
488 "libFLAC-config",
489 "libFLAC-headers",
490 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900491 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900492 "libarect",
493 "libasync_safe",
494 "libaudio_system_headers",
495 "libaudioutils",
496 "libaudioutils",
497 "libaudioutils_fixedfft",
498 "libavcdec",
499 "libavcenc",
500 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000501 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900502 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900503 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900504 "libbluetooth-types-header",
505 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900506 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000507 "libcap",
508 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900509 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000510 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900511 "libcodec2_hidl@1.1",
512 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000513 "libcodec2_soft_aacdec",
514 "libcodec2_soft_aacenc",
515 "libcodec2_soft_amrnbdec",
516 "libcodec2_soft_amrnbenc",
517 "libcodec2_soft_amrwbdec",
518 "libcodec2_soft_amrwbenc",
519 "libcodec2_soft_av1dec_gav1",
520 "libcodec2_soft_avcdec",
521 "libcodec2_soft_avcenc",
522 "libcodec2_soft_common",
523 "libcodec2_soft_flacdec",
524 "libcodec2_soft_flacenc",
525 "libcodec2_soft_g711alawdec",
526 "libcodec2_soft_g711mlawdec",
527 "libcodec2_soft_gsmdec",
528 "libcodec2_soft_h263dec",
529 "libcodec2_soft_h263enc",
530 "libcodec2_soft_hevcdec",
531 "libcodec2_soft_hevcenc",
532 "libcodec2_soft_mp3dec",
533 "libcodec2_soft_mpeg2dec",
534 "libcodec2_soft_mpeg4dec",
535 "libcodec2_soft_mpeg4enc",
536 "libcodec2_soft_opusdec",
537 "libcodec2_soft_opusenc",
538 "libcodec2_soft_rawdec",
539 "libcodec2_soft_vorbisdec",
540 "libcodec2_soft_vp8dec",
541 "libcodec2_soft_vp8enc",
542 "libcodec2_soft_vp9dec",
543 "libcodec2_soft_vp9enc",
544 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000545 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900546 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000547 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900548 "libfmq",
549 "libgav1",
550 "libgralloctypes",
551 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000552 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900553 "libgsm",
554 "libgui_bufferqueue_static",
555 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000556 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900557 "libhardware_headers",
558 "libhevcdec",
559 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000560 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900561 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000562 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900563 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000564 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900565 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000566 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900567 "libminijail_gen_constants",
568 "libminijail_gen_constants_obj",
569 "libminijail_gen_syscall",
570 "libminijail_gen_syscall_obj",
571 "libminijail_generated",
572 "libmpeg2dec",
573 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000574 "libnativebridge_lazy",
575 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900576 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000577 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900578 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000579 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000581 "libscudo_wrapper",
582 "libsfplugin_ccodec_utils",
583 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900584 "libstagefright_amrnbdec",
585 "libstagefright_amrnbenc",
586 "libstagefright_amrwbdec",
587 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000588 "libstagefright_bufferpool@2.0.1",
589 "libstagefright_bufferqueue_helper",
590 "libstagefright_enc_common",
591 "libstagefright_flacdec",
592 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900593 "libstagefright_foundation_headers",
594 "libstagefright_headers",
595 "libstagefright_m4vh263dec",
596 "libstagefright_m4vh263enc",
597 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000598 "libsync",
599 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900600 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000601 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000602 "libvorbisidec",
603 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900604 "libyuv",
605 "libyuv_static",
606 "media_ndk_headers",
607 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000608 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900609 }
610 //
611 // Module separator
612 //
613 m["com.android.mediaprovider"] = []string{
614 "MediaProvider",
615 "MediaProviderGoogle",
616 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900617 "libbase_ndk",
618 "libfuse",
619 "libfuse_jni",
620 "libnativehelper_header_only",
621 }
622 //
623 // Module separator
624 //
625 m["com.android.permission"] = []string{
626 "androidx.annotation_annotation",
627 "androidx.annotation_annotation-nodeps",
628 "androidx.lifecycle_lifecycle-common",
629 "androidx.lifecycle_lifecycle-common-java8",
630 "androidx.lifecycle_lifecycle-common-java8-nodeps",
631 "androidx.lifecycle_lifecycle-common-nodeps",
632 "kotlin-annotations",
633 "kotlin-stdlib",
634 "kotlin-stdlib-jdk7",
635 "kotlin-stdlib-jdk8",
636 "kotlinx-coroutines-android",
637 "kotlinx-coroutines-android-nodeps",
638 "kotlinx-coroutines-core",
639 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900640 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000641 }
642 //
643 // Module separator
644 //
645 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900646 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 "libarm-optimized-routines-math",
648 "libasync_safe",
649 "libasync_safe_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900650 "libc_aeabi",
651 "libc_bionic",
652 "libc_bionic_ndk",
653 "libc_bootstrap",
654 "libc_common",
655 "libc_common_shared",
656 "libc_common_static",
657 "libc_dns",
658 "libc_dynamic_dispatch",
659 "libc_fortify",
660 "libc_freebsd",
661 "libc_freebsd_large_stack",
662 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900663 "libc_init_dynamic",
664 "libc_init_static",
665 "libc_jemalloc_wrapper",
666 "libc_netbsd",
667 "libc_nomalloc",
668 "libc_nopthread",
669 "libc_openbsd",
670 "libc_openbsd_large_stack",
671 "libc_openbsd_ndk",
672 "libc_pthread",
673 "libc_static_dispatch",
674 "libc_syscalls",
675 "libc_tzcode",
676 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900677 "libdebuggerd",
678 "libdebuggerd_common_headers",
679 "libdebuggerd_handler_core",
680 "libdebuggerd_handler_fallback",
681 "libdexfile_external_headers",
682 "libdexfile_support",
683 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900684 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900685 "libgtest_prod",
686 "libjemalloc5",
687 "liblinker_main",
688 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900689 "liblz4",
690 "liblzma",
691 "libprocessgroup_headers",
692 "libprocinfo",
693 "libpropertyinfoparser",
694 "libscudo",
695 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900696 "libsystemproperties",
697 "libtombstoned_client_static",
698 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900699 "libz",
700 "libziparchive",
701 }
702 //
703 // Module separator
704 //
705 m["com.android.resolv"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900706 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 "libgtest_prod",
Jiyong Park0f80c182020-01-31 02:49:53 +0900708 "libnativehelper_header_only",
709 "libnetd_client_headers",
710 "libnetd_resolv",
711 "libnetdutils",
712 "libprocessgroup",
713 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900714 "libstatslog_resolv",
715 "libstatspush_compat",
716 "libstatssocket",
717 "libstatssocket_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900718 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900719 "netd_event_listener_interface-ndk_platform",
720 "server_configurable_flags",
721 "stats_proto",
722 }
723 //
724 // Module separator
725 //
726 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900727 "libnativehelper_compat_libc++",
728 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900729 "libcgrouprc",
730 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900731 "libprocessgroup",
732 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900733 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900734 "libvndksupport",
735 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000736 }
737 //
738 // Module separator
739 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900740 m["com.android.wifi"] = []string{
741 "PlatformProperties",
742 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900743 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900744 "android.hardware.wifi-V1.1-java",
745 "android.hardware.wifi-V1.2-java",
746 "android.hardware.wifi-V1.3-java",
747 "android.hardware.wifi-V1.4-java",
748 "android.hardware.wifi.hostapd-V1.0-java",
749 "android.hardware.wifi.hostapd-V1.1-java",
750 "android.hardware.wifi.hostapd-V1.2-java",
751 "android.hardware.wifi.supplicant-V1.0-java",
752 "android.hardware.wifi.supplicant-V1.1-java",
753 "android.hardware.wifi.supplicant-V1.2-java",
754 "android.hardware.wifi.supplicant-V1.3-java",
755 "android.hidl.base-V1.0-java",
756 "android.hidl.manager-V1.0-java",
757 "android.hidl.manager-V1.1-java",
758 "android.hidl.manager-V1.2-java",
759 "androidx.annotation_annotation",
760 "androidx.annotation_annotation-nodeps",
761 "bouncycastle-unbundled",
762 "dnsresolver_aidl_interface-V2-java",
763 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900764 "framework-wifi-pre-jarjar",
765 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900766 "ipmemorystore-aidl-interfaces-V3-java",
767 "ipmemorystore-aidl-interfaces-java",
768 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900769 "libnanohttpd",
770 "libprocessgroup",
771 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900772 "libwifi-jni",
773 "net-utils-services-common",
774 "netd_aidl_interface-V2-java",
775 "netd_aidl_interface-unstable-java",
776 "netd_event_listener_interface-java",
777 "netlink-client",
778 "networkstack-aidl-interfaces-unstable-java",
779 "networkstack-client",
780 "services.net",
781 "wifi-lite-protos",
782 "wifi-nano-protos",
783 "wifi-service-pre-jarjar",
784 "wifi-service-resources",
785 "prebuilt_androidx.annotation_annotation-nodeps",
786 }
787 //
788 // Module separator
789 //
790 m["com.android.sdkext"] = []string{
791 "fmtlib_ndk",
792 "libbase_ndk",
793 "libprotobuf-cpp-lite-ndk",
794 }
795 //
796 // Module separator
797 //
798 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900799 "libprocessgroup_headers",
800 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900801 }
802 //
803 // Module separator
804 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000805 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900806 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900807 "libclang_rt",
808 "libgcc_stripped",
809 "libprofile-clang-extras",
810 "libprofile-clang-extras_ndk",
811 "libprofile-extras",
812 "libprofile-extras_ndk",
813 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900814 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000815 return m
816}
817
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900818func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900819 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800820 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900821 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900822 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700823 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900824 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900825
Jooyung Han31c470b2019-10-18 16:26:59 +0900826 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900827 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900828
829 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
830 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
831 sort.Strings(*apexFileContextsInfos)
832 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
833 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900834}
835
Jooyung Han31c470b2019-10-18 16:26:59 +0900836func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
837 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
838 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
839}
840
Jiyong Parkd1063c12019-07-17 20:08:41 +0900841func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900842 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900843 ctx.BottomUp("apex", apexMutator).Parallel()
844 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
845 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900846}
847
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900848// Mark the direct and transitive dependencies of apex bundles so that they
849// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900850func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800851 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900852 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000853 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han5e9013b2020-03-10 06:23:13 +0900854 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han5417f772020-03-12 18:37:20 +0900855 ApexName: mctx.ModuleName(),
856 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900857 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900858 directDep = true
859 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800860 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900861 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900863
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800864 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900865 return
866 }
867
Paul Duffin923e8a52020-03-30 15:33:32 +0100868 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900869
Jiyong Parkf760cae2020-02-12 07:53:12 +0900870 mctx.VisitDirectDeps(func(child android.Module) {
871 depName := mctx.OtherModuleName(child)
872 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +0900873 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800874 android.UpdateApexDependency(apexBundles, depName, directDep)
875 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900876 }
877 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900878}
879
880// Create apex variations if a module is included in APEX(s).
881func apexMutator(mctx android.BottomUpMutatorContext) {
882 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900883 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000884 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900885 // apex bundle itself is mutated so that it and its modules have same
886 // apex variant.
887 apexBundleName := mctx.ModuleName()
888 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900889 } else if o, ok := mctx.Module().(*OverrideApex); ok {
890 apexBundleName := o.GetOverriddenModuleName()
891 if apexBundleName == "" {
892 mctx.ModuleErrorf("base property is not set")
893 return
894 }
895 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900896 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900897
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900898}
Sundong Ahne9b55722019-09-06 17:37:42 +0900899
Jooyung Han7a78a922019-10-08 21:59:58 +0900900var (
901 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
902 apexFileContextsInfosMutex sync.Mutex
903)
904
905func apexFileContextsInfos(config android.Config) *[]string {
906 return config.Once(apexFileContextsInfosKey, func() interface{} {
907 return &[]string{}
908 }).(*[]string)
909}
910
Jooyung Han54aca7b2019-11-20 02:26:02 +0900911func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900912 apexFileContextsInfosMutex.Lock()
913 defer apexFileContextsInfosMutex.Unlock()
914 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900915 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900916}
917
Sundong Ahne9b55722019-09-06 17:37:42 +0900918func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900919 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900920 var variants []string
921 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
922 case "image":
923 variants = append(variants, imageApexType, flattenedApexType)
924 case "zip":
925 variants = append(variants, zipApexType)
926 case "both":
927 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
928 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900929 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900930 return
931 }
932
933 modules := mctx.CreateLocalVariations(variants...)
934
935 for i, v := range variants {
936 switch v {
937 case imageApexType:
938 modules[i].(*apexBundle).properties.ApexType = imageApex
939 case zipApexType:
940 modules[i].(*apexBundle).properties.ApexType = zipApex
941 case flattenedApexType:
942 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900943 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900944 modules[i].(*apexBundle).MakeAsSystemExt()
945 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900946 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900947 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900948 } else if _, ok := mctx.Module().(*OverrideApex); ok {
949 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900950 }
951}
952
Jooyung Han5c998b92019-06-27 11:30:33 +0900953func apexUsesMutator(mctx android.BottomUpMutatorContext) {
954 if ab, ok := mctx.Module().(*apexBundle); ok {
955 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
956 }
957}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900958
Jooyung Handc782442019-11-01 03:14:38 +0900959var (
960 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
961)
962
963// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
964// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
965// which may cause compatibility issues. (e.g. libbinder)
966// Even though libbinder restricts its availability via 'apex_available' property and relies on
967// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
968// to avoid similar problems.
969func useVendorWhitelist(config android.Config) []string {
970 return config.Once(useVendorWhitelistKey, func() interface{} {
971 return []string{
972 // swcodec uses "vendor" variants for smaller size
973 "com.android.media.swcodec",
974 "test_com.android.media.swcodec",
975 }
976 }).([]string)
977}
978
979// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
980// called before the first call to useVendorWhitelist()
981func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
982 config.Once(useVendorWhitelistKey, func() interface{} {
983 return whitelist
984 })
985}
986
Jooyung Han01a868d2020-02-27 13:40:44 +0900987type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800988 // List of native libraries
989 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900990
Jooyung Han643adc42020-02-27 13:50:06 +0900991 // List of JNI libraries
992 Jni_libs []string
993
Alex Light9670d332019-01-29 18:07:33 -0800994 // List of native executables
995 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900996
Roland Levillain630846d2019-06-26 12:48:34 +0100997 // List of native tests
998 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800999}
Jooyung Han344d5432019-08-23 11:17:39 +09001000
Alex Light9670d332019-01-29 18:07:33 -08001001type apexMultilibProperties struct {
1002 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001003 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001004
1005 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001006 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001007
1008 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001009 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001010
1011 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001012 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001013
1014 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001015 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001016}
1017
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001018type apexBundleProperties struct {
1019 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001020 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001021 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001022
Jiyong Park40e26a22019-02-08 02:53:06 +09001023 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1024 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001025 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001026
Roland Levillain411c5842019-09-19 16:37:20 +01001027 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1028 // device (/apex/<apex_name>).
1029 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001030 Apex_name *string
1031
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001032 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001033 // For platform APEXes, this should points to a file under /system/sepolicy
1034 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1035 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001036
Jooyung Han01a868d2020-02-27 13:40:44 +09001037 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001038
1039 // List of java libraries that are embedded inside this APEX bundle
1040 Java_libs []string
1041
1042 // List of prebuilt files that are embedded inside this APEX bundle
1043 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001044
1045 // Name of the apex_key module that provides the private key to sign APEX
1046 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001047
Alex Light5098a612018-11-29 17:12:15 -08001048 // The type of APEX to build. Controls what the APEX payload is. Either
1049 // 'image', 'zip' or 'both'. Default: 'image'.
1050 Payload_type *string
1051
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001052 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1053 // or an android_app_certificate module name in the form ":module".
1054 Certificate *string
1055
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001056 // Whether this APEX is installable to one of the partitions. Default: true.
1057 Installable *bool
1058
Jiyong Parkda6eb592018-12-19 17:12:36 +09001059 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1060 // Default is false.
1061 Use_vendor *bool
1062
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001063 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1064 Ignore_system_library_special_case *bool
1065
Alex Light9670d332019-01-29 18:07:33 -08001066 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001067
Jiyong Parkf97782b2019-02-13 20:28:58 +09001068 // List of sanitizer names that this APEX is enabled for
1069 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001070
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001071 PreventInstall bool `blueprint:"mutated"`
1072
1073 HideFromMake bool `blueprint:"mutated"`
1074
Jooyung Han5c998b92019-06-27 11:30:33 +09001075 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1076 Provide_cpp_shared_libs *bool
1077
1078 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1079 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001080
1081 // A txt file containing list of files that are whitelisted to be included in this APEX.
1082 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001083
Sundong Ahnabb64432019-10-22 13:58:29 +09001084 // package format of this apex variant; could be non-flattened, flattened, or zip.
1085 // imageApex, zipApex or flattened
1086 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001087
Jiyong Parkd1063c12019-07-17 20:08:41 +09001088 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1089 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1090 // is implied. This value affects all modules included in this APEX. In other words, they are
1091 // also built with the SDKs specified here.
1092 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001093
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001094 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1095 // Should be only used in tests#.
1096 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001097
Jiyong Park956305c2020-01-09 12:32:06 +09001098 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001099
1100 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1101 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1102 // like symlinking to the system libs. Default is false.
1103 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001104
1105 // The minimum SDK version that this apex must be compatibile with.
1106 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001107}
1108
1109type apexTargetBundleProperties struct {
1110 Target struct {
1111 // Multilib properties only for android.
1112 Android struct {
1113 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001114 }
Jooyung Han344d5432019-08-23 11:17:39 +09001115
Alex Light9670d332019-01-29 18:07:33 -08001116 // Multilib properties only for host.
1117 Host struct {
1118 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001119 }
Jooyung Han344d5432019-08-23 11:17:39 +09001120
Alex Light9670d332019-01-29 18:07:33 -08001121 // Multilib properties only for host linux_bionic.
1122 Linux_bionic struct {
1123 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001124 }
Jooyung Han344d5432019-08-23 11:17:39 +09001125
Alex Light9670d332019-01-29 18:07:33 -08001126 // Multilib properties only for host linux_glibc.
1127 Linux_glibc struct {
1128 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001129 }
1130 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001131}
1132
Jiyong Park5d790c32019-11-15 18:40:32 +09001133type overridableProperties struct {
1134 // List of APKs to package inside APEX
1135 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001136
1137 // Names of modules to be overridden. Listed modules can only be other binaries
1138 // (in Make or Soong).
1139 // This does not completely prevent installation of the overridden binaries, but if both
1140 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1141 // from PRODUCT_PACKAGES.
1142 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001143
1144 // Logging Parent value
1145 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001146
1147 // Apex Container Package Name.
1148 // Override value for attribute package:name in AndroidManifest.xml
1149 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001150}
1151
Alex Light5098a612018-11-29 17:12:15 -08001152type apexPackaging int
1153
1154const (
1155 imageApex apexPackaging = iota
1156 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001157 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001158)
1159
Sundong Ahnabb64432019-10-22 13:58:29 +09001160// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001161func (a apexPackaging) suffix() string {
1162 switch a {
1163 case imageApex:
1164 return imageApexSuffix
1165 case zipApex:
1166 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001167 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001168 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001169 }
1170}
1171
1172func (a apexPackaging) name() string {
1173 switch a {
1174 case imageApex:
1175 return imageApexType
1176 case zipApex:
1177 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001178 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001179 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001180 }
1181}
1182
Jiyong Parkf653b052019-11-18 15:39:01 +09001183type apexFileClass int
1184
1185const (
1186 etc apexFileClass = iota
1187 nativeSharedLib
1188 nativeExecutable
1189 shBinary
1190 pyBinary
1191 goBinary
1192 javaSharedLib
1193 nativeTest
1194 app
1195)
1196
Jiyong Park8fd61922018-11-08 02:50:25 +09001197func (class apexFileClass) NameInMake() string {
1198 switch class {
1199 case etc:
1200 return "ETC"
1201 case nativeSharedLib:
1202 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001203 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001204 return "EXECUTABLES"
1205 case javaSharedLib:
1206 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001207 case nativeTest:
1208 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001209 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001210 // b/142537672 Why isn't this APP? We want to have full control over
1211 // the paths and file names of the apk file under the flattend APEX.
1212 // If this is set to APP, then the paths and file names are modified
1213 // by the Make build system. For example, it is installed to
1214 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1215 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1216 // appends module name (which is <apexname>.<Appname> to the path.
1217 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001218 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001219 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001220 }
1221}
1222
Jiyong Parkf653b052019-11-18 15:39:01 +09001223// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001224type apexFile struct {
1225 builtFile android.Path
1226 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001227 installDir string
1228 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001229 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001230 // list of symlinks that will be created in installDir that point to this apexFile
1231 symlinks []string
1232 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001233 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001234
1235 requiredModuleNames []string
1236 targetRequiredModuleNames []string
1237 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001238
Colin Cross503c1d02020-01-28 14:00:53 -08001239 jacocoReportClassesFile android.Path // only for javalibs and apps
1240 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001241 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001242
1243 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001244}
1245
Jiyong Park1833cef2019-12-13 13:28:36 +09001246func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1247 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001248 builtFile: builtFile,
1249 moduleName: moduleName,
1250 installDir: installDir,
1251 class: class,
1252 module: module,
1253 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001254 if module != nil {
1255 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001256 ret.requiredModuleNames = module.RequiredModuleNames()
1257 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1258 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001259 }
1260 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001261}
1262
1263func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001264 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001265}
1266
Jiyong Park7cd10e32020-01-14 09:22:18 +09001267// Path() returns path of this apex file relative to the APEX root
1268func (af *apexFile) Path() string {
1269 return filepath.Join(af.installDir, af.builtFile.Base())
1270}
1271
1272// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1273func (af *apexFile) SymlinkPaths() []string {
1274 var ret []string
1275 for _, symlink := range af.symlinks {
1276 ret = append(ret, filepath.Join(af.installDir, symlink))
1277 }
1278 return ret
1279}
1280
1281func (af *apexFile) AvailableToPlatform() bool {
1282 if af.module == nil {
1283 return false
1284 }
1285 if am, ok := af.module.(android.ApexModule); ok {
1286 return am.AvailableFor(android.AvailableToPlatform)
1287 }
1288 return false
1289}
1290
Jiyong Park678c8812020-02-07 17:25:49 +09001291type depInfo struct {
1292 to string
1293 from []string
1294 isExternal bool
1295}
1296
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001297type apexBundle struct {
1298 android.ModuleBase
1299 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001300 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001301 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001302
Jiyong Park5d790c32019-11-15 18:40:32 +09001303 properties apexBundleProperties
1304 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001305 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001306
Jooyung Hanf21c7972019-12-16 22:32:06 +09001307 // specific to apex_vndk modules
1308 vndkProperties apexVndkProperties
1309
Colin Crossa4925902018-11-16 11:36:28 -08001310 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001311 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001312 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001313
Jiyong Park03b68dd2019-07-26 23:20:40 +09001314 prebuiltFileToDelete string
1315
Jiyong Park42cca6c2019-04-01 11:15:50 +09001316 public_key_file android.Path
1317 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001318
1319 container_certificate_file android.Path
1320 container_private_key_file android.Path
1321
Jooyung Han54aca7b2019-11-20 02:26:02 +09001322 fileContexts android.Path
1323
Jiyong Park8fd61922018-11-08 02:50:25 +09001324 // list of files to be included in this apex
1325 filesInfo []apexFile
1326
Jiyong Park956305c2020-01-09 12:32:06 +09001327 // list of module names that should be installed along with this APEX
1328 requiredDeps []string
1329
Jiyong Park956305c2020-01-09 12:32:06 +09001330 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001331 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001332
Sundong Ahnabb64432019-10-22 13:58:29 +09001333 testApex bool
1334 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001335 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001336 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001337
Jooyung Han214bf372019-11-12 13:03:50 +09001338 manifestJsonOut android.WritablePath
1339 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001340
Jooyung Han002ab682020-01-08 01:57:58 +09001341 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001342 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001343 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001344 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1345 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001346
1347 // Suffix of module name in Android.mk
1348 // ".flattened", ".apex", ".zipapex", or ""
1349 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001350
1351 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001352
1353 // Whether to create symlink to the system file instead of having a file
1354 // inside the apex or not
1355 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001356
1357 // Struct holding the merged notice file paths in different formats
1358 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001359}
1360
Jiyong Park397e55e2018-10-24 21:09:55 +09001361func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001362 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001363 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001364 // Use *FarVariation* to be able to depend on modules having
1365 // conflicting variations with this module. This is required since
1366 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1367 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001368 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001369 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001370 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001371 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001372 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001373
Jooyung Han643adc42020-02-27 13:50:06 +09001374 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1375 {Mutator: "image", Variation: imageVariation},
1376 {Mutator: "link", Variation: "shared"},
1377 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1378 }...), jniLibTag, nativeModules.Jni_libs...)
1379
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001380 ctx.AddFarVariationDependencies(append(target.Variations(),
1381 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001382 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001383
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001384 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001385 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001386 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001387 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001388}
1389
Alex Light9670d332019-01-29 18:07:33 -08001390func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1391 if ctx.Os().Class == android.Device {
1392 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1393 } else {
1394 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1395 if ctx.Os().Bionic() {
1396 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1397 } else {
1398 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1399 }
1400 }
1401}
1402
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001403func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001404 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1405 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1406 }
1407
Jiyong Park397e55e2018-10-24 21:09:55 +09001408 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001409 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001410
1411 a.combineProperties(ctx)
1412
Jiyong Park397e55e2018-10-24 21:09:55 +09001413 has32BitTarget := false
1414 for _, target := range targets {
1415 if target.Arch.ArchType.Multilib == "lib32" {
1416 has32BitTarget = true
1417 }
1418 }
1419 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001420 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001421 // multilib.both
1422 addDependenciesForNativeModules(ctx,
1423 ApexNativeDependencies{
1424 Native_shared_libs: a.properties.Native_shared_libs,
1425 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001426 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001427 Binaries: nil,
1428 },
1429 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001430
Jiyong Park397e55e2018-10-24 21:09:55 +09001431 // Add native modules targetting both ABIs
1432 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001433 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001434 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001435 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001436
Alex Light3d673592019-01-18 14:37:31 -08001437 isPrimaryAbi := i == 0
1438 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001439 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001440 // multilib.first
1441 addDependenciesForNativeModules(ctx,
1442 ApexNativeDependencies{
1443 Native_shared_libs: nil,
1444 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001445 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001446 Binaries: a.properties.Binaries,
1447 },
1448 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001449
1450 // Add native modules targetting the first ABI
1451 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001452 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001453 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001454 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001455 }
1456
1457 switch target.Arch.ArchType.Multilib {
1458 case "lib32":
1459 // Add native modules targetting 32-bit ABI
1460 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001461 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001462 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001463 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001464
1465 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001466 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001467 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001468 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001469 case "lib64":
1470 // Add native modules targetting 64-bit ABI
1471 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001472 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001473 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001474 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001475
1476 if !has32BitTarget {
1477 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001478 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001479 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001480 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001481 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001482
1483 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1484 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1485 if sanitizer == "hwaddress" {
1486 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001487 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001488 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001489 break
1490 }
1491 }
1492 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001493 }
1494
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001495 }
1496
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001497 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1498 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1499 // b/144532908
1500 archForPrebuiltEtc := config.Arches()[0]
1501 for _, arch := range config.Arches() {
1502 // Prefer 64-bit arch if there is any
1503 if arch.ArchType.Multilib == "lib64" {
1504 archForPrebuiltEtc = arch
1505 break
1506 }
1507 }
1508 ctx.AddFarVariationDependencies([]blueprint.Variation{
1509 {Mutator: "os", Variation: ctx.Os().String()},
1510 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1511 }, prebuiltTag, a.properties.Prebuilts...)
1512
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001513 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1514 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001515
Ulya Trafimovich44561882020-01-03 13:25:54 +00001516 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1517 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1518 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1519 javaLibTag, "jacocoagent")
1520 }
1521
Jiyong Park23c52b02019-02-02 13:13:47 +09001522 if String(a.properties.Key) == "" {
1523 ctx.ModuleErrorf("key is missing")
1524 return
1525 }
1526 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001527
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001528 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001529 if cert != "" {
1530 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001531 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001532
1533 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1534 if len(a.properties.Uses_sdks) > 0 {
1535 sdkRefs := []android.SdkRef{}
1536 for _, str := range a.properties.Uses_sdks {
1537 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1538 sdkRefs = append(sdkRefs, parsed)
1539 }
1540 a.BuildWithSdks(sdkRefs)
1541 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001542}
1543
Jiyong Park5d790c32019-11-15 18:40:32 +09001544func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1545 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1546 androidAppTag, a.overridableProperties.Apps...)
1547}
1548
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001549func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1550 // direct deps of an APEX bundle are all part of the APEX bundle
1551 return true
1552}
1553
Colin Cross0ea8ba82019-06-06 14:33:29 -07001554func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001555 moduleName := ctx.ModuleName()
1556 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1557 // we check with the pseudo module name to see if its certificate is overridden.
1558 if a.vndkApex {
1559 moduleName = vndkApexName
1560 }
1561 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001562 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001563 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001564 }
1565 return String(a.properties.Certificate)
1566}
1567
Colin Cross41955e82019-05-29 14:40:35 -07001568func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1569 switch tag {
1570 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001571 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001572 default:
1573 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001574 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001575}
1576
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001577func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001578 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001579}
1580
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001581func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1582 return proptools.Bool(a.properties.Test_only_no_hashtree)
1583}
1584
Jiyong Park7c1dc612019-01-05 11:15:24 +09001585func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001586 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001587 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001588 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001589 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001590 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001591 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001592 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001593 }
1594}
1595
Jiyong Parkf97782b2019-02-13 20:28:58 +09001596func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1597 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1598 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1599 }
1600}
1601
Jiyong Park388ef3f2019-01-28 19:47:32 +09001602func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001603 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1604 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001605 }
1606
1607 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001608 globalSanitizerNames := []string{}
1609 if a.Host() {
1610 globalSanitizerNames = ctx.Config().SanitizeHost()
1611 } else {
1612 arches := ctx.Config().SanitizeDeviceArch()
1613 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1614 globalSanitizerNames = ctx.Config().SanitizeDevice()
1615 }
1616 }
1617 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001618}
1619
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001620func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001621 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001622}
1623
1624func (a *apexBundle) PreventInstall() {
1625 a.properties.PreventInstall = true
1626}
1627
1628func (a *apexBundle) HideFromMake() {
1629 a.properties.HideFromMake = true
1630}
1631
Jiyong Park956305c2020-01-09 12:32:06 +09001632func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1633 a.properties.IsCoverageVariant = coverage
1634}
1635
Jiyong Parkf653b052019-11-18 15:39:01 +09001636// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001637func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001638 // Decide the APEX-local directory by the multilib of the library
1639 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001640 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001641 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001642 case "lib32":
1643 dirInApex = "lib"
1644 case "lib64":
1645 dirInApex = "lib64"
1646 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001647 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001648 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001649 }
Jooyung Han35155c42020-02-06 17:33:20 +09001650 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001651 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001652 // Special case for Bionic libs and other libs installed with them. This is
1653 // to prevent those libs from being included in the search path
1654 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1655 // those libs in the Runtime APEX are available via the legacy paths in
1656 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1657 // to the legacy paths and thus will be loaded into the default linker
1658 // namespace (aka "platform" namespace). If the libs are directly in
1659 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1660 // into the runtime linker namespace, which will result in double loading of
1661 // them, which isn't supported.
1662 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001663 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001664
Jiyong Parkf653b052019-11-18 15:39:01 +09001665 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001666 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001667}
1668
Jiyong Park1833cef2019-12-13 13:28:36 +09001669func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001670 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001671 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001672 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001673 }
Jooyung Han35155c42020-02-06 17:33:20 +09001674 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001675 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001676 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001677 af.symlinks = cc.Symlinks()
1678 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001679}
1680
Jiyong Park1833cef2019-12-13 13:28:36 +09001681func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001682 dirInApex := "bin"
1683 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001684 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001685}
Jiyong Park1833cef2019-12-13 13:28:36 +09001686func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001687 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001688 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1689 if err != nil {
1690 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001692 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001693 fileToCopy := android.PathForOutput(ctx, s)
1694 // NB: Since go binaries are static we don't need the module for anything here, which is
1695 // good since the go tool is a blueprint.Module not an android.Module like we would
1696 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001697 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001698}
1699
Jiyong Park1833cef2019-12-13 13:28:36 +09001700func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001701 dirInApex := filepath.Join("bin", sh.SubDir())
1702 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001703 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001704 af.symlinks = sh.Symlinks()
1705 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001706}
1707
Jooyung Han58f26ab2019-12-18 15:34:32 +09001708// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1709type javaLibrary interface {
1710 android.Module
1711 java.Dependency
1712}
1713
1714func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001715 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001716 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001717 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1718 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1719 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001720}
1721
Jiyong Park1833cef2019-12-13 13:28:36 +09001722func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001723 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1724 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001725 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001726}
1727
atrost6e126252020-01-27 17:01:16 +00001728func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1729 dirInApex := filepath.Join("etc", config.SubDir())
1730 fileToCopy := config.CompatConfig()
1731 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1732}
1733
Jiyong Park1833cef2019-12-13 13:28:36 +09001734func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001735 android.Module
1736 Privileged() bool
1737 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001738 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001739 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001740}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001741 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001742 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001743 appDir = "priv-app"
1744 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001745 dirInApex := filepath.Join(appDir, pkgName)
1746 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001747 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1748 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001749 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001750
1751 if app, ok := aapp.(interface {
1752 OverriddenManifestPackageName() string
1753 }); ok {
1754 af.overriddenPackageName = app.OverriddenManifestPackageName()
1755 }
Jiyong Park618922e2020-01-08 13:35:43 +09001756 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001757}
1758
Roland Levillain935639d2019-08-13 14:55:28 +01001759// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1760type flattenedApexContext struct {
1761 android.ModuleContext
1762}
1763
1764func (c *flattenedApexContext) InstallBypassMake() bool {
1765 return true
1766}
1767
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001768// Function called while walking an APEX's payload dependencies.
1769//
1770// Return true if the `to` module should be visited, false otherwise.
1771type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1772
Jiyong Park201cedd2020-02-07 17:25:49 +09001773// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001774func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001775 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001776 am, ok := child.(android.ApexModule)
1777 if !ok || !am.CanHaveApexVariants() {
1778 return false
1779 }
1780
1781 // Check for the direct dependencies that contribute to the payload
1782 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1783 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001784 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001785 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001786 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001787 return false
1788 }
1789
1790 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001791 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001792 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001793 }
1794
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001795 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001796 })
1797}
1798
Jooyung Han03b51852020-02-26 22:45:42 +09001799func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1800 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1801 if ver != "current" {
1802 minSdkVersion, err := strconv.Atoi(ver)
1803 if err != nil {
1804 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1805 }
1806 return minSdkVersion
1807 }
1808 return android.FutureApiLevel
1809}
1810
Jiyong Park201cedd2020-02-07 17:25:49 +09001811// Ensures that the dependencies are marked as available for this APEX
1812func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1813 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1814 if ctx.Host() || a.testApex || a.vndkApex {
1815 return
1816 }
1817
Jiyong Park58d10902020-03-28 14:43:19 +09001818 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1819 // Requiring them and their transitive depencies with apex_available is not right
1820 // because they just add noise.
1821 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1822 return
1823 }
1824
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001825 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1826 if externalDep {
1827 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1828 return false
1829 }
1830
Jiyong Park201cedd2020-02-07 17:25:49 +09001831 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001832 fromName := ctx.OtherModuleName(from)
1833 toName := ctx.OtherModuleName(to)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001834 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1835 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001836 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001837 message := ""
1838 for _, m := range ctx.GetWalkPath()[1:] {
1839 message = fmt.Sprintf("%s\n -> %s", message, m.String())
1840 }
1841 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 +01001842 // Visit this module's dependencies to check and report any issues with their availability.
1843 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001844 })
1845}
1846
Jiyong Park678c8812020-02-07 17:25:49 +09001847// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1848func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1849 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001850 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001851 if from.Name() == to.Name() {
1852 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001853 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1854 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001855 }
1856
1857 if info, exists := a.depInfos[to.Name()]; exists {
1858 if !android.InList(from.Name(), info.from) {
1859 info.from = append(info.from, from.Name())
1860 }
1861 info.isExternal = info.isExternal && externalDep
1862 a.depInfos[to.Name()] = info
1863 } else {
1864 a.depInfos[to.Name()] = depInfo{
1865 to: to.Name(),
1866 from: []string{from.Name()},
1867 isExternal: externalDep,
1868 }
1869 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001870
1871 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1872 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001873 })
1874}
1875
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001876func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001877 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1878 switch a.properties.ApexType {
1879 case imageApex:
1880 if buildFlattenedAsDefault {
1881 a.suffix = imageApexSuffix
1882 } else {
1883 a.suffix = ""
1884 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001885
1886 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001887 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001888 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001889 }
1890 case zipApex:
1891 if proptools.String(a.properties.Payload_type) == "zip" {
1892 a.suffix = ""
1893 a.primaryApexType = true
1894 } else {
1895 a.suffix = zipApexSuffix
1896 }
1897 case flattenedApex:
1898 if buildFlattenedAsDefault {
1899 a.suffix = ""
1900 a.primaryApexType = true
1901 } else {
1902 a.suffix = flattenedSuffix
1903 }
Alex Light5098a612018-11-29 17:12:15 -08001904 }
1905
Roland Levillain630846d2019-06-26 12:48:34 +01001906 if len(a.properties.Tests) > 0 && !a.testApex {
1907 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1908 return
1909 }
1910
Jiyong Park0f80c182020-01-31 02:49:53 +09001911 a.checkApexAvailability(ctx)
1912
Jiyong Park678c8812020-02-07 17:25:49 +09001913 a.collectDepsInfo(ctx)
1914
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001915 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1916
Jooyung Hane1633032019-08-01 17:41:43 +09001917 // native lib dependencies
1918 var provideNativeLibs []string
1919 var requireNativeLibs []string
1920
Jooyung Han5c998b92019-06-27 11:30:33 +09001921 // Check if "uses" requirements are met with dependent apexBundles
1922 var providedNativeSharedLibs []string
1923 useVendor := proptools.Bool(a.properties.Use_vendor)
1924 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1925 if ctx.OtherModuleDependencyTag(m) != usesTag {
1926 return
1927 }
1928 otherName := ctx.OtherModuleName(m)
1929 other, ok := m.(*apexBundle)
1930 if !ok {
1931 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1932 return
1933 }
1934 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1935 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1936 return
1937 }
1938 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1939 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1940 return
1941 }
1942 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1943 })
1944
Jiyong Parkf653b052019-11-18 15:39:01 +09001945 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001946 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001947 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001948 depTag := ctx.OtherModuleDependencyTag(child)
1949 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001950 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001951 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001952 case sharedLibTag, jniLibTag:
1953 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001954 if c, ok := child.(*cc.Module); ok {
1955 // bootstrap bionic libs are treated as provided by system
1956 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1957 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001958 }
Jooyung Han643adc42020-02-27 13:50:06 +09001959 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1960 fi.isJniLib = isJniLib
1961 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001962 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001963 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001964 propertyName := "native_shared_libs"
1965 if isJniLib {
1966 propertyName = "jni_libs"
1967 }
1968 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001969 }
1970 case executableTag:
1971 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001972 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001973 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001974 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001975 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001976 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001977 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001978 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001979 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001980 } else {
Alex Light778127a2019-02-27 14:19:50 -08001981 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 +09001982 }
1983 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001984 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001985 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001986 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001987 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1988 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001989 filesInfo = append(filesInfo, af)
1990 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001991 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001992 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1993 af := apexFileForJavaLibrary(ctx, sdkLib)
1994 if !af.Ok() {
1995 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1996 return false
1997 }
1998 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001999 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002000 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002001 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002002 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002003 case androidAppTag:
2004 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2005 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002006 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002007 return true // track transitive dependencies
2008 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002009 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002010 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2011 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002012 } else {
2013 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2014 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002015 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002016 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002017 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002018 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2019 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002020 } else {
atrost6e126252020-01-27 17:01:16 +00002021 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002022 }
Roland Levillain630846d2019-06-26 12:48:34 +01002023 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002024 if ccTest, ok := child.(*cc.Module); ok {
2025 if ccTest.IsTestPerSrcAllTestsVariation() {
2026 // Multiple-output test module (where `test_per_src: true`).
2027 //
2028 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2029 // We do not add this variation to `filesInfo`, as it has no output;
2030 // however, we do add the other variations of this module as indirect
2031 // dependencies (see below).
2032 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002033 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002034 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002035 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002036 af.class = nativeTest
2037 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002038 }
Roland Levillain630846d2019-06-26 12:48:34 +01002039 } else {
2040 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2041 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002042 case keyTag:
2043 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002044 a.private_key_file = key.private_key_file
2045 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002046 } else {
2047 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002048 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002049 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002050 case certificateTag:
2051 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002052 a.container_certificate_file = dep.Certificate.Pem
2053 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002054 } else {
2055 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2056 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002057 case android.PrebuiltDepTag:
2058 // If the prebuilt is force disabled, remember to delete the prebuilt file
2059 // that might have been installed in the previous builds
2060 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2061 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2062 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002063 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002064 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002065 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002066 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002067 // We cannot use a switch statement on `depTag` here as the checked
2068 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002069 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002070 if cc, ok := child.(*cc.Module); ok {
2071 if android.InList(cc.Name(), providedNativeSharedLibs) {
2072 // If we're using a shared library which is provided from other APEX,
2073 // don't include it in this APEX
2074 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002075 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002076 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002077 // If the dependency is a stubs lib, don't include it in this APEX,
2078 // but make sure that the lib is installed on the device.
2079 // In case no APEX is having the lib, the lib is installed to the system
2080 // partition.
2081 //
2082 // Always include if we are a host-apex however since those won't have any
2083 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002084 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2085 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002086 }
Jooyung Hane1633032019-08-01 17:41:43 +09002087 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002088 // Don't track further
2089 return false
2090 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002091 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002092 af.transitiveDep = true
2093 filesInfo = append(filesInfo, af)
2094 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002095 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002096 } else if cc.IsTestPerSrcDepTag(depTag) {
2097 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002098 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002099 // Handle modules created as `test_per_src` variations of a single test module:
2100 // use the name of the generated test binary (`fileToCopy`) instead of the name
2101 // of the original test module (`depName`, shared by all `test_per_src`
2102 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002103 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002104 // these are not considered transitive dep
2105 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002106 filesInfo = append(filesInfo, af)
2107 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002108 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002109 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002110 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2111 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002112 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2113 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2114 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2115 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002116 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002117 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002118 }
2119 }
2120 }
2121 return false
2122 })
2123
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002124 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2125 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2126 // via the global boot image config.
2127 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002128 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002129 dirInApex := filepath.Join("javalib", arch.String())
2130 for _, f := range files {
2131 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002132 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002133 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002134 }
2135 }
2136 }
2137
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002138 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002139 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2140 return
2141 }
2142
Jiyong Park8fd61922018-11-08 02:50:25 +09002143 // remove duplicates in filesInfo
2144 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002145 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002146 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002147 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002148 if e, ok := encountered[dest]; !ok {
2149 encountered[dest] = f
2150 } else {
2151 // If a module is directly included and also transitively depended on
2152 // consider it as directly included.
2153 e.transitiveDep = e.transitiveDep && f.transitiveDep
2154 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002155 }
2156 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002157 var result []apexFile
2158 for _, v := range encountered {
2159 result = append(result, v)
2160 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002161 return result
2162 }
2163 filesInfo = removeDup(filesInfo)
2164
2165 // to have consistent build rules
2166 sort.Slice(filesInfo, func(i, j int) bool {
2167 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2168 })
2169
Jiyong Park8fd61922018-11-08 02:50:25 +09002170 a.installDir = android.PathForModuleInstall(ctx, "apex")
2171 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002172
Jooyung Han54aca7b2019-11-20 02:26:02 +09002173 if a.properties.ApexType != zipApex {
2174 if a.properties.File_contexts == nil {
2175 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2176 } else {
2177 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2178 if a.Platform() {
2179 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2180 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2181 }
2182 }
2183 }
2184 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2185 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2186 return
2187 }
2188 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002189 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2190 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2191 // the same library in the system partition, thus effectively sharing the same libraries
2192 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2193 // in the APEX.
2194 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2195 a.installable() &&
2196 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002197
Jiyong Park9d677202020-02-19 16:29:35 +09002198 // We don't need the optimization for updatable APEXes, as it might give false signal
2199 // to the system health when the APEXes are still bundled (b/149805758)
2200 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2201 a.linkToSystemLib = false
2202 }
2203
Jiyong Park638d30e2020-02-26 18:27:19 +09002204 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2205 if ctx.Host() {
2206 a.linkToSystemLib = false
2207 }
2208
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002209 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002210 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2211
2212 a.setCertificateAndPrivateKey(ctx)
2213 if a.properties.ApexType == flattenedApex {
2214 a.buildFlattenedApex(ctx)
2215 } else {
2216 a.buildUnflattenedApex(ctx)
2217 }
2218
Jooyung Han002ab682020-01-08 01:57:58 +09002219 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002220
2221 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002222}
2223
Jooyung Han5e9013b2020-03-10 06:23:13 +09002224func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002225 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002226 moduleName = normalizeModuleName(moduleName)
2227
2228 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2229 return true
2230 }
2231
2232 key = android.AvailableToAnyApex
2233 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2234 return true
2235 }
2236
2237 return false
2238}
2239
2240func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002241 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2242 // system. Trim the prefix for the check since they are confusing
2243 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2244 if strings.HasPrefix(moduleName, "libclang_rt.") {
2245 // This module has many arch variants that depend on the product being built.
2246 // We don't want to list them all
2247 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002248 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002249 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002250}
2251
Jooyung Han344d5432019-08-23 11:17:39 +09002252func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002253 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002254 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002255 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002256 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002257 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002258 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2259 })
Alex Light5098a612018-11-29 17:12:15 -08002260 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002261 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002262 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002263 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002264 return module
2265}
Jiyong Park30ca9372019-02-07 16:27:23 +09002266
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002267func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002268 bundle := newApexBundle()
2269 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002270 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002271 return bundle
2272}
2273
Jiyong Parkfce0b422020-02-11 03:56:06 +09002274// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2275// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002276func testApexBundleFactory() android.Module {
2277 bundle := newApexBundle()
2278 bundle.testApex = true
2279 return bundle
2280}
2281
Jiyong Parkfce0b422020-02-11 03:56:06 +09002282// apex packages other modules into an APEX file which is a packaging format for system-level
2283// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002284func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002285 return newApexBundle()
2286}
2287
Jiyong Park30ca9372019-02-07 16:27:23 +09002288//
2289// Defaults
2290//
2291type Defaults struct {
2292 android.ModuleBase
2293 android.DefaultsModuleBase
2294}
2295
Jiyong Park30ca9372019-02-07 16:27:23 +09002296func defaultsFactory() android.Module {
2297 return DefaultsFactory()
2298}
2299
2300func DefaultsFactory(props ...interface{}) android.Module {
2301 module := &Defaults{}
2302
2303 module.AddProperties(props...)
2304 module.AddProperties(
2305 &apexBundleProperties{},
2306 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002307 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002308 )
2309
2310 android.InitDefaultsModule(module)
2311 return module
2312}
Jiyong Park5d790c32019-11-15 18:40:32 +09002313
2314//
2315// OverrideApex
2316//
2317type OverrideApex struct {
2318 android.ModuleBase
2319 android.OverrideModuleBase
2320}
2321
2322func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2323 // All the overrides happen in the base module.
2324}
2325
2326// override_apex is used to create an apex module based on another apex module
2327// by overriding some of its properties.
2328func overrideApexFactory() android.Module {
2329 m := &OverrideApex{}
2330 m.AddProperties(&overridableProperties{})
2331
2332 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2333 android.InitOverrideModule(m)
2334 return m
2335}