blob: 15952074724266099d6294f5502c4f4d1c3eca70 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinc5192442020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jooyung Han03b51852020-02-26 22:45:42 +090023 "strconv"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090025 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090026
27 "android/soong/android"
28 "android/soong/cc"
29 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080030 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090031
32 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080033 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090034 "github.com/google/blueprint/proptools"
35)
36
Jooyung Han72bd2f82019-10-23 16:46:38 +090037const (
38 imageApexSuffix = ".apex"
39 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090040 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080041
Sundong Ahnabb64432019-10-22 13:58:29 +090042 imageApexType = "image"
43 zipApexType = "zip"
44 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090045)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090046
47type dependencyTag struct {
48 blueprint.BaseDependencyTag
49 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090050
51 // determines if the dependent will be part of the APEX payload
52 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090053}
54
55var (
Jiyong Park0f80c182020-01-31 02:49:53 +090056 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090057 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090058 executableTag = dependencyTag{name: "executable", payload: true}
59 javaLibTag = dependencyTag{name: "javaLib", payload: true}
60 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
61 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090062 keyTag = dependencyTag{name: "key"}
63 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090064 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090065 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000066 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000067
68 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069)
70
Paul Duffin7d74e7b2020-03-06 12:30:13 +000071// Transform the map of apex -> modules to module -> apexes.
72func invertApexWhiteList(m map[string][]string) map[string][]string {
73 r := make(map[string][]string)
74 for apex, modules := range m {
75 for _, module := range modules {
76 r[module] = append(r[module], apex)
77 }
78 }
79 return r
80}
81
82// Retrieve the while list of apexes to which the supplied module belongs.
83func WhitelistedApexAvailable(moduleName string) []string {
84 return inverseApexAvailWl[normalizeModuleName(moduleName)]
85}
86
Anton Hanssoneec79eb2020-01-10 15:12:39 +000087// This is a map from apex to modules, which overrides the
88// apex_available setting for that particular module to make
89// it available for the apex regardless of its setting.
90// TODO(b/147364041): remove this
91func makeApexAvailableWhitelist() map[string][]string {
92 // The "Module separator"s below are employed to minimize merge conflicts.
93 m := make(map[string][]string)
94 //
95 // Module separator
96 //
Jiyong Park0f80c182020-01-31 02:49:53 +090097 m["com.android.adbd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "libadbd_auth",
Jiyong Park0f80c182020-01-31 02:49:53 +090099 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "libcap",
Jiyong Park0f80c182020-01-31 02:49:53 +0900101 "libmdnssd",
102 "libminijail",
103 "libminijail_gen_constants",
104 "libminijail_gen_constants_obj",
105 "libminijail_gen_syscall",
106 "libminijail_gen_syscall_obj",
107 "libminijail_generated",
108 "libpackagelistparser",
109 "libpcre2",
110 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 }
112 //
113 // Module separator
114 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000115 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900116 "art_cmdlineparser_headers",
117 "art_disassembler_headers",
118 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900119 "bionic_libc_platform_headers",
120 "core-repackaged-icu4j",
121 "cpp-define-generator-asm-support",
122 "cpp-define-generator-definitions",
123 "crtbegin_dynamic",
124 "crtbegin_dynamic1",
125 "crtbegin_so1",
126 "crtbrand",
127 "conscrypt.module.intra.core.api.stubs",
128 "dex2oat_headers",
129 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900131 "javavm_headers",
132 "jni_platform_headers",
133 "libPlatformProperties",
134 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000135 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900136 "libandroidicuinit",
137 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000138 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900139 "libasync_safe",
Jiyong Park0f80c182020-01-31 02:49:53 +0900140 "libdexfile_all_headers",
141 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000142 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900143 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000144 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900145 "libfdlibm",
146 "libgtest_prod",
147 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000148 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900149 "libicuuc_headers",
150 "libicuuc_stubdata",
151 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000153 "liblzma",
154 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "libnativebridge-headers",
156 "libnativehelper_header_only",
157 "libnativeloader-headers",
158 "libnpt_headers",
159 "libopenjdkjvmti_headers",
160 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000163 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "libv8",
165 "libv8base",
166 "libv8gen",
167 "libv8platform",
168 "libv8sampler",
169 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000170 "libvixl",
171 "libvixld",
172 "libz",
173 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900174 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000175 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000176 m["com.android.art.debug"] = artApexContents
177 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000178 //
179 // Module separator
180 //
181 m["com.android.bluetooth.updatable"] = []string{
182 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000183 "android.hardware.bluetooth.a2dp@1.0",
184 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900185 "android.hardware.bluetooth@1.0",
186 "android.hardware.bluetooth@1.1",
187 "android.hardware.graphics.bufferqueue@1.0",
188 "android.hardware.graphics.bufferqueue@2.0",
189 "android.hardware.graphics.common@1.0",
190 "android.hardware.graphics.common@1.1",
191 "android.hardware.graphics.common@1.2",
192 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000193 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900194 "android.hidl.token@1.0",
195 "android.hidl.token@1.0-utils",
196 "avrcp-target-service",
197 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900198 "bluetooth-protos-lite",
199 "bluetooth.mapsapi",
200 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900201 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900202 "ipmemorystore-aidl-interfaces-V5-java",
203 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900204 "internal_include_headers",
205 "lib-bt-packets",
206 "lib-bt-packets-avrcp",
207 "lib-bt-packets-base",
208 "libFraunhoferAAC",
209 "libaudio-a2dp-hw-utils",
210 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900211 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000212 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900213 "libbluetooth-types",
214 "libbluetooth-types-header",
215 "libbluetooth_gd",
216 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000217 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900218 "libbt-audio-hal-interface",
219 "libbt-bta",
220 "libbt-common",
221 "libbt-hci",
222 "libbt-platform-protos-lite",
223 "libbt-protos-lite",
224 "libbt-sbc-decoder",
225 "libbt-sbc-encoder",
226 "libbt-stack",
227 "libbt-utils",
228 "libbtcore",
229 "libbtdevice",
230 "libbte",
231 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000232 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000233 "libevent",
234 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900235 "libg722codec",
236 "libgtest_prod",
237 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900238 "libmedia_headers",
239 "libmodpb64",
240 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000241 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 "libstagefright_foundation_headers",
244 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000245 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900246 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000247 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900248 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000249 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900250 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900251 "net-utils-services-common",
252 "netd_aidl_interface-unstable-java",
253 "netd_event_listener_interface-java",
254 "netlink-client",
255 "networkstack-aidl-interfaces-unstable-java",
256 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900257 "sap-api-java-static",
258 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000259 }
260 //
261 // Module separator
262 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900263 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000264 //
265 // Module separator
266 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900268 "boringssl_self_test",
Jiyong Park0f80c182020-01-31 02:49:53 +0900269 "libnativehelper_header_only",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900270 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 }
272 //
273 // Module separator
274 //
275 m["com.android.extservices"] = []string{
276 "flatbuffer_headers",
277 "liblua",
278 "libtextclassifier",
279 "libtextclassifier_hash_static",
280 "libtflite_static",
281 "libutf",
282 "libz_current",
283 "tensorflow_headers",
284 }
285 //
286 // Module separator
287 //
288 m["com.android.cronet"] = []string{
289 "cronet_impl_common_java",
290 "cronet_impl_native_java",
291 "cronet_impl_platform_java",
292 "libcronet.80.0.3986.0",
293 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900294 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 "prebuilt_libcronet.80.0.3986.0",
296 }
297 //
298 // Module separator
299 //
300 m["com.android.neuralnetworks"] = []string{
301 "android.hardware.neuralnetworks@1.0",
302 "android.hardware.neuralnetworks@1.1",
303 "android.hardware.neuralnetworks@1.2",
304 "android.hardware.neuralnetworks@1.3",
305 "android.hidl.allocator@1.0",
306 "android.hidl.memory.token@1.0",
307 "android.hidl.memory@1.0",
308 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900309 "gemmlowp_headers",
310 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900311 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900312 "libeigen",
313 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900314 "libmath",
315 "libneuralnetworks_common",
316 "libneuralnetworks_headers",
317 "libprocessgroup",
318 "libprocessgroup_headers",
319 "libprocpartition",
320 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900321 "libtextclassifier_hash",
322 "libtextclassifier_hash_headers",
323 "libtextclassifier_hash_static",
324 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900325 "philox_random",
326 "philox_random_headers",
327 "tensorflow_headers",
328 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000329 //
330 // Module separator
331 //
332 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000333 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900334 "android.hardware.cas.native@1.0",
335 "android.hardware.cas@1.0",
336 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000337 "android.hardware.configstore@1.0",
338 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000339 "android.hardware.graphics.allocator@2.0",
340 "android.hardware.graphics.allocator@3.0",
341 "android.hardware.graphics.bufferqueue@1.0",
342 "android.hardware.graphics.bufferqueue@2.0",
343 "android.hardware.graphics.common@1.0",
344 "android.hardware.graphics.common@1.1",
345 "android.hardware.graphics.common@1.2",
346 "android.hardware.graphics.mapper@2.0",
347 "android.hardware.graphics.mapper@2.1",
348 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900349 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000350 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900351 "android.hidl.allocator@1.0",
352 "android.hidl.memory.token@1.0",
353 "android.hidl.memory@1.0",
354 "android.hidl.token@1.0",
355 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900356 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900357 "gl_headers",
358 "libEGL",
359 "libEGL_blobCache",
360 "libEGL_getProcAddress",
361 "libFLAC",
362 "libFLAC-config",
363 "libFLAC-headers",
364 "libGLESv2",
365 "libaacextractor",
366 "libamrextractor",
367 "libarect",
368 "libasync_safe",
369 "libaudio_system_headers",
370 "libaudioclient",
371 "libaudioclient_headers",
372 "libaudiofoundation",
373 "libaudiofoundation_headers",
374 "libaudiomanager",
375 "libaudiopolicy",
376 "libaudioutils",
377 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900378 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900379 "libbluetooth-types-header",
380 "libbufferhub",
381 "libbufferhub_headers",
382 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900383 "libc_malloc_debug_backtrace",
384 "libcamera_client",
385 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900386 "libdexfile_external_headers",
387 "libdexfile_support",
388 "libdvr_headers",
389 "libexpat",
390 "libfifo",
391 "libflacextractor",
392 "libgrallocusage",
393 "libgraphicsenv",
394 "libgui",
395 "libgui_headers",
396 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900397 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900398 "liblzma",
399 "libmath",
400 "libmedia",
401 "libmedia_codeclist",
402 "libmedia_headers",
403 "libmedia_helper",
404 "libmedia_helper_headers",
405 "libmedia_midiiowrapper",
406 "libmedia_omx",
407 "libmediautils",
408 "libmidiextractor",
409 "libmkvextractor",
410 "libmp3extractor",
411 "libmp4extractor",
412 "libmpeg2extractor",
413 "libnativebase_headers",
414 "libnativebridge-headers",
415 "libnativebridge_lazy",
416 "libnativeloader-headers",
417 "libnativeloader_lazy",
418 "libnativewindow_headers",
419 "libnblog",
420 "liboggextractor",
421 "libpackagelistparser",
422 "libpcre2",
423 "libpdx",
424 "libpdx_default_transport",
425 "libpdx_headers",
426 "libpdx_uds",
427 "libprocessgroup",
428 "libprocessgroup_headers",
429 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900430 "libsonivox",
431 "libspeexresampler",
432 "libspeexresampler",
433 "libstagefright_esds",
434 "libstagefright_flacdec",
435 "libstagefright_flacdec",
436 "libstagefright_foundation",
437 "libstagefright_foundation_headers",
438 "libstagefright_foundation_without_imemory",
439 "libstagefright_headers",
440 "libstagefright_id3",
441 "libstagefright_metadatautils",
442 "libstagefright_mpeg2extractor",
443 "libstagefright_mpeg2support",
444 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900445 "libui",
446 "libui_headers",
447 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900448 "libvibrator",
449 "libvorbisidec",
450 "libwavextractor",
451 "libwebm",
452 "media_ndk_headers",
453 "media_plugin_headers",
454 "updatable-media",
455 }
456 //
457 // Module separator
458 //
459 m["com.android.media.swcodec"] = []string{
460 "android.frameworks.bufferhub@1.0",
461 "android.hardware.common-ndk_platform",
462 "android.hardware.configstore-utils",
463 "android.hardware.configstore@1.0",
464 "android.hardware.configstore@1.1",
465 "android.hardware.graphics.allocator@2.0",
466 "android.hardware.graphics.allocator@3.0",
467 "android.hardware.graphics.bufferqueue@1.0",
468 "android.hardware.graphics.bufferqueue@2.0",
469 "android.hardware.graphics.common-ndk_platform",
470 "android.hardware.graphics.common@1.0",
471 "android.hardware.graphics.common@1.1",
472 "android.hardware.graphics.common@1.2",
473 "android.hardware.graphics.mapper@2.0",
474 "android.hardware.graphics.mapper@2.1",
475 "android.hardware.graphics.mapper@3.0",
476 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000477 "android.hardware.media.bufferpool@2.0",
478 "android.hardware.media.c2@1.0",
479 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900480 "android.hardware.media@1.0",
481 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000482 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900483 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000484 "android.hidl.safe_union@1.0",
485 "android.hidl.token@1.0",
486 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900487 "libEGL",
488 "libFLAC",
489 "libFLAC-config",
490 "libFLAC-headers",
491 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900492 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900493 "libarect",
494 "libasync_safe",
495 "libaudio_system_headers",
496 "libaudioutils",
497 "libaudioutils",
498 "libaudioutils_fixedfft",
499 "libavcdec",
500 "libavcenc",
501 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000502 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900503 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900504 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900505 "libbluetooth-types-header",
506 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900507 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000508 "libcap",
509 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900510 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000511 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900512 "libcodec2_hidl@1.1",
513 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000514 "libcodec2_soft_aacdec",
515 "libcodec2_soft_aacenc",
516 "libcodec2_soft_amrnbdec",
517 "libcodec2_soft_amrnbenc",
518 "libcodec2_soft_amrwbdec",
519 "libcodec2_soft_amrwbenc",
520 "libcodec2_soft_av1dec_gav1",
521 "libcodec2_soft_avcdec",
522 "libcodec2_soft_avcenc",
523 "libcodec2_soft_common",
524 "libcodec2_soft_flacdec",
525 "libcodec2_soft_flacenc",
526 "libcodec2_soft_g711alawdec",
527 "libcodec2_soft_g711mlawdec",
528 "libcodec2_soft_gsmdec",
529 "libcodec2_soft_h263dec",
530 "libcodec2_soft_h263enc",
531 "libcodec2_soft_hevcdec",
532 "libcodec2_soft_hevcenc",
533 "libcodec2_soft_mp3dec",
534 "libcodec2_soft_mpeg2dec",
535 "libcodec2_soft_mpeg4dec",
536 "libcodec2_soft_mpeg4enc",
537 "libcodec2_soft_opusdec",
538 "libcodec2_soft_opusenc",
539 "libcodec2_soft_rawdec",
540 "libcodec2_soft_vorbisdec",
541 "libcodec2_soft_vp8dec",
542 "libcodec2_soft_vp8enc",
543 "libcodec2_soft_vp9dec",
544 "libcodec2_soft_vp9enc",
545 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000546 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900547 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000548 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900549 "libfmq",
550 "libgav1",
551 "libgralloctypes",
552 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000553 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900554 "libgsm",
555 "libgui_bufferqueue_static",
556 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000557 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900558 "libhardware_headers",
559 "libhevcdec",
560 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000561 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000563 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900564 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000565 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900566 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000567 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900568 "libminijail_gen_constants",
569 "libminijail_gen_constants_obj",
570 "libminijail_gen_syscall",
571 "libminijail_gen_syscall_obj",
572 "libminijail_generated",
573 "libmpeg2dec",
574 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000575 "libnativebridge_lazy",
576 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900577 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000578 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900579 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000580 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000582 "libscudo_wrapper",
583 "libsfplugin_ccodec_utils",
584 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900585 "libstagefright_amrnbdec",
586 "libstagefright_amrnbenc",
587 "libstagefright_amrwbdec",
588 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000589 "libstagefright_bufferpool@2.0.1",
590 "libstagefright_bufferqueue_helper",
591 "libstagefright_enc_common",
592 "libstagefright_flacdec",
593 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libstagefright_foundation_headers",
595 "libstagefright_headers",
596 "libstagefright_m4vh263dec",
597 "libstagefright_m4vh263enc",
598 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000599 "libsync",
600 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900601 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000602 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000603 "libvorbisidec",
604 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 "libyuv",
606 "libyuv_static",
607 "media_ndk_headers",
608 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000609 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900610 }
611 //
612 // Module separator
613 //
614 m["com.android.mediaprovider"] = []string{
615 "MediaProvider",
616 "MediaProviderGoogle",
617 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900618 "libbase_ndk",
619 "libfuse",
620 "libfuse_jni",
621 "libnativehelper_header_only",
622 }
623 //
624 // Module separator
625 //
626 m["com.android.permission"] = []string{
627 "androidx.annotation_annotation",
628 "androidx.annotation_annotation-nodeps",
629 "androidx.lifecycle_lifecycle-common",
630 "androidx.lifecycle_lifecycle-common-java8",
631 "androidx.lifecycle_lifecycle-common-java8-nodeps",
632 "androidx.lifecycle_lifecycle-common-nodeps",
633 "kotlin-annotations",
634 "kotlin-stdlib",
635 "kotlin-stdlib-jdk7",
636 "kotlin-stdlib-jdk8",
637 "kotlinx-coroutines-android",
638 "kotlinx-coroutines-android-nodeps",
639 "kotlinx-coroutines-core",
640 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900641 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000642 }
643 //
644 // Module separator
645 //
646 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900648 "libarm-optimized-routines-math",
649 "libasync_safe",
650 "libasync_safe_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900651 "libc_aeabi",
652 "libc_bionic",
653 "libc_bionic_ndk",
654 "libc_bootstrap",
655 "libc_common",
656 "libc_common_shared",
657 "libc_common_static",
658 "libc_dns",
659 "libc_dynamic_dispatch",
660 "libc_fortify",
661 "libc_freebsd",
662 "libc_freebsd_large_stack",
663 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900664 "libc_init_dynamic",
665 "libc_init_static",
666 "libc_jemalloc_wrapper",
667 "libc_netbsd",
668 "libc_nomalloc",
669 "libc_nopthread",
670 "libc_openbsd",
671 "libc_openbsd_large_stack",
672 "libc_openbsd_ndk",
673 "libc_pthread",
674 "libc_static_dispatch",
675 "libc_syscalls",
676 "libc_tzcode",
677 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900678 "libdebuggerd",
679 "libdebuggerd_common_headers",
680 "libdebuggerd_handler_core",
681 "libdebuggerd_handler_fallback",
682 "libdexfile_external_headers",
683 "libdexfile_support",
684 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900685 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900686 "libgtest_prod",
687 "libjemalloc5",
688 "liblinker_main",
689 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900690 "liblz4",
691 "liblzma",
692 "libprocessgroup_headers",
693 "libprocinfo",
694 "libpropertyinfoparser",
695 "libscudo",
696 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900697 "libsystemproperties",
698 "libtombstoned_client_static",
699 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900700 "libz",
701 "libziparchive",
702 }
703 //
704 // Module separator
705 //
706 m["com.android.resolv"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Park0f80c182020-01-31 02:49:53 +0900708 "libgtest_prod",
Jiyong Park0f80c182020-01-31 02:49:53 +0900709 "libnativehelper_header_only",
710 "libnetd_client_headers",
711 "libnetd_resolv",
712 "libnetdutils",
713 "libprocessgroup",
714 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900715 "libstatslog_resolv",
716 "libstatspush_compat",
717 "libstatssocket",
718 "libstatssocket_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900719 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900720 "netd_event_listener_interface-ndk_platform",
721 "server_configurable_flags",
722 "stats_proto",
723 }
724 //
725 // Module separator
726 //
727 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900728 "libnativehelper_compat_libc++",
729 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900730 "libcgrouprc",
731 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900732 "libprocessgroup",
733 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900734 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900735 "libvndksupport",
736 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000737 }
738 //
739 // Module separator
740 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900741 m["com.android.wifi"] = []string{
742 "PlatformProperties",
743 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900744 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900745 "android.hardware.wifi-V1.1-java",
746 "android.hardware.wifi-V1.2-java",
747 "android.hardware.wifi-V1.3-java",
748 "android.hardware.wifi-V1.4-java",
749 "android.hardware.wifi.hostapd-V1.0-java",
750 "android.hardware.wifi.hostapd-V1.1-java",
751 "android.hardware.wifi.hostapd-V1.2-java",
752 "android.hardware.wifi.supplicant-V1.0-java",
753 "android.hardware.wifi.supplicant-V1.1-java",
754 "android.hardware.wifi.supplicant-V1.2-java",
755 "android.hardware.wifi.supplicant-V1.3-java",
756 "android.hidl.base-V1.0-java",
757 "android.hidl.manager-V1.0-java",
758 "android.hidl.manager-V1.1-java",
759 "android.hidl.manager-V1.2-java",
760 "androidx.annotation_annotation",
761 "androidx.annotation_annotation-nodeps",
762 "bouncycastle-unbundled",
763 "dnsresolver_aidl_interface-V2-java",
764 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900765 "framework-wifi-pre-jarjar",
766 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900767 "ipmemorystore-aidl-interfaces-V3-java",
768 "ipmemorystore-aidl-interfaces-java",
769 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900770 "libnanohttpd",
771 "libprocessgroup",
772 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900773 "libwifi-jni",
774 "net-utils-services-common",
775 "netd_aidl_interface-V2-java",
776 "netd_aidl_interface-unstable-java",
777 "netd_event_listener_interface-java",
778 "netlink-client",
779 "networkstack-aidl-interfaces-unstable-java",
780 "networkstack-client",
781 "services.net",
782 "wifi-lite-protos",
783 "wifi-nano-protos",
784 "wifi-service-pre-jarjar",
785 "wifi-service-resources",
786 "prebuilt_androidx.annotation_annotation-nodeps",
787 }
788 //
789 // Module separator
790 //
791 m["com.android.sdkext"] = []string{
792 "fmtlib_ndk",
793 "libbase_ndk",
794 "libprotobuf-cpp-lite-ndk",
795 }
796 //
797 // Module separator
798 //
799 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900800 "libprocessgroup_headers",
801 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900802 }
803 //
804 // Module separator
805 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000806 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900807 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900808 "libclang_rt",
809 "libgcc_stripped",
810 "libprofile-clang-extras",
811 "libprofile-clang-extras_ndk",
812 "libprofile-extras",
813 "libprofile-extras_ndk",
814 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900815 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000816 return m
817}
818
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900819func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900820 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800821 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900822 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900823 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700824 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900825 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900826
Jooyung Han31c470b2019-10-18 16:26:59 +0900827 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900828 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900829
830 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
831 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
832 sort.Strings(*apexFileContextsInfos)
833 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
834 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900835}
836
Jooyung Han31c470b2019-10-18 16:26:59 +0900837func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
838 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
839 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
840}
841
Jiyong Parkd1063c12019-07-17 20:08:41 +0900842func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900843 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900844 ctx.BottomUp("apex", apexMutator).Parallel()
845 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
846 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900847}
848
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900849// Mark the direct and transitive dependencies of apex bundles so that they
850// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900851func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800852 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900853 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000854 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han5e9013b2020-03-10 06:23:13 +0900855 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han5417f772020-03-12 18:37:20 +0900856 ApexName: mctx.ModuleName(),
857 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900858 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900859 directDep = true
860 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800861 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900862 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900863 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900864
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800865 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900866 return
867 }
868
Paul Duffin923e8a52020-03-30 15:33:32 +0100869 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900870
Jiyong Parkf760cae2020-02-12 07:53:12 +0900871 mctx.VisitDirectDeps(func(child android.Module) {
872 depName := mctx.OtherModuleName(child)
873 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100874 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800875 android.UpdateApexDependency(apexBundles, depName, directDep)
876 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900877 }
878 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900879}
880
Paul Duffin65347702020-03-31 15:23:40 +0100881// If a module in an APEX depends on a module from an SDK then it needs an APEX
882// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
883func inAnySdk(module android.Module) bool {
884 if sa, ok := module.(android.SdkAware); ok {
885 return sa.IsInAnySdk()
886 }
887
888 return false
889}
890
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900891// Create apex variations if a module is included in APEX(s).
892func apexMutator(mctx android.BottomUpMutatorContext) {
893 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900894 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000895 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900896 // apex bundle itself is mutated so that it and its modules have same
897 // apex variant.
898 apexBundleName := mctx.ModuleName()
899 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900900 } else if o, ok := mctx.Module().(*OverrideApex); ok {
901 apexBundleName := o.GetOverriddenModuleName()
902 if apexBundleName == "" {
903 mctx.ModuleErrorf("base property is not set")
904 return
905 }
906 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900907 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900908
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900909}
Sundong Ahne9b55722019-09-06 17:37:42 +0900910
Jooyung Han7a78a922019-10-08 21:59:58 +0900911var (
912 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
913 apexFileContextsInfosMutex sync.Mutex
914)
915
916func apexFileContextsInfos(config android.Config) *[]string {
917 return config.Once(apexFileContextsInfosKey, func() interface{} {
918 return &[]string{}
919 }).(*[]string)
920}
921
Jooyung Han54aca7b2019-11-20 02:26:02 +0900922func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900923 apexFileContextsInfosMutex.Lock()
924 defer apexFileContextsInfosMutex.Unlock()
925 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900926 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900927}
928
Sundong Ahne9b55722019-09-06 17:37:42 +0900929func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900930 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900931 var variants []string
932 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
933 case "image":
934 variants = append(variants, imageApexType, flattenedApexType)
935 case "zip":
936 variants = append(variants, zipApexType)
937 case "both":
938 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
939 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900940 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900941 return
942 }
943
944 modules := mctx.CreateLocalVariations(variants...)
945
946 for i, v := range variants {
947 switch v {
948 case imageApexType:
949 modules[i].(*apexBundle).properties.ApexType = imageApex
950 case zipApexType:
951 modules[i].(*apexBundle).properties.ApexType = zipApex
952 case flattenedApexType:
953 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900954 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900955 modules[i].(*apexBundle).MakeAsSystemExt()
956 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900957 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900958 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900959 } else if _, ok := mctx.Module().(*OverrideApex); ok {
960 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900961 }
962}
963
Jooyung Han5c998b92019-06-27 11:30:33 +0900964func apexUsesMutator(mctx android.BottomUpMutatorContext) {
965 if ab, ok := mctx.Module().(*apexBundle); ok {
966 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
967 }
968}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900969
Jooyung Handc782442019-11-01 03:14:38 +0900970var (
971 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
972)
973
974// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
975// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
976// which may cause compatibility issues. (e.g. libbinder)
977// Even though libbinder restricts its availability via 'apex_available' property and relies on
978// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
979// to avoid similar problems.
980func useVendorWhitelist(config android.Config) []string {
981 return config.Once(useVendorWhitelistKey, func() interface{} {
982 return []string{
983 // swcodec uses "vendor" variants for smaller size
984 "com.android.media.swcodec",
985 "test_com.android.media.swcodec",
986 }
987 }).([]string)
988}
989
990// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
991// called before the first call to useVendorWhitelist()
992func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
993 config.Once(useVendorWhitelistKey, func() interface{} {
994 return whitelist
995 })
996}
997
Jooyung Han01a868d2020-02-27 13:40:44 +0900998type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800999 // List of native libraries
1000 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001001
Jooyung Han643adc42020-02-27 13:50:06 +09001002 // List of JNI libraries
1003 Jni_libs []string
1004
Alex Light9670d332019-01-29 18:07:33 -08001005 // List of native executables
1006 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001007
Roland Levillain630846d2019-06-26 12:48:34 +01001008 // List of native tests
1009 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001010}
Jooyung Han344d5432019-08-23 11:17:39 +09001011
Alex Light9670d332019-01-29 18:07:33 -08001012type apexMultilibProperties struct {
1013 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001014 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001015
1016 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001017 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001018
1019 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001020 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001021
1022 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001023 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001024
1025 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001026 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001027}
1028
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001029type apexBundleProperties struct {
1030 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001031 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001032 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001033
Jiyong Park40e26a22019-02-08 02:53:06 +09001034 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1035 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001036 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001037
Roland Levillain411c5842019-09-19 16:37:20 +01001038 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1039 // device (/apex/<apex_name>).
1040 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001041 Apex_name *string
1042
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001043 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001044 // For platform APEXes, this should points to a file under /system/sepolicy
1045 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1046 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001047
Jooyung Han01a868d2020-02-27 13:40:44 +09001048 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001049
1050 // List of java libraries that are embedded inside this APEX bundle
1051 Java_libs []string
1052
1053 // List of prebuilt files that are embedded inside this APEX bundle
1054 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001055
1056 // Name of the apex_key module that provides the private key to sign APEX
1057 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001058
Alex Light5098a612018-11-29 17:12:15 -08001059 // The type of APEX to build. Controls what the APEX payload is. Either
1060 // 'image', 'zip' or 'both'. Default: 'image'.
1061 Payload_type *string
1062
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001063 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1064 // or an android_app_certificate module name in the form ":module".
1065 Certificate *string
1066
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001067 // Whether this APEX is installable to one of the partitions. Default: true.
1068 Installable *bool
1069
Jiyong Parkda6eb592018-12-19 17:12:36 +09001070 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1071 // Default is false.
1072 Use_vendor *bool
1073
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001074 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1075 Ignore_system_library_special_case *bool
1076
Alex Light9670d332019-01-29 18:07:33 -08001077 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001078
Jiyong Parkf97782b2019-02-13 20:28:58 +09001079 // List of sanitizer names that this APEX is enabled for
1080 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001081
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001082 PreventInstall bool `blueprint:"mutated"`
1083
1084 HideFromMake bool `blueprint:"mutated"`
1085
Jooyung Han5c998b92019-06-27 11:30:33 +09001086 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1087 Provide_cpp_shared_libs *bool
1088
1089 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1090 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001091
1092 // A txt file containing list of files that are whitelisted to be included in this APEX.
1093 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001094
Sundong Ahnabb64432019-10-22 13:58:29 +09001095 // package format of this apex variant; could be non-flattened, flattened, or zip.
1096 // imageApex, zipApex or flattened
1097 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001098
Jiyong Parkd1063c12019-07-17 20:08:41 +09001099 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1100 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1101 // is implied. This value affects all modules included in this APEX. In other words, they are
1102 // also built with the SDKs specified here.
1103 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001104
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001105 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1106 // Should be only used in tests#.
1107 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001108
Jiyong Park956305c2020-01-09 12:32:06 +09001109 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001110
1111 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1112 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1113 // like symlinking to the system libs. Default is false.
1114 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001115
1116 // The minimum SDK version that this apex must be compatibile with.
1117 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001118}
1119
1120type apexTargetBundleProperties struct {
1121 Target struct {
1122 // Multilib properties only for android.
1123 Android struct {
1124 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001125 }
Jooyung Han344d5432019-08-23 11:17:39 +09001126
Alex Light9670d332019-01-29 18:07:33 -08001127 // Multilib properties only for host.
1128 Host struct {
1129 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001130 }
Jooyung Han344d5432019-08-23 11:17:39 +09001131
Alex Light9670d332019-01-29 18:07:33 -08001132 // Multilib properties only for host linux_bionic.
1133 Linux_bionic struct {
1134 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001135 }
Jooyung Han344d5432019-08-23 11:17:39 +09001136
Alex Light9670d332019-01-29 18:07:33 -08001137 // Multilib properties only for host linux_glibc.
1138 Linux_glibc struct {
1139 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001140 }
1141 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001142}
1143
Jiyong Park5d790c32019-11-15 18:40:32 +09001144type overridableProperties struct {
1145 // List of APKs to package inside APEX
1146 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001147
1148 // Names of modules to be overridden. Listed modules can only be other binaries
1149 // (in Make or Soong).
1150 // This does not completely prevent installation of the overridden binaries, but if both
1151 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1152 // from PRODUCT_PACKAGES.
1153 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001154
1155 // Logging Parent value
1156 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001157
1158 // Apex Container Package Name.
1159 // Override value for attribute package:name in AndroidManifest.xml
1160 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001161}
1162
Alex Light5098a612018-11-29 17:12:15 -08001163type apexPackaging int
1164
1165const (
1166 imageApex apexPackaging = iota
1167 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001168 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001169)
1170
Sundong Ahnabb64432019-10-22 13:58:29 +09001171// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001172func (a apexPackaging) suffix() string {
1173 switch a {
1174 case imageApex:
1175 return imageApexSuffix
1176 case zipApex:
1177 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001178 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001179 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001180 }
1181}
1182
1183func (a apexPackaging) name() string {
1184 switch a {
1185 case imageApex:
1186 return imageApexType
1187 case zipApex:
1188 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001189 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001190 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001191 }
1192}
1193
Jiyong Parkf653b052019-11-18 15:39:01 +09001194type apexFileClass int
1195
1196const (
1197 etc apexFileClass = iota
1198 nativeSharedLib
1199 nativeExecutable
1200 shBinary
1201 pyBinary
1202 goBinary
1203 javaSharedLib
1204 nativeTest
1205 app
1206)
1207
Jiyong Park8fd61922018-11-08 02:50:25 +09001208func (class apexFileClass) NameInMake() string {
1209 switch class {
1210 case etc:
1211 return "ETC"
1212 case nativeSharedLib:
1213 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001214 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001215 return "EXECUTABLES"
1216 case javaSharedLib:
1217 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001218 case nativeTest:
1219 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001220 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001221 // b/142537672 Why isn't this APP? We want to have full control over
1222 // the paths and file names of the apk file under the flattend APEX.
1223 // If this is set to APP, then the paths and file names are modified
1224 // by the Make build system. For example, it is installed to
1225 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1226 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1227 // appends module name (which is <apexname>.<Appname> to the path.
1228 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001229 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001230 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001231 }
1232}
1233
Jiyong Parkf653b052019-11-18 15:39:01 +09001234// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001235type apexFile struct {
1236 builtFile android.Path
1237 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001238 installDir string
1239 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001240 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001241 // list of symlinks that will be created in installDir that point to this apexFile
1242 symlinks []string
1243 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001244 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001245
1246 requiredModuleNames []string
1247 targetRequiredModuleNames []string
1248 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001249
Colin Cross503c1d02020-01-28 14:00:53 -08001250 jacocoReportClassesFile android.Path // only for javalibs and apps
1251 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001252 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001253
1254 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001255}
1256
Jiyong Park1833cef2019-12-13 13:28:36 +09001257func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1258 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001259 builtFile: builtFile,
1260 moduleName: moduleName,
1261 installDir: installDir,
1262 class: class,
1263 module: module,
1264 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001265 if module != nil {
1266 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001267 ret.requiredModuleNames = module.RequiredModuleNames()
1268 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1269 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001270 }
1271 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001272}
1273
1274func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001275 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001276}
1277
Jiyong Park7cd10e32020-01-14 09:22:18 +09001278// Path() returns path of this apex file relative to the APEX root
1279func (af *apexFile) Path() string {
1280 return filepath.Join(af.installDir, af.builtFile.Base())
1281}
1282
1283// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1284func (af *apexFile) SymlinkPaths() []string {
1285 var ret []string
1286 for _, symlink := range af.symlinks {
1287 ret = append(ret, filepath.Join(af.installDir, symlink))
1288 }
1289 return ret
1290}
1291
1292func (af *apexFile) AvailableToPlatform() bool {
1293 if af.module == nil {
1294 return false
1295 }
1296 if am, ok := af.module.(android.ApexModule); ok {
1297 return am.AvailableFor(android.AvailableToPlatform)
1298 }
1299 return false
1300}
1301
Jiyong Park678c8812020-02-07 17:25:49 +09001302type depInfo struct {
1303 to string
1304 from []string
1305 isExternal bool
1306}
1307
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001308type apexBundle struct {
1309 android.ModuleBase
1310 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001311 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001312 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001313
Jiyong Park5d790c32019-11-15 18:40:32 +09001314 properties apexBundleProperties
1315 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001316 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001317
Jooyung Hanf21c7972019-12-16 22:32:06 +09001318 // specific to apex_vndk modules
1319 vndkProperties apexVndkProperties
1320
Colin Crossa4925902018-11-16 11:36:28 -08001321 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001322 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001323 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001324
Jiyong Park03b68dd2019-07-26 23:20:40 +09001325 prebuiltFileToDelete string
1326
Jiyong Park42cca6c2019-04-01 11:15:50 +09001327 public_key_file android.Path
1328 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001329
1330 container_certificate_file android.Path
1331 container_private_key_file android.Path
1332
Jooyung Han54aca7b2019-11-20 02:26:02 +09001333 fileContexts android.Path
1334
Jiyong Park8fd61922018-11-08 02:50:25 +09001335 // list of files to be included in this apex
1336 filesInfo []apexFile
1337
Jiyong Park956305c2020-01-09 12:32:06 +09001338 // list of module names that should be installed along with this APEX
1339 requiredDeps []string
1340
Jiyong Park956305c2020-01-09 12:32:06 +09001341 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001342 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001343
Sundong Ahnabb64432019-10-22 13:58:29 +09001344 testApex bool
1345 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001346 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001347 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001348
Jooyung Han214bf372019-11-12 13:03:50 +09001349 manifestJsonOut android.WritablePath
1350 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001351
Jooyung Han002ab682020-01-08 01:57:58 +09001352 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001353 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001354 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001355 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1356 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001357
1358 // Suffix of module name in Android.mk
1359 // ".flattened", ".apex", ".zipapex", or ""
1360 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001361
1362 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001363
1364 // Whether to create symlink to the system file instead of having a file
1365 // inside the apex or not
1366 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001367
1368 // Struct holding the merged notice file paths in different formats
1369 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001370}
1371
Jiyong Park397e55e2018-10-24 21:09:55 +09001372func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001373 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001374 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001375 // Use *FarVariation* to be able to depend on modules having
1376 // conflicting variations with this module. This is required since
1377 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1378 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001379 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001380 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001381 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001382 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001383 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001384
Jooyung Han643adc42020-02-27 13:50:06 +09001385 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1386 {Mutator: "image", Variation: imageVariation},
1387 {Mutator: "link", Variation: "shared"},
1388 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1389 }...), jniLibTag, nativeModules.Jni_libs...)
1390
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001391 ctx.AddFarVariationDependencies(append(target.Variations(),
1392 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001393 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001394
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001395 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001396 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001397 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001398 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001399}
1400
Alex Light9670d332019-01-29 18:07:33 -08001401func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1402 if ctx.Os().Class == android.Device {
1403 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1404 } else {
1405 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1406 if ctx.Os().Bionic() {
1407 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1408 } else {
1409 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1410 }
1411 }
1412}
1413
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001414func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001415 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1416 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1417 }
1418
Jiyong Park397e55e2018-10-24 21:09:55 +09001419 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001420 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001421
1422 a.combineProperties(ctx)
1423
Jiyong Park397e55e2018-10-24 21:09:55 +09001424 has32BitTarget := false
1425 for _, target := range targets {
1426 if target.Arch.ArchType.Multilib == "lib32" {
1427 has32BitTarget = true
1428 }
1429 }
1430 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001431 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001432 // multilib.both
1433 addDependenciesForNativeModules(ctx,
1434 ApexNativeDependencies{
1435 Native_shared_libs: a.properties.Native_shared_libs,
1436 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001437 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001438 Binaries: nil,
1439 },
1440 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001441
Jiyong Park397e55e2018-10-24 21:09:55 +09001442 // Add native modules targetting both ABIs
1443 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001444 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001445 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001446 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001447
Alex Light3d673592019-01-18 14:37:31 -08001448 isPrimaryAbi := i == 0
1449 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001450 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001451 // multilib.first
1452 addDependenciesForNativeModules(ctx,
1453 ApexNativeDependencies{
1454 Native_shared_libs: nil,
1455 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001456 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001457 Binaries: a.properties.Binaries,
1458 },
1459 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001460
1461 // Add native modules targetting the first ABI
1462 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001463 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001464 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001465 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001466 }
1467
1468 switch target.Arch.ArchType.Multilib {
1469 case "lib32":
1470 // Add native modules targetting 32-bit ABI
1471 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001472 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001473 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001474 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001475
1476 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001477 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001478 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001479 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001480 case "lib64":
1481 // Add native modules targetting 64-bit ABI
1482 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001483 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001484 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001485 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001486
1487 if !has32BitTarget {
1488 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001489 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001490 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001491 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001492 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001493
1494 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1495 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1496 if sanitizer == "hwaddress" {
1497 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001498 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001499 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001500 break
1501 }
1502 }
1503 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001504 }
1505
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001506 }
1507
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001508 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1509 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1510 // b/144532908
1511 archForPrebuiltEtc := config.Arches()[0]
1512 for _, arch := range config.Arches() {
1513 // Prefer 64-bit arch if there is any
1514 if arch.ArchType.Multilib == "lib64" {
1515 archForPrebuiltEtc = arch
1516 break
1517 }
1518 }
1519 ctx.AddFarVariationDependencies([]blueprint.Variation{
1520 {Mutator: "os", Variation: ctx.Os().String()},
1521 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1522 }, prebuiltTag, a.properties.Prebuilts...)
1523
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001524 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1525 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001526
Ulya Trafimovich44561882020-01-03 13:25:54 +00001527 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1528 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1529 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1530 javaLibTag, "jacocoagent")
1531 }
1532
Jiyong Park23c52b02019-02-02 13:13:47 +09001533 if String(a.properties.Key) == "" {
1534 ctx.ModuleErrorf("key is missing")
1535 return
1536 }
1537 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001538
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001539 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001540 if cert != "" {
1541 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001542 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001543
1544 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1545 if len(a.properties.Uses_sdks) > 0 {
1546 sdkRefs := []android.SdkRef{}
1547 for _, str := range a.properties.Uses_sdks {
1548 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1549 sdkRefs = append(sdkRefs, parsed)
1550 }
1551 a.BuildWithSdks(sdkRefs)
1552 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001553}
1554
Jiyong Park5d790c32019-11-15 18:40:32 +09001555func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1556 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1557 androidAppTag, a.overridableProperties.Apps...)
1558}
1559
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001560func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1561 // direct deps of an APEX bundle are all part of the APEX bundle
1562 return true
1563}
1564
Colin Cross0ea8ba82019-06-06 14:33:29 -07001565func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001566 moduleName := ctx.ModuleName()
1567 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1568 // we check with the pseudo module name to see if its certificate is overridden.
1569 if a.vndkApex {
1570 moduleName = vndkApexName
1571 }
1572 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001573 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001574 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001575 }
1576 return String(a.properties.Certificate)
1577}
1578
Colin Cross41955e82019-05-29 14:40:35 -07001579func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1580 switch tag {
1581 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001582 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001583 default:
1584 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001585 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001586}
1587
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001588func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001589 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001590}
1591
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001592func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1593 return proptools.Bool(a.properties.Test_only_no_hashtree)
1594}
1595
Jiyong Park7c1dc612019-01-05 11:15:24 +09001596func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001597 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001598 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001599 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001600 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001601 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001602 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001603 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001604 }
1605}
1606
Jiyong Parkf97782b2019-02-13 20:28:58 +09001607func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1608 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1609 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1610 }
1611}
1612
Jiyong Park388ef3f2019-01-28 19:47:32 +09001613func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001614 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1615 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001616 }
1617
1618 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001619 globalSanitizerNames := []string{}
1620 if a.Host() {
1621 globalSanitizerNames = ctx.Config().SanitizeHost()
1622 } else {
1623 arches := ctx.Config().SanitizeDeviceArch()
1624 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1625 globalSanitizerNames = ctx.Config().SanitizeDevice()
1626 }
1627 }
1628 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001629}
1630
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001631func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001632 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001633}
1634
1635func (a *apexBundle) PreventInstall() {
1636 a.properties.PreventInstall = true
1637}
1638
1639func (a *apexBundle) HideFromMake() {
1640 a.properties.HideFromMake = true
1641}
1642
Jiyong Park956305c2020-01-09 12:32:06 +09001643func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1644 a.properties.IsCoverageVariant = coverage
1645}
1646
Jiyong Parkf653b052019-11-18 15:39:01 +09001647// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001648func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001649 // Decide the APEX-local directory by the multilib of the library
1650 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001651 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001652 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001653 case "lib32":
1654 dirInApex = "lib"
1655 case "lib64":
1656 dirInApex = "lib64"
1657 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001658 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001659 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001660 }
Jooyung Han35155c42020-02-06 17:33:20 +09001661 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001662 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001663 // Special case for Bionic libs and other libs installed with them. This is
1664 // to prevent those libs from being included in the search path
1665 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1666 // those libs in the Runtime APEX are available via the legacy paths in
1667 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1668 // to the legacy paths and thus will be loaded into the default linker
1669 // namespace (aka "platform" namespace). If the libs are directly in
1670 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1671 // into the runtime linker namespace, which will result in double loading of
1672 // them, which isn't supported.
1673 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001674 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001675
Jiyong Parkf653b052019-11-18 15:39:01 +09001676 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001677 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001678}
1679
Jiyong Park1833cef2019-12-13 13:28:36 +09001680func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001681 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001682 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001683 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001684 }
Jooyung Han35155c42020-02-06 17:33:20 +09001685 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001687 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 af.symlinks = cc.Symlinks()
1689 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001690}
1691
Jiyong Park1833cef2019-12-13 13:28:36 +09001692func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001693 dirInApex := "bin"
1694 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001695 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001696}
Jiyong Park1833cef2019-12-13 13:28:36 +09001697func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001698 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001699 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1700 if err != nil {
1701 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001702 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001703 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001704 fileToCopy := android.PathForOutput(ctx, s)
1705 // NB: Since go binaries are static we don't need the module for anything here, which is
1706 // good since the go tool is a blueprint.Module not an android.Module like we would
1707 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001708 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001709}
1710
Jiyong Park1833cef2019-12-13 13:28:36 +09001711func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001712 dirInApex := filepath.Join("bin", sh.SubDir())
1713 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001714 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001715 af.symlinks = sh.Symlinks()
1716 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001717}
1718
Jooyung Han58f26ab2019-12-18 15:34:32 +09001719// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1720type javaLibrary interface {
1721 android.Module
1722 java.Dependency
1723}
1724
1725func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001726 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001727 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001728 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1729 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1730 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001731}
1732
Jiyong Park1833cef2019-12-13 13:28:36 +09001733func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001734 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1735 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001736 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001737}
1738
atrost6e126252020-01-27 17:01:16 +00001739func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1740 dirInApex := filepath.Join("etc", config.SubDir())
1741 fileToCopy := config.CompatConfig()
1742 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1743}
1744
Jiyong Park1833cef2019-12-13 13:28:36 +09001745func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001746 android.Module
1747 Privileged() bool
1748 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001749 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001750 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001751}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001752 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001753 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001754 appDir = "priv-app"
1755 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001756 dirInApex := filepath.Join(appDir, pkgName)
1757 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001758 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1759 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001760 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001761
1762 if app, ok := aapp.(interface {
1763 OverriddenManifestPackageName() string
1764 }); ok {
1765 af.overriddenPackageName = app.OverriddenManifestPackageName()
1766 }
Jiyong Park618922e2020-01-08 13:35:43 +09001767 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001768}
1769
Roland Levillain935639d2019-08-13 14:55:28 +01001770// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1771type flattenedApexContext struct {
1772 android.ModuleContext
1773}
1774
1775func (c *flattenedApexContext) InstallBypassMake() bool {
1776 return true
1777}
1778
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001779// Function called while walking an APEX's payload dependencies.
1780//
1781// Return true if the `to` module should be visited, false otherwise.
1782type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1783
Jiyong Park201cedd2020-02-07 17:25:49 +09001784// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001785func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001786 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001787 am, ok := child.(android.ApexModule)
1788 if !ok || !am.CanHaveApexVariants() {
1789 return false
1790 }
1791
1792 // Check for the direct dependencies that contribute to the payload
1793 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1794 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001795 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001796 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001797 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001798 return false
1799 }
1800
1801 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001802 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001803 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001804 }
1805
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001806 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001807 })
1808}
1809
Jooyung Han03b51852020-02-26 22:45:42 +09001810func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1811 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1812 if ver != "current" {
1813 minSdkVersion, err := strconv.Atoi(ver)
1814 if err != nil {
1815 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1816 }
1817 return minSdkVersion
1818 }
1819 return android.FutureApiLevel
1820}
1821
Paul Duffinc5192442020-03-31 11:31:36 +01001822// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1823// a dependency tag.
1824var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1825
1826func PrettyPrintTag(tag blueprint.DependencyTag) string {
1827 // Use tag's custom String() method if available.
1828 if stringer, ok := tag.(fmt.Stringer); ok {
1829 return stringer.String()
1830 }
1831
1832 // Otherwise, get a default string representation of the tag's struct.
1833 tagString := fmt.Sprintf("%#v", tag)
1834
1835 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1836 tagString = tagCleaner.ReplaceAllString(tagString, "")
1837 return tagString
1838}
1839
Jiyong Park201cedd2020-02-07 17:25:49 +09001840// Ensures that the dependencies are marked as available for this APEX
1841func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1842 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1843 if ctx.Host() || a.testApex || a.vndkApex {
1844 return
1845 }
1846
Jiyong Park58d10902020-03-28 14:43:19 +09001847 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1848 // Requiring them and their transitive depencies with apex_available is not right
1849 // because they just add noise.
1850 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1851 return
1852 }
1853
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001854 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1855 if externalDep {
1856 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1857 return false
1858 }
1859
Jiyong Park201cedd2020-02-07 17:25:49 +09001860 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001861 fromName := ctx.OtherModuleName(from)
1862 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001863
1864 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1865 // do any of its dependencies.
1866 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1867 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1868 return false
1869 }
1870
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001871 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1872 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001873 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001874 message := ""
Paul Duffinc5192442020-03-31 11:31:36 +01001875 tagPath := ctx.GetTagPath()
1876 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1877 walkPath := ctx.GetWalkPath()[1:]
1878 for i, m := range walkPath {
1879 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffindf915ff2020-03-30 17:58:21 +01001880 }
1881 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001882 // Visit this module's dependencies to check and report any issues with their availability.
1883 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001884 })
1885}
1886
Jiyong Park678c8812020-02-07 17:25:49 +09001887// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1888func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1889 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001890 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001891 if from.Name() == to.Name() {
1892 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001893 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1894 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001895 }
1896
1897 if info, exists := a.depInfos[to.Name()]; exists {
1898 if !android.InList(from.Name(), info.from) {
1899 info.from = append(info.from, from.Name())
1900 }
1901 info.isExternal = info.isExternal && externalDep
1902 a.depInfos[to.Name()] = info
1903 } else {
1904 a.depInfos[to.Name()] = depInfo{
1905 to: to.Name(),
1906 from: []string{from.Name()},
1907 isExternal: externalDep,
1908 }
1909 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001910
1911 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1912 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001913 })
1914}
1915
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001916func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001917 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1918 switch a.properties.ApexType {
1919 case imageApex:
1920 if buildFlattenedAsDefault {
1921 a.suffix = imageApexSuffix
1922 } else {
1923 a.suffix = ""
1924 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001925
1926 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001927 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001928 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001929 }
1930 case zipApex:
1931 if proptools.String(a.properties.Payload_type) == "zip" {
1932 a.suffix = ""
1933 a.primaryApexType = true
1934 } else {
1935 a.suffix = zipApexSuffix
1936 }
1937 case flattenedApex:
1938 if buildFlattenedAsDefault {
1939 a.suffix = ""
1940 a.primaryApexType = true
1941 } else {
1942 a.suffix = flattenedSuffix
1943 }
Alex Light5098a612018-11-29 17:12:15 -08001944 }
1945
Roland Levillain630846d2019-06-26 12:48:34 +01001946 if len(a.properties.Tests) > 0 && !a.testApex {
1947 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1948 return
1949 }
1950
Jiyong Park0f80c182020-01-31 02:49:53 +09001951 a.checkApexAvailability(ctx)
1952
Jiyong Park678c8812020-02-07 17:25:49 +09001953 a.collectDepsInfo(ctx)
1954
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001955 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1956
Jooyung Hane1633032019-08-01 17:41:43 +09001957 // native lib dependencies
1958 var provideNativeLibs []string
1959 var requireNativeLibs []string
1960
Jooyung Han5c998b92019-06-27 11:30:33 +09001961 // Check if "uses" requirements are met with dependent apexBundles
1962 var providedNativeSharedLibs []string
1963 useVendor := proptools.Bool(a.properties.Use_vendor)
1964 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1965 if ctx.OtherModuleDependencyTag(m) != usesTag {
1966 return
1967 }
1968 otherName := ctx.OtherModuleName(m)
1969 other, ok := m.(*apexBundle)
1970 if !ok {
1971 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1972 return
1973 }
1974 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1975 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1976 return
1977 }
1978 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1979 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1980 return
1981 }
1982 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1983 })
1984
Jiyong Parkf653b052019-11-18 15:39:01 +09001985 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001986 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001987 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001988 depTag := ctx.OtherModuleDependencyTag(child)
1989 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001990 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001991 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001992 case sharedLibTag, jniLibTag:
1993 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001994 if c, ok := child.(*cc.Module); ok {
1995 // bootstrap bionic libs are treated as provided by system
1996 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1997 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001998 }
Jooyung Han643adc42020-02-27 13:50:06 +09001999 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2000 fi.isJniLib = isJniLib
2001 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002002 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002003 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002004 propertyName := "native_shared_libs"
2005 if isJniLib {
2006 propertyName = "jni_libs"
2007 }
2008 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002009 }
2010 case executableTag:
2011 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002012 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002013 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002014 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002015 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002016 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002017 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002018 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002019 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002020 } else {
Alex Light778127a2019-02-27 14:19:50 -08002021 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 +09002022 }
2023 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002024 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002025 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002026 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002027 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2028 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002029 filesInfo = append(filesInfo, af)
2030 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002031 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002032 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2033 af := apexFileForJavaLibrary(ctx, sdkLib)
2034 if !af.Ok() {
2035 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2036 return false
2037 }
2038 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002039 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002040 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002041 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002042 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002043 case androidAppTag:
2044 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2045 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002046 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002047 return true // track transitive dependencies
2048 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002049 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002050 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2051 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002052 } else {
2053 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2054 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002055 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002056 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002057 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002058 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2059 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002060 } else {
atrost6e126252020-01-27 17:01:16 +00002061 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002062 }
Roland Levillain630846d2019-06-26 12:48:34 +01002063 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002064 if ccTest, ok := child.(*cc.Module); ok {
2065 if ccTest.IsTestPerSrcAllTestsVariation() {
2066 // Multiple-output test module (where `test_per_src: true`).
2067 //
2068 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2069 // We do not add this variation to `filesInfo`, as it has no output;
2070 // however, we do add the other variations of this module as indirect
2071 // dependencies (see below).
2072 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002073 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002074 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002075 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002076 af.class = nativeTest
2077 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002078 }
Roland Levillain630846d2019-06-26 12:48:34 +01002079 } else {
2080 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2081 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002082 case keyTag:
2083 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002084 a.private_key_file = key.private_key_file
2085 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002086 } else {
2087 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002088 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002089 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002090 case certificateTag:
2091 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002092 a.container_certificate_file = dep.Certificate.Pem
2093 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002094 } else {
2095 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2096 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002097 case android.PrebuiltDepTag:
2098 // If the prebuilt is force disabled, remember to delete the prebuilt file
2099 // that might have been installed in the previous builds
2100 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2101 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2102 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002103 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002104 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002105 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002106 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002107 // We cannot use a switch statement on `depTag` here as the checked
2108 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002109 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002110 if cc, ok := child.(*cc.Module); ok {
2111 if android.InList(cc.Name(), providedNativeSharedLibs) {
2112 // If we're using a shared library which is provided from other APEX,
2113 // don't include it in this APEX
2114 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002115 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002116 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002117 // If the dependency is a stubs lib, don't include it in this APEX,
2118 // but make sure that the lib is installed on the device.
2119 // In case no APEX is having the lib, the lib is installed to the system
2120 // partition.
2121 //
2122 // Always include if we are a host-apex however since those won't have any
2123 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002124 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2125 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002126 }
Jooyung Hane1633032019-08-01 17:41:43 +09002127 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002128 // Don't track further
2129 return false
2130 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002131 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002132 af.transitiveDep = true
2133 filesInfo = append(filesInfo, af)
2134 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002135 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002136 } else if cc.IsTestPerSrcDepTag(depTag) {
2137 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002138 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002139 // Handle modules created as `test_per_src` variations of a single test module:
2140 // use the name of the generated test binary (`fileToCopy`) instead of the name
2141 // of the original test module (`depName`, shared by all `test_per_src`
2142 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002143 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002144 // these are not considered transitive dep
2145 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002146 filesInfo = append(filesInfo, af)
2147 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002148 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002149 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002150 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2151 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002152 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2153 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2154 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2155 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002156 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002157 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002158 }
2159 }
2160 }
2161 return false
2162 })
2163
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002164 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2165 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2166 // via the global boot image config.
2167 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002168 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002169 dirInApex := filepath.Join("javalib", arch.String())
2170 for _, f := range files {
2171 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002172 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002173 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002174 }
2175 }
2176 }
2177
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002178 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002179 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2180 return
2181 }
2182
Jiyong Park8fd61922018-11-08 02:50:25 +09002183 // remove duplicates in filesInfo
2184 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002185 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002186 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002187 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002188 if e, ok := encountered[dest]; !ok {
2189 encountered[dest] = f
2190 } else {
2191 // If a module is directly included and also transitively depended on
2192 // consider it as directly included.
2193 e.transitiveDep = e.transitiveDep && f.transitiveDep
2194 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002195 }
2196 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002197 var result []apexFile
2198 for _, v := range encountered {
2199 result = append(result, v)
2200 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002201 return result
2202 }
2203 filesInfo = removeDup(filesInfo)
2204
2205 // to have consistent build rules
2206 sort.Slice(filesInfo, func(i, j int) bool {
2207 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2208 })
2209
Jiyong Park8fd61922018-11-08 02:50:25 +09002210 a.installDir = android.PathForModuleInstall(ctx, "apex")
2211 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002212
Jooyung Han54aca7b2019-11-20 02:26:02 +09002213 if a.properties.ApexType != zipApex {
2214 if a.properties.File_contexts == nil {
2215 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2216 } else {
2217 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2218 if a.Platform() {
2219 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2220 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2221 }
2222 }
2223 }
2224 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2225 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2226 return
2227 }
2228 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002229 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2230 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2231 // the same library in the system partition, thus effectively sharing the same libraries
2232 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2233 // in the APEX.
2234 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2235 a.installable() &&
2236 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002237
Jiyong Park9d677202020-02-19 16:29:35 +09002238 // We don't need the optimization for updatable APEXes, as it might give false signal
2239 // to the system health when the APEXes are still bundled (b/149805758)
2240 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2241 a.linkToSystemLib = false
2242 }
2243
Jiyong Park638d30e2020-02-26 18:27:19 +09002244 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2245 if ctx.Host() {
2246 a.linkToSystemLib = false
2247 }
2248
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002249 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002250 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2251
2252 a.setCertificateAndPrivateKey(ctx)
2253 if a.properties.ApexType == flattenedApex {
2254 a.buildFlattenedApex(ctx)
2255 } else {
2256 a.buildUnflattenedApex(ctx)
2257 }
2258
Jooyung Han002ab682020-01-08 01:57:58 +09002259 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002260
2261 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002262}
2263
Jooyung Han5e9013b2020-03-10 06:23:13 +09002264func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002265 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002266 moduleName = normalizeModuleName(moduleName)
2267
2268 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2269 return true
2270 }
2271
2272 key = android.AvailableToAnyApex
2273 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2274 return true
2275 }
2276
2277 return false
2278}
2279
2280func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002281 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2282 // system. Trim the prefix for the check since they are confusing
2283 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2284 if strings.HasPrefix(moduleName, "libclang_rt.") {
2285 // This module has many arch variants that depend on the product being built.
2286 // We don't want to list them all
2287 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002288 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002289 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002290}
2291
Jooyung Han344d5432019-08-23 11:17:39 +09002292func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002293 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002294 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002295 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002296 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002297 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002298 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2299 })
Alex Light5098a612018-11-29 17:12:15 -08002300 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002301 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002302 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002303 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002304 return module
2305}
Jiyong Park30ca9372019-02-07 16:27:23 +09002306
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002307func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002308 bundle := newApexBundle()
2309 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002310 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002311 return bundle
2312}
2313
Jiyong Parkfce0b422020-02-11 03:56:06 +09002314// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2315// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002316func testApexBundleFactory() android.Module {
2317 bundle := newApexBundle()
2318 bundle.testApex = true
2319 return bundle
2320}
2321
Jiyong Parkfce0b422020-02-11 03:56:06 +09002322// apex packages other modules into an APEX file which is a packaging format for system-level
2323// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002324func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002325 return newApexBundle()
2326}
2327
Jiyong Park30ca9372019-02-07 16:27:23 +09002328//
2329// Defaults
2330//
2331type Defaults struct {
2332 android.ModuleBase
2333 android.DefaultsModuleBase
2334}
2335
Jiyong Park30ca9372019-02-07 16:27:23 +09002336func defaultsFactory() android.Module {
2337 return DefaultsFactory()
2338}
2339
2340func DefaultsFactory(props ...interface{}) android.Module {
2341 module := &Defaults{}
2342
2343 module.AddProperties(props...)
2344 module.AddProperties(
2345 &apexBundleProperties{},
2346 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002347 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002348 )
2349
2350 android.InitDefaultsModule(module)
2351 return module
2352}
Jiyong Park5d790c32019-11-15 18:40:32 +09002353
2354//
2355// OverrideApex
2356//
2357type OverrideApex struct {
2358 android.ModuleBase
2359 android.OverrideModuleBase
2360}
2361
2362func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2363 // All the overrides happen in the base module.
2364}
2365
2366// override_apex is used to create an apex module based on another apex module
2367// by overriding some of its properties.
2368func overrideApexFactory() android.Module {
2369 m := &OverrideApex{}
2370 m.AddProperties(&overridableProperties{})
2371
2372 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2373 android.InitOverrideModule(m)
2374 return m
2375}