blob: 3e73283976ca32e3ba91206e8b6c7fa252d3b8c6 [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",
Jiyong Park0f80c182020-01-31 02:49:53 +0900822 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000823 return m
824}
825
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900826func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900827 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800828 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900829 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900830 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700831 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900832 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900833
Jooyung Han31c470b2019-10-18 16:26:59 +0900834 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900835 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900836
837 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
838 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
839 sort.Strings(*apexFileContextsInfos)
840 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
841 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900842}
843
Jooyung Han31c470b2019-10-18 16:26:59 +0900844func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
845 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
846 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
847}
848
Jiyong Parkd1063c12019-07-17 20:08:41 +0900849func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900850 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900851 ctx.BottomUp("apex", apexMutator).Parallel()
852 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
853 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900854}
855
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900856// Mark the direct and transitive dependencies of apex bundles so that they
857// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900858func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800859 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900860 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000861 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han5e9013b2020-03-10 06:23:13 +0900862 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han5417f772020-03-12 18:37:20 +0900863 ApexName: mctx.ModuleName(),
864 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900865 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900866 directDep = true
867 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800868 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900869 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900870 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900871
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800872 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900873 return
874 }
875
Jooyung Han5e9013b2020-03-10 06:23:13 +0900876 cur := mctx.Module().(interface {
877 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
878 })
879
Jiyong Parkf760cae2020-02-12 07:53:12 +0900880 mctx.VisitDirectDeps(func(child android.Module) {
881 depName := mctx.OtherModuleName(child)
882 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +0900883 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800884 android.UpdateApexDependency(apexBundles, depName, directDep)
885 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900886 }
887 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900888}
889
890// Create apex variations if a module is included in APEX(s).
891func apexMutator(mctx android.BottomUpMutatorContext) {
892 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900893 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000894 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900895 // apex bundle itself is mutated so that it and its modules have same
896 // apex variant.
897 apexBundleName := mctx.ModuleName()
898 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900899 } else if o, ok := mctx.Module().(*OverrideApex); ok {
900 apexBundleName := o.GetOverriddenModuleName()
901 if apexBundleName == "" {
902 mctx.ModuleErrorf("base property is not set")
903 return
904 }
905 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900906 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900907
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900908}
Sundong Ahne9b55722019-09-06 17:37:42 +0900909
Jooyung Han7a78a922019-10-08 21:59:58 +0900910var (
911 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
912 apexFileContextsInfosMutex sync.Mutex
913)
914
915func apexFileContextsInfos(config android.Config) *[]string {
916 return config.Once(apexFileContextsInfosKey, func() interface{} {
917 return &[]string{}
918 }).(*[]string)
919}
920
Jooyung Han54aca7b2019-11-20 02:26:02 +0900921func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900922 apexFileContextsInfosMutex.Lock()
923 defer apexFileContextsInfosMutex.Unlock()
924 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900925 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900926}
927
Sundong Ahne9b55722019-09-06 17:37:42 +0900928func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900929 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900930 var variants []string
931 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
932 case "image":
933 variants = append(variants, imageApexType, flattenedApexType)
934 case "zip":
935 variants = append(variants, zipApexType)
936 case "both":
937 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
938 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900939 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900940 return
941 }
942
943 modules := mctx.CreateLocalVariations(variants...)
944
945 for i, v := range variants {
946 switch v {
947 case imageApexType:
948 modules[i].(*apexBundle).properties.ApexType = imageApex
949 case zipApexType:
950 modules[i].(*apexBundle).properties.ApexType = zipApex
951 case flattenedApexType:
952 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900953 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900954 modules[i].(*apexBundle).MakeAsSystemExt()
955 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900956 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900957 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900958 } else if _, ok := mctx.Module().(*OverrideApex); ok {
959 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900960 }
961}
962
Jooyung Han5c998b92019-06-27 11:30:33 +0900963func apexUsesMutator(mctx android.BottomUpMutatorContext) {
964 if ab, ok := mctx.Module().(*apexBundle); ok {
965 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
966 }
967}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900968
Jooyung Handc782442019-11-01 03:14:38 +0900969var (
970 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
971)
972
973// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
974// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
975// which may cause compatibility issues. (e.g. libbinder)
976// Even though libbinder restricts its availability via 'apex_available' property and relies on
977// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
978// to avoid similar problems.
979func useVendorWhitelist(config android.Config) []string {
980 return config.Once(useVendorWhitelistKey, func() interface{} {
981 return []string{
982 // swcodec uses "vendor" variants for smaller size
983 "com.android.media.swcodec",
984 "test_com.android.media.swcodec",
985 }
986 }).([]string)
987}
988
989// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
990// called before the first call to useVendorWhitelist()
991func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
992 config.Once(useVendorWhitelistKey, func() interface{} {
993 return whitelist
994 })
995}
996
Jooyung Han01a868d2020-02-27 13:40:44 +0900997type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800998 // List of native libraries
999 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001000
Jooyung Han643adc42020-02-27 13:50:06 +09001001 // List of JNI libraries
1002 Jni_libs []string
1003
Alex Light9670d332019-01-29 18:07:33 -08001004 // List of native executables
1005 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001006
Roland Levillain630846d2019-06-26 12:48:34 +01001007 // List of native tests
1008 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001009}
Jooyung Han344d5432019-08-23 11:17:39 +09001010
Alex Light9670d332019-01-29 18:07:33 -08001011type apexMultilibProperties struct {
1012 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001013 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001014
1015 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001016 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001017
1018 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001019 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001020
1021 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001022 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001023
1024 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001025 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001026}
1027
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001028type apexBundleProperties struct {
1029 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001030 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001031 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001032
Jiyong Park40e26a22019-02-08 02:53:06 +09001033 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1034 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001035 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001036
Roland Levillain411c5842019-09-19 16:37:20 +01001037 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1038 // device (/apex/<apex_name>).
1039 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001040 Apex_name *string
1041
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001042 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001043 // For platform APEXes, this should points to a file under /system/sepolicy
1044 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1045 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001046
Jooyung Han01a868d2020-02-27 13:40:44 +09001047 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001048
1049 // List of java libraries that are embedded inside this APEX bundle
1050 Java_libs []string
1051
1052 // List of prebuilt files that are embedded inside this APEX bundle
1053 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001054
1055 // Name of the apex_key module that provides the private key to sign APEX
1056 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001057
Alex Light5098a612018-11-29 17:12:15 -08001058 // The type of APEX to build. Controls what the APEX payload is. Either
1059 // 'image', 'zip' or 'both'. Default: 'image'.
1060 Payload_type *string
1061
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001062 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1063 // or an android_app_certificate module name in the form ":module".
1064 Certificate *string
1065
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001066 // Whether this APEX is installable to one of the partitions. Default: true.
1067 Installable *bool
1068
Jiyong Parkda6eb592018-12-19 17:12:36 +09001069 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1070 // Default is false.
1071 Use_vendor *bool
1072
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001073 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1074 Ignore_system_library_special_case *bool
1075
Alex Light9670d332019-01-29 18:07:33 -08001076 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001077
Jiyong Parkf97782b2019-02-13 20:28:58 +09001078 // List of sanitizer names that this APEX is enabled for
1079 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001080
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001081 PreventInstall bool `blueprint:"mutated"`
1082
1083 HideFromMake bool `blueprint:"mutated"`
1084
Jooyung Han5c998b92019-06-27 11:30:33 +09001085 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1086 Provide_cpp_shared_libs *bool
1087
1088 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1089 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001090
1091 // A txt file containing list of files that are whitelisted to be included in this APEX.
1092 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001093
Sundong Ahnabb64432019-10-22 13:58:29 +09001094 // package format of this apex variant; could be non-flattened, flattened, or zip.
1095 // imageApex, zipApex or flattened
1096 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001097
Jiyong Parkd1063c12019-07-17 20:08:41 +09001098 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1099 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1100 // is implied. This value affects all modules included in this APEX. In other words, they are
1101 // also built with the SDKs specified here.
1102 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001103
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001104 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1105 // Should be only used in tests#.
1106 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001107
Jiyong Park956305c2020-01-09 12:32:06 +09001108 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001109
1110 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1111 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1112 // like symlinking to the system libs. Default is false.
1113 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001114
1115 // The minimum SDK version that this apex must be compatibile with.
1116 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001117}
1118
1119type apexTargetBundleProperties struct {
1120 Target struct {
1121 // Multilib properties only for android.
1122 Android struct {
1123 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001124 }
Jooyung Han344d5432019-08-23 11:17:39 +09001125
Alex Light9670d332019-01-29 18:07:33 -08001126 // Multilib properties only for host.
1127 Host struct {
1128 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001129 }
Jooyung Han344d5432019-08-23 11:17:39 +09001130
Alex Light9670d332019-01-29 18:07:33 -08001131 // Multilib properties only for host linux_bionic.
1132 Linux_bionic struct {
1133 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001134 }
Jooyung Han344d5432019-08-23 11:17:39 +09001135
Alex Light9670d332019-01-29 18:07:33 -08001136 // Multilib properties only for host linux_glibc.
1137 Linux_glibc struct {
1138 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001139 }
1140 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001141}
1142
Jiyong Park5d790c32019-11-15 18:40:32 +09001143type overridableProperties struct {
1144 // List of APKs to package inside APEX
1145 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001146
1147 // Names of modules to be overridden. Listed modules can only be other binaries
1148 // (in Make or Soong).
1149 // This does not completely prevent installation of the overridden binaries, but if both
1150 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1151 // from PRODUCT_PACKAGES.
1152 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001153
1154 // Logging Parent value
1155 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001156
1157 // Apex Container Package Name.
1158 // Override value for attribute package:name in AndroidManifest.xml
1159 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001160}
1161
Alex Light5098a612018-11-29 17:12:15 -08001162type apexPackaging int
1163
1164const (
1165 imageApex apexPackaging = iota
1166 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001167 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001168)
1169
Sundong Ahnabb64432019-10-22 13:58:29 +09001170// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001171func (a apexPackaging) suffix() string {
1172 switch a {
1173 case imageApex:
1174 return imageApexSuffix
1175 case zipApex:
1176 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001177 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001178 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001179 }
1180}
1181
1182func (a apexPackaging) name() string {
1183 switch a {
1184 case imageApex:
1185 return imageApexType
1186 case zipApex:
1187 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001188 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001189 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001190 }
1191}
1192
Jiyong Parkf653b052019-11-18 15:39:01 +09001193type apexFileClass int
1194
1195const (
1196 etc apexFileClass = iota
1197 nativeSharedLib
1198 nativeExecutable
1199 shBinary
1200 pyBinary
1201 goBinary
1202 javaSharedLib
1203 nativeTest
1204 app
1205)
1206
Jiyong Park8fd61922018-11-08 02:50:25 +09001207func (class apexFileClass) NameInMake() string {
1208 switch class {
1209 case etc:
1210 return "ETC"
1211 case nativeSharedLib:
1212 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001213 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001214 return "EXECUTABLES"
1215 case javaSharedLib:
1216 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001217 case nativeTest:
1218 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001219 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001220 // b/142537672 Why isn't this APP? We want to have full control over
1221 // the paths and file names of the apk file under the flattend APEX.
1222 // If this is set to APP, then the paths and file names are modified
1223 // by the Make build system. For example, it is installed to
1224 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1225 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1226 // appends module name (which is <apexname>.<Appname> to the path.
1227 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001228 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001229 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001230 }
1231}
1232
Jiyong Parkf653b052019-11-18 15:39:01 +09001233// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001234type apexFile struct {
1235 builtFile android.Path
1236 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001237 installDir string
1238 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001239 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001240 // list of symlinks that will be created in installDir that point to this apexFile
1241 symlinks []string
1242 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001243 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001244
1245 requiredModuleNames []string
1246 targetRequiredModuleNames []string
1247 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001248
Colin Cross503c1d02020-01-28 14:00:53 -08001249 jacocoReportClassesFile android.Path // only for javalibs and apps
1250 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001251 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001252
1253 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001254}
1255
Jiyong Park1833cef2019-12-13 13:28:36 +09001256func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1257 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001258 builtFile: builtFile,
1259 moduleName: moduleName,
1260 installDir: installDir,
1261 class: class,
1262 module: module,
1263 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001264 if module != nil {
1265 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001266 ret.requiredModuleNames = module.RequiredModuleNames()
1267 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1268 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001269 }
1270 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001271}
1272
1273func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001274 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001275}
1276
Jiyong Park7cd10e32020-01-14 09:22:18 +09001277// Path() returns path of this apex file relative to the APEX root
1278func (af *apexFile) Path() string {
1279 return filepath.Join(af.installDir, af.builtFile.Base())
1280}
1281
1282// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1283func (af *apexFile) SymlinkPaths() []string {
1284 var ret []string
1285 for _, symlink := range af.symlinks {
1286 ret = append(ret, filepath.Join(af.installDir, symlink))
1287 }
1288 return ret
1289}
1290
1291func (af *apexFile) AvailableToPlatform() bool {
1292 if af.module == nil {
1293 return false
1294 }
1295 if am, ok := af.module.(android.ApexModule); ok {
1296 return am.AvailableFor(android.AvailableToPlatform)
1297 }
1298 return false
1299}
1300
Jiyong Park678c8812020-02-07 17:25:49 +09001301type depInfo struct {
1302 to string
1303 from []string
1304 isExternal bool
1305}
1306
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001307type apexBundle struct {
1308 android.ModuleBase
1309 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001310 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001311 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001312
Jiyong Park5d790c32019-11-15 18:40:32 +09001313 properties apexBundleProperties
1314 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001315 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001316
Jooyung Hanf21c7972019-12-16 22:32:06 +09001317 // specific to apex_vndk modules
1318 vndkProperties apexVndkProperties
1319
Colin Crossa4925902018-11-16 11:36:28 -08001320 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001321 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001322 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001323
Jiyong Park03b68dd2019-07-26 23:20:40 +09001324 prebuiltFileToDelete string
1325
Jiyong Park42cca6c2019-04-01 11:15:50 +09001326 public_key_file android.Path
1327 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001328
1329 container_certificate_file android.Path
1330 container_private_key_file android.Path
1331
Jooyung Han54aca7b2019-11-20 02:26:02 +09001332 fileContexts android.Path
1333
Jiyong Park8fd61922018-11-08 02:50:25 +09001334 // list of files to be included in this apex
1335 filesInfo []apexFile
1336
Jiyong Park956305c2020-01-09 12:32:06 +09001337 // list of module names that should be installed along with this APEX
1338 requiredDeps []string
1339
Jiyong Park956305c2020-01-09 12:32:06 +09001340 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001341 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001342
Sundong Ahnabb64432019-10-22 13:58:29 +09001343 testApex bool
1344 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001345 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001346 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001347
Jooyung Han214bf372019-11-12 13:03:50 +09001348 manifestJsonOut android.WritablePath
1349 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001350
Jooyung Han002ab682020-01-08 01:57:58 +09001351 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001352 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001353 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001354 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1355 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001356
1357 // Suffix of module name in Android.mk
1358 // ".flattened", ".apex", ".zipapex", or ""
1359 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001360
1361 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001362
1363 // Whether to create symlink to the system file instead of having a file
1364 // inside the apex or not
1365 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001366
1367 // Struct holding the merged notice file paths in different formats
1368 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001369}
1370
Jiyong Park397e55e2018-10-24 21:09:55 +09001371func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001372 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001373 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001374 // Use *FarVariation* to be able to depend on modules having
1375 // conflicting variations with this module. This is required since
1376 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1377 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001378 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001379 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001380 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001381 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001382 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001383
Jooyung Han643adc42020-02-27 13:50:06 +09001384 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1385 {Mutator: "image", Variation: imageVariation},
1386 {Mutator: "link", Variation: "shared"},
1387 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1388 }...), jniLibTag, nativeModules.Jni_libs...)
1389
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001390 ctx.AddFarVariationDependencies(append(target.Variations(),
1391 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001392 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001393
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001394 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001395 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001396 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001397 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001398}
1399
Alex Light9670d332019-01-29 18:07:33 -08001400func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1401 if ctx.Os().Class == android.Device {
1402 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1403 } else {
1404 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1405 if ctx.Os().Bionic() {
1406 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1407 } else {
1408 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1409 }
1410 }
1411}
1412
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001413func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001414 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1415 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1416 }
1417
Jiyong Park397e55e2018-10-24 21:09:55 +09001418 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001419 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001420
1421 a.combineProperties(ctx)
1422
Jiyong Park397e55e2018-10-24 21:09:55 +09001423 has32BitTarget := false
1424 for _, target := range targets {
1425 if target.Arch.ArchType.Multilib == "lib32" {
1426 has32BitTarget = true
1427 }
1428 }
1429 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001430 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001431 // multilib.both
1432 addDependenciesForNativeModules(ctx,
1433 ApexNativeDependencies{
1434 Native_shared_libs: a.properties.Native_shared_libs,
1435 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001436 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001437 Binaries: nil,
1438 },
1439 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001440
Jiyong Park397e55e2018-10-24 21:09:55 +09001441 // Add native modules targetting both ABIs
1442 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001443 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001444 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001445 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001446
Alex Light3d673592019-01-18 14:37:31 -08001447 isPrimaryAbi := i == 0
1448 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001449 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001450 // multilib.first
1451 addDependenciesForNativeModules(ctx,
1452 ApexNativeDependencies{
1453 Native_shared_libs: nil,
1454 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001455 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001456 Binaries: a.properties.Binaries,
1457 },
1458 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001459
1460 // Add native modules targetting the first ABI
1461 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001462 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001463 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001464 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001465 }
1466
1467 switch target.Arch.ArchType.Multilib {
1468 case "lib32":
1469 // Add native modules targetting 32-bit ABI
1470 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001471 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001472 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001473 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001474
1475 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001476 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001477 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001478 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001479 case "lib64":
1480 // Add native modules targetting 64-bit ABI
1481 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001482 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001483 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001484 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001485
1486 if !has32BitTarget {
1487 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001488 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001489 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001490 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001491 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001492
1493 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1494 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1495 if sanitizer == "hwaddress" {
1496 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001497 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001498 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001499 break
1500 }
1501 }
1502 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001503 }
1504
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001505 }
1506
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001507 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1508 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1509 // b/144532908
1510 archForPrebuiltEtc := config.Arches()[0]
1511 for _, arch := range config.Arches() {
1512 // Prefer 64-bit arch if there is any
1513 if arch.ArchType.Multilib == "lib64" {
1514 archForPrebuiltEtc = arch
1515 break
1516 }
1517 }
1518 ctx.AddFarVariationDependencies([]blueprint.Variation{
1519 {Mutator: "os", Variation: ctx.Os().String()},
1520 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1521 }, prebuiltTag, a.properties.Prebuilts...)
1522
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001523 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1524 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001525
Ulya Trafimovich44561882020-01-03 13:25:54 +00001526 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1527 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1528 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1529 javaLibTag, "jacocoagent")
1530 }
1531
Jiyong Park23c52b02019-02-02 13:13:47 +09001532 if String(a.properties.Key) == "" {
1533 ctx.ModuleErrorf("key is missing")
1534 return
1535 }
1536 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001537
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001538 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001539 if cert != "" {
1540 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001541 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001542
1543 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1544 if len(a.properties.Uses_sdks) > 0 {
1545 sdkRefs := []android.SdkRef{}
1546 for _, str := range a.properties.Uses_sdks {
1547 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1548 sdkRefs = append(sdkRefs, parsed)
1549 }
1550 a.BuildWithSdks(sdkRefs)
1551 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001552}
1553
Jiyong Park5d790c32019-11-15 18:40:32 +09001554func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1555 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1556 androidAppTag, a.overridableProperties.Apps...)
1557}
1558
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001559func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1560 // direct deps of an APEX bundle are all part of the APEX bundle
1561 return true
1562}
1563
Colin Cross0ea8ba82019-06-06 14:33:29 -07001564func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001565 moduleName := ctx.ModuleName()
1566 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1567 // we check with the pseudo module name to see if its certificate is overridden.
1568 if a.vndkApex {
1569 moduleName = vndkApexName
1570 }
1571 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001572 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001573 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001574 }
1575 return String(a.properties.Certificate)
1576}
1577
Colin Cross41955e82019-05-29 14:40:35 -07001578func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1579 switch tag {
1580 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001581 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001582 default:
1583 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001584 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001585}
1586
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001587func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001588 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001589}
1590
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001591func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1592 return proptools.Bool(a.properties.Test_only_no_hashtree)
1593}
1594
Jiyong Park7c1dc612019-01-05 11:15:24 +09001595func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001596 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001597 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001598 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001599 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001600 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001601 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001602 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001603 }
1604}
1605
Jiyong Parkf97782b2019-02-13 20:28:58 +09001606func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1607 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1608 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1609 }
1610}
1611
Jiyong Park388ef3f2019-01-28 19:47:32 +09001612func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001613 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1614 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001615 }
1616
1617 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001618 globalSanitizerNames := []string{}
1619 if a.Host() {
1620 globalSanitizerNames = ctx.Config().SanitizeHost()
1621 } else {
1622 arches := ctx.Config().SanitizeDeviceArch()
1623 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1624 globalSanitizerNames = ctx.Config().SanitizeDevice()
1625 }
1626 }
1627 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001628}
1629
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001630func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001631 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001632}
1633
1634func (a *apexBundle) PreventInstall() {
1635 a.properties.PreventInstall = true
1636}
1637
1638func (a *apexBundle) HideFromMake() {
1639 a.properties.HideFromMake = true
1640}
1641
Jiyong Park956305c2020-01-09 12:32:06 +09001642func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1643 a.properties.IsCoverageVariant = coverage
1644}
1645
Jiyong Parkf653b052019-11-18 15:39:01 +09001646// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001647func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001648 // Decide the APEX-local directory by the multilib of the library
1649 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001650 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001651 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001652 case "lib32":
1653 dirInApex = "lib"
1654 case "lib64":
1655 dirInApex = "lib64"
1656 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001657 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001658 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001659 }
Jooyung Han35155c42020-02-06 17:33:20 +09001660 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001661 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001662 // Special case for Bionic libs and other libs installed with them. This is
1663 // to prevent those libs from being included in the search path
1664 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1665 // those libs in the Runtime APEX are available via the legacy paths in
1666 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1667 // to the legacy paths and thus will be loaded into the default linker
1668 // namespace (aka "platform" namespace). If the libs are directly in
1669 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1670 // into the runtime linker namespace, which will result in double loading of
1671 // them, which isn't supported.
1672 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001673 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001674
Jiyong Parkf653b052019-11-18 15:39:01 +09001675 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001676 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001677}
1678
Jiyong Park1833cef2019-12-13 13:28:36 +09001679func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001680 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001681 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001682 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001683 }
Jooyung Han35155c42020-02-06 17:33:20 +09001684 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001685 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001686 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001687 af.symlinks = cc.Symlinks()
1688 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001689}
1690
Jiyong Park1833cef2019-12-13 13:28:36 +09001691func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001692 dirInApex := "bin"
1693 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001694 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001695}
Jiyong Park1833cef2019-12-13 13:28:36 +09001696func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001697 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001698 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1699 if err != nil {
1700 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001701 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001702 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001703 fileToCopy := android.PathForOutput(ctx, s)
1704 // NB: Since go binaries are static we don't need the module for anything here, which is
1705 // good since the go tool is a blueprint.Module not an android.Module like we would
1706 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001707 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001708}
1709
Jiyong Park1833cef2019-12-13 13:28:36 +09001710func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001711 dirInApex := filepath.Join("bin", sh.SubDir())
1712 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001713 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001714 af.symlinks = sh.Symlinks()
1715 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001716}
1717
Jooyung Han58f26ab2019-12-18 15:34:32 +09001718// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1719type javaLibrary interface {
1720 android.Module
1721 java.Dependency
1722}
1723
1724func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001725 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001726 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001727 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1728 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1729 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001730}
1731
Jiyong Park1833cef2019-12-13 13:28:36 +09001732func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001733 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1734 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001735 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001736}
1737
atrost6e126252020-01-27 17:01:16 +00001738func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1739 dirInApex := filepath.Join("etc", config.SubDir())
1740 fileToCopy := config.CompatConfig()
1741 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1742}
1743
Jiyong Park1833cef2019-12-13 13:28:36 +09001744func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001745 android.Module
1746 Privileged() bool
1747 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001748 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001749 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001750}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001751 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001752 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001753 appDir = "priv-app"
1754 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001755 dirInApex := filepath.Join(appDir, pkgName)
1756 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001757 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1758 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001759 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001760
1761 if app, ok := aapp.(interface {
1762 OverriddenManifestPackageName() string
1763 }); ok {
1764 af.overriddenPackageName = app.OverriddenManifestPackageName()
1765 }
Jiyong Park618922e2020-01-08 13:35:43 +09001766 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001767}
1768
Roland Levillain935639d2019-08-13 14:55:28 +01001769// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1770type flattenedApexContext struct {
1771 android.ModuleContext
1772}
1773
1774func (c *flattenedApexContext) InstallBypassMake() bool {
1775 return true
1776}
1777
Jiyong Park201cedd2020-02-07 17:25:49 +09001778// Visit dependencies that contributes to the payload of this APEX
1779func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1780 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001781 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1782 am, ok := child.(android.ApexModule)
1783 if !ok || !am.CanHaveApexVariants() {
1784 return false
1785 }
1786
1787 // Check for the direct dependencies that contribute to the payload
1788 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1789 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001790 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001791 return true
1792 }
1793 return false
1794 }
1795
1796 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001797 if am.ApexName() != "" {
Jiyong Park201cedd2020-02-07 17:25:49 +09001798 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001799 return true
1800 }
1801
Jiyong Park201cedd2020-02-07 17:25:49 +09001802 do(ctx, parent, am, true /* externalDep */)
1803
Jiyong Park0f80c182020-01-31 02:49:53 +09001804 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1805 return false
1806 })
1807}
1808
Jooyung Han03b51852020-02-26 22:45:42 +09001809func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1810 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1811 if ver != "current" {
1812 minSdkVersion, err := strconv.Atoi(ver)
1813 if err != nil {
1814 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1815 }
1816 return minSdkVersion
1817 }
1818 return android.FutureApiLevel
1819}
1820
Jiyong Park201cedd2020-02-07 17:25:49 +09001821// Ensures that the dependencies are marked as available for this APEX
1822func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1823 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1824 if ctx.Host() || a.testApex || a.vndkApex {
1825 return
1826 }
1827
1828 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1829 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001830 fromName := ctx.OtherModuleName(from)
1831 toName := ctx.OtherModuleName(to)
1832 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001833 return
1834 }
Jooyung Han5e9013b2020-03-10 06:23:13 +09001835 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", fromName, toName)
Jiyong Park201cedd2020-02-07 17:25:49 +09001836 })
1837}
1838
Jiyong Park678c8812020-02-07 17:25:49 +09001839// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1840func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1841 a.depInfos = make(map[string]depInfo)
1842 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1843 if from.Name() == to.Name() {
1844 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
1845 return
1846 }
1847
1848 if info, exists := a.depInfos[to.Name()]; exists {
1849 if !android.InList(from.Name(), info.from) {
1850 info.from = append(info.from, from.Name())
1851 }
1852 info.isExternal = info.isExternal && externalDep
1853 a.depInfos[to.Name()] = info
1854 } else {
1855 a.depInfos[to.Name()] = depInfo{
1856 to: to.Name(),
1857 from: []string{from.Name()},
1858 isExternal: externalDep,
1859 }
1860 }
1861 })
1862}
1863
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001864func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001865 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1866 switch a.properties.ApexType {
1867 case imageApex:
1868 if buildFlattenedAsDefault {
1869 a.suffix = imageApexSuffix
1870 } else {
1871 a.suffix = ""
1872 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001873
1874 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001875 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001876 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001877 }
1878 case zipApex:
1879 if proptools.String(a.properties.Payload_type) == "zip" {
1880 a.suffix = ""
1881 a.primaryApexType = true
1882 } else {
1883 a.suffix = zipApexSuffix
1884 }
1885 case flattenedApex:
1886 if buildFlattenedAsDefault {
1887 a.suffix = ""
1888 a.primaryApexType = true
1889 } else {
1890 a.suffix = flattenedSuffix
1891 }
Alex Light5098a612018-11-29 17:12:15 -08001892 }
1893
Roland Levillain630846d2019-06-26 12:48:34 +01001894 if len(a.properties.Tests) > 0 && !a.testApex {
1895 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1896 return
1897 }
1898
Jiyong Park0f80c182020-01-31 02:49:53 +09001899 a.checkApexAvailability(ctx)
1900
Jiyong Park678c8812020-02-07 17:25:49 +09001901 a.collectDepsInfo(ctx)
1902
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001903 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1904
Jooyung Hane1633032019-08-01 17:41:43 +09001905 // native lib dependencies
1906 var provideNativeLibs []string
1907 var requireNativeLibs []string
1908
Jooyung Han5c998b92019-06-27 11:30:33 +09001909 // Check if "uses" requirements are met with dependent apexBundles
1910 var providedNativeSharedLibs []string
1911 useVendor := proptools.Bool(a.properties.Use_vendor)
1912 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1913 if ctx.OtherModuleDependencyTag(m) != usesTag {
1914 return
1915 }
1916 otherName := ctx.OtherModuleName(m)
1917 other, ok := m.(*apexBundle)
1918 if !ok {
1919 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1920 return
1921 }
1922 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1923 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1924 return
1925 }
1926 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1927 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1928 return
1929 }
1930 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1931 })
1932
Jiyong Parkf653b052019-11-18 15:39:01 +09001933 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001934 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001935 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001936 depTag := ctx.OtherModuleDependencyTag(child)
1937 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001938 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001939 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001940 case sharedLibTag, jniLibTag:
1941 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001942 if c, ok := child.(*cc.Module); ok {
1943 // bootstrap bionic libs are treated as provided by system
1944 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1945 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001946 }
Jooyung Han643adc42020-02-27 13:50:06 +09001947 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1948 fi.isJniLib = isJniLib
1949 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001950 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001951 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001952 propertyName := "native_shared_libs"
1953 if isJniLib {
1954 propertyName = "jni_libs"
1955 }
1956 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001957 }
1958 case executableTag:
1959 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001960 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001961 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001962 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001963 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001964 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001965 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001966 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001967 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001968 } else {
Alex Light778127a2019-02-27 14:19:50 -08001969 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 +09001970 }
1971 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001972 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001973 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001974 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001975 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1976 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001977 filesInfo = append(filesInfo, af)
1978 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001979 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001980 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1981 af := apexFileForJavaLibrary(ctx, sdkLib)
1982 if !af.Ok() {
1983 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1984 return false
1985 }
1986 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001987 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001988 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001989 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001990 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001991 case androidAppTag:
1992 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1993 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001994 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001995 return true // track transitive dependencies
1996 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001997 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00001998 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
1999 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002000 } else {
2001 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2002 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002003 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002004 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002005 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002006 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2007 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002008 } else {
atrost6e126252020-01-27 17:01:16 +00002009 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002010 }
Roland Levillain630846d2019-06-26 12:48:34 +01002011 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002012 if ccTest, ok := child.(*cc.Module); ok {
2013 if ccTest.IsTestPerSrcAllTestsVariation() {
2014 // Multiple-output test module (where `test_per_src: true`).
2015 //
2016 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2017 // We do not add this variation to `filesInfo`, as it has no output;
2018 // however, we do add the other variations of this module as indirect
2019 // dependencies (see below).
2020 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002021 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002022 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002023 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002024 af.class = nativeTest
2025 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002026 }
Roland Levillain630846d2019-06-26 12:48:34 +01002027 } else {
2028 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2029 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002030 case keyTag:
2031 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002032 a.private_key_file = key.private_key_file
2033 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002034 } else {
2035 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002036 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002037 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002038 case certificateTag:
2039 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002040 a.container_certificate_file = dep.Certificate.Pem
2041 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002042 } else {
2043 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2044 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002045 case android.PrebuiltDepTag:
2046 // If the prebuilt is force disabled, remember to delete the prebuilt file
2047 // that might have been installed in the previous builds
2048 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2049 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2050 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002051 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002052 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002053 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002054 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002055 // We cannot use a switch statement on `depTag` here as the checked
2056 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002057 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002058 if cc, ok := child.(*cc.Module); ok {
2059 if android.InList(cc.Name(), providedNativeSharedLibs) {
2060 // If we're using a shared library which is provided from other APEX,
2061 // don't include it in this APEX
2062 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002063 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002064 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002065 // If the dependency is a stubs lib, don't include it in this APEX,
2066 // but make sure that the lib is installed on the device.
2067 // In case no APEX is having the lib, the lib is installed to the system
2068 // partition.
2069 //
2070 // Always include if we are a host-apex however since those won't have any
2071 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002072 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2073 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002074 }
Jooyung Hane1633032019-08-01 17:41:43 +09002075 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002076 // Don't track further
2077 return false
2078 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002079 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002080 af.transitiveDep = true
2081 filesInfo = append(filesInfo, af)
2082 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002083 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002084 } else if cc.IsTestPerSrcDepTag(depTag) {
2085 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002086 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002087 // Handle modules created as `test_per_src` variations of a single test module:
2088 // use the name of the generated test binary (`fileToCopy`) instead of the name
2089 // of the original test module (`depName`, shared by all `test_per_src`
2090 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002091 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002092 // these are not considered transitive dep
2093 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002094 filesInfo = append(filesInfo, af)
2095 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002096 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002097 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002098 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2099 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002100 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2101 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2102 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2103 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002104 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002105 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002106 }
2107 }
2108 }
2109 return false
2110 })
2111
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002112 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2113 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2114 // via the global boot image config.
2115 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002116 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002117 dirInApex := filepath.Join("javalib", arch.String())
2118 for _, f := range files {
2119 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002120 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002121 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002122 }
2123 }
2124 }
2125
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002126 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002127 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2128 return
2129 }
2130
Jiyong Park8fd61922018-11-08 02:50:25 +09002131 // remove duplicates in filesInfo
2132 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002133 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002134 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002135 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002136 if e, ok := encountered[dest]; !ok {
2137 encountered[dest] = f
2138 } else {
2139 // If a module is directly included and also transitively depended on
2140 // consider it as directly included.
2141 e.transitiveDep = e.transitiveDep && f.transitiveDep
2142 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002143 }
2144 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002145 var result []apexFile
2146 for _, v := range encountered {
2147 result = append(result, v)
2148 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002149 return result
2150 }
2151 filesInfo = removeDup(filesInfo)
2152
2153 // to have consistent build rules
2154 sort.Slice(filesInfo, func(i, j int) bool {
2155 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2156 })
2157
Jiyong Park8fd61922018-11-08 02:50:25 +09002158 a.installDir = android.PathForModuleInstall(ctx, "apex")
2159 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002160
Jooyung Han54aca7b2019-11-20 02:26:02 +09002161 if a.properties.ApexType != zipApex {
2162 if a.properties.File_contexts == nil {
2163 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2164 } else {
2165 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2166 if a.Platform() {
2167 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2168 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2169 }
2170 }
2171 }
2172 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2173 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2174 return
2175 }
2176 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002177 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2178 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2179 // the same library in the system partition, thus effectively sharing the same libraries
2180 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2181 // in the APEX.
2182 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2183 a.installable() &&
2184 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002185
Jiyong Park9d677202020-02-19 16:29:35 +09002186 // We don't need the optimization for updatable APEXes, as it might give false signal
2187 // to the system health when the APEXes are still bundled (b/149805758)
2188 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2189 a.linkToSystemLib = false
2190 }
2191
Jiyong Park638d30e2020-02-26 18:27:19 +09002192 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2193 if ctx.Host() {
2194 a.linkToSystemLib = false
2195 }
2196
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002197 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002198 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2199
2200 a.setCertificateAndPrivateKey(ctx)
2201 if a.properties.ApexType == flattenedApex {
2202 a.buildFlattenedApex(ctx)
2203 } else {
2204 a.buildUnflattenedApex(ctx)
2205 }
2206
Jooyung Han002ab682020-01-08 01:57:58 +09002207 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002208
2209 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002210}
2211
Jooyung Han5e9013b2020-03-10 06:23:13 +09002212func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002213 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002214 moduleName = normalizeModuleName(moduleName)
2215
2216 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2217 return true
2218 }
2219
2220 key = android.AvailableToAnyApex
2221 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2222 return true
2223 }
2224
2225 return false
2226}
2227
2228func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002229 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2230 // system. Trim the prefix for the check since they are confusing
2231 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2232 if strings.HasPrefix(moduleName, "libclang_rt.") {
2233 // This module has many arch variants that depend on the product being built.
2234 // We don't want to list them all
2235 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002236 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002237 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002238}
2239
Jooyung Han344d5432019-08-23 11:17:39 +09002240func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002241 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002242 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002243 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002244 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002245 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002246 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2247 })
Alex Light5098a612018-11-29 17:12:15 -08002248 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002249 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002250 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002251 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002252 return module
2253}
Jiyong Park30ca9372019-02-07 16:27:23 +09002254
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002255func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002256 bundle := newApexBundle()
2257 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002258 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002259 return bundle
2260}
2261
Jiyong Parkfce0b422020-02-11 03:56:06 +09002262// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2263// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002264func testApexBundleFactory() android.Module {
2265 bundle := newApexBundle()
2266 bundle.testApex = true
2267 return bundle
2268}
2269
Jiyong Parkfce0b422020-02-11 03:56:06 +09002270// apex packages other modules into an APEX file which is a packaging format for system-level
2271// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002272func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002273 return newApexBundle()
2274}
2275
Jiyong Park30ca9372019-02-07 16:27:23 +09002276//
2277// Defaults
2278//
2279type Defaults struct {
2280 android.ModuleBase
2281 android.DefaultsModuleBase
2282}
2283
Jiyong Park30ca9372019-02-07 16:27:23 +09002284func defaultsFactory() android.Module {
2285 return DefaultsFactory()
2286}
2287
2288func DefaultsFactory(props ...interface{}) android.Module {
2289 module := &Defaults{}
2290
2291 module.AddProperties(props...)
2292 module.AddProperties(
2293 &apexBundleProperties{},
2294 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002295 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002296 )
2297
2298 android.InitDefaultsModule(module)
2299 return module
2300}
Jiyong Park5d790c32019-11-15 18:40:32 +09002301
2302//
2303// OverrideApex
2304//
2305type OverrideApex struct {
2306 android.ModuleBase
2307 android.OverrideModuleBase
2308}
2309
2310func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2311 // All the overrides happen in the base module.
2312}
2313
2314// override_apex is used to create an apex module based on another apex module
2315// by overriding some of its properties.
2316func overrideApexFactory() android.Module {
2317 m := &OverrideApex{}
2318 m.AddProperties(&overridableProperties{})
2319
2320 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2321 android.InitOverrideModule(m)
2322 return m
2323}