blob: 5a5c02f218ef8947af678ddc95eb5c4cd04de760 [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()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090066)
67
Anton Hanssoneec79eb2020-01-10 15:12:39 +000068// This is a map from apex to modules, which overrides the
69// apex_available setting for that particular module to make
70// it available for the apex regardless of its setting.
71// TODO(b/147364041): remove this
72func makeApexAvailableWhitelist() map[string][]string {
73 // The "Module separator"s below are employed to minimize merge conflicts.
74 m := make(map[string][]string)
75 //
76 // Module separator
77 //
Jiyong Park0f80c182020-01-31 02:49:53 +090078 m["com.android.adbd"] = []string{
79 "adbd",
80 "bcm_object",
81 "fmtlib",
82 "libadbconnection_server",
83 "libadbd",
84 "libadbd_auth",
85 "libadbd_core",
86 "libadbd_services",
87 "libasyncio",
88 "libbacktrace_headers",
89 "libbase",
90 "libbase_headers",
91 "libbuildversion",
92 "libc++",
93 "libcap",
94 "libcrypto",
95 "libcrypto_utils",
96 "libcutils",
97 "libcutils_headers",
98 "libdiagnose_usb",
Jiyong Park0f80c182020-01-31 02:49:53 +090099 "liblog_headers",
100 "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",
110 "libqemu_pipe",
111 "libselinux",
112 "libsystem_headers",
113 "libutils_headers",
114 }
115 //
116 // Module separator
117 //
118 m["com.android.appsearch"] = []string{
119 "icing-java-proto-lite",
120 "libprotobuf-java-lite",
121 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000122 //
123 // Module separator
124 //
125 m["com.android.art"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900126 "art_cmdlineparser_headers",
127 "art_disassembler_headers",
128 "art_libartbase_headers",
129 "bcm_object",
130 "bionic_libc_platform_headers",
131 "core-repackaged-icu4j",
132 "cpp-define-generator-asm-support",
133 "cpp-define-generator-definitions",
134 "crtbegin_dynamic",
135 "crtbegin_dynamic1",
136 "crtbegin_so1",
137 "crtbrand",
138 "conscrypt.module.intra.core.api.stubs",
139 "dex2oat_headers",
140 "dt_fd_forward_export",
141 "fmtlib",
142 "icu4c_extra_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000143 "jacocoagent",
Jiyong Park0f80c182020-01-31 02:49:53 +0900144 "javavm_headers",
145 "jni_platform_headers",
146 "libPlatformProperties",
147 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000148 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900149 "libandroidicuinit",
150 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000151 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "libasync_safe",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000153 "libbacktrace",
154 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000156 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900157 "libc++_static",
158 "libc++abi",
159 "libc++demangle",
160 "libc_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libcrypto",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libdexfile_all_headers",
163 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000164 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900165 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000166 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900167 "libfdlibm",
168 "libgtest_prod",
169 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000170 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900171 "libicuuc_headers",
172 "libicuuc_stubdata",
173 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900174 "liblog_headers",
175 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000176 "liblzma",
177 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900178 "libnativebridge-headers",
179 "libnativehelper_header_only",
180 "libnativeloader-headers",
181 "libnpt_headers",
182 "libopenjdkjvmti_headers",
183 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000184 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900185 "libprotobuf-cpp-lite",
186 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000187 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900188 "libv8",
189 "libv8base",
190 "libv8gen",
191 "libv8platform",
192 "libv8sampler",
193 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000194 "libvixl",
195 "libvixld",
196 "libz",
197 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900198 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000199 }
200 //
201 // Module separator
202 //
203 m["com.android.bluetooth.updatable"] = []string{
204 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000205 "android.hardware.bluetooth.a2dp@1.0",
206 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900207 "android.hardware.bluetooth@1.0",
208 "android.hardware.bluetooth@1.1",
209 "android.hardware.graphics.bufferqueue@1.0",
210 "android.hardware.graphics.bufferqueue@2.0",
211 "android.hardware.graphics.common@1.0",
212 "android.hardware.graphics.common@1.1",
213 "android.hardware.graphics.common@1.2",
214 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000215 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900216 "android.hidl.token@1.0",
217 "android.hidl.token@1.0-utils",
218 "avrcp-target-service",
219 "avrcp_headers",
220 "bcm_object",
221 "bluetooth-protos-lite",
222 "bluetooth.mapsapi",
223 "com.android.vcard",
224 "fmtlib",
225 "guava",
226 "internal_include_headers",
227 "lib-bt-packets",
228 "lib-bt-packets-avrcp",
229 "lib-bt-packets-base",
230 "libFraunhoferAAC",
231 "libaudio-a2dp-hw-utils",
232 "libaudio-hearing-aid-hw-utils",
233 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000234 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900235 "libbase_headers",
236 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000237 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900238 "libbluetooth-types",
239 "libbluetooth-types-header",
240 "libbluetooth_gd",
241 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000242 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 "libbt-audio-hal-interface",
244 "libbt-bta",
245 "libbt-common",
246 "libbt-hci",
247 "libbt-platform-protos-lite",
248 "libbt-protos-lite",
249 "libbt-sbc-decoder",
250 "libbt-sbc-encoder",
251 "libbt-stack",
252 "libbt-utils",
253 "libbtcore",
254 "libbtdevice",
255 "libbte",
256 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000257 "libc++",
258 "libchrome",
259 "libcrypto",
260 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900261 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000262 "libevent",
263 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900264 "libg722codec",
265 "libgtest_prod",
266 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000267 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900268 "libhidlbase-impl-internal",
269 "libhidltransport-impl-internal",
270 "libhwbinder-impl-internal",
271 "libjsoncpp",
272 "liblog_headers",
273 "libmedia_headers",
274 "libmodpb64",
275 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000276 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900277 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000278 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900279 "libprotobuf-java-lite",
280 "libprotobuf-java-micro",
281 "libstagefright_foundation_headers",
282 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000283 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900284 "libstatssocket",
285 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000286 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900287 "libudrv-uipc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900288 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000289 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900290 "media_plugin_headers",
291 "sap-api-java-static",
292 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000293 }
294 //
295 // Module separator
296 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900297 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000298 //
299 // Module separator
300 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900301 m["com.android.conscrypt"] = []string{
302 "bcm_object",
303 "boringssl_self_test",
304 "libc++",
305 "libcrypto",
306 "libnativehelper_header_only",
307 "libssl",
308 }
309 //
310 // Module separator
311 //
312 m["com.android.extservices"] = []string{
313 "flatbuffer_headers",
314 "liblua",
315 "libtextclassifier",
316 "libtextclassifier_hash_static",
317 "libtflite_static",
318 "libutf",
319 "libz_current",
320 "tensorflow_headers",
321 }
322 //
323 // Module separator
324 //
325 m["com.android.cronet"] = []string{
326 "cronet_impl_common_java",
327 "cronet_impl_native_java",
328 "cronet_impl_platform_java",
329 "libcronet.80.0.3986.0",
330 "org.chromium.net.cronet",
331 "prebuilt_libcronet.80.0.3986.0",
332 }
333 //
334 // Module separator
335 //
336 m["com.android.neuralnetworks"] = []string{
337 "android.hardware.neuralnetworks@1.0",
338 "android.hardware.neuralnetworks@1.1",
339 "android.hardware.neuralnetworks@1.2",
340 "android.hardware.neuralnetworks@1.3",
341 "android.hidl.allocator@1.0",
342 "android.hidl.memory.token@1.0",
343 "android.hidl.memory@1.0",
344 "android.hidl.safe_union@1.0",
345 "bcm_object",
346 "fmtlib",
347 "gemmlowp_headers",
348 "libarect",
349 "libbacktrace_headers",
350 "libbase",
351 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900352 "libbuildversion",
353 "libc++",
354 "libcrypto",
355 "libcrypto_static",
356 "libcutils",
357 "libcutils_headers",
358 "libeigen",
359 "libfmq",
360 "libhidlbase",
361 "libhidlbase-impl-internal",
362 "libhidlmemory",
363 "libhidltransport-impl-internal",
364 "libhwbinder-impl-internal",
365 "libjsoncpp",
366 "liblog_headers",
367 "libmath",
368 "libneuralnetworks_common",
369 "libneuralnetworks_headers",
370 "libprocessgroup",
371 "libprocessgroup_headers",
372 "libprocpartition",
373 "libsync",
374 "libsystem_headers",
375 "libtextclassifier_hash",
376 "libtextclassifier_hash_headers",
377 "libtextclassifier_hash_static",
378 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900379 "libutils_headers",
380 "philox_random",
381 "philox_random_headers",
382 "tensorflow_headers",
383 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000384 //
385 // Module separator
386 //
387 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000388 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900389 "android.hardware.cas.native@1.0",
390 "android.hardware.cas@1.0",
391 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000392 "android.hardware.configstore@1.0",
393 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000394 "android.hardware.graphics.allocator@2.0",
395 "android.hardware.graphics.allocator@3.0",
396 "android.hardware.graphics.bufferqueue@1.0",
397 "android.hardware.graphics.bufferqueue@2.0",
398 "android.hardware.graphics.common@1.0",
399 "android.hardware.graphics.common@1.1",
400 "android.hardware.graphics.common@1.2",
401 "android.hardware.graphics.mapper@2.0",
402 "android.hardware.graphics.mapper@2.1",
403 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900404 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000405 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900406 "android.hidl.allocator@1.0",
407 "android.hidl.memory.token@1.0",
408 "android.hidl.memory@1.0",
409 "android.hidl.token@1.0",
410 "android.hidl.token@1.0-utils",
411 "bcm_object",
412 "bionic_libc_platform_headers",
413 "fmtlib",
414 "gl_headers",
415 "libEGL",
416 "libEGL_blobCache",
417 "libEGL_getProcAddress",
418 "libFLAC",
419 "libFLAC-config",
420 "libFLAC-headers",
421 "libGLESv2",
422 "libaacextractor",
423 "libamrextractor",
424 "libarect",
425 "libasync_safe",
426 "libaudio_system_headers",
427 "libaudioclient",
428 "libaudioclient_headers",
429 "libaudiofoundation",
430 "libaudiofoundation_headers",
431 "libaudiomanager",
432 "libaudiopolicy",
433 "libaudioutils",
434 "libaudioutils_fixedfft",
435 "libbacktrace",
436 "libbacktrace_headers",
437 "libbase",
438 "libbase_headers",
439 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900440 "libbluetooth-types-header",
441 "libbufferhub",
442 "libbufferhub_headers",
443 "libbufferhubqueue",
444 "libc++",
445 "libc_headers",
446 "libc_malloc_debug_backtrace",
447 "libcamera_client",
448 "libcamera_metadata",
449 "libcrypto",
450 "libcutils",
451 "libcutils_headers",
452 "libdexfile_external_headers",
453 "libdexfile_support",
454 "libdvr_headers",
455 "libexpat",
456 "libfifo",
457 "libflacextractor",
458 "libgrallocusage",
459 "libgraphicsenv",
460 "libgui",
461 "libgui_headers",
462 "libhardware_headers",
463 "libhidlbase",
464 "libhidlbase-impl-internal",
465 "libhidlmemory",
466 "libhidltransport-impl-internal",
467 "libhwbinder-impl-internal",
468 "libinput",
469 "libjsoncpp",
470 "liblog_headers",
471 "liblzma",
472 "libmath",
473 "libmedia",
474 "libmedia_codeclist",
475 "libmedia_headers",
476 "libmedia_helper",
477 "libmedia_helper_headers",
478 "libmedia_midiiowrapper",
479 "libmedia_omx",
480 "libmediautils",
481 "libmidiextractor",
482 "libmkvextractor",
483 "libmp3extractor",
484 "libmp4extractor",
485 "libmpeg2extractor",
486 "libnativebase_headers",
487 "libnativebridge-headers",
488 "libnativebridge_lazy",
489 "libnativeloader-headers",
490 "libnativeloader_lazy",
491 "libnativewindow_headers",
492 "libnblog",
493 "liboggextractor",
494 "libpackagelistparser",
495 "libpcre2",
496 "libpdx",
497 "libpdx_default_transport",
498 "libpdx_headers",
499 "libpdx_uds",
500 "libprocessgroup",
501 "libprocessgroup_headers",
502 "libprocinfo",
503 "libselinux",
504 "libsonivox",
505 "libspeexresampler",
506 "libspeexresampler",
507 "libstagefright_esds",
508 "libstagefright_flacdec",
509 "libstagefright_flacdec",
510 "libstagefright_foundation",
511 "libstagefright_foundation_headers",
512 "libstagefright_foundation_without_imemory",
513 "libstagefright_headers",
514 "libstagefright_id3",
515 "libstagefright_metadatautils",
516 "libstagefright_mpeg2extractor",
517 "libstagefright_mpeg2support",
518 "libsync",
519 "libsystem_headers",
520 "libui",
521 "libui_headers",
522 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900523 "libutils_headers",
524 "libvibrator",
525 "libvorbisidec",
526 "libwavextractor",
527 "libwebm",
528 "media_ndk_headers",
529 "media_plugin_headers",
530 "updatable-media",
531 }
532 //
533 // Module separator
534 //
535 m["com.android.media.swcodec"] = []string{
536 "android.frameworks.bufferhub@1.0",
537 "android.hardware.common-ndk_platform",
538 "android.hardware.configstore-utils",
539 "android.hardware.configstore@1.0",
540 "android.hardware.configstore@1.1",
541 "android.hardware.graphics.allocator@2.0",
542 "android.hardware.graphics.allocator@3.0",
543 "android.hardware.graphics.bufferqueue@1.0",
544 "android.hardware.graphics.bufferqueue@2.0",
545 "android.hardware.graphics.common-ndk_platform",
546 "android.hardware.graphics.common@1.0",
547 "android.hardware.graphics.common@1.1",
548 "android.hardware.graphics.common@1.2",
549 "android.hardware.graphics.mapper@2.0",
550 "android.hardware.graphics.mapper@2.1",
551 "android.hardware.graphics.mapper@3.0",
552 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000553 "android.hardware.media.bufferpool@2.0",
554 "android.hardware.media.c2@1.0",
555 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900556 "android.hardware.media@1.0",
557 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000558 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900559 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000560 "android.hidl.safe_union@1.0",
561 "android.hidl.token@1.0",
562 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900563 "fmtlib",
564 "libEGL",
565 "libFLAC",
566 "libFLAC-config",
567 "libFLAC-headers",
568 "libFraunhoferAAC",
569 "libarect",
570 "libasync_safe",
571 "libaudio_system_headers",
572 "libaudioutils",
573 "libaudioutils",
574 "libaudioutils_fixedfft",
575 "libavcdec",
576 "libavcenc",
577 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000578 "libavservices_minijail",
579 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000581 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900582 "libbase_headers",
583 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900584 "libbluetooth-types-header",
585 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000586 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900587 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000588 "libcap",
589 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900590 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000591 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900592 "libcodec2_hidl@1.1",
593 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000594 "libcodec2_soft_aacdec",
595 "libcodec2_soft_aacenc",
596 "libcodec2_soft_amrnbdec",
597 "libcodec2_soft_amrnbenc",
598 "libcodec2_soft_amrwbdec",
599 "libcodec2_soft_amrwbenc",
600 "libcodec2_soft_av1dec_gav1",
601 "libcodec2_soft_avcdec",
602 "libcodec2_soft_avcenc",
603 "libcodec2_soft_common",
604 "libcodec2_soft_flacdec",
605 "libcodec2_soft_flacenc",
606 "libcodec2_soft_g711alawdec",
607 "libcodec2_soft_g711mlawdec",
608 "libcodec2_soft_gsmdec",
609 "libcodec2_soft_h263dec",
610 "libcodec2_soft_h263enc",
611 "libcodec2_soft_hevcdec",
612 "libcodec2_soft_hevcenc",
613 "libcodec2_soft_mp3dec",
614 "libcodec2_soft_mpeg2dec",
615 "libcodec2_soft_mpeg4dec",
616 "libcodec2_soft_mpeg4enc",
617 "libcodec2_soft_opusdec",
618 "libcodec2_soft_opusenc",
619 "libcodec2_soft_rawdec",
620 "libcodec2_soft_vorbisdec",
621 "libcodec2_soft_vp8dec",
622 "libcodec2_soft_vp8enc",
623 "libcodec2_soft_vp9dec",
624 "libcodec2_soft_vp9enc",
625 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000626 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900627 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000628 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900629 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000630 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900631 "libfmq",
632 "libgav1",
633 "libgralloctypes",
634 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000635 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900636 "libgsm",
637 "libgui_bufferqueue_static",
638 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000639 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900640 "libhardware_headers",
641 "libhevcdec",
642 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000643 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900644 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000645 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900646 "libhidltransport-impl-internal",
647 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000648 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900649 "libjpeg",
650 "libjsoncpp",
651 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000652 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900653 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000654 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900655 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000656 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900657 "libminijail_gen_constants",
658 "libminijail_gen_constants_obj",
659 "libminijail_gen_syscall",
660 "libminijail_gen_syscall_obj",
661 "libminijail_generated",
662 "libmpeg2dec",
663 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000664 "libnativebridge_lazy",
665 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900666 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000667 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900668 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000669 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900670 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000671 "libscudo_wrapper",
672 "libsfplugin_ccodec_utils",
673 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900674 "libstagefright_amrnbdec",
675 "libstagefright_amrnbenc",
676 "libstagefright_amrwbdec",
677 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000678 "libstagefright_bufferpool@2.0.1",
679 "libstagefright_bufferqueue_helper",
680 "libstagefright_enc_common",
681 "libstagefright_flacdec",
682 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900683 "libstagefright_foundation_headers",
684 "libstagefright_headers",
685 "libstagefright_m4vh263dec",
686 "libstagefright_m4vh263enc",
687 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000688 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900689 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000690 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900691 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000692 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900693 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000694 "libvorbisidec",
695 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900696 "libyuv",
697 "libyuv_static",
698 "media_ndk_headers",
699 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000700 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900701 }
702 //
703 // Module separator
704 //
705 m["com.android.mediaprovider"] = []string{
706 "MediaProvider",
707 "MediaProviderGoogle",
708 "fmtlib_ndk",
709 "guava",
710 "libbase_ndk",
711 "libfuse",
712 "libfuse_jni",
713 "libnativehelper_header_only",
714 }
715 //
716 // Module separator
717 //
718 m["com.android.permission"] = []string{
719 "androidx.annotation_annotation",
720 "androidx.annotation_annotation-nodeps",
721 "androidx.lifecycle_lifecycle-common",
722 "androidx.lifecycle_lifecycle-common-java8",
723 "androidx.lifecycle_lifecycle-common-java8-nodeps",
724 "androidx.lifecycle_lifecycle-common-nodeps",
725 "kotlin-annotations",
726 "kotlin-stdlib",
727 "kotlin-stdlib-jdk7",
728 "kotlin-stdlib-jdk8",
729 "kotlinx-coroutines-android",
730 "kotlinx-coroutines-android-nodeps",
731 "kotlinx-coroutines-core",
732 "kotlinx-coroutines-core-nodeps",
733 "libprotobuf-java-lite",
734 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000735 }
736 //
737 // Module separator
738 //
739 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900740 "bionic_libc_platform_headers",
741 "fmtlib",
742 "libarm-optimized-routines-math",
743 "libasync_safe",
744 "libasync_safe_headers",
745 "libbacktrace_headers",
746 "libbase",
747 "libbase_headers",
748 "libc++",
749 "libc_aeabi",
750 "libc_bionic",
751 "libc_bionic_ndk",
752 "libc_bootstrap",
753 "libc_common",
754 "libc_common_shared",
755 "libc_common_static",
756 "libc_dns",
757 "libc_dynamic_dispatch",
758 "libc_fortify",
759 "libc_freebsd",
760 "libc_freebsd_large_stack",
761 "libc_gdtoa",
762 "libc_headers",
763 "libc_init_dynamic",
764 "libc_init_static",
765 "libc_jemalloc_wrapper",
766 "libc_netbsd",
767 "libc_nomalloc",
768 "libc_nopthread",
769 "libc_openbsd",
770 "libc_openbsd_large_stack",
771 "libc_openbsd_ndk",
772 "libc_pthread",
773 "libc_static_dispatch",
774 "libc_syscalls",
775 "libc_tzcode",
776 "libc_unwind_static",
777 "libcutils",
778 "libcutils_headers",
779 "libdebuggerd",
780 "libdebuggerd_common_headers",
781 "libdebuggerd_handler_core",
782 "libdebuggerd_handler_fallback",
783 "libdexfile_external_headers",
784 "libdexfile_support",
785 "libdexfile_support_static",
786 "libgtest_prod",
787 "libjemalloc5",
788 "liblinker_main",
789 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900790 "liblog_headers",
791 "liblz4",
792 "liblzma",
793 "libprocessgroup_headers",
794 "libprocinfo",
795 "libpropertyinfoparser",
796 "libscudo",
797 "libstdc++",
798 "libsystem_headers",
799 "libsystemproperties",
800 "libtombstoned_client_static",
801 "libunwindstack",
802 "libutils_headers",
803 "libz",
804 "libziparchive",
805 }
806 //
807 // Module separator
808 //
809 m["com.android.resolv"] = []string{
810 "bcm_object",
811 "dnsresolver_aidl_interface-unstable-ndk_platform",
812 "fmtlib",
813 "libbacktrace_headers",
814 "libbase",
815 "libbase_headers",
816 "libc++",
817 "libcrypto",
818 "libcutils",
819 "libcutils_headers",
820 "libgtest_prod",
821 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900822 "liblog_headers",
823 "libnativehelper_header_only",
824 "libnetd_client_headers",
825 "libnetd_resolv",
826 "libnetdutils",
827 "libprocessgroup",
828 "libprocessgroup_headers",
829 "libprotobuf-cpp-lite",
830 "libssl",
831 "libstatslog_resolv",
832 "libstatspush_compat",
833 "libstatssocket",
834 "libstatssocket_headers",
835 "libsystem_headers",
836 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900837 "libutils_headers",
838 "netd_event_listener_interface-ndk_platform",
839 "server_configurable_flags",
840 "stats_proto",
841 }
842 //
843 // Module separator
844 //
845 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000846 "libbase",
847 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900848 "libnativehelper_compat_libc++",
849 "android.hardware.tetheroffload.config@1.0",
850 "fmtlib",
851 "libbacktrace_headers",
852 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900853 "libcgrouprc",
854 "libcgrouprc_format",
855 "libcutils",
856 "libcutils_headers",
857 "libhidlbase",
858 "libhidlbase-impl-internal",
859 "libhidltransport-impl-internal",
860 "libhwbinder-impl-internal",
861 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900862 "liblog_headers",
863 "libprocessgroup",
864 "libprocessgroup_headers",
865 "libsystem_headers",
866 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900867 "libutils_headers",
868 "libvndksupport",
869 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000870 }
871 //
872 // Module separator
873 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900874 m["com.android.wifi"] = []string{
875 "PlatformProperties",
876 "android.hardware.wifi-V1.0-java",
877 "android.hardware.wifi-V1.1-java",
878 "android.hardware.wifi-V1.2-java",
879 "android.hardware.wifi-V1.3-java",
880 "android.hardware.wifi-V1.4-java",
881 "android.hardware.wifi.hostapd-V1.0-java",
882 "android.hardware.wifi.hostapd-V1.1-java",
883 "android.hardware.wifi.hostapd-V1.2-java",
884 "android.hardware.wifi.supplicant-V1.0-java",
885 "android.hardware.wifi.supplicant-V1.1-java",
886 "android.hardware.wifi.supplicant-V1.2-java",
887 "android.hardware.wifi.supplicant-V1.3-java",
888 "android.hidl.base-V1.0-java",
889 "android.hidl.manager-V1.0-java",
890 "android.hidl.manager-V1.1-java",
891 "android.hidl.manager-V1.2-java",
892 "androidx.annotation_annotation",
893 "androidx.annotation_annotation-nodeps",
894 "bouncycastle-unbundled",
895 "dnsresolver_aidl_interface-V2-java",
896 "error_prone_annotations",
897 "ipmemorystore-aidl-interfaces-V3-java",
898 "ipmemorystore-aidl-interfaces-java",
899 "ksoap2",
900 "libbacktrace_headers",
901 "libbase",
902 "libbase_headers",
903 "libc++",
904 "libcutils",
905 "libcutils_headers",
906 "liblog_headers",
907 "libnanohttpd",
908 "libprocessgroup",
909 "libprocessgroup_headers",
910 "libprotobuf-java-lite",
911 "libprotobuf-java-nano",
912 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900913 "libutils_headers",
914 "libwifi-jni",
915 "net-utils-services-common",
916 "netd_aidl_interface-V2-java",
917 "netd_aidl_interface-unstable-java",
918 "netd_event_listener_interface-java",
919 "netlink-client",
920 "networkstack-aidl-interfaces-unstable-java",
921 "networkstack-client",
922 "services.net",
923 "wifi-lite-protos",
924 "wifi-nano-protos",
925 "wifi-service-pre-jarjar",
926 "wifi-service-resources",
927 "prebuilt_androidx.annotation_annotation-nodeps",
928 }
929 //
930 // Module separator
931 //
932 m["com.android.sdkext"] = []string{
933 "fmtlib_ndk",
934 "libbase_ndk",
935 "libprotobuf-cpp-lite-ndk",
936 }
937 //
938 // Module separator
939 //
940 m["com.android.os.statsd"] = []string{
941 "libbacktrace_headers",
942 "libbase_headers",
943 "libc++",
944 "libcutils",
945 "libcutils_headers",
946 "liblog_headers",
947 "libprocessgroup_headers",
948 "libstatssocket",
949 "libsystem_headers",
950 "libutils_headers",
951 }
952 //
953 // Module separator
954 //
955 m["//any"] = []string{
956 "crtbegin_dynamic",
957 "crtbegin_dynamic1",
958 "crtbegin_so",
959 "crtbegin_so1",
960 "crtbegin_static",
961 "crtbrand",
962 "crtend_android",
963 "crtend_so",
964 "libatomic",
965 "libc++_static",
966 "libc++abi",
967 "libc++demangle",
968 "libc_headers",
969 "libclang_rt",
970 "libgcc_stripped",
971 "libprofile-clang-extras",
972 "libprofile-clang-extras_ndk",
973 "libprofile-extras",
974 "libprofile-extras_ndk",
975 "libunwind_llvm",
976 "ndk_crtbegin_dynamic.27",
977 "ndk_crtbegin_so.16",
978 "ndk_crtbegin_so.19",
979 "ndk_crtbegin_so.21",
980 "ndk_crtbegin_so.24",
981 "ndk_crtbegin_so.27",
982 "ndk_crtend_android.27",
983 "ndk_crtend_so.16",
984 "ndk_crtend_so.19",
985 "ndk_crtend_so.21",
986 "ndk_crtend_so.24",
987 "ndk_crtend_so.27",
988 "ndk_libandroid_support",
989 "ndk_libc++_static",
990 "ndk_libc++abi",
991 "ndk_libunwind",
992 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000993 return m
994}
995
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900996func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900997 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800998 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900999 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001000 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001001 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001002 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001003
Jooyung Han31c470b2019-10-18 16:26:59 +09001004 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001005 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001006
1007 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1008 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1009 sort.Strings(*apexFileContextsInfos)
1010 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1011 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001012}
1013
Jooyung Han31c470b2019-10-18 16:26:59 +09001014func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1015 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1016 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1017}
1018
Jiyong Parkd1063c12019-07-17 20:08:41 +09001019func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001020 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001021 ctx.BottomUp("apex", apexMutator).Parallel()
1022 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1023 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001024}
1025
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001026// Mark the direct and transitive dependencies of apex bundles so that they
1027// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001028func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001029 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001030 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001031 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han03b51852020-02-26 22:45:42 +09001032 minSdkVersion := a.minSdkVersion(mctx)
1033
1034 apexBundles = []android.ApexInfo{
1035 android.ApexInfo{
1036 ApexName: mctx.ModuleName(),
1037 LegacyAndroid10Support: proptools.Bool(a.properties.Legacy_android10_support),
1038 MinSdkVersion: minSdkVersion,
1039 },
1040 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001041 directDep = true
1042 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001043 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001044 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001045 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001046
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001047 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001048 return
1049 }
1050
1051 mctx.VisitDirectDeps(func(child android.Module) {
1052 depName := mctx.OtherModuleName(child)
1053 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
1054 (directDep || am.DepIsInSameApex(mctx, child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001055 android.UpdateApexDependency(apexBundles, depName, directDep)
1056 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001057 }
1058 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001059}
1060
1061// Create apex variations if a module is included in APEX(s).
1062func apexMutator(mctx android.BottomUpMutatorContext) {
1063 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001064 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001065 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001066 // apex bundle itself is mutated so that it and its modules have same
1067 // apex variant.
1068 apexBundleName := mctx.ModuleName()
1069 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001070 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1071 apexBundleName := o.GetOverriddenModuleName()
1072 if apexBundleName == "" {
1073 mctx.ModuleErrorf("base property is not set")
1074 return
1075 }
1076 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001077 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001078
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001079}
Sundong Ahne9b55722019-09-06 17:37:42 +09001080
Jooyung Han7a78a922019-10-08 21:59:58 +09001081var (
1082 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1083 apexFileContextsInfosMutex sync.Mutex
1084)
1085
1086func apexFileContextsInfos(config android.Config) *[]string {
1087 return config.Once(apexFileContextsInfosKey, func() interface{} {
1088 return &[]string{}
1089 }).(*[]string)
1090}
1091
Jooyung Han54aca7b2019-11-20 02:26:02 +09001092func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001093 apexFileContextsInfosMutex.Lock()
1094 defer apexFileContextsInfosMutex.Unlock()
1095 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001096 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001097}
1098
Sundong Ahne9b55722019-09-06 17:37:42 +09001099func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001100 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001101 var variants []string
1102 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1103 case "image":
1104 variants = append(variants, imageApexType, flattenedApexType)
1105 case "zip":
1106 variants = append(variants, zipApexType)
1107 case "both":
1108 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1109 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001110 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001111 return
1112 }
1113
1114 modules := mctx.CreateLocalVariations(variants...)
1115
1116 for i, v := range variants {
1117 switch v {
1118 case imageApexType:
1119 modules[i].(*apexBundle).properties.ApexType = imageApex
1120 case zipApexType:
1121 modules[i].(*apexBundle).properties.ApexType = zipApex
1122 case flattenedApexType:
1123 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001124 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001125 modules[i].(*apexBundle).MakeAsSystemExt()
1126 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001127 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001128 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001129 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1130 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001131 }
1132}
1133
Jooyung Han5c998b92019-06-27 11:30:33 +09001134func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1135 if ab, ok := mctx.Module().(*apexBundle); ok {
1136 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1137 }
1138}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001139
Jooyung Handc782442019-11-01 03:14:38 +09001140var (
1141 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1142)
1143
1144// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1145// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1146// which may cause compatibility issues. (e.g. libbinder)
1147// Even though libbinder restricts its availability via 'apex_available' property and relies on
1148// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1149// to avoid similar problems.
1150func useVendorWhitelist(config android.Config) []string {
1151 return config.Once(useVendorWhitelistKey, func() interface{} {
1152 return []string{
1153 // swcodec uses "vendor" variants for smaller size
1154 "com.android.media.swcodec",
1155 "test_com.android.media.swcodec",
1156 }
1157 }).([]string)
1158}
1159
1160// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1161// called before the first call to useVendorWhitelist()
1162func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1163 config.Once(useVendorWhitelistKey, func() interface{} {
1164 return whitelist
1165 })
1166}
1167
Jooyung Han01a868d2020-02-27 13:40:44 +09001168type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001169 // List of native libraries
1170 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001171
Jooyung Han643adc42020-02-27 13:50:06 +09001172 // List of JNI libraries
1173 Jni_libs []string
1174
Alex Light9670d332019-01-29 18:07:33 -08001175 // List of native executables
1176 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001177
Roland Levillain630846d2019-06-26 12:48:34 +01001178 // List of native tests
1179 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001180}
Jooyung Han344d5432019-08-23 11:17:39 +09001181
Alex Light9670d332019-01-29 18:07:33 -08001182type apexMultilibProperties struct {
1183 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001184 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001185
1186 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001187 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001188
1189 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001190 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001191
1192 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001193 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001194
1195 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001196 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001197}
1198
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001199type apexBundleProperties struct {
1200 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001201 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001202 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001203
Jiyong Park40e26a22019-02-08 02:53:06 +09001204 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1205 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001206 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001207
Roland Levillain411c5842019-09-19 16:37:20 +01001208 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1209 // device (/apex/<apex_name>).
1210 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001211 Apex_name *string
1212
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001213 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001214 // For platform APEXes, this should points to a file under /system/sepolicy
1215 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1216 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001217
Jooyung Han01a868d2020-02-27 13:40:44 +09001218 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001219
1220 // List of java libraries that are embedded inside this APEX bundle
1221 Java_libs []string
1222
1223 // List of prebuilt files that are embedded inside this APEX bundle
1224 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001225
1226 // Name of the apex_key module that provides the private key to sign APEX
1227 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001228
Alex Light5098a612018-11-29 17:12:15 -08001229 // The type of APEX to build. Controls what the APEX payload is. Either
1230 // 'image', 'zip' or 'both'. Default: 'image'.
1231 Payload_type *string
1232
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001233 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1234 // or an android_app_certificate module name in the form ":module".
1235 Certificate *string
1236
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001237 // Whether this APEX is installable to one of the partitions. Default: true.
1238 Installable *bool
1239
Jiyong Parkda6eb592018-12-19 17:12:36 +09001240 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1241 // Default is false.
1242 Use_vendor *bool
1243
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001244 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1245 Ignore_system_library_special_case *bool
1246
Alex Light9670d332019-01-29 18:07:33 -08001247 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001248
Jiyong Parkf97782b2019-02-13 20:28:58 +09001249 // List of sanitizer names that this APEX is enabled for
1250 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001251
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001252 PreventInstall bool `blueprint:"mutated"`
1253
1254 HideFromMake bool `blueprint:"mutated"`
1255
Jooyung Han5c998b92019-06-27 11:30:33 +09001256 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1257 Provide_cpp_shared_libs *bool
1258
1259 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1260 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001261
1262 // A txt file containing list of files that are whitelisted to be included in this APEX.
1263 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001264
Sundong Ahnabb64432019-10-22 13:58:29 +09001265 // package format of this apex variant; could be non-flattened, flattened, or zip.
1266 // imageApex, zipApex or flattened
1267 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001268
Jiyong Parkd1063c12019-07-17 20:08:41 +09001269 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1270 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1271 // is implied. This value affects all modules included in this APEX. In other words, they are
1272 // also built with the SDKs specified here.
1273 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001274
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001275 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1276 // Should be only used in tests#.
1277 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001278
1279 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1280 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1281 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001282
1283 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001284
1285 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1286 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1287 // like symlinking to the system libs. Default is false.
1288 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001289
1290 // The minimum SDK version that this apex must be compatibile with.
1291 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001292}
1293
1294type apexTargetBundleProperties struct {
1295 Target struct {
1296 // Multilib properties only for android.
1297 Android struct {
1298 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001299 }
Jooyung Han344d5432019-08-23 11:17:39 +09001300
Alex Light9670d332019-01-29 18:07:33 -08001301 // Multilib properties only for host.
1302 Host struct {
1303 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001304 }
Jooyung Han344d5432019-08-23 11:17:39 +09001305
Alex Light9670d332019-01-29 18:07:33 -08001306 // Multilib properties only for host linux_bionic.
1307 Linux_bionic struct {
1308 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001309 }
Jooyung Han344d5432019-08-23 11:17:39 +09001310
Alex Light9670d332019-01-29 18:07:33 -08001311 // Multilib properties only for host linux_glibc.
1312 Linux_glibc struct {
1313 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001314 }
1315 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001316}
1317
Jiyong Park5d790c32019-11-15 18:40:32 +09001318type overridableProperties struct {
1319 // List of APKs to package inside APEX
1320 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001321
1322 // Names of modules to be overridden. Listed modules can only be other binaries
1323 // (in Make or Soong).
1324 // This does not completely prevent installation of the overridden binaries, but if both
1325 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1326 // from PRODUCT_PACKAGES.
1327 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001328
1329 // Logging Parent value
1330 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001331}
1332
Alex Light5098a612018-11-29 17:12:15 -08001333type apexPackaging int
1334
1335const (
1336 imageApex apexPackaging = iota
1337 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001338 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001339)
1340
Sundong Ahnabb64432019-10-22 13:58:29 +09001341// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001342func (a apexPackaging) suffix() string {
1343 switch a {
1344 case imageApex:
1345 return imageApexSuffix
1346 case zipApex:
1347 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001348 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001349 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001350 }
1351}
1352
1353func (a apexPackaging) name() string {
1354 switch a {
1355 case imageApex:
1356 return imageApexType
1357 case zipApex:
1358 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001359 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001360 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001361 }
1362}
1363
Jiyong Parkf653b052019-11-18 15:39:01 +09001364type apexFileClass int
1365
1366const (
1367 etc apexFileClass = iota
1368 nativeSharedLib
1369 nativeExecutable
1370 shBinary
1371 pyBinary
1372 goBinary
1373 javaSharedLib
1374 nativeTest
1375 app
1376)
1377
Jiyong Park8fd61922018-11-08 02:50:25 +09001378func (class apexFileClass) NameInMake() string {
1379 switch class {
1380 case etc:
1381 return "ETC"
1382 case nativeSharedLib:
1383 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001384 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001385 return "EXECUTABLES"
1386 case javaSharedLib:
1387 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001388 case nativeTest:
1389 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001390 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001391 // b/142537672 Why isn't this APP? We want to have full control over
1392 // the paths and file names of the apk file under the flattend APEX.
1393 // If this is set to APP, then the paths and file names are modified
1394 // by the Make build system. For example, it is installed to
1395 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1396 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1397 // appends module name (which is <apexname>.<Appname> to the path.
1398 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001399 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001400 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001401 }
1402}
1403
Jiyong Parkf653b052019-11-18 15:39:01 +09001404// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001405type apexFile struct {
1406 builtFile android.Path
1407 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001408 installDir string
1409 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001410 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001411 // list of symlinks that will be created in installDir that point to this apexFile
1412 symlinks []string
1413 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001414 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001415
1416 requiredModuleNames []string
1417 targetRequiredModuleNames []string
1418 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001419
Colin Cross503c1d02020-01-28 14:00:53 -08001420 jacocoReportClassesFile android.Path // only for javalibs and apps
1421 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001422 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001423
1424 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001425}
1426
Jiyong Park1833cef2019-12-13 13:28:36 +09001427func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1428 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001429 builtFile: builtFile,
1430 moduleName: moduleName,
1431 installDir: installDir,
1432 class: class,
1433 module: module,
1434 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001435 if module != nil {
1436 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001437 ret.requiredModuleNames = module.RequiredModuleNames()
1438 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1439 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001440 }
1441 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001442}
1443
1444func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001445 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001446}
1447
Jiyong Park7cd10e32020-01-14 09:22:18 +09001448// Path() returns path of this apex file relative to the APEX root
1449func (af *apexFile) Path() string {
1450 return filepath.Join(af.installDir, af.builtFile.Base())
1451}
1452
1453// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1454func (af *apexFile) SymlinkPaths() []string {
1455 var ret []string
1456 for _, symlink := range af.symlinks {
1457 ret = append(ret, filepath.Join(af.installDir, symlink))
1458 }
1459 return ret
1460}
1461
1462func (af *apexFile) AvailableToPlatform() bool {
1463 if af.module == nil {
1464 return false
1465 }
1466 if am, ok := af.module.(android.ApexModule); ok {
1467 return am.AvailableFor(android.AvailableToPlatform)
1468 }
1469 return false
1470}
1471
Jiyong Park678c8812020-02-07 17:25:49 +09001472type depInfo struct {
1473 to string
1474 from []string
1475 isExternal bool
1476}
1477
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001478type apexBundle struct {
1479 android.ModuleBase
1480 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001481 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001482 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001483
Jiyong Park5d790c32019-11-15 18:40:32 +09001484 properties apexBundleProperties
1485 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001486 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001487
Jooyung Hanf21c7972019-12-16 22:32:06 +09001488 // specific to apex_vndk modules
1489 vndkProperties apexVndkProperties
1490
Colin Crossa4925902018-11-16 11:36:28 -08001491 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001492 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001493 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001494
Jiyong Park03b68dd2019-07-26 23:20:40 +09001495 prebuiltFileToDelete string
1496
Jiyong Park42cca6c2019-04-01 11:15:50 +09001497 public_key_file android.Path
1498 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001499
1500 container_certificate_file android.Path
1501 container_private_key_file android.Path
1502
Jooyung Han54aca7b2019-11-20 02:26:02 +09001503 fileContexts android.Path
1504
Jiyong Park8fd61922018-11-08 02:50:25 +09001505 // list of files to be included in this apex
1506 filesInfo []apexFile
1507
Jiyong Park956305c2020-01-09 12:32:06 +09001508 // list of module names that should be installed along with this APEX
1509 requiredDeps []string
1510
Jiyong Park956305c2020-01-09 12:32:06 +09001511 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001512 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001513
Sundong Ahnabb64432019-10-22 13:58:29 +09001514 testApex bool
1515 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001516 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001517 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001518
Jooyung Han214bf372019-11-12 13:03:50 +09001519 manifestJsonOut android.WritablePath
1520 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001521
Jooyung Han002ab682020-01-08 01:57:58 +09001522 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001523 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001524 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001525 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1526 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001527
1528 // Suffix of module name in Android.mk
1529 // ".flattened", ".apex", ".zipapex", or ""
1530 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001531
1532 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001533
1534 // Whether to create symlink to the system file instead of having a file
1535 // inside the apex or not
1536 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001537
1538 // Struct holding the merged notice file paths in different formats
1539 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001540}
1541
Jiyong Park397e55e2018-10-24 21:09:55 +09001542func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001543 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001544 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001545 // Use *FarVariation* to be able to depend on modules having
1546 // conflicting variations with this module. This is required since
1547 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1548 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001549 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001550 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001551 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001552 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001553 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001554
Jooyung Han643adc42020-02-27 13:50:06 +09001555 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1556 {Mutator: "image", Variation: imageVariation},
1557 {Mutator: "link", Variation: "shared"},
1558 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1559 }...), jniLibTag, nativeModules.Jni_libs...)
1560
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001561 ctx.AddFarVariationDependencies(append(target.Variations(),
1562 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001563 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001564
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001565 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001566 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001567 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001568 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001569}
1570
Alex Light9670d332019-01-29 18:07:33 -08001571func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1572 if ctx.Os().Class == android.Device {
1573 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1574 } else {
1575 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1576 if ctx.Os().Bionic() {
1577 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1578 } else {
1579 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1580 }
1581 }
1582}
1583
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001584func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001585 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1586 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1587 }
1588
Jiyong Park397e55e2018-10-24 21:09:55 +09001589 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001590 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001591
1592 a.combineProperties(ctx)
1593
Jiyong Park397e55e2018-10-24 21:09:55 +09001594 has32BitTarget := false
1595 for _, target := range targets {
1596 if target.Arch.ArchType.Multilib == "lib32" {
1597 has32BitTarget = true
1598 }
1599 }
1600 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001601 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001602 // multilib.both
1603 addDependenciesForNativeModules(ctx,
1604 ApexNativeDependencies{
1605 Native_shared_libs: a.properties.Native_shared_libs,
1606 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001607 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001608 Binaries: nil,
1609 },
1610 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001611
Jiyong Park397e55e2018-10-24 21:09:55 +09001612 // Add native modules targetting both ABIs
1613 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001614 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001615 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001616 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001617
Alex Light3d673592019-01-18 14:37:31 -08001618 isPrimaryAbi := i == 0
1619 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001620 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001621 // multilib.first
1622 addDependenciesForNativeModules(ctx,
1623 ApexNativeDependencies{
1624 Native_shared_libs: nil,
1625 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001626 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001627 Binaries: a.properties.Binaries,
1628 },
1629 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001630
1631 // Add native modules targetting the first ABI
1632 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001633 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001634 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001635 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001636 }
1637
1638 switch target.Arch.ArchType.Multilib {
1639 case "lib32":
1640 // Add native modules targetting 32-bit ABI
1641 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001642 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001643 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001644 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001645
1646 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001647 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001648 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001649 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001650 case "lib64":
1651 // Add native modules targetting 64-bit ABI
1652 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001653 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001654 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001655 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001656
1657 if !has32BitTarget {
1658 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001659 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001660 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001661 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001662 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001663
1664 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1665 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1666 if sanitizer == "hwaddress" {
1667 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001668 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001669 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001670 break
1671 }
1672 }
1673 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001674 }
1675
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001676 }
1677
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001678 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1679 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1680 // b/144532908
1681 archForPrebuiltEtc := config.Arches()[0]
1682 for _, arch := range config.Arches() {
1683 // Prefer 64-bit arch if there is any
1684 if arch.ArchType.Multilib == "lib64" {
1685 archForPrebuiltEtc = arch
1686 break
1687 }
1688 }
1689 ctx.AddFarVariationDependencies([]blueprint.Variation{
1690 {Mutator: "os", Variation: ctx.Os().String()},
1691 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1692 }, prebuiltTag, a.properties.Prebuilts...)
1693
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001694 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1695 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001696
Ulya Trafimovich44561882020-01-03 13:25:54 +00001697 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1698 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1699 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1700 javaLibTag, "jacocoagent")
1701 }
1702
Jiyong Park23c52b02019-02-02 13:13:47 +09001703 if String(a.properties.Key) == "" {
1704 ctx.ModuleErrorf("key is missing")
1705 return
1706 }
1707 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001708
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001709 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001710 if cert != "" {
1711 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001712 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001713
1714 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1715 if len(a.properties.Uses_sdks) > 0 {
1716 sdkRefs := []android.SdkRef{}
1717 for _, str := range a.properties.Uses_sdks {
1718 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1719 sdkRefs = append(sdkRefs, parsed)
1720 }
1721 a.BuildWithSdks(sdkRefs)
1722 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001723}
1724
Jiyong Park5d790c32019-11-15 18:40:32 +09001725func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1726 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1727 androidAppTag, a.overridableProperties.Apps...)
1728}
1729
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001730func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1731 // direct deps of an APEX bundle are all part of the APEX bundle
1732 return true
1733}
1734
Colin Cross0ea8ba82019-06-06 14:33:29 -07001735func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001736 moduleName := ctx.ModuleName()
1737 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1738 // we check with the pseudo module name to see if its certificate is overridden.
1739 if a.vndkApex {
1740 moduleName = vndkApexName
1741 }
1742 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001743 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001744 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001745 }
1746 return String(a.properties.Certificate)
1747}
1748
Colin Cross41955e82019-05-29 14:40:35 -07001749func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1750 switch tag {
1751 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001752 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001753 default:
1754 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001755 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001756}
1757
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001758func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001759 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001760}
1761
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001762func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1763 return proptools.Bool(a.properties.Test_only_no_hashtree)
1764}
1765
Jiyong Park7c1dc612019-01-05 11:15:24 +09001766func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001767 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001768 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001769 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001770 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001771 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001772 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001773 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001774 }
1775}
1776
Jiyong Parkf97782b2019-02-13 20:28:58 +09001777func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1778 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1779 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1780 }
1781}
1782
Jiyong Park388ef3f2019-01-28 19:47:32 +09001783func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001784 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1785 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001786 }
1787
1788 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001789 globalSanitizerNames := []string{}
1790 if a.Host() {
1791 globalSanitizerNames = ctx.Config().SanitizeHost()
1792 } else {
1793 arches := ctx.Config().SanitizeDeviceArch()
1794 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1795 globalSanitizerNames = ctx.Config().SanitizeDevice()
1796 }
1797 }
1798 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001799}
1800
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001801func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001802 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001803}
1804
1805func (a *apexBundle) PreventInstall() {
1806 a.properties.PreventInstall = true
1807}
1808
1809func (a *apexBundle) HideFromMake() {
1810 a.properties.HideFromMake = true
1811}
1812
Jiyong Park956305c2020-01-09 12:32:06 +09001813func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1814 a.properties.IsCoverageVariant = coverage
1815}
1816
Jiyong Parkf653b052019-11-18 15:39:01 +09001817// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001818func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001819 // Decide the APEX-local directory by the multilib of the library
1820 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001821 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001822 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001823 case "lib32":
1824 dirInApex = "lib"
1825 case "lib64":
1826 dirInApex = "lib64"
1827 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001828 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001829 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001830 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001831 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001832 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001833 // Special case for Bionic libs and other libs installed with them. This is
1834 // to prevent those libs from being included in the search path
1835 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1836 // those libs in the Runtime APEX are available via the legacy paths in
1837 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1838 // to the legacy paths and thus will be loaded into the default linker
1839 // namespace (aka "platform" namespace). If the libs are directly in
1840 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1841 // into the runtime linker namespace, which will result in double loading of
1842 // them, which isn't supported.
1843 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001844 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001845
Jiyong Parkf653b052019-11-18 15:39:01 +09001846 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001847 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001848}
1849
Jiyong Park1833cef2019-12-13 13:28:36 +09001850func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001851 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001852 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001853 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001854 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001855 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001856 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001857 af.symlinks = cc.Symlinks()
1858 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001859}
1860
Jiyong Park1833cef2019-12-13 13:28:36 +09001861func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001862 dirInApex := "bin"
1863 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001864 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001865}
Jiyong Park1833cef2019-12-13 13:28:36 +09001866func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001867 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001868 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1869 if err != nil {
1870 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001871 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001872 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001873 fileToCopy := android.PathForOutput(ctx, s)
1874 // NB: Since go binaries are static we don't need the module for anything here, which is
1875 // good since the go tool is a blueprint.Module not an android.Module like we would
1876 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001877 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001878}
1879
Jiyong Park1833cef2019-12-13 13:28:36 +09001880func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001881 dirInApex := filepath.Join("bin", sh.SubDir())
1882 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001883 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001884 af.symlinks = sh.Symlinks()
1885 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001886}
1887
Jooyung Han58f26ab2019-12-18 15:34:32 +09001888// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1889type javaLibrary interface {
1890 android.Module
1891 java.Dependency
1892}
1893
1894func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001895 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001896 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001897 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1898 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1899 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001900}
1901
Jiyong Park1833cef2019-12-13 13:28:36 +09001902func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001903 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1904 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001905 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001906}
1907
atrost6e126252020-01-27 17:01:16 +00001908func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1909 dirInApex := filepath.Join("etc", config.SubDir())
1910 fileToCopy := config.CompatConfig()
1911 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1912}
1913
Jiyong Park1833cef2019-12-13 13:28:36 +09001914func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001915 android.Module
1916 Privileged() bool
1917 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001918 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001919 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001920}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001921 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001922 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001923 appDir = "priv-app"
1924 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001925 dirInApex := filepath.Join(appDir, pkgName)
1926 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001927 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1928 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001929 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001930
1931 if app, ok := aapp.(interface {
1932 OverriddenManifestPackageName() string
1933 }); ok {
1934 af.overriddenPackageName = app.OverriddenManifestPackageName()
1935 }
Jiyong Park618922e2020-01-08 13:35:43 +09001936 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001937}
1938
Roland Levillain935639d2019-08-13 14:55:28 +01001939// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1940type flattenedApexContext struct {
1941 android.ModuleContext
1942}
1943
1944func (c *flattenedApexContext) InstallBypassMake() bool {
1945 return true
1946}
1947
Jiyong Park201cedd2020-02-07 17:25:49 +09001948// Visit dependencies that contributes to the payload of this APEX
1949func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1950 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001951 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1952 am, ok := child.(android.ApexModule)
1953 if !ok || !am.CanHaveApexVariants() {
1954 return false
1955 }
1956
1957 // Check for the direct dependencies that contribute to the payload
1958 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1959 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001960 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001961 return true
1962 }
1963 return false
1964 }
1965
1966 // Check for the indirect dependencies if it is considered as part of the APEX
1967 if am.DepIsInSameApex(ctx, am) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001968 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001969 return true
1970 }
1971
Jiyong Park201cedd2020-02-07 17:25:49 +09001972 do(ctx, parent, am, true /* externalDep */)
1973
Jiyong Park0f80c182020-01-31 02:49:53 +09001974 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1975 return false
1976 })
1977}
1978
Jooyung Han03b51852020-02-26 22:45:42 +09001979func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1980 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1981 if ver != "current" {
1982 minSdkVersion, err := strconv.Atoi(ver)
1983 if err != nil {
1984 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1985 }
1986 return minSdkVersion
1987 }
1988 return android.FutureApiLevel
1989}
1990
Jiyong Park201cedd2020-02-07 17:25:49 +09001991// Ensures that the dependencies are marked as available for this APEX
1992func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1993 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1994 if ctx.Host() || a.testApex || a.vndkApex {
1995 return
1996 }
1997
1998 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1999 apexName := ctx.ModuleName()
2000 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, to) {
2001 return
2002 }
Jiyong Park65cc4f72020-03-09 14:29:18 +09002003 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", from.Name(), to.Name())
Jiyong Park201cedd2020-02-07 17:25:49 +09002004 })
2005}
2006
Jiyong Park678c8812020-02-07 17:25:49 +09002007// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
2008func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
2009 a.depInfos = make(map[string]depInfo)
2010 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2011 if from.Name() == to.Name() {
2012 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
2013 return
2014 }
2015
2016 if info, exists := a.depInfos[to.Name()]; exists {
2017 if !android.InList(from.Name(), info.from) {
2018 info.from = append(info.from, from.Name())
2019 }
2020 info.isExternal = info.isExternal && externalDep
2021 a.depInfos[to.Name()] = info
2022 } else {
2023 a.depInfos[to.Name()] = depInfo{
2024 to: to.Name(),
2025 from: []string{from.Name()},
2026 isExternal: externalDep,
2027 }
2028 }
2029 })
2030}
2031
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002032func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002033 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2034 switch a.properties.ApexType {
2035 case imageApex:
2036 if buildFlattenedAsDefault {
2037 a.suffix = imageApexSuffix
2038 } else {
2039 a.suffix = ""
2040 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002041
2042 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002043 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002044 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002045 }
2046 case zipApex:
2047 if proptools.String(a.properties.Payload_type) == "zip" {
2048 a.suffix = ""
2049 a.primaryApexType = true
2050 } else {
2051 a.suffix = zipApexSuffix
2052 }
2053 case flattenedApex:
2054 if buildFlattenedAsDefault {
2055 a.suffix = ""
2056 a.primaryApexType = true
2057 } else {
2058 a.suffix = flattenedSuffix
2059 }
Alex Light5098a612018-11-29 17:12:15 -08002060 }
2061
Roland Levillain630846d2019-06-26 12:48:34 +01002062 if len(a.properties.Tests) > 0 && !a.testApex {
2063 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2064 return
2065 }
2066
Jiyong Park0f80c182020-01-31 02:49:53 +09002067 a.checkApexAvailability(ctx)
2068
Jiyong Park678c8812020-02-07 17:25:49 +09002069 a.collectDepsInfo(ctx)
2070
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002071 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2072
Jooyung Hane1633032019-08-01 17:41:43 +09002073 // native lib dependencies
2074 var provideNativeLibs []string
2075 var requireNativeLibs []string
2076
Jooyung Han5c998b92019-06-27 11:30:33 +09002077 // Check if "uses" requirements are met with dependent apexBundles
2078 var providedNativeSharedLibs []string
2079 useVendor := proptools.Bool(a.properties.Use_vendor)
2080 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2081 if ctx.OtherModuleDependencyTag(m) != usesTag {
2082 return
2083 }
2084 otherName := ctx.OtherModuleName(m)
2085 other, ok := m.(*apexBundle)
2086 if !ok {
2087 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2088 return
2089 }
2090 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2091 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2092 return
2093 }
2094 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2095 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2096 return
2097 }
2098 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2099 })
2100
Jiyong Parkf653b052019-11-18 15:39:01 +09002101 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002102 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002103 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002104 depTag := ctx.OtherModuleDependencyTag(child)
2105 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002106 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002107 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002108 case sharedLibTag, jniLibTag:
2109 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002110 if c, ok := child.(*cc.Module); ok {
2111 // bootstrap bionic libs are treated as provided by system
2112 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2113 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002114 }
Jooyung Han643adc42020-02-27 13:50:06 +09002115 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2116 fi.isJniLib = isJniLib
2117 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002118 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002119 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002120 propertyName := "native_shared_libs"
2121 if isJniLib {
2122 propertyName = "jni_libs"
2123 }
2124 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002125 }
2126 case executableTag:
2127 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002128 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002129 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002130 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002131 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002132 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002133 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002134 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002135 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002136 } else {
Alex Light778127a2019-02-27 14:19:50 -08002137 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 +09002138 }
2139 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002140 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002141 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002142 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002143 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2144 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002145 filesInfo = append(filesInfo, af)
2146 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002147 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002148 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2149 af := apexFileForJavaLibrary(ctx, sdkLib)
2150 if !af.Ok() {
2151 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2152 return false
2153 }
2154 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002155 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002156 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002157 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002158 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002159 case androidAppTag:
2160 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2161 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002162 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002163 return true // track transitive dependencies
2164 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002165 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002166 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2167 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002168 } else {
2169 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2170 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002171 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002172 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002173 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002174 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2175 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002176 } else {
atrost6e126252020-01-27 17:01:16 +00002177 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002178 }
Roland Levillain630846d2019-06-26 12:48:34 +01002179 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002180 if ccTest, ok := child.(*cc.Module); ok {
2181 if ccTest.IsTestPerSrcAllTestsVariation() {
2182 // Multiple-output test module (where `test_per_src: true`).
2183 //
2184 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2185 // We do not add this variation to `filesInfo`, as it has no output;
2186 // however, we do add the other variations of this module as indirect
2187 // dependencies (see below).
2188 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002189 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002190 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002191 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002192 af.class = nativeTest
2193 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002194 }
Roland Levillain630846d2019-06-26 12:48:34 +01002195 } else {
2196 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2197 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002198 case keyTag:
2199 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002200 a.private_key_file = key.private_key_file
2201 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002202 } else {
2203 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002204 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002205 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002206 case certificateTag:
2207 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002208 a.container_certificate_file = dep.Certificate.Pem
2209 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002210 } else {
2211 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2212 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002213 case android.PrebuiltDepTag:
2214 // If the prebuilt is force disabled, remember to delete the prebuilt file
2215 // that might have been installed in the previous builds
2216 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2217 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2218 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002219 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002220 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002221 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002222 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002223 // We cannot use a switch statement on `depTag` here as the checked
2224 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002225 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002226 if cc, ok := child.(*cc.Module); ok {
2227 if android.InList(cc.Name(), providedNativeSharedLibs) {
2228 // If we're using a shared library which is provided from other APEX,
2229 // don't include it in this APEX
2230 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002231 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002232 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002233 // If the dependency is a stubs lib, don't include it in this APEX,
2234 // but make sure that the lib is installed on the device.
2235 // In case no APEX is having the lib, the lib is installed to the system
2236 // partition.
2237 //
2238 // Always include if we are a host-apex however since those won't have any
2239 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002240 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2241 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002242 }
Jooyung Hane1633032019-08-01 17:41:43 +09002243 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002244 // Don't track further
2245 return false
2246 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002247 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002248 af.transitiveDep = true
2249 filesInfo = append(filesInfo, af)
2250 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002251 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002252 } else if cc.IsTestPerSrcDepTag(depTag) {
2253 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002254 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002255 // Handle modules created as `test_per_src` variations of a single test module:
2256 // use the name of the generated test binary (`fileToCopy`) instead of the name
2257 // of the original test module (`depName`, shared by all `test_per_src`
2258 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002259 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002260 // these are not considered transitive dep
2261 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002262 filesInfo = append(filesInfo, af)
2263 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002264 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002265 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002266 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2267 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002268 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2269 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2270 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2271 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002272 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002273 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002274 }
2275 }
2276 }
2277 return false
2278 })
2279
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002280 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2281 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2282 // via the global boot image config.
2283 if a.artApex {
2284 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2285 dirInApex := filepath.Join("javalib", arch.String())
2286 for _, f := range files {
2287 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002288 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002289 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002290 }
2291 }
2292 }
2293
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002294 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002295 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2296 return
2297 }
2298
Jiyong Park8fd61922018-11-08 02:50:25 +09002299 // remove duplicates in filesInfo
2300 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002301 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002302 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002303 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002304 if e, ok := encountered[dest]; !ok {
2305 encountered[dest] = f
2306 } else {
2307 // If a module is directly included and also transitively depended on
2308 // consider it as directly included.
2309 e.transitiveDep = e.transitiveDep && f.transitiveDep
2310 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002311 }
2312 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002313 var result []apexFile
2314 for _, v := range encountered {
2315 result = append(result, v)
2316 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002317 return result
2318 }
2319 filesInfo = removeDup(filesInfo)
2320
2321 // to have consistent build rules
2322 sort.Slice(filesInfo, func(i, j int) bool {
2323 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2324 })
2325
Jiyong Park8fd61922018-11-08 02:50:25 +09002326 a.installDir = android.PathForModuleInstall(ctx, "apex")
2327 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002328
Jooyung Han54aca7b2019-11-20 02:26:02 +09002329 if a.properties.ApexType != zipApex {
2330 if a.properties.File_contexts == nil {
2331 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2332 } else {
2333 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2334 if a.Platform() {
2335 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2336 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2337 }
2338 }
2339 }
2340 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2341 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2342 return
2343 }
2344 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002345 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2346 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2347 // the same library in the system partition, thus effectively sharing the same libraries
2348 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2349 // in the APEX.
2350 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2351 a.installable() &&
2352 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002353
Jiyong Park9d677202020-02-19 16:29:35 +09002354 // We don't need the optimization for updatable APEXes, as it might give false signal
2355 // to the system health when the APEXes are still bundled (b/149805758)
2356 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2357 a.linkToSystemLib = false
2358 }
2359
Jiyong Park638d30e2020-02-26 18:27:19 +09002360 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2361 if ctx.Host() {
2362 a.linkToSystemLib = false
2363 }
2364
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002365 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002366 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2367
2368 a.setCertificateAndPrivateKey(ctx)
2369 if a.properties.ApexType == flattenedApex {
2370 a.buildFlattenedApex(ctx)
2371 } else {
2372 a.buildUnflattenedApex(ctx)
2373 }
2374
Jooyung Han002ab682020-01-08 01:57:58 +09002375 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002376
2377 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002378}
2379
Jiyong Park0f80c182020-01-31 02:49:53 +09002380func whitelistedApexAvailable(apex string, module android.Module) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002381 key := apex
2382 key = strings.Replace(key, "test_", "", 1)
2383 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2384 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2385
2386 moduleName := module.Name()
Jiyong Park0f80c182020-01-31 02:49:53 +09002387 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2388 // system. Trim the prefix for the check since they are confusing
2389 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2390 if strings.HasPrefix(moduleName, "libclang_rt.") {
2391 // This module has many arch variants that depend on the product being built.
2392 // We don't want to list them all
2393 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002394 }
2395
2396 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2397 return true
2398 }
2399
Jiyong Park0f80c182020-01-31 02:49:53 +09002400 key = "//any"
2401 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2402 return true
2403 }
2404
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002405 return false
2406}
2407
Jooyung Han344d5432019-08-23 11:17:39 +09002408func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002409 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002410 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002411 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002412 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002413 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002414 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2415 })
Alex Light5098a612018-11-29 17:12:15 -08002416 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002417 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002418 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002419 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002420 return module
2421}
Jiyong Park30ca9372019-02-07 16:27:23 +09002422
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002423func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002424 bundle := newApexBundle()
2425 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002426 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002427 return bundle
2428}
2429
Jiyong Parkfce0b422020-02-11 03:56:06 +09002430// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2431// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002432func testApexBundleFactory() android.Module {
2433 bundle := newApexBundle()
2434 bundle.testApex = true
2435 return bundle
2436}
2437
Jiyong Parkfce0b422020-02-11 03:56:06 +09002438// apex packages other modules into an APEX file which is a packaging format for system-level
2439// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002440func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002441 return newApexBundle()
2442}
2443
Jiyong Park30ca9372019-02-07 16:27:23 +09002444//
2445// Defaults
2446//
2447type Defaults struct {
2448 android.ModuleBase
2449 android.DefaultsModuleBase
2450}
2451
Jiyong Park30ca9372019-02-07 16:27:23 +09002452func defaultsFactory() android.Module {
2453 return DefaultsFactory()
2454}
2455
2456func DefaultsFactory(props ...interface{}) android.Module {
2457 module := &Defaults{}
2458
2459 module.AddProperties(props...)
2460 module.AddProperties(
2461 &apexBundleProperties{},
2462 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002463 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002464 )
2465
2466 android.InitDefaultsModule(module)
2467 return module
2468}
Jiyong Park5d790c32019-11-15 18:40:32 +09002469
2470//
2471// OverrideApex
2472//
2473type OverrideApex struct {
2474 android.ModuleBase
2475 android.OverrideModuleBase
2476}
2477
2478func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2479 // All the overrides happen in the base module.
2480}
2481
2482// override_apex is used to create an apex module based on another apex module
2483// by overriding some of its properties.
2484func overrideApexFactory() android.Module {
2485 m := &OverrideApex{}
2486 m.AddProperties(&overridableProperties{})
2487
2488 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2489 android.InitOverrideModule(m)
2490 return m
2491}