blob: 3fd49057b19a7e809972979afa4ff42b50150507 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jooyung Han03b51852020-02-26 22:45:42 +090022 "strconv"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Jiyong Park0f80c182020-01-31 02:49:53 +090096 m["com.android.adbd"] = []string{
97 "adbd",
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "libadbconnection_server",
99 "libadbd",
100 "libadbd_auth",
101 "libadbd_core",
102 "libadbd_services",
103 "libasyncio",
Jiyong Park0f80c182020-01-31 02:49:53 +0900104 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900105 "libcap",
Jiyong Park0f80c182020-01-31 02:49:53 +0900106 "libdiagnose_usb",
Jiyong Park0f80c182020-01-31 02:49:53 +0900107 "libmdnssd",
108 "libminijail",
109 "libminijail_gen_constants",
110 "libminijail_gen_constants_obj",
111 "libminijail_gen_syscall",
112 "libminijail_gen_syscall_obj",
113 "libminijail_generated",
114 "libpackagelistparser",
115 "libpcre2",
116 "libprocessgroup_headers",
117 "libqemu_pipe",
Jiyong Park0f80c182020-01-31 02:49:53 +0900118 }
119 //
120 // Module separator
121 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000122 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900123 "art_cmdlineparser_headers",
124 "art_disassembler_headers",
125 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900126 "bionic_libc_platform_headers",
127 "core-repackaged-icu4j",
128 "cpp-define-generator-asm-support",
129 "cpp-define-generator-definitions",
130 "crtbegin_dynamic",
131 "crtbegin_dynamic1",
132 "crtbegin_so1",
133 "crtbrand",
134 "conscrypt.module.intra.core.api.stubs",
135 "dex2oat_headers",
136 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900137 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900138 "javavm_headers",
139 "jni_platform_headers",
140 "libPlatformProperties",
141 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000142 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900143 "libandroidicuinit",
144 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000145 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900146 "libasync_safe",
Jiyong Park0f80c182020-01-31 02:49:53 +0900147 "libdexfile_all_headers",
148 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000149 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900150 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000151 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "libfdlibm",
153 "libgtest_prod",
154 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000155 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900156 "libicuuc_headers",
157 "libicuuc_stubdata",
158 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900159 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000160 "liblzma",
161 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libnativebridge-headers",
163 "libnativehelper_header_only",
164 "libnativeloader-headers",
165 "libnpt_headers",
166 "libopenjdkjvmti_headers",
167 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000168 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900169 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000170 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900171 "libv8",
172 "libv8base",
173 "libv8gen",
174 "libv8platform",
175 "libv8sampler",
176 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 "libvixl",
178 "libvixld",
179 "libz",
180 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900181 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000182 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000183 m["com.android.art.debug"] = artApexContents
184 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000185 //
186 // Module separator
187 //
188 m["com.android.bluetooth.updatable"] = []string{
189 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000190 "android.hardware.bluetooth.a2dp@1.0",
191 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900192 "android.hardware.bluetooth@1.0",
193 "android.hardware.bluetooth@1.1",
194 "android.hardware.graphics.bufferqueue@1.0",
195 "android.hardware.graphics.bufferqueue@2.0",
196 "android.hardware.graphics.common@1.0",
197 "android.hardware.graphics.common@1.1",
198 "android.hardware.graphics.common@1.2",
199 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000200 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900201 "android.hidl.token@1.0",
202 "android.hidl.token@1.0-utils",
203 "avrcp-target-service",
204 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900205 "bluetooth-protos-lite",
206 "bluetooth.mapsapi",
207 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900208 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900209 "ipmemorystore-aidl-interfaces-V5-java",
210 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900211 "internal_include_headers",
212 "lib-bt-packets",
213 "lib-bt-packets-avrcp",
214 "lib-bt-packets-base",
215 "libFraunhoferAAC",
216 "libaudio-a2dp-hw-utils",
217 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900218 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000219 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900220 "libbluetooth-types",
221 "libbluetooth-types-header",
222 "libbluetooth_gd",
223 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000224 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900225 "libbt-audio-hal-interface",
226 "libbt-bta",
227 "libbt-common",
228 "libbt-hci",
229 "libbt-platform-protos-lite",
230 "libbt-protos-lite",
231 "libbt-sbc-decoder",
232 "libbt-sbc-encoder",
233 "libbt-stack",
234 "libbt-utils",
235 "libbtcore",
236 "libbtdevice",
237 "libbte",
238 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000239 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000240 "libevent",
241 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libg722codec",
243 "libgtest_prod",
244 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900245 "libmedia_headers",
246 "libmodpb64",
247 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000248 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900249 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900250 "libstagefright_foundation_headers",
251 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000252 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900253 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000254 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900255 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000256 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900257 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900258 "net-utils-services-common",
259 "netd_aidl_interface-unstable-java",
260 "netd_event_listener_interface-java",
261 "netlink-client",
262 "networkstack-aidl-interfaces-unstable-java",
263 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900264 "sap-api-java-static",
265 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000266 }
267 //
268 // Module separator
269 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900270 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000271 //
272 // Module separator
273 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900274 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900275 "boringssl_self_test",
Jiyong Park0f80c182020-01-31 02:49:53 +0900276 "libnativehelper_header_only",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900277 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900278 }
279 //
280 // Module separator
281 //
282 m["com.android.extservices"] = []string{
283 "flatbuffer_headers",
284 "liblua",
285 "libtextclassifier",
286 "libtextclassifier_hash_static",
287 "libtflite_static",
288 "libutf",
289 "libz_current",
290 "tensorflow_headers",
291 }
292 //
293 // Module separator
294 //
295 m["com.android.cronet"] = []string{
296 "cronet_impl_common_java",
297 "cronet_impl_native_java",
298 "cronet_impl_platform_java",
299 "libcronet.80.0.3986.0",
300 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900301 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900302 "prebuilt_libcronet.80.0.3986.0",
303 }
304 //
305 // Module separator
306 //
307 m["com.android.neuralnetworks"] = []string{
308 "android.hardware.neuralnetworks@1.0",
309 "android.hardware.neuralnetworks@1.1",
310 "android.hardware.neuralnetworks@1.2",
311 "android.hardware.neuralnetworks@1.3",
312 "android.hidl.allocator@1.0",
313 "android.hidl.memory.token@1.0",
314 "android.hidl.memory@1.0",
315 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900316 "gemmlowp_headers",
317 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900318 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900319 "libeigen",
320 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900321 "libmath",
322 "libneuralnetworks_common",
323 "libneuralnetworks_headers",
324 "libprocessgroup",
325 "libprocessgroup_headers",
326 "libprocpartition",
327 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900328 "libtextclassifier_hash",
329 "libtextclassifier_hash_headers",
330 "libtextclassifier_hash_static",
331 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900332 "philox_random",
333 "philox_random_headers",
334 "tensorflow_headers",
335 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000336 //
337 // Module separator
338 //
339 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000340 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900341 "android.hardware.cas.native@1.0",
342 "android.hardware.cas@1.0",
343 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000344 "android.hardware.configstore@1.0",
345 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000346 "android.hardware.graphics.allocator@2.0",
347 "android.hardware.graphics.allocator@3.0",
348 "android.hardware.graphics.bufferqueue@1.0",
349 "android.hardware.graphics.bufferqueue@2.0",
350 "android.hardware.graphics.common@1.0",
351 "android.hardware.graphics.common@1.1",
352 "android.hardware.graphics.common@1.2",
353 "android.hardware.graphics.mapper@2.0",
354 "android.hardware.graphics.mapper@2.1",
355 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900356 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000357 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900358 "android.hidl.allocator@1.0",
359 "android.hidl.memory.token@1.0",
360 "android.hidl.memory@1.0",
361 "android.hidl.token@1.0",
362 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900363 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900364 "gl_headers",
365 "libEGL",
366 "libEGL_blobCache",
367 "libEGL_getProcAddress",
368 "libFLAC",
369 "libFLAC-config",
370 "libFLAC-headers",
371 "libGLESv2",
372 "libaacextractor",
373 "libamrextractor",
374 "libarect",
375 "libasync_safe",
376 "libaudio_system_headers",
377 "libaudioclient",
378 "libaudioclient_headers",
379 "libaudiofoundation",
380 "libaudiofoundation_headers",
381 "libaudiomanager",
382 "libaudiopolicy",
383 "libaudioutils",
384 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900385 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900386 "libbluetooth-types-header",
387 "libbufferhub",
388 "libbufferhub_headers",
389 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900390 "libc_malloc_debug_backtrace",
391 "libcamera_client",
392 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900393 "libdexfile_external_headers",
394 "libdexfile_support",
395 "libdvr_headers",
396 "libexpat",
397 "libfifo",
398 "libflacextractor",
399 "libgrallocusage",
400 "libgraphicsenv",
401 "libgui",
402 "libgui_headers",
403 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900404 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900405 "liblzma",
406 "libmath",
407 "libmedia",
408 "libmedia_codeclist",
409 "libmedia_headers",
410 "libmedia_helper",
411 "libmedia_helper_headers",
412 "libmedia_midiiowrapper",
413 "libmedia_omx",
414 "libmediautils",
415 "libmidiextractor",
416 "libmkvextractor",
417 "libmp3extractor",
418 "libmp4extractor",
419 "libmpeg2extractor",
420 "libnativebase_headers",
421 "libnativebridge-headers",
422 "libnativebridge_lazy",
423 "libnativeloader-headers",
424 "libnativeloader_lazy",
425 "libnativewindow_headers",
426 "libnblog",
427 "liboggextractor",
428 "libpackagelistparser",
429 "libpcre2",
430 "libpdx",
431 "libpdx_default_transport",
432 "libpdx_headers",
433 "libpdx_uds",
434 "libprocessgroup",
435 "libprocessgroup_headers",
436 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900437 "libsonivox",
438 "libspeexresampler",
439 "libspeexresampler",
440 "libstagefright_esds",
441 "libstagefright_flacdec",
442 "libstagefright_flacdec",
443 "libstagefright_foundation",
444 "libstagefright_foundation_headers",
445 "libstagefright_foundation_without_imemory",
446 "libstagefright_headers",
447 "libstagefright_id3",
448 "libstagefright_metadatautils",
449 "libstagefright_mpeg2extractor",
450 "libstagefright_mpeg2support",
451 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900452 "libui",
453 "libui_headers",
454 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900455 "libvibrator",
456 "libvorbisidec",
457 "libwavextractor",
458 "libwebm",
459 "media_ndk_headers",
460 "media_plugin_headers",
461 "updatable-media",
462 }
463 //
464 // Module separator
465 //
466 m["com.android.media.swcodec"] = []string{
467 "android.frameworks.bufferhub@1.0",
468 "android.hardware.common-ndk_platform",
469 "android.hardware.configstore-utils",
470 "android.hardware.configstore@1.0",
471 "android.hardware.configstore@1.1",
472 "android.hardware.graphics.allocator@2.0",
473 "android.hardware.graphics.allocator@3.0",
474 "android.hardware.graphics.bufferqueue@1.0",
475 "android.hardware.graphics.bufferqueue@2.0",
476 "android.hardware.graphics.common-ndk_platform",
477 "android.hardware.graphics.common@1.0",
478 "android.hardware.graphics.common@1.1",
479 "android.hardware.graphics.common@1.2",
480 "android.hardware.graphics.mapper@2.0",
481 "android.hardware.graphics.mapper@2.1",
482 "android.hardware.graphics.mapper@3.0",
483 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000484 "android.hardware.media.bufferpool@2.0",
485 "android.hardware.media.c2@1.0",
486 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900487 "android.hardware.media@1.0",
488 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000489 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900490 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000491 "android.hidl.safe_union@1.0",
492 "android.hidl.token@1.0",
493 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900494 "libEGL",
495 "libFLAC",
496 "libFLAC-config",
497 "libFLAC-headers",
498 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900499 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900500 "libarect",
501 "libasync_safe",
502 "libaudio_system_headers",
503 "libaudioutils",
504 "libaudioutils",
505 "libaudioutils_fixedfft",
506 "libavcdec",
507 "libavcenc",
508 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000509 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900510 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900511 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900512 "libbluetooth-types-header",
513 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900514 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000515 "libcap",
516 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900517 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000518 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900519 "libcodec2_hidl@1.1",
520 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000521 "libcodec2_soft_aacdec",
522 "libcodec2_soft_aacenc",
523 "libcodec2_soft_amrnbdec",
524 "libcodec2_soft_amrnbenc",
525 "libcodec2_soft_amrwbdec",
526 "libcodec2_soft_amrwbenc",
527 "libcodec2_soft_av1dec_gav1",
528 "libcodec2_soft_avcdec",
529 "libcodec2_soft_avcenc",
530 "libcodec2_soft_common",
531 "libcodec2_soft_flacdec",
532 "libcodec2_soft_flacenc",
533 "libcodec2_soft_g711alawdec",
534 "libcodec2_soft_g711mlawdec",
535 "libcodec2_soft_gsmdec",
536 "libcodec2_soft_h263dec",
537 "libcodec2_soft_h263enc",
538 "libcodec2_soft_hevcdec",
539 "libcodec2_soft_hevcenc",
540 "libcodec2_soft_mp3dec",
541 "libcodec2_soft_mpeg2dec",
542 "libcodec2_soft_mpeg4dec",
543 "libcodec2_soft_mpeg4enc",
544 "libcodec2_soft_opusdec",
545 "libcodec2_soft_opusenc",
546 "libcodec2_soft_rawdec",
547 "libcodec2_soft_vorbisdec",
548 "libcodec2_soft_vp8dec",
549 "libcodec2_soft_vp8enc",
550 "libcodec2_soft_vp9dec",
551 "libcodec2_soft_vp9enc",
552 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000553 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900554 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000555 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900556 "libfmq",
557 "libgav1",
558 "libgralloctypes",
559 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000560 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900561 "libgsm",
562 "libgui_bufferqueue_static",
563 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000564 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900565 "libhardware_headers",
566 "libhevcdec",
567 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000568 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900569 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000570 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900571 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000572 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900573 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000574 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900575 "libminijail_gen_constants",
576 "libminijail_gen_constants_obj",
577 "libminijail_gen_syscall",
578 "libminijail_gen_syscall_obj",
579 "libminijail_generated",
580 "libmpeg2dec",
581 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000582 "libnativebridge_lazy",
583 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900584 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000585 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900586 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000587 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900588 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000589 "libscudo_wrapper",
590 "libsfplugin_ccodec_utils",
591 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900592 "libstagefright_amrnbdec",
593 "libstagefright_amrnbenc",
594 "libstagefright_amrwbdec",
595 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000596 "libstagefright_bufferpool@2.0.1",
597 "libstagefright_bufferqueue_helper",
598 "libstagefright_enc_common",
599 "libstagefright_flacdec",
600 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900601 "libstagefright_foundation_headers",
602 "libstagefright_headers",
603 "libstagefright_m4vh263dec",
604 "libstagefright_m4vh263enc",
605 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000606 "libsync",
607 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900608 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000609 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000610 "libvorbisidec",
611 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900612 "libyuv",
613 "libyuv_static",
614 "media_ndk_headers",
615 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000616 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900617 }
618 //
619 // Module separator
620 //
621 m["com.android.mediaprovider"] = []string{
622 "MediaProvider",
623 "MediaProviderGoogle",
624 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900625 "libbase_ndk",
626 "libfuse",
627 "libfuse_jni",
628 "libnativehelper_header_only",
629 }
630 //
631 // Module separator
632 //
633 m["com.android.permission"] = []string{
634 "androidx.annotation_annotation",
635 "androidx.annotation_annotation-nodeps",
636 "androidx.lifecycle_lifecycle-common",
637 "androidx.lifecycle_lifecycle-common-java8",
638 "androidx.lifecycle_lifecycle-common-java8-nodeps",
639 "androidx.lifecycle_lifecycle-common-nodeps",
640 "kotlin-annotations",
641 "kotlin-stdlib",
642 "kotlin-stdlib-jdk7",
643 "kotlin-stdlib-jdk8",
644 "kotlinx-coroutines-android",
645 "kotlinx-coroutines-android-nodeps",
646 "kotlinx-coroutines-core",
647 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900648 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000649 }
650 //
651 // Module separator
652 //
653 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900654 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900655 "libarm-optimized-routines-math",
656 "libasync_safe",
657 "libasync_safe_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900658 "libc_aeabi",
659 "libc_bionic",
660 "libc_bionic_ndk",
661 "libc_bootstrap",
662 "libc_common",
663 "libc_common_shared",
664 "libc_common_static",
665 "libc_dns",
666 "libc_dynamic_dispatch",
667 "libc_fortify",
668 "libc_freebsd",
669 "libc_freebsd_large_stack",
670 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900671 "libc_init_dynamic",
672 "libc_init_static",
673 "libc_jemalloc_wrapper",
674 "libc_netbsd",
675 "libc_nomalloc",
676 "libc_nopthread",
677 "libc_openbsd",
678 "libc_openbsd_large_stack",
679 "libc_openbsd_ndk",
680 "libc_pthread",
681 "libc_static_dispatch",
682 "libc_syscalls",
683 "libc_tzcode",
684 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900685 "libdebuggerd",
686 "libdebuggerd_common_headers",
687 "libdebuggerd_handler_core",
688 "libdebuggerd_handler_fallback",
689 "libdexfile_external_headers",
690 "libdexfile_support",
691 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900692 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900693 "libgtest_prod",
694 "libjemalloc5",
695 "liblinker_main",
696 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900697 "liblz4",
698 "liblzma",
699 "libprocessgroup_headers",
700 "libprocinfo",
701 "libpropertyinfoparser",
702 "libscudo",
703 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900704 "libsystemproperties",
705 "libtombstoned_client_static",
706 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 "libz",
708 "libziparchive",
709 }
710 //
711 // Module separator
712 //
713 m["com.android.resolv"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900714 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Park0f80c182020-01-31 02:49:53 +0900715 "libgtest_prod",
Jiyong Park0f80c182020-01-31 02:49:53 +0900716 "libnativehelper_header_only",
717 "libnetd_client_headers",
718 "libnetd_resolv",
719 "libnetdutils",
720 "libprocessgroup",
721 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900722 "libstatslog_resolv",
723 "libstatspush_compat",
724 "libstatssocket",
725 "libstatssocket_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900726 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900727 "netd_event_listener_interface-ndk_platform",
728 "server_configurable_flags",
729 "stats_proto",
730 }
731 //
732 // Module separator
733 //
734 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900735 "libnativehelper_compat_libc++",
736 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900737 "libcgrouprc",
738 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900739 "libprocessgroup",
740 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900741 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900742 "libvndksupport",
743 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000744 }
745 //
746 // Module separator
747 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900748 m["com.android.wifi"] = []string{
749 "PlatformProperties",
750 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900751 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900752 "android.hardware.wifi-V1.1-java",
753 "android.hardware.wifi-V1.2-java",
754 "android.hardware.wifi-V1.3-java",
755 "android.hardware.wifi-V1.4-java",
756 "android.hardware.wifi.hostapd-V1.0-java",
757 "android.hardware.wifi.hostapd-V1.1-java",
758 "android.hardware.wifi.hostapd-V1.2-java",
759 "android.hardware.wifi.supplicant-V1.0-java",
760 "android.hardware.wifi.supplicant-V1.1-java",
761 "android.hardware.wifi.supplicant-V1.2-java",
762 "android.hardware.wifi.supplicant-V1.3-java",
763 "android.hidl.base-V1.0-java",
764 "android.hidl.manager-V1.0-java",
765 "android.hidl.manager-V1.1-java",
766 "android.hidl.manager-V1.2-java",
767 "androidx.annotation_annotation",
768 "androidx.annotation_annotation-nodeps",
769 "bouncycastle-unbundled",
770 "dnsresolver_aidl_interface-V2-java",
771 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900772 "framework-wifi-pre-jarjar",
773 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900774 "ipmemorystore-aidl-interfaces-V3-java",
775 "ipmemorystore-aidl-interfaces-java",
776 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900777 "libnanohttpd",
778 "libprocessgroup",
779 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900780 "libwifi-jni",
781 "net-utils-services-common",
782 "netd_aidl_interface-V2-java",
783 "netd_aidl_interface-unstable-java",
784 "netd_event_listener_interface-java",
785 "netlink-client",
786 "networkstack-aidl-interfaces-unstable-java",
787 "networkstack-client",
788 "services.net",
789 "wifi-lite-protos",
790 "wifi-nano-protos",
791 "wifi-service-pre-jarjar",
792 "wifi-service-resources",
793 "prebuilt_androidx.annotation_annotation-nodeps",
794 }
795 //
796 // Module separator
797 //
798 m["com.android.sdkext"] = []string{
799 "fmtlib_ndk",
800 "libbase_ndk",
801 "libprotobuf-cpp-lite-ndk",
802 }
803 //
804 // Module separator
805 //
806 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900807 "libprocessgroup_headers",
808 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900809 }
810 //
811 // Module separator
812 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000813 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900814 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900815 "libclang_rt",
816 "libgcc_stripped",
817 "libprofile-clang-extras",
818 "libprofile-clang-extras_ndk",
819 "libprofile-extras",
820 "libprofile-extras_ndk",
821 "libunwind_llvm",
822 "ndk_crtbegin_dynamic.27",
823 "ndk_crtbegin_so.16",
824 "ndk_crtbegin_so.19",
825 "ndk_crtbegin_so.21",
826 "ndk_crtbegin_so.24",
827 "ndk_crtbegin_so.27",
828 "ndk_crtend_android.27",
829 "ndk_crtend_so.16",
830 "ndk_crtend_so.19",
831 "ndk_crtend_so.21",
832 "ndk_crtend_so.24",
833 "ndk_crtend_so.27",
834 "ndk_libandroid_support",
835 "ndk_libc++_static",
836 "ndk_libc++abi",
837 "ndk_libunwind",
838 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000839 return m
840}
841
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900842func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900843 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800844 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900845 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900846 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700847 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900848 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900849
Jooyung Han31c470b2019-10-18 16:26:59 +0900850 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900851 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900852
853 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
854 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
855 sort.Strings(*apexFileContextsInfos)
856 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
857 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900858}
859
Jooyung Han31c470b2019-10-18 16:26:59 +0900860func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
861 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
862 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
863}
864
Jiyong Parkd1063c12019-07-17 20:08:41 +0900865func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900866 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900867 ctx.BottomUp("apex", apexMutator).Parallel()
868 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
869 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900870}
871
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900872// Mark the direct and transitive dependencies of apex bundles so that they
873// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900874func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800875 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900876 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000877 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han5e9013b2020-03-10 06:23:13 +0900878 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han5417f772020-03-12 18:37:20 +0900879 ApexName: mctx.ModuleName(),
880 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900881 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900882 directDep = true
883 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800884 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900885 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900886 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900887
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800888 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900889 return
890 }
891
Jooyung Han5e9013b2020-03-10 06:23:13 +0900892 cur := mctx.Module().(interface {
893 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
894 })
895
Jiyong Parkf760cae2020-02-12 07:53:12 +0900896 mctx.VisitDirectDeps(func(child android.Module) {
897 depName := mctx.OtherModuleName(child)
898 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +0900899 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800900 android.UpdateApexDependency(apexBundles, depName, directDep)
901 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900902 }
903 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900904}
905
906// Create apex variations if a module is included in APEX(s).
907func apexMutator(mctx android.BottomUpMutatorContext) {
908 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900909 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000910 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900911 // apex bundle itself is mutated so that it and its modules have same
912 // apex variant.
913 apexBundleName := mctx.ModuleName()
914 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900915 } else if o, ok := mctx.Module().(*OverrideApex); ok {
916 apexBundleName := o.GetOverriddenModuleName()
917 if apexBundleName == "" {
918 mctx.ModuleErrorf("base property is not set")
919 return
920 }
921 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900922 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900923
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900924}
Sundong Ahne9b55722019-09-06 17:37:42 +0900925
Jooyung Han7a78a922019-10-08 21:59:58 +0900926var (
927 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
928 apexFileContextsInfosMutex sync.Mutex
929)
930
931func apexFileContextsInfos(config android.Config) *[]string {
932 return config.Once(apexFileContextsInfosKey, func() interface{} {
933 return &[]string{}
934 }).(*[]string)
935}
936
Jooyung Han54aca7b2019-11-20 02:26:02 +0900937func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900938 apexFileContextsInfosMutex.Lock()
939 defer apexFileContextsInfosMutex.Unlock()
940 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900941 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900942}
943
Sundong Ahne9b55722019-09-06 17:37:42 +0900944func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900945 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900946 var variants []string
947 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
948 case "image":
949 variants = append(variants, imageApexType, flattenedApexType)
950 case "zip":
951 variants = append(variants, zipApexType)
952 case "both":
953 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
954 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900955 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900956 return
957 }
958
959 modules := mctx.CreateLocalVariations(variants...)
960
961 for i, v := range variants {
962 switch v {
963 case imageApexType:
964 modules[i].(*apexBundle).properties.ApexType = imageApex
965 case zipApexType:
966 modules[i].(*apexBundle).properties.ApexType = zipApex
967 case flattenedApexType:
968 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900969 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900970 modules[i].(*apexBundle).MakeAsSystemExt()
971 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900972 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900973 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900974 } else if _, ok := mctx.Module().(*OverrideApex); ok {
975 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900976 }
977}
978
Jooyung Han5c998b92019-06-27 11:30:33 +0900979func apexUsesMutator(mctx android.BottomUpMutatorContext) {
980 if ab, ok := mctx.Module().(*apexBundle); ok {
981 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
982 }
983}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900984
Jooyung Handc782442019-11-01 03:14:38 +0900985var (
986 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
987)
988
989// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
990// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
991// which may cause compatibility issues. (e.g. libbinder)
992// Even though libbinder restricts its availability via 'apex_available' property and relies on
993// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
994// to avoid similar problems.
995func useVendorWhitelist(config android.Config) []string {
996 return config.Once(useVendorWhitelistKey, func() interface{} {
997 return []string{
998 // swcodec uses "vendor" variants for smaller size
999 "com.android.media.swcodec",
1000 "test_com.android.media.swcodec",
1001 }
1002 }).([]string)
1003}
1004
1005// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1006// called before the first call to useVendorWhitelist()
1007func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1008 config.Once(useVendorWhitelistKey, func() interface{} {
1009 return whitelist
1010 })
1011}
1012
Jooyung Han01a868d2020-02-27 13:40:44 +09001013type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001014 // List of native libraries
1015 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001016
Jooyung Han643adc42020-02-27 13:50:06 +09001017 // List of JNI libraries
1018 Jni_libs []string
1019
Alex Light9670d332019-01-29 18:07:33 -08001020 // List of native executables
1021 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001022
Roland Levillain630846d2019-06-26 12:48:34 +01001023 // List of native tests
1024 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001025}
Jooyung Han344d5432019-08-23 11:17:39 +09001026
Alex Light9670d332019-01-29 18:07:33 -08001027type apexMultilibProperties struct {
1028 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001029 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001030
1031 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001032 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001033
1034 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001035 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001036
1037 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001038 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001039
1040 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001041 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001042}
1043
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001044type apexBundleProperties struct {
1045 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001046 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001047 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001048
Jiyong Park40e26a22019-02-08 02:53:06 +09001049 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1050 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001051 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001052
Roland Levillain411c5842019-09-19 16:37:20 +01001053 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1054 // device (/apex/<apex_name>).
1055 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001056 Apex_name *string
1057
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001058 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001059 // For platform APEXes, this should points to a file under /system/sepolicy
1060 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1061 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001062
Jooyung Han01a868d2020-02-27 13:40:44 +09001063 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001064
1065 // List of java libraries that are embedded inside this APEX bundle
1066 Java_libs []string
1067
1068 // List of prebuilt files that are embedded inside this APEX bundle
1069 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001070
1071 // Name of the apex_key module that provides the private key to sign APEX
1072 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001073
Alex Light5098a612018-11-29 17:12:15 -08001074 // The type of APEX to build. Controls what the APEX payload is. Either
1075 // 'image', 'zip' or 'both'. Default: 'image'.
1076 Payload_type *string
1077
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001078 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1079 // or an android_app_certificate module name in the form ":module".
1080 Certificate *string
1081
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001082 // Whether this APEX is installable to one of the partitions. Default: true.
1083 Installable *bool
1084
Jiyong Parkda6eb592018-12-19 17:12:36 +09001085 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1086 // Default is false.
1087 Use_vendor *bool
1088
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001089 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1090 Ignore_system_library_special_case *bool
1091
Alex Light9670d332019-01-29 18:07:33 -08001092 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001093
Jiyong Parkf97782b2019-02-13 20:28:58 +09001094 // List of sanitizer names that this APEX is enabled for
1095 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001096
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001097 PreventInstall bool `blueprint:"mutated"`
1098
1099 HideFromMake bool `blueprint:"mutated"`
1100
Jooyung Han5c998b92019-06-27 11:30:33 +09001101 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1102 Provide_cpp_shared_libs *bool
1103
1104 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1105 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001106
1107 // A txt file containing list of files that are whitelisted to be included in this APEX.
1108 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001109
Sundong Ahnabb64432019-10-22 13:58:29 +09001110 // package format of this apex variant; could be non-flattened, flattened, or zip.
1111 // imageApex, zipApex or flattened
1112 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001113
Jiyong Parkd1063c12019-07-17 20:08:41 +09001114 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1115 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1116 // is implied. This value affects all modules included in this APEX. In other words, they are
1117 // also built with the SDKs specified here.
1118 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001119
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001120 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1121 // Should be only used in tests#.
1122 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001123
Jiyong Park956305c2020-01-09 12:32:06 +09001124 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001125
1126 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1127 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1128 // like symlinking to the system libs. Default is false.
1129 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001130
1131 // The minimum SDK version that this apex must be compatibile with.
1132 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001133}
1134
1135type apexTargetBundleProperties struct {
1136 Target struct {
1137 // Multilib properties only for android.
1138 Android struct {
1139 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001140 }
Jooyung Han344d5432019-08-23 11:17:39 +09001141
Alex Light9670d332019-01-29 18:07:33 -08001142 // Multilib properties only for host.
1143 Host struct {
1144 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001145 }
Jooyung Han344d5432019-08-23 11:17:39 +09001146
Alex Light9670d332019-01-29 18:07:33 -08001147 // Multilib properties only for host linux_bionic.
1148 Linux_bionic struct {
1149 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001150 }
Jooyung Han344d5432019-08-23 11:17:39 +09001151
Alex Light9670d332019-01-29 18:07:33 -08001152 // Multilib properties only for host linux_glibc.
1153 Linux_glibc struct {
1154 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001155 }
1156 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001157}
1158
Jiyong Park5d790c32019-11-15 18:40:32 +09001159type overridableProperties struct {
1160 // List of APKs to package inside APEX
1161 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001162
1163 // Names of modules to be overridden. Listed modules can only be other binaries
1164 // (in Make or Soong).
1165 // This does not completely prevent installation of the overridden binaries, but if both
1166 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1167 // from PRODUCT_PACKAGES.
1168 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001169
1170 // Logging Parent value
1171 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001172
1173 // Apex Container Package Name.
1174 // Override value for attribute package:name in AndroidManifest.xml
1175 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001176}
1177
Alex Light5098a612018-11-29 17:12:15 -08001178type apexPackaging int
1179
1180const (
1181 imageApex apexPackaging = iota
1182 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001183 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001184)
1185
Sundong Ahnabb64432019-10-22 13:58:29 +09001186// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001187func (a apexPackaging) suffix() string {
1188 switch a {
1189 case imageApex:
1190 return imageApexSuffix
1191 case zipApex:
1192 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001193 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001194 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001195 }
1196}
1197
1198func (a apexPackaging) name() string {
1199 switch a {
1200 case imageApex:
1201 return imageApexType
1202 case zipApex:
1203 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001204 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001205 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001206 }
1207}
1208
Jiyong Parkf653b052019-11-18 15:39:01 +09001209type apexFileClass int
1210
1211const (
1212 etc apexFileClass = iota
1213 nativeSharedLib
1214 nativeExecutable
1215 shBinary
1216 pyBinary
1217 goBinary
1218 javaSharedLib
1219 nativeTest
1220 app
1221)
1222
Jiyong Park8fd61922018-11-08 02:50:25 +09001223func (class apexFileClass) NameInMake() string {
1224 switch class {
1225 case etc:
1226 return "ETC"
1227 case nativeSharedLib:
1228 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001229 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001230 return "EXECUTABLES"
1231 case javaSharedLib:
1232 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001233 case nativeTest:
1234 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001235 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001236 // b/142537672 Why isn't this APP? We want to have full control over
1237 // the paths and file names of the apk file under the flattend APEX.
1238 // If this is set to APP, then the paths and file names are modified
1239 // by the Make build system. For example, it is installed to
1240 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1241 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1242 // appends module name (which is <apexname>.<Appname> to the path.
1243 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001244 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001245 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001246 }
1247}
1248
Jiyong Parkf653b052019-11-18 15:39:01 +09001249// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001250type apexFile struct {
1251 builtFile android.Path
1252 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001253 installDir string
1254 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001255 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001256 // list of symlinks that will be created in installDir that point to this apexFile
1257 symlinks []string
1258 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001259 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001260
1261 requiredModuleNames []string
1262 targetRequiredModuleNames []string
1263 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001264
Colin Cross503c1d02020-01-28 14:00:53 -08001265 jacocoReportClassesFile android.Path // only for javalibs and apps
1266 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001267 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001268
1269 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001270}
1271
Jiyong Park1833cef2019-12-13 13:28:36 +09001272func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1273 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001274 builtFile: builtFile,
1275 moduleName: moduleName,
1276 installDir: installDir,
1277 class: class,
1278 module: module,
1279 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001280 if module != nil {
1281 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001282 ret.requiredModuleNames = module.RequiredModuleNames()
1283 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1284 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001285 }
1286 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001287}
1288
1289func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001290 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001291}
1292
Jiyong Park7cd10e32020-01-14 09:22:18 +09001293// Path() returns path of this apex file relative to the APEX root
1294func (af *apexFile) Path() string {
1295 return filepath.Join(af.installDir, af.builtFile.Base())
1296}
1297
1298// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1299func (af *apexFile) SymlinkPaths() []string {
1300 var ret []string
1301 for _, symlink := range af.symlinks {
1302 ret = append(ret, filepath.Join(af.installDir, symlink))
1303 }
1304 return ret
1305}
1306
1307func (af *apexFile) AvailableToPlatform() bool {
1308 if af.module == nil {
1309 return false
1310 }
1311 if am, ok := af.module.(android.ApexModule); ok {
1312 return am.AvailableFor(android.AvailableToPlatform)
1313 }
1314 return false
1315}
1316
Jiyong Park678c8812020-02-07 17:25:49 +09001317type depInfo struct {
1318 to string
1319 from []string
1320 isExternal bool
1321}
1322
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001323type apexBundle struct {
1324 android.ModuleBase
1325 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001326 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001327 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001328
Jiyong Park5d790c32019-11-15 18:40:32 +09001329 properties apexBundleProperties
1330 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001331 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001332
Jooyung Hanf21c7972019-12-16 22:32:06 +09001333 // specific to apex_vndk modules
1334 vndkProperties apexVndkProperties
1335
Colin Crossa4925902018-11-16 11:36:28 -08001336 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001337 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001338 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001339
Jiyong Park03b68dd2019-07-26 23:20:40 +09001340 prebuiltFileToDelete string
1341
Jiyong Park42cca6c2019-04-01 11:15:50 +09001342 public_key_file android.Path
1343 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001344
1345 container_certificate_file android.Path
1346 container_private_key_file android.Path
1347
Jooyung Han54aca7b2019-11-20 02:26:02 +09001348 fileContexts android.Path
1349
Jiyong Park8fd61922018-11-08 02:50:25 +09001350 // list of files to be included in this apex
1351 filesInfo []apexFile
1352
Jiyong Park956305c2020-01-09 12:32:06 +09001353 // list of module names that should be installed along with this APEX
1354 requiredDeps []string
1355
Jiyong Park956305c2020-01-09 12:32:06 +09001356 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001357 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001358
Sundong Ahnabb64432019-10-22 13:58:29 +09001359 testApex bool
1360 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001361 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001362 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001363
Jooyung Han214bf372019-11-12 13:03:50 +09001364 manifestJsonOut android.WritablePath
1365 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001366
Jooyung Han002ab682020-01-08 01:57:58 +09001367 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001368 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001369 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001370 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1371 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001372
1373 // Suffix of module name in Android.mk
1374 // ".flattened", ".apex", ".zipapex", or ""
1375 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001376
1377 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001378
1379 // Whether to create symlink to the system file instead of having a file
1380 // inside the apex or not
1381 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001382
1383 // Struct holding the merged notice file paths in different formats
1384 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001385}
1386
Jiyong Park397e55e2018-10-24 21:09:55 +09001387func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001388 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001389 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001390 // Use *FarVariation* to be able to depend on modules having
1391 // conflicting variations with this module. This is required since
1392 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1393 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001394 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001395 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001396 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001397 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001398 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001399
Jooyung Han643adc42020-02-27 13:50:06 +09001400 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1401 {Mutator: "image", Variation: imageVariation},
1402 {Mutator: "link", Variation: "shared"},
1403 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1404 }...), jniLibTag, nativeModules.Jni_libs...)
1405
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001406 ctx.AddFarVariationDependencies(append(target.Variations(),
1407 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001408 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001409
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001410 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001411 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001412 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001413 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001414}
1415
Alex Light9670d332019-01-29 18:07:33 -08001416func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1417 if ctx.Os().Class == android.Device {
1418 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1419 } else {
1420 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1421 if ctx.Os().Bionic() {
1422 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1423 } else {
1424 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1425 }
1426 }
1427}
1428
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001429func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001430 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1431 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1432 }
1433
Jiyong Park397e55e2018-10-24 21:09:55 +09001434 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001435 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001436
1437 a.combineProperties(ctx)
1438
Jiyong Park397e55e2018-10-24 21:09:55 +09001439 has32BitTarget := false
1440 for _, target := range targets {
1441 if target.Arch.ArchType.Multilib == "lib32" {
1442 has32BitTarget = true
1443 }
1444 }
1445 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001446 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001447 // multilib.both
1448 addDependenciesForNativeModules(ctx,
1449 ApexNativeDependencies{
1450 Native_shared_libs: a.properties.Native_shared_libs,
1451 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001452 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001453 Binaries: nil,
1454 },
1455 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001456
Jiyong Park397e55e2018-10-24 21:09:55 +09001457 // Add native modules targetting both ABIs
1458 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001459 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001460 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001461 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001462
Alex Light3d673592019-01-18 14:37:31 -08001463 isPrimaryAbi := i == 0
1464 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001465 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001466 // multilib.first
1467 addDependenciesForNativeModules(ctx,
1468 ApexNativeDependencies{
1469 Native_shared_libs: nil,
1470 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001471 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001472 Binaries: a.properties.Binaries,
1473 },
1474 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001475
1476 // Add native modules targetting the first ABI
1477 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001478 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001479 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001480 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001481 }
1482
1483 switch target.Arch.ArchType.Multilib {
1484 case "lib32":
1485 // Add native modules targetting 32-bit ABI
1486 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001487 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001488 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001489 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001490
1491 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001492 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001493 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001494 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001495 case "lib64":
1496 // Add native modules targetting 64-bit ABI
1497 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001498 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001499 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001500 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001501
1502 if !has32BitTarget {
1503 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001504 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001505 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001506 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001507 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001508
1509 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1510 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1511 if sanitizer == "hwaddress" {
1512 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001513 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001514 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001515 break
1516 }
1517 }
1518 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001519 }
1520
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001521 }
1522
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001523 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1524 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1525 // b/144532908
1526 archForPrebuiltEtc := config.Arches()[0]
1527 for _, arch := range config.Arches() {
1528 // Prefer 64-bit arch if there is any
1529 if arch.ArchType.Multilib == "lib64" {
1530 archForPrebuiltEtc = arch
1531 break
1532 }
1533 }
1534 ctx.AddFarVariationDependencies([]blueprint.Variation{
1535 {Mutator: "os", Variation: ctx.Os().String()},
1536 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1537 }, prebuiltTag, a.properties.Prebuilts...)
1538
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001539 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1540 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001541
Ulya Trafimovich44561882020-01-03 13:25:54 +00001542 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1543 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1544 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1545 javaLibTag, "jacocoagent")
1546 }
1547
Jiyong Park23c52b02019-02-02 13:13:47 +09001548 if String(a.properties.Key) == "" {
1549 ctx.ModuleErrorf("key is missing")
1550 return
1551 }
1552 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001553
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001554 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001555 if cert != "" {
1556 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001557 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001558
1559 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1560 if len(a.properties.Uses_sdks) > 0 {
1561 sdkRefs := []android.SdkRef{}
1562 for _, str := range a.properties.Uses_sdks {
1563 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1564 sdkRefs = append(sdkRefs, parsed)
1565 }
1566 a.BuildWithSdks(sdkRefs)
1567 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001568}
1569
Jiyong Park5d790c32019-11-15 18:40:32 +09001570func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1571 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1572 androidAppTag, a.overridableProperties.Apps...)
1573}
1574
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001575func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1576 // direct deps of an APEX bundle are all part of the APEX bundle
1577 return true
1578}
1579
Colin Cross0ea8ba82019-06-06 14:33:29 -07001580func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001581 moduleName := ctx.ModuleName()
1582 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1583 // we check with the pseudo module name to see if its certificate is overridden.
1584 if a.vndkApex {
1585 moduleName = vndkApexName
1586 }
1587 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001588 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001589 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001590 }
1591 return String(a.properties.Certificate)
1592}
1593
Colin Cross41955e82019-05-29 14:40:35 -07001594func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1595 switch tag {
1596 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001597 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001598 default:
1599 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001600 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001601}
1602
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001603func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001604 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001605}
1606
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001607func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1608 return proptools.Bool(a.properties.Test_only_no_hashtree)
1609}
1610
Jiyong Park7c1dc612019-01-05 11:15:24 +09001611func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001612 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001613 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001614 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001615 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001616 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001617 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001618 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001619 }
1620}
1621
Jiyong Parkf97782b2019-02-13 20:28:58 +09001622func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1623 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1624 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1625 }
1626}
1627
Jiyong Park388ef3f2019-01-28 19:47:32 +09001628func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001629 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1630 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001631 }
1632
1633 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001634 globalSanitizerNames := []string{}
1635 if a.Host() {
1636 globalSanitizerNames = ctx.Config().SanitizeHost()
1637 } else {
1638 arches := ctx.Config().SanitizeDeviceArch()
1639 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1640 globalSanitizerNames = ctx.Config().SanitizeDevice()
1641 }
1642 }
1643 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001644}
1645
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001646func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001647 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001648}
1649
1650func (a *apexBundle) PreventInstall() {
1651 a.properties.PreventInstall = true
1652}
1653
1654func (a *apexBundle) HideFromMake() {
1655 a.properties.HideFromMake = true
1656}
1657
Jiyong Park956305c2020-01-09 12:32:06 +09001658func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1659 a.properties.IsCoverageVariant = coverage
1660}
1661
Jiyong Parkf653b052019-11-18 15:39:01 +09001662// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001663func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001664 // Decide the APEX-local directory by the multilib of the library
1665 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001666 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001667 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001668 case "lib32":
1669 dirInApex = "lib"
1670 case "lib64":
1671 dirInApex = "lib64"
1672 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001673 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001674 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001675 }
Jooyung Han35155c42020-02-06 17:33:20 +09001676 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001677 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001678 // Special case for Bionic libs and other libs installed with them. This is
1679 // to prevent those libs from being included in the search path
1680 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1681 // those libs in the Runtime APEX are available via the legacy paths in
1682 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1683 // to the legacy paths and thus will be loaded into the default linker
1684 // namespace (aka "platform" namespace). If the libs are directly in
1685 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1686 // into the runtime linker namespace, which will result in double loading of
1687 // them, which isn't supported.
1688 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001689 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001690
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001692 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001693}
1694
Jiyong Park1833cef2019-12-13 13:28:36 +09001695func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001696 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001697 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001698 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001699 }
Jooyung Han35155c42020-02-06 17:33:20 +09001700 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001701 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001702 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001703 af.symlinks = cc.Symlinks()
1704 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001705}
1706
Jiyong Park1833cef2019-12-13 13:28:36 +09001707func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001708 dirInApex := "bin"
1709 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001710 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001711}
Jiyong Park1833cef2019-12-13 13:28:36 +09001712func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001713 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001714 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1715 if err != nil {
1716 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001717 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001718 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001719 fileToCopy := android.PathForOutput(ctx, s)
1720 // NB: Since go binaries are static we don't need the module for anything here, which is
1721 // good since the go tool is a blueprint.Module not an android.Module like we would
1722 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001723 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001724}
1725
Jiyong Park1833cef2019-12-13 13:28:36 +09001726func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001727 dirInApex := filepath.Join("bin", sh.SubDir())
1728 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001729 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001730 af.symlinks = sh.Symlinks()
1731 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001732}
1733
Jooyung Han58f26ab2019-12-18 15:34:32 +09001734// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1735type javaLibrary interface {
1736 android.Module
1737 java.Dependency
1738}
1739
1740func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001741 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001742 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001743 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1744 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1745 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001746}
1747
Jiyong Park1833cef2019-12-13 13:28:36 +09001748func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001749 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1750 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001751 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001752}
1753
atrost6e126252020-01-27 17:01:16 +00001754func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1755 dirInApex := filepath.Join("etc", config.SubDir())
1756 fileToCopy := config.CompatConfig()
1757 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1758}
1759
Jiyong Park1833cef2019-12-13 13:28:36 +09001760func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001761 android.Module
1762 Privileged() bool
1763 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001764 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001765 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001766}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001767 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001768 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001769 appDir = "priv-app"
1770 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001771 dirInApex := filepath.Join(appDir, pkgName)
1772 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001773 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1774 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001775 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001776
1777 if app, ok := aapp.(interface {
1778 OverriddenManifestPackageName() string
1779 }); ok {
1780 af.overriddenPackageName = app.OverriddenManifestPackageName()
1781 }
Jiyong Park618922e2020-01-08 13:35:43 +09001782 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001783}
1784
Roland Levillain935639d2019-08-13 14:55:28 +01001785// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1786type flattenedApexContext struct {
1787 android.ModuleContext
1788}
1789
1790func (c *flattenedApexContext) InstallBypassMake() bool {
1791 return true
1792}
1793
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001794// Function called while walking an APEX's payload dependencies.
1795//
1796// Return true if the `to` module should be visited, false otherwise.
1797type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1798
Jiyong Park201cedd2020-02-07 17:25:49 +09001799// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001800func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001801 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001802 am, ok := child.(android.ApexModule)
1803 if !ok || !am.CanHaveApexVariants() {
1804 return false
1805 }
1806
1807 // Check for the direct dependencies that contribute to the payload
1808 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1809 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001810 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001811 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001812 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001813 return false
1814 }
1815
1816 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001817 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001818 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001819 }
1820
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001821 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001822 })
1823}
1824
Jooyung Han03b51852020-02-26 22:45:42 +09001825func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1826 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1827 if ver != "current" {
1828 minSdkVersion, err := strconv.Atoi(ver)
1829 if err != nil {
1830 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1831 }
1832 return minSdkVersion
1833 }
1834 return android.FutureApiLevel
1835}
1836
Jiyong Park201cedd2020-02-07 17:25:49 +09001837// Ensures that the dependencies are marked as available for this APEX
1838func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1839 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1840 if ctx.Host() || a.testApex || a.vndkApex {
1841 return
1842 }
1843
Jiyong Park58d10902020-03-28 14:43:19 +09001844 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1845 // Requiring them and their transitive depencies with apex_available is not right
1846 // because they just add noise.
1847 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1848 return
1849 }
1850
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001851 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1852 if externalDep {
1853 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1854 return false
1855 }
1856
Jiyong Park201cedd2020-02-07 17:25:49 +09001857 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001858 fromName := ctx.OtherModuleName(from)
1859 toName := ctx.OtherModuleName(to)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001860 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1861 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001862 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001863 message := ""
1864 for _, m := range ctx.GetWalkPath()[1:] {
1865 message = fmt.Sprintf("%s\n -> %s", message, m.String())
1866 }
1867 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001868 // Visit this module's dependencies to check and report any issues with their availability.
1869 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001870 })
1871}
1872
Jiyong Park678c8812020-02-07 17:25:49 +09001873// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1874func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1875 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001876 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001877 if from.Name() == to.Name() {
1878 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001879 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1880 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001881 }
1882
1883 if info, exists := a.depInfos[to.Name()]; exists {
1884 if !android.InList(from.Name(), info.from) {
1885 info.from = append(info.from, from.Name())
1886 }
1887 info.isExternal = info.isExternal && externalDep
1888 a.depInfos[to.Name()] = info
1889 } else {
1890 a.depInfos[to.Name()] = depInfo{
1891 to: to.Name(),
1892 from: []string{from.Name()},
1893 isExternal: externalDep,
1894 }
1895 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001896
1897 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1898 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001899 })
1900}
1901
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001902func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001903 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1904 switch a.properties.ApexType {
1905 case imageApex:
1906 if buildFlattenedAsDefault {
1907 a.suffix = imageApexSuffix
1908 } else {
1909 a.suffix = ""
1910 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001911
1912 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001913 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001914 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001915 }
1916 case zipApex:
1917 if proptools.String(a.properties.Payload_type) == "zip" {
1918 a.suffix = ""
1919 a.primaryApexType = true
1920 } else {
1921 a.suffix = zipApexSuffix
1922 }
1923 case flattenedApex:
1924 if buildFlattenedAsDefault {
1925 a.suffix = ""
1926 a.primaryApexType = true
1927 } else {
1928 a.suffix = flattenedSuffix
1929 }
Alex Light5098a612018-11-29 17:12:15 -08001930 }
1931
Roland Levillain630846d2019-06-26 12:48:34 +01001932 if len(a.properties.Tests) > 0 && !a.testApex {
1933 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1934 return
1935 }
1936
Jiyong Park0f80c182020-01-31 02:49:53 +09001937 a.checkApexAvailability(ctx)
1938
Jiyong Park678c8812020-02-07 17:25:49 +09001939 a.collectDepsInfo(ctx)
1940
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001941 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1942
Jooyung Hane1633032019-08-01 17:41:43 +09001943 // native lib dependencies
1944 var provideNativeLibs []string
1945 var requireNativeLibs []string
1946
Jooyung Han5c998b92019-06-27 11:30:33 +09001947 // Check if "uses" requirements are met with dependent apexBundles
1948 var providedNativeSharedLibs []string
1949 useVendor := proptools.Bool(a.properties.Use_vendor)
1950 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1951 if ctx.OtherModuleDependencyTag(m) != usesTag {
1952 return
1953 }
1954 otherName := ctx.OtherModuleName(m)
1955 other, ok := m.(*apexBundle)
1956 if !ok {
1957 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1958 return
1959 }
1960 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1961 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1962 return
1963 }
1964 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1965 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1966 return
1967 }
1968 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1969 })
1970
Jiyong Parkf653b052019-11-18 15:39:01 +09001971 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001972 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001973 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001974 depTag := ctx.OtherModuleDependencyTag(child)
1975 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001976 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001977 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001978 case sharedLibTag, jniLibTag:
1979 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001980 if c, ok := child.(*cc.Module); ok {
1981 // bootstrap bionic libs are treated as provided by system
1982 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1983 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001984 }
Jooyung Han643adc42020-02-27 13:50:06 +09001985 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1986 fi.isJniLib = isJniLib
1987 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001988 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001989 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001990 propertyName := "native_shared_libs"
1991 if isJniLib {
1992 propertyName = "jni_libs"
1993 }
1994 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001995 }
1996 case executableTag:
1997 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001998 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001999 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002000 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002001 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002002 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002003 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002004 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002005 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002006 } else {
Alex Light778127a2019-02-27 14:19:50 -08002007 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 +09002008 }
2009 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002010 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002011 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002012 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002013 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2014 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002015 filesInfo = append(filesInfo, af)
2016 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002017 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002018 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2019 af := apexFileForJavaLibrary(ctx, sdkLib)
2020 if !af.Ok() {
2021 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2022 return false
2023 }
2024 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002025 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002026 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002027 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002028 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002029 case androidAppTag:
2030 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2031 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002032 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002033 return true // track transitive dependencies
2034 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002035 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002036 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2037 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002038 } else {
2039 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2040 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002041 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002042 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002043 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002044 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2045 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002046 } else {
atrost6e126252020-01-27 17:01:16 +00002047 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002048 }
Roland Levillain630846d2019-06-26 12:48:34 +01002049 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002050 if ccTest, ok := child.(*cc.Module); ok {
2051 if ccTest.IsTestPerSrcAllTestsVariation() {
2052 // Multiple-output test module (where `test_per_src: true`).
2053 //
2054 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2055 // We do not add this variation to `filesInfo`, as it has no output;
2056 // however, we do add the other variations of this module as indirect
2057 // dependencies (see below).
2058 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002059 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002060 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002061 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002062 af.class = nativeTest
2063 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002064 }
Roland Levillain630846d2019-06-26 12:48:34 +01002065 } else {
2066 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2067 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002068 case keyTag:
2069 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002070 a.private_key_file = key.private_key_file
2071 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002072 } else {
2073 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002074 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002075 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002076 case certificateTag:
2077 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002078 a.container_certificate_file = dep.Certificate.Pem
2079 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002080 } else {
2081 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2082 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002083 case android.PrebuiltDepTag:
2084 // If the prebuilt is force disabled, remember to delete the prebuilt file
2085 // that might have been installed in the previous builds
2086 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2087 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2088 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002089 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002090 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002091 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002092 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002093 // We cannot use a switch statement on `depTag` here as the checked
2094 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002095 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002096 if cc, ok := child.(*cc.Module); ok {
2097 if android.InList(cc.Name(), providedNativeSharedLibs) {
2098 // If we're using a shared library which is provided from other APEX,
2099 // don't include it in this APEX
2100 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002101 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002102 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002103 // If the dependency is a stubs lib, don't include it in this APEX,
2104 // but make sure that the lib is installed on the device.
2105 // In case no APEX is having the lib, the lib is installed to the system
2106 // partition.
2107 //
2108 // Always include if we are a host-apex however since those won't have any
2109 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002110 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2111 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002112 }
Jooyung Hane1633032019-08-01 17:41:43 +09002113 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002114 // Don't track further
2115 return false
2116 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002117 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002118 af.transitiveDep = true
2119 filesInfo = append(filesInfo, af)
2120 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002121 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002122 } else if cc.IsTestPerSrcDepTag(depTag) {
2123 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002124 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002125 // Handle modules created as `test_per_src` variations of a single test module:
2126 // use the name of the generated test binary (`fileToCopy`) instead of the name
2127 // of the original test module (`depName`, shared by all `test_per_src`
2128 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002129 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002130 // these are not considered transitive dep
2131 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002132 filesInfo = append(filesInfo, af)
2133 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002134 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002135 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002136 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2137 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002138 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2139 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2140 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2141 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002142 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002143 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002144 }
2145 }
2146 }
2147 return false
2148 })
2149
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002150 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2151 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2152 // via the global boot image config.
2153 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002154 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002155 dirInApex := filepath.Join("javalib", arch.String())
2156 for _, f := range files {
2157 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002158 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002159 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002160 }
2161 }
2162 }
2163
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002164 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002165 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2166 return
2167 }
2168
Jiyong Park8fd61922018-11-08 02:50:25 +09002169 // remove duplicates in filesInfo
2170 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002171 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002172 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002173 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002174 if e, ok := encountered[dest]; !ok {
2175 encountered[dest] = f
2176 } else {
2177 // If a module is directly included and also transitively depended on
2178 // consider it as directly included.
2179 e.transitiveDep = e.transitiveDep && f.transitiveDep
2180 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002181 }
2182 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002183 var result []apexFile
2184 for _, v := range encountered {
2185 result = append(result, v)
2186 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002187 return result
2188 }
2189 filesInfo = removeDup(filesInfo)
2190
2191 // to have consistent build rules
2192 sort.Slice(filesInfo, func(i, j int) bool {
2193 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2194 })
2195
Jiyong Park8fd61922018-11-08 02:50:25 +09002196 a.installDir = android.PathForModuleInstall(ctx, "apex")
2197 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002198
Jooyung Han54aca7b2019-11-20 02:26:02 +09002199 if a.properties.ApexType != zipApex {
2200 if a.properties.File_contexts == nil {
2201 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2202 } else {
2203 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2204 if a.Platform() {
2205 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2206 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2207 }
2208 }
2209 }
2210 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2211 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2212 return
2213 }
2214 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002215 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2216 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2217 // the same library in the system partition, thus effectively sharing the same libraries
2218 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2219 // in the APEX.
2220 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2221 a.installable() &&
2222 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002223
Jiyong Park9d677202020-02-19 16:29:35 +09002224 // We don't need the optimization for updatable APEXes, as it might give false signal
2225 // to the system health when the APEXes are still bundled (b/149805758)
2226 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2227 a.linkToSystemLib = false
2228 }
2229
Jiyong Park638d30e2020-02-26 18:27:19 +09002230 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2231 if ctx.Host() {
2232 a.linkToSystemLib = false
2233 }
2234
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002235 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002236 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2237
2238 a.setCertificateAndPrivateKey(ctx)
2239 if a.properties.ApexType == flattenedApex {
2240 a.buildFlattenedApex(ctx)
2241 } else {
2242 a.buildUnflattenedApex(ctx)
2243 }
2244
Jooyung Han002ab682020-01-08 01:57:58 +09002245 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002246
2247 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002248}
2249
Jooyung Han5e9013b2020-03-10 06:23:13 +09002250func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002251 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002252 moduleName = normalizeModuleName(moduleName)
2253
2254 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2255 return true
2256 }
2257
2258 key = android.AvailableToAnyApex
2259 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2260 return true
2261 }
2262
2263 return false
2264}
2265
2266func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002267 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2268 // system. Trim the prefix for the check since they are confusing
2269 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2270 if strings.HasPrefix(moduleName, "libclang_rt.") {
2271 // This module has many arch variants that depend on the product being built.
2272 // We don't want to list them all
2273 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002274 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002275 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002276}
2277
Jooyung Han344d5432019-08-23 11:17:39 +09002278func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002279 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002280 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002281 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002282 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002283 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002284 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2285 })
Alex Light5098a612018-11-29 17:12:15 -08002286 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002287 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002288 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002289 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002290 return module
2291}
Jiyong Park30ca9372019-02-07 16:27:23 +09002292
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002293func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002294 bundle := newApexBundle()
2295 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002296 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002297 return bundle
2298}
2299
Jiyong Parkfce0b422020-02-11 03:56:06 +09002300// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2301// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002302func testApexBundleFactory() android.Module {
2303 bundle := newApexBundle()
2304 bundle.testApex = true
2305 return bundle
2306}
2307
Jiyong Parkfce0b422020-02-11 03:56:06 +09002308// apex packages other modules into an APEX file which is a packaging format for system-level
2309// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002310func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002311 return newApexBundle()
2312}
2313
Jiyong Park30ca9372019-02-07 16:27:23 +09002314//
2315// Defaults
2316//
2317type Defaults struct {
2318 android.ModuleBase
2319 android.DefaultsModuleBase
2320}
2321
Jiyong Park30ca9372019-02-07 16:27:23 +09002322func defaultsFactory() android.Module {
2323 return DefaultsFactory()
2324}
2325
2326func DefaultsFactory(props ...interface{}) android.Module {
2327 module := &Defaults{}
2328
2329 module.AddProperties(props...)
2330 module.AddProperties(
2331 &apexBundleProperties{},
2332 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002333 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002334 )
2335
2336 android.InitDefaultsModule(module)
2337 return module
2338}
Jiyong Park5d790c32019-11-15 18:40:32 +09002339
2340//
2341// OverrideApex
2342//
2343type OverrideApex struct {
2344 android.ModuleBase
2345 android.OverrideModuleBase
2346}
2347
2348func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2349 // All the overrides happen in the base module.
2350}
2351
2352// override_apex is used to create an apex module based on another apex module
2353// by overriding some of its properties.
2354func overrideApexFactory() android.Module {
2355 m := &OverrideApex{}
2356 m.AddProperties(&overridableProperties{})
2357
2358 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2359 android.InitOverrideModule(m)
2360 return m
2361}