blob: 46ccc507349e7fc4642b1f19fbb60de73cc523d6 [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"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Jiyong Park0f80c182020-01-31 02:49:53 +090096 m["com.android.adbd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090097 "libadbd_auth",
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +090099 "libcap",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "libmdnssd",
101 "libminijail",
102 "libminijail_gen_constants",
103 "libminijail_gen_constants_obj",
104 "libminijail_gen_syscall",
105 "libminijail_gen_syscall_obj",
106 "libminijail_generated",
107 "libpackagelistparser",
108 "libpcre2",
109 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900110 }
111 //
112 // Module separator
113 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000114 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900115 "art_cmdlineparser_headers",
116 "art_disassembler_headers",
117 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900118 "bionic_libc_platform_headers",
119 "core-repackaged-icu4j",
120 "cpp-define-generator-asm-support",
121 "cpp-define-generator-definitions",
122 "crtbegin_dynamic",
123 "crtbegin_dynamic1",
124 "crtbegin_so1",
125 "crtbrand",
Jiyong Park0f80c182020-01-31 02:49:53 +0900126 "dex2oat_headers",
127 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900128 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900129 "javavm_headers",
130 "jni_platform_headers",
131 "libPlatformProperties",
132 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000133 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900134 "libandroidicuinit",
135 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000136 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900137 "libasync_safe",
Jiyong Park0f80c182020-01-31 02:49:53 +0900138 "libdexfile_all_headers",
139 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000140 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900141 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000142 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900143 "libfdlibm",
144 "libgtest_prod",
145 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000146 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900147 "libicuuc_headers",
148 "libicuuc_stubdata",
149 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900150 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000151 "liblzma",
152 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900153 "libnativebridge-headers",
154 "libnativehelper_header_only",
155 "libnativeloader-headers",
156 "libnpt_headers",
157 "libopenjdkjvmti_headers",
158 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000159 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900160 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libv8",
163 "libv8base",
164 "libv8gen",
165 "libv8platform",
166 "libv8sampler",
167 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000168 "libvixl",
169 "libvixld",
170 "libz",
171 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900172 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000173 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000174 m["com.android.art.debug"] = artApexContents
175 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000176 //
177 // Module separator
178 //
179 m["com.android.bluetooth.updatable"] = []string{
180 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000181 "android.hardware.bluetooth.a2dp@1.0",
182 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900183 "android.hardware.bluetooth@1.0",
184 "android.hardware.bluetooth@1.1",
185 "android.hardware.graphics.bufferqueue@1.0",
186 "android.hardware.graphics.bufferqueue@2.0",
187 "android.hardware.graphics.common@1.0",
188 "android.hardware.graphics.common@1.1",
189 "android.hardware.graphics.common@1.2",
190 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000191 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900192 "android.hidl.token@1.0",
193 "android.hidl.token@1.0-utils",
194 "avrcp-target-service",
195 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "bluetooth-protos-lite",
197 "bluetooth.mapsapi",
198 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900199 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900200 "ipmemorystore-aidl-interfaces-V5-java",
201 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900202 "internal_include_headers",
203 "lib-bt-packets",
204 "lib-bt-packets-avrcp",
205 "lib-bt-packets-base",
206 "libFraunhoferAAC",
207 "libaudio-a2dp-hw-utils",
208 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900209 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000210 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900211 "libbluetooth-types",
212 "libbluetooth-types-header",
213 "libbluetooth_gd",
214 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000215 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900216 "libbt-audio-hal-interface",
217 "libbt-bta",
218 "libbt-common",
219 "libbt-hci",
220 "libbt-platform-protos-lite",
221 "libbt-protos-lite",
222 "libbt-sbc-decoder",
223 "libbt-sbc-encoder",
224 "libbt-stack",
225 "libbt-utils",
226 "libbtcore",
227 "libbtdevice",
228 "libbte",
229 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000230 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000231 "libevent",
232 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900233 "libg722codec",
234 "libgtest_prod",
235 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900236 "libmedia_headers",
237 "libmodpb64",
238 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000239 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900240 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 "libstagefright_foundation_headers",
242 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000243 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900244 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000245 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900246 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000247 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900248 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900249 "net-utils-services-common",
250 "netd_aidl_interface-unstable-java",
251 "netd_event_listener_interface-java",
252 "netlink-client",
253 "networkstack-aidl-interfaces-unstable-java",
254 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900255 "sap-api-java-static",
256 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000257 }
258 //
259 // Module separator
260 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900261 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000262 //
263 // Module separator
264 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900265 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900266 "boringssl_self_test",
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 "libnativehelper_header_only",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900268 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900269 }
270 //
271 // Module separator
272 //
273 m["com.android.extservices"] = []string{
274 "flatbuffer_headers",
275 "liblua",
276 "libtextclassifier",
277 "libtextclassifier_hash_static",
278 "libtflite_static",
279 "libutf",
280 "libz_current",
281 "tensorflow_headers",
282 }
283 //
284 // Module separator
285 //
286 m["com.android.cronet"] = []string{
287 "cronet_impl_common_java",
288 "cronet_impl_native_java",
289 "cronet_impl_platform_java",
290 "libcronet.80.0.3986.0",
291 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900292 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900293 "prebuilt_libcronet.80.0.3986.0",
294 }
295 //
296 // Module separator
297 //
298 m["com.android.neuralnetworks"] = []string{
299 "android.hardware.neuralnetworks@1.0",
300 "android.hardware.neuralnetworks@1.1",
301 "android.hardware.neuralnetworks@1.2",
302 "android.hardware.neuralnetworks@1.3",
303 "android.hidl.allocator@1.0",
304 "android.hidl.memory.token@1.0",
305 "android.hidl.memory@1.0",
306 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900307 "gemmlowp_headers",
308 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900309 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900310 "libeigen",
311 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900312 "libmath",
313 "libneuralnetworks_common",
314 "libneuralnetworks_headers",
315 "libprocessgroup",
316 "libprocessgroup_headers",
317 "libprocpartition",
318 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900319 "libtextclassifier_hash",
320 "libtextclassifier_hash_headers",
321 "libtextclassifier_hash_static",
322 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900323 "philox_random",
324 "philox_random_headers",
325 "tensorflow_headers",
326 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000327 //
328 // Module separator
329 //
330 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000331 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900332 "android.hardware.cas.native@1.0",
333 "android.hardware.cas@1.0",
334 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000335 "android.hardware.configstore@1.0",
336 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000337 "android.hardware.graphics.allocator@2.0",
338 "android.hardware.graphics.allocator@3.0",
339 "android.hardware.graphics.bufferqueue@1.0",
340 "android.hardware.graphics.bufferqueue@2.0",
341 "android.hardware.graphics.common@1.0",
342 "android.hardware.graphics.common@1.1",
343 "android.hardware.graphics.common@1.2",
344 "android.hardware.graphics.mapper@2.0",
345 "android.hardware.graphics.mapper@2.1",
346 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900347 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000348 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900349 "android.hidl.allocator@1.0",
350 "android.hidl.memory.token@1.0",
351 "android.hidl.memory@1.0",
352 "android.hidl.token@1.0",
353 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900354 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900355 "gl_headers",
356 "libEGL",
357 "libEGL_blobCache",
358 "libEGL_getProcAddress",
359 "libFLAC",
360 "libFLAC-config",
361 "libFLAC-headers",
362 "libGLESv2",
363 "libaacextractor",
364 "libamrextractor",
365 "libarect",
366 "libasync_safe",
367 "libaudio_system_headers",
368 "libaudioclient",
369 "libaudioclient_headers",
370 "libaudiofoundation",
371 "libaudiofoundation_headers",
372 "libaudiomanager",
373 "libaudiopolicy",
374 "libaudioutils",
375 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900376 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900377 "libbluetooth-types-header",
378 "libbufferhub",
379 "libbufferhub_headers",
380 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900381 "libc_malloc_debug_backtrace",
382 "libcamera_client",
383 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900384 "libdexfile_external_headers",
385 "libdexfile_support",
386 "libdvr_headers",
387 "libexpat",
388 "libfifo",
389 "libflacextractor",
390 "libgrallocusage",
391 "libgraphicsenv",
392 "libgui",
393 "libgui_headers",
394 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900395 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900396 "liblzma",
397 "libmath",
398 "libmedia",
399 "libmedia_codeclist",
400 "libmedia_headers",
401 "libmedia_helper",
402 "libmedia_helper_headers",
403 "libmedia_midiiowrapper",
404 "libmedia_omx",
405 "libmediautils",
406 "libmidiextractor",
407 "libmkvextractor",
408 "libmp3extractor",
409 "libmp4extractor",
410 "libmpeg2extractor",
411 "libnativebase_headers",
412 "libnativebridge-headers",
413 "libnativebridge_lazy",
414 "libnativeloader-headers",
415 "libnativeloader_lazy",
416 "libnativewindow_headers",
417 "libnblog",
418 "liboggextractor",
419 "libpackagelistparser",
420 "libpcre2",
421 "libpdx",
422 "libpdx_default_transport",
423 "libpdx_headers",
424 "libpdx_uds",
425 "libprocessgroup",
426 "libprocessgroup_headers",
427 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900428 "libsonivox",
429 "libspeexresampler",
430 "libspeexresampler",
431 "libstagefright_esds",
432 "libstagefright_flacdec",
433 "libstagefright_flacdec",
434 "libstagefright_foundation",
435 "libstagefright_foundation_headers",
436 "libstagefright_foundation_without_imemory",
437 "libstagefright_headers",
438 "libstagefright_id3",
439 "libstagefright_metadatautils",
440 "libstagefright_mpeg2extractor",
441 "libstagefright_mpeg2support",
442 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900443 "libui",
444 "libui_headers",
445 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900446 "libvibrator",
447 "libvorbisidec",
448 "libwavextractor",
449 "libwebm",
450 "media_ndk_headers",
451 "media_plugin_headers",
452 "updatable-media",
453 }
454 //
455 // Module separator
456 //
457 m["com.android.media.swcodec"] = []string{
458 "android.frameworks.bufferhub@1.0",
459 "android.hardware.common-ndk_platform",
460 "android.hardware.configstore-utils",
461 "android.hardware.configstore@1.0",
462 "android.hardware.configstore@1.1",
463 "android.hardware.graphics.allocator@2.0",
464 "android.hardware.graphics.allocator@3.0",
465 "android.hardware.graphics.bufferqueue@1.0",
466 "android.hardware.graphics.bufferqueue@2.0",
467 "android.hardware.graphics.common-ndk_platform",
468 "android.hardware.graphics.common@1.0",
469 "android.hardware.graphics.common@1.1",
470 "android.hardware.graphics.common@1.2",
471 "android.hardware.graphics.mapper@2.0",
472 "android.hardware.graphics.mapper@2.1",
473 "android.hardware.graphics.mapper@3.0",
474 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000475 "android.hardware.media.bufferpool@2.0",
476 "android.hardware.media.c2@1.0",
477 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900478 "android.hardware.media@1.0",
479 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000480 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900481 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000482 "android.hidl.safe_union@1.0",
483 "android.hidl.token@1.0",
484 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900485 "libEGL",
486 "libFLAC",
487 "libFLAC-config",
488 "libFLAC-headers",
489 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900490 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900491 "libarect",
492 "libasync_safe",
493 "libaudio_system_headers",
494 "libaudioutils",
495 "libaudioutils",
496 "libaudioutils_fixedfft",
497 "libavcdec",
498 "libavcenc",
499 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000500 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900501 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900502 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900503 "libbluetooth-types-header",
504 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900505 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000506 "libcap",
507 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900508 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000509 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900510 "libcodec2_hidl@1.1",
511 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000512 "libcodec2_soft_aacdec",
513 "libcodec2_soft_aacenc",
514 "libcodec2_soft_amrnbdec",
515 "libcodec2_soft_amrnbenc",
516 "libcodec2_soft_amrwbdec",
517 "libcodec2_soft_amrwbenc",
518 "libcodec2_soft_av1dec_gav1",
519 "libcodec2_soft_avcdec",
520 "libcodec2_soft_avcenc",
521 "libcodec2_soft_common",
522 "libcodec2_soft_flacdec",
523 "libcodec2_soft_flacenc",
524 "libcodec2_soft_g711alawdec",
525 "libcodec2_soft_g711mlawdec",
526 "libcodec2_soft_gsmdec",
527 "libcodec2_soft_h263dec",
528 "libcodec2_soft_h263enc",
529 "libcodec2_soft_hevcdec",
530 "libcodec2_soft_hevcenc",
531 "libcodec2_soft_mp3dec",
532 "libcodec2_soft_mpeg2dec",
533 "libcodec2_soft_mpeg4dec",
534 "libcodec2_soft_mpeg4enc",
535 "libcodec2_soft_opusdec",
536 "libcodec2_soft_opusenc",
537 "libcodec2_soft_rawdec",
538 "libcodec2_soft_vorbisdec",
539 "libcodec2_soft_vp8dec",
540 "libcodec2_soft_vp8enc",
541 "libcodec2_soft_vp9dec",
542 "libcodec2_soft_vp9enc",
543 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000544 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900545 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000546 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900547 "libfmq",
548 "libgav1",
549 "libgralloctypes",
550 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000551 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900552 "libgsm",
553 "libgui_bufferqueue_static",
554 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000555 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900556 "libhardware_headers",
557 "libhevcdec",
558 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000559 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900560 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000561 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000563 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900564 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000565 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900566 "libminijail_gen_constants",
567 "libminijail_gen_constants_obj",
568 "libminijail_gen_syscall",
569 "libminijail_gen_syscall_obj",
570 "libminijail_generated",
571 "libmpeg2dec",
572 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000573 "libnativebridge_lazy",
574 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900575 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000576 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900577 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000578 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900579 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000580 "libscudo_wrapper",
581 "libsfplugin_ccodec_utils",
582 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900583 "libstagefright_amrnbdec",
584 "libstagefright_amrnbenc",
585 "libstagefright_amrwbdec",
586 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000587 "libstagefright_bufferpool@2.0.1",
588 "libstagefright_bufferqueue_helper",
589 "libstagefright_enc_common",
590 "libstagefright_flacdec",
591 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900592 "libstagefright_foundation_headers",
593 "libstagefright_headers",
594 "libstagefright_m4vh263dec",
595 "libstagefright_m4vh263enc",
596 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000597 "libsync",
598 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900599 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000600 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000601 "libvorbisidec",
602 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900603 "libyuv",
604 "libyuv_static",
605 "media_ndk_headers",
606 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000607 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900608 }
609 //
610 // Module separator
611 //
612 m["com.android.mediaprovider"] = []string{
613 "MediaProvider",
614 "MediaProviderGoogle",
615 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900616 "libbase_ndk",
617 "libfuse",
618 "libfuse_jni",
619 "libnativehelper_header_only",
620 }
621 //
622 // Module separator
623 //
624 m["com.android.permission"] = []string{
625 "androidx.annotation_annotation",
626 "androidx.annotation_annotation-nodeps",
627 "androidx.lifecycle_lifecycle-common",
628 "androidx.lifecycle_lifecycle-common-java8",
629 "androidx.lifecycle_lifecycle-common-java8-nodeps",
630 "androidx.lifecycle_lifecycle-common-nodeps",
631 "kotlin-annotations",
632 "kotlin-stdlib",
633 "kotlin-stdlib-jdk7",
634 "kotlin-stdlib-jdk8",
635 "kotlinx-coroutines-android",
636 "kotlinx-coroutines-android-nodeps",
637 "kotlinx-coroutines-core",
638 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900639 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000640 }
641 //
642 // Module separator
643 //
644 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900645 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900646 "libarm-optimized-routines-math",
647 "libasync_safe",
648 "libasync_safe_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900649 "libc_aeabi",
650 "libc_bionic",
651 "libc_bionic_ndk",
652 "libc_bootstrap",
653 "libc_common",
654 "libc_common_shared",
655 "libc_common_static",
656 "libc_dns",
657 "libc_dynamic_dispatch",
658 "libc_fortify",
659 "libc_freebsd",
660 "libc_freebsd_large_stack",
661 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900662 "libc_init_dynamic",
663 "libc_init_static",
664 "libc_jemalloc_wrapper",
665 "libc_netbsd",
666 "libc_nomalloc",
667 "libc_nopthread",
668 "libc_openbsd",
669 "libc_openbsd_large_stack",
670 "libc_openbsd_ndk",
671 "libc_pthread",
672 "libc_static_dispatch",
673 "libc_syscalls",
674 "libc_tzcode",
675 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900676 "libdebuggerd",
677 "libdebuggerd_common_headers",
678 "libdebuggerd_handler_core",
679 "libdebuggerd_handler_fallback",
680 "libdexfile_external_headers",
681 "libdexfile_support",
682 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900683 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900684 "libgtest_prod",
685 "libjemalloc5",
686 "liblinker_main",
687 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900688 "liblz4",
689 "liblzma",
690 "libprocessgroup_headers",
691 "libprocinfo",
692 "libpropertyinfoparser",
693 "libscudo",
694 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900695 "libsystemproperties",
696 "libtombstoned_client_static",
697 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900698 "libz",
699 "libziparchive",
700 }
701 //
702 // Module separator
703 //
704 m["com.android.resolv"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900705 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Park0f80c182020-01-31 02:49:53 +0900706 "libgtest_prod",
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 "libnativehelper_header_only",
708 "libnetd_client_headers",
709 "libnetd_resolv",
710 "libnetdutils",
711 "libprocessgroup",
712 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900713 "libstatslog_resolv",
714 "libstatspush_compat",
715 "libstatssocket",
716 "libstatssocket_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900717 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900718 "netd_event_listener_interface-ndk_platform",
719 "server_configurable_flags",
720 "stats_proto",
721 }
722 //
723 // Module separator
724 //
725 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900726 "libnativehelper_compat_libc++",
727 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900728 "libcgrouprc",
729 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900730 "libprocessgroup",
731 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900732 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900733 "libvndksupport",
734 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000735 }
736 //
737 // Module separator
738 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900739 m["com.android.wifi"] = []string{
740 "PlatformProperties",
741 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900742 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900743 "android.hardware.wifi-V1.1-java",
744 "android.hardware.wifi-V1.2-java",
745 "android.hardware.wifi-V1.3-java",
746 "android.hardware.wifi-V1.4-java",
747 "android.hardware.wifi.hostapd-V1.0-java",
748 "android.hardware.wifi.hostapd-V1.1-java",
749 "android.hardware.wifi.hostapd-V1.2-java",
750 "android.hardware.wifi.supplicant-V1.0-java",
751 "android.hardware.wifi.supplicant-V1.1-java",
752 "android.hardware.wifi.supplicant-V1.2-java",
753 "android.hardware.wifi.supplicant-V1.3-java",
754 "android.hidl.base-V1.0-java",
755 "android.hidl.manager-V1.0-java",
756 "android.hidl.manager-V1.1-java",
757 "android.hidl.manager-V1.2-java",
758 "androidx.annotation_annotation",
759 "androidx.annotation_annotation-nodeps",
760 "bouncycastle-unbundled",
761 "dnsresolver_aidl_interface-V2-java",
762 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900763 "framework-wifi-pre-jarjar",
764 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900765 "ipmemorystore-aidl-interfaces-V3-java",
766 "ipmemorystore-aidl-interfaces-java",
767 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900768 "libnanohttpd",
769 "libprocessgroup",
770 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900771 "libwifi-jni",
772 "net-utils-services-common",
773 "netd_aidl_interface-V2-java",
774 "netd_aidl_interface-unstable-java",
775 "netd_event_listener_interface-java",
776 "netlink-client",
777 "networkstack-aidl-interfaces-unstable-java",
778 "networkstack-client",
779 "services.net",
780 "wifi-lite-protos",
781 "wifi-nano-protos",
782 "wifi-service-pre-jarjar",
783 "wifi-service-resources",
784 "prebuilt_androidx.annotation_annotation-nodeps",
785 }
786 //
787 // Module separator
788 //
789 m["com.android.sdkext"] = []string{
790 "fmtlib_ndk",
791 "libbase_ndk",
792 "libprotobuf-cpp-lite-ndk",
793 }
794 //
795 // Module separator
796 //
797 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900798 "libprocessgroup_headers",
799 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900800 }
801 //
802 // Module separator
803 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000804 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900805 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900806 "libclang_rt",
807 "libgcc_stripped",
808 "libprofile-clang-extras",
809 "libprofile-clang-extras_ndk",
810 "libprofile-extras",
811 "libprofile-extras_ndk",
812 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900813 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000814 return m
815}
816
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900817func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900818 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800819 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900820 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900821 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700822 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900823 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900824
Jooyung Han31c470b2019-10-18 16:26:59 +0900825 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900826 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900827
828 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
829 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
830 sort.Strings(*apexFileContextsInfos)
831 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
832 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900833}
834
Jooyung Han31c470b2019-10-18 16:26:59 +0900835func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
836 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
837 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
838}
839
Jiyong Parkd1063c12019-07-17 20:08:41 +0900840func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900841 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900842 ctx.BottomUp("apex", apexMutator).Parallel()
843 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
844 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900845}
846
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900847// Mark the direct and transitive dependencies of apex bundles so that they
848// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900849func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800850 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900851 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000852 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han5e9013b2020-03-10 06:23:13 +0900853 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han5417f772020-03-12 18:37:20 +0900854 ApexName: mctx.ModuleName(),
855 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900856 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900857 directDep = true
858 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800859 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900860 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900861 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900862
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800863 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900864 return
865 }
866
Paul Duffin923e8a52020-03-30 15:33:32 +0100867 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900868
Jiyong Parkf760cae2020-02-12 07:53:12 +0900869 mctx.VisitDirectDeps(func(child android.Module) {
870 depName := mctx.OtherModuleName(child)
871 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100872 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800873 android.UpdateApexDependency(apexBundles, depName, directDep)
874 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900875 }
876 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877}
878
Paul Duffin65347702020-03-31 15:23:40 +0100879// If a module in an APEX depends on a module from an SDK then it needs an APEX
880// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
881func inAnySdk(module android.Module) bool {
882 if sa, ok := module.(android.SdkAware); ok {
883 return sa.IsInAnySdk()
884 }
885
886 return false
887}
888
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900889// Create apex variations if a module is included in APEX(s).
890func apexMutator(mctx android.BottomUpMutatorContext) {
891 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900892 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000893 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900894 // apex bundle itself is mutated so that it and its modules have same
895 // apex variant.
896 apexBundleName := mctx.ModuleName()
897 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900898 } else if o, ok := mctx.Module().(*OverrideApex); ok {
899 apexBundleName := o.GetOverriddenModuleName()
900 if apexBundleName == "" {
901 mctx.ModuleErrorf("base property is not set")
902 return
903 }
904 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900905 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900906
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900907}
Sundong Ahne9b55722019-09-06 17:37:42 +0900908
Jooyung Han7a78a922019-10-08 21:59:58 +0900909var (
910 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
911 apexFileContextsInfosMutex sync.Mutex
912)
913
914func apexFileContextsInfos(config android.Config) *[]string {
915 return config.Once(apexFileContextsInfosKey, func() interface{} {
916 return &[]string{}
917 }).(*[]string)
918}
919
Jooyung Han54aca7b2019-11-20 02:26:02 +0900920func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900921 apexFileContextsInfosMutex.Lock()
922 defer apexFileContextsInfosMutex.Unlock()
923 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900924 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900925}
926
Sundong Ahne9b55722019-09-06 17:37:42 +0900927func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900928 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900929 var variants []string
930 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
931 case "image":
932 variants = append(variants, imageApexType, flattenedApexType)
933 case "zip":
934 variants = append(variants, zipApexType)
935 case "both":
936 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
937 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900938 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900939 return
940 }
941
942 modules := mctx.CreateLocalVariations(variants...)
943
944 for i, v := range variants {
945 switch v {
946 case imageApexType:
947 modules[i].(*apexBundle).properties.ApexType = imageApex
948 case zipApexType:
949 modules[i].(*apexBundle).properties.ApexType = zipApex
950 case flattenedApexType:
951 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900952 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900953 modules[i].(*apexBundle).MakeAsSystemExt()
954 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900955 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900956 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900957 } else if _, ok := mctx.Module().(*OverrideApex); ok {
958 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900959 }
960}
961
Jooyung Han5c998b92019-06-27 11:30:33 +0900962func apexUsesMutator(mctx android.BottomUpMutatorContext) {
963 if ab, ok := mctx.Module().(*apexBundle); ok {
964 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
965 }
966}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900967
Jooyung Handc782442019-11-01 03:14:38 +0900968var (
969 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
970)
971
972// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
973// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
974// which may cause compatibility issues. (e.g. libbinder)
975// Even though libbinder restricts its availability via 'apex_available' property and relies on
976// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
977// to avoid similar problems.
978func useVendorWhitelist(config android.Config) []string {
979 return config.Once(useVendorWhitelistKey, func() interface{} {
980 return []string{
981 // swcodec uses "vendor" variants for smaller size
982 "com.android.media.swcodec",
983 "test_com.android.media.swcodec",
984 }
985 }).([]string)
986}
987
988// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
989// called before the first call to useVendorWhitelist()
990func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
991 config.Once(useVendorWhitelistKey, func() interface{} {
992 return whitelist
993 })
994}
995
Jooyung Han01a868d2020-02-27 13:40:44 +0900996type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800997 // List of native libraries
998 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900999
Jooyung Han643adc42020-02-27 13:50:06 +09001000 // List of JNI libraries
1001 Jni_libs []string
1002
Alex Light9670d332019-01-29 18:07:33 -08001003 // List of native executables
1004 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001005
Roland Levillain630846d2019-06-26 12:48:34 +01001006 // List of native tests
1007 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001008}
Jooyung Han344d5432019-08-23 11:17:39 +09001009
Alex Light9670d332019-01-29 18:07:33 -08001010type apexMultilibProperties struct {
1011 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001012 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001013
1014 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001015 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001016
1017 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001018 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001019
1020 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001021 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001022
1023 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001024 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001025}
1026
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001027type apexBundleProperties struct {
1028 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001029 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001030 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001031
Jiyong Park40e26a22019-02-08 02:53:06 +09001032 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1033 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001034 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001035
Roland Levillain411c5842019-09-19 16:37:20 +01001036 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1037 // device (/apex/<apex_name>).
1038 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001039 Apex_name *string
1040
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001041 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001042 // For platform APEXes, this should points to a file under /system/sepolicy
1043 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1044 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001045
Jooyung Han01a868d2020-02-27 13:40:44 +09001046 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001047
1048 // List of java libraries that are embedded inside this APEX bundle
1049 Java_libs []string
1050
1051 // List of prebuilt files that are embedded inside this APEX bundle
1052 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001053
1054 // Name of the apex_key module that provides the private key to sign APEX
1055 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001056
Alex Light5098a612018-11-29 17:12:15 -08001057 // The type of APEX to build. Controls what the APEX payload is. Either
1058 // 'image', 'zip' or 'both'. Default: 'image'.
1059 Payload_type *string
1060
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001061 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1062 // or an android_app_certificate module name in the form ":module".
1063 Certificate *string
1064
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001065 // Whether this APEX is installable to one of the partitions. Default: true.
1066 Installable *bool
1067
Jiyong Parkda6eb592018-12-19 17:12:36 +09001068 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1069 // Default is false.
1070 Use_vendor *bool
1071
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001072 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1073 Ignore_system_library_special_case *bool
1074
Alex Light9670d332019-01-29 18:07:33 -08001075 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001076
Jiyong Parkf97782b2019-02-13 20:28:58 +09001077 // List of sanitizer names that this APEX is enabled for
1078 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001079
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001080 PreventInstall bool `blueprint:"mutated"`
1081
1082 HideFromMake bool `blueprint:"mutated"`
1083
Jooyung Han5c998b92019-06-27 11:30:33 +09001084 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1085 Provide_cpp_shared_libs *bool
1086
1087 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1088 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001089
1090 // A txt file containing list of files that are whitelisted to be included in this APEX.
1091 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001092
Sundong Ahnabb64432019-10-22 13:58:29 +09001093 // package format of this apex variant; could be non-flattened, flattened, or zip.
1094 // imageApex, zipApex or flattened
1095 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001096
Jiyong Parkd1063c12019-07-17 20:08:41 +09001097 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1098 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1099 // is implied. This value affects all modules included in this APEX. In other words, they are
1100 // also built with the SDKs specified here.
1101 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001102
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001103 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1104 // Should be only used in tests#.
1105 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001106
Jiyong Park956305c2020-01-09 12:32:06 +09001107 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001108
1109 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1110 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1111 // like symlinking to the system libs. Default is false.
1112 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001113
1114 // The minimum SDK version that this apex must be compatibile with.
1115 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001116}
1117
1118type apexTargetBundleProperties struct {
1119 Target struct {
1120 // Multilib properties only for android.
1121 Android struct {
1122 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001123 }
Jooyung Han344d5432019-08-23 11:17:39 +09001124
Alex Light9670d332019-01-29 18:07:33 -08001125 // Multilib properties only for host.
1126 Host struct {
1127 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001128 }
Jooyung Han344d5432019-08-23 11:17:39 +09001129
Alex Light9670d332019-01-29 18:07:33 -08001130 // Multilib properties only for host linux_bionic.
1131 Linux_bionic struct {
1132 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001133 }
Jooyung Han344d5432019-08-23 11:17:39 +09001134
Alex Light9670d332019-01-29 18:07:33 -08001135 // Multilib properties only for host linux_glibc.
1136 Linux_glibc struct {
1137 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001138 }
1139 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001140}
1141
Jiyong Park5d790c32019-11-15 18:40:32 +09001142type overridableProperties struct {
1143 // List of APKs to package inside APEX
1144 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001145
1146 // Names of modules to be overridden. Listed modules can only be other binaries
1147 // (in Make or Soong).
1148 // This does not completely prevent installation of the overridden binaries, but if both
1149 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1150 // from PRODUCT_PACKAGES.
1151 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001152
1153 // Logging Parent value
1154 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001155
1156 // Apex Container Package Name.
1157 // Override value for attribute package:name in AndroidManifest.xml
1158 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001159}
1160
Alex Light5098a612018-11-29 17:12:15 -08001161type apexPackaging int
1162
1163const (
1164 imageApex apexPackaging = iota
1165 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001166 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001167)
1168
Sundong Ahnabb64432019-10-22 13:58:29 +09001169// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001170func (a apexPackaging) suffix() string {
1171 switch a {
1172 case imageApex:
1173 return imageApexSuffix
1174 case zipApex:
1175 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001176 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001177 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001178 }
1179}
1180
1181func (a apexPackaging) name() string {
1182 switch a {
1183 case imageApex:
1184 return imageApexType
1185 case zipApex:
1186 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001187 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001188 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001189 }
1190}
1191
Jiyong Parkf653b052019-11-18 15:39:01 +09001192type apexFileClass int
1193
1194const (
1195 etc apexFileClass = iota
1196 nativeSharedLib
1197 nativeExecutable
1198 shBinary
1199 pyBinary
1200 goBinary
1201 javaSharedLib
1202 nativeTest
1203 app
1204)
1205
Jiyong Park8fd61922018-11-08 02:50:25 +09001206func (class apexFileClass) NameInMake() string {
1207 switch class {
1208 case etc:
1209 return "ETC"
1210 case nativeSharedLib:
1211 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001212 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001213 return "EXECUTABLES"
1214 case javaSharedLib:
1215 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001216 case nativeTest:
1217 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001218 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001219 // b/142537672 Why isn't this APP? We want to have full control over
1220 // the paths and file names of the apk file under the flattend APEX.
1221 // If this is set to APP, then the paths and file names are modified
1222 // by the Make build system. For example, it is installed to
1223 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1224 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1225 // appends module name (which is <apexname>.<Appname> to the path.
1226 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001227 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001228 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001229 }
1230}
1231
Jiyong Parkf653b052019-11-18 15:39:01 +09001232// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001233type apexFile struct {
1234 builtFile android.Path
1235 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001236 installDir string
1237 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001238 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001239 // list of symlinks that will be created in installDir that point to this apexFile
1240 symlinks []string
1241 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001242 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001243
1244 requiredModuleNames []string
1245 targetRequiredModuleNames []string
1246 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001247
Colin Cross503c1d02020-01-28 14:00:53 -08001248 jacocoReportClassesFile android.Path // only for javalibs and apps
1249 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001250 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001251
1252 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001253}
1254
Jiyong Park1833cef2019-12-13 13:28:36 +09001255func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1256 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001257 builtFile: builtFile,
1258 moduleName: moduleName,
1259 installDir: installDir,
1260 class: class,
1261 module: module,
1262 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001263 if module != nil {
1264 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001265 ret.requiredModuleNames = module.RequiredModuleNames()
1266 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1267 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001268 }
1269 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001270}
1271
1272func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001273 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001274}
1275
Jiyong Park7cd10e32020-01-14 09:22:18 +09001276// Path() returns path of this apex file relative to the APEX root
1277func (af *apexFile) Path() string {
1278 return filepath.Join(af.installDir, af.builtFile.Base())
1279}
1280
1281// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1282func (af *apexFile) SymlinkPaths() []string {
1283 var ret []string
1284 for _, symlink := range af.symlinks {
1285 ret = append(ret, filepath.Join(af.installDir, symlink))
1286 }
1287 return ret
1288}
1289
1290func (af *apexFile) AvailableToPlatform() bool {
1291 if af.module == nil {
1292 return false
1293 }
1294 if am, ok := af.module.(android.ApexModule); ok {
1295 return am.AvailableFor(android.AvailableToPlatform)
1296 }
1297 return false
1298}
1299
Jiyong Park678c8812020-02-07 17:25:49 +09001300type depInfo struct {
1301 to string
1302 from []string
1303 isExternal bool
1304}
1305
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001306type apexBundle struct {
1307 android.ModuleBase
1308 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001309 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001310 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001311
Jiyong Park5d790c32019-11-15 18:40:32 +09001312 properties apexBundleProperties
1313 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001314 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001315
Jooyung Hanf21c7972019-12-16 22:32:06 +09001316 // specific to apex_vndk modules
1317 vndkProperties apexVndkProperties
1318
Colin Crossa4925902018-11-16 11:36:28 -08001319 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001320 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001321 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001322
Jiyong Park03b68dd2019-07-26 23:20:40 +09001323 prebuiltFileToDelete string
1324
Jiyong Park42cca6c2019-04-01 11:15:50 +09001325 public_key_file android.Path
1326 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001327
1328 container_certificate_file android.Path
1329 container_private_key_file android.Path
1330
Jooyung Han54aca7b2019-11-20 02:26:02 +09001331 fileContexts android.Path
1332
Jiyong Park8fd61922018-11-08 02:50:25 +09001333 // list of files to be included in this apex
1334 filesInfo []apexFile
1335
Jiyong Park956305c2020-01-09 12:32:06 +09001336 // list of module names that should be installed along with this APEX
1337 requiredDeps []string
1338
Jiyong Park956305c2020-01-09 12:32:06 +09001339 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001340 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001341
Sundong Ahnabb64432019-10-22 13:58:29 +09001342 testApex bool
1343 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001344 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001345 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001346
Jooyung Han214bf372019-11-12 13:03:50 +09001347 manifestJsonOut android.WritablePath
1348 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001349
Jooyung Han002ab682020-01-08 01:57:58 +09001350 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001351 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001352 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001353 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1354 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001355
1356 // Suffix of module name in Android.mk
1357 // ".flattened", ".apex", ".zipapex", or ""
1358 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001359
1360 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001361
1362 // Whether to create symlink to the system file instead of having a file
1363 // inside the apex or not
1364 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001365
1366 // Struct holding the merged notice file paths in different formats
1367 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001368}
1369
Jiyong Park397e55e2018-10-24 21:09:55 +09001370func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001371 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001372 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001373 // Use *FarVariation* to be able to depend on modules having
1374 // conflicting variations with this module. This is required since
1375 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1376 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001377 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001378 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001379 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001380 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001381 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001382
Jooyung Han643adc42020-02-27 13:50:06 +09001383 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1384 {Mutator: "image", Variation: imageVariation},
1385 {Mutator: "link", Variation: "shared"},
1386 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1387 }...), jniLibTag, nativeModules.Jni_libs...)
1388
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001389 ctx.AddFarVariationDependencies(append(target.Variations(),
1390 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001391 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001392
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001393 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001394 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001395 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001396 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001397}
1398
Alex Light9670d332019-01-29 18:07:33 -08001399func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1400 if ctx.Os().Class == android.Device {
1401 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1402 } else {
1403 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1404 if ctx.Os().Bionic() {
1405 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1406 } else {
1407 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1408 }
1409 }
1410}
1411
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001412func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001413 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1414 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1415 }
1416
Jiyong Park397e55e2018-10-24 21:09:55 +09001417 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001418 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001419
1420 a.combineProperties(ctx)
1421
Jiyong Park397e55e2018-10-24 21:09:55 +09001422 has32BitTarget := false
1423 for _, target := range targets {
1424 if target.Arch.ArchType.Multilib == "lib32" {
1425 has32BitTarget = true
1426 }
1427 }
1428 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001429 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001430 // multilib.both
1431 addDependenciesForNativeModules(ctx,
1432 ApexNativeDependencies{
1433 Native_shared_libs: a.properties.Native_shared_libs,
1434 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001435 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001436 Binaries: nil,
1437 },
1438 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001439
Jiyong Park397e55e2018-10-24 21:09:55 +09001440 // Add native modules targetting both ABIs
1441 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001442 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001443 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001444 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001445
Alex Light3d673592019-01-18 14:37:31 -08001446 isPrimaryAbi := i == 0
1447 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001448 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001449 // multilib.first
1450 addDependenciesForNativeModules(ctx,
1451 ApexNativeDependencies{
1452 Native_shared_libs: nil,
1453 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001454 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001455 Binaries: a.properties.Binaries,
1456 },
1457 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001458
1459 // Add native modules targetting the first ABI
1460 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001461 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001462 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001463 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001464 }
1465
1466 switch target.Arch.ArchType.Multilib {
1467 case "lib32":
1468 // Add native modules targetting 32-bit ABI
1469 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001470 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001471 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001472 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001473
1474 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001475 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001476 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001477 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001478 case "lib64":
1479 // Add native modules targetting 64-bit ABI
1480 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001481 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001482 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001483 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001484
1485 if !has32BitTarget {
1486 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001487 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001488 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001489 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001490 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001491
1492 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1493 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1494 if sanitizer == "hwaddress" {
1495 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001496 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001497 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001498 break
1499 }
1500 }
1501 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001502 }
1503
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001504 }
1505
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001506 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1507 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1508 // b/144532908
1509 archForPrebuiltEtc := config.Arches()[0]
1510 for _, arch := range config.Arches() {
1511 // Prefer 64-bit arch if there is any
1512 if arch.ArchType.Multilib == "lib64" {
1513 archForPrebuiltEtc = arch
1514 break
1515 }
1516 }
1517 ctx.AddFarVariationDependencies([]blueprint.Variation{
1518 {Mutator: "os", Variation: ctx.Os().String()},
1519 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1520 }, prebuiltTag, a.properties.Prebuilts...)
1521
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001522 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1523 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001524
Ulya Trafimovich44561882020-01-03 13:25:54 +00001525 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1526 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1527 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1528 javaLibTag, "jacocoagent")
1529 }
1530
Jiyong Park23c52b02019-02-02 13:13:47 +09001531 if String(a.properties.Key) == "" {
1532 ctx.ModuleErrorf("key is missing")
1533 return
1534 }
1535 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001536
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001537 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001538 if cert != "" {
1539 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001540 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001541
1542 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1543 if len(a.properties.Uses_sdks) > 0 {
1544 sdkRefs := []android.SdkRef{}
1545 for _, str := range a.properties.Uses_sdks {
1546 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1547 sdkRefs = append(sdkRefs, parsed)
1548 }
1549 a.BuildWithSdks(sdkRefs)
1550 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001551}
1552
Jiyong Park5d790c32019-11-15 18:40:32 +09001553func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1554 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1555 androidAppTag, a.overridableProperties.Apps...)
1556}
1557
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001558func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1559 // direct deps of an APEX bundle are all part of the APEX bundle
1560 return true
1561}
1562
Colin Cross0ea8ba82019-06-06 14:33:29 -07001563func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001564 moduleName := ctx.ModuleName()
1565 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1566 // we check with the pseudo module name to see if its certificate is overridden.
1567 if a.vndkApex {
1568 moduleName = vndkApexName
1569 }
1570 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001571 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001572 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001573 }
1574 return String(a.properties.Certificate)
1575}
1576
Colin Cross41955e82019-05-29 14:40:35 -07001577func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1578 switch tag {
1579 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001580 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001581 default:
1582 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001583 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001584}
1585
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001586func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001587 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001588}
1589
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001590func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1591 return proptools.Bool(a.properties.Test_only_no_hashtree)
1592}
1593
Jiyong Park7c1dc612019-01-05 11:15:24 +09001594func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001595 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001596 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001597 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001598 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001599 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001600 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001601 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001602 }
1603}
1604
Jiyong Parkf97782b2019-02-13 20:28:58 +09001605func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1606 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1607 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1608 }
1609}
1610
Jiyong Park388ef3f2019-01-28 19:47:32 +09001611func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001612 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1613 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001614 }
1615
1616 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001617 globalSanitizerNames := []string{}
1618 if a.Host() {
1619 globalSanitizerNames = ctx.Config().SanitizeHost()
1620 } else {
1621 arches := ctx.Config().SanitizeDeviceArch()
1622 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1623 globalSanitizerNames = ctx.Config().SanitizeDevice()
1624 }
1625 }
1626 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001627}
1628
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001629func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001630 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001631}
1632
1633func (a *apexBundle) PreventInstall() {
1634 a.properties.PreventInstall = true
1635}
1636
1637func (a *apexBundle) HideFromMake() {
1638 a.properties.HideFromMake = true
1639}
1640
Jiyong Park956305c2020-01-09 12:32:06 +09001641func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1642 a.properties.IsCoverageVariant = coverage
1643}
1644
Jiyong Parkf653b052019-11-18 15:39:01 +09001645// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001646func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001647 // Decide the APEX-local directory by the multilib of the library
1648 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001649 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001650 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001651 case "lib32":
1652 dirInApex = "lib"
1653 case "lib64":
1654 dirInApex = "lib64"
1655 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001656 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001657 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001658 }
Jooyung Han35155c42020-02-06 17:33:20 +09001659 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001660 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001661 // Special case for Bionic libs and other libs installed with them. This is
1662 // to prevent those libs from being included in the search path
1663 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1664 // those libs in the Runtime APEX are available via the legacy paths in
1665 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1666 // to the legacy paths and thus will be loaded into the default linker
1667 // namespace (aka "platform" namespace). If the libs are directly in
1668 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1669 // into the runtime linker namespace, which will result in double loading of
1670 // them, which isn't supported.
1671 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001672 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001673
Jiyong Parkf653b052019-11-18 15:39:01 +09001674 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001675 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001676}
1677
Jiyong Park1833cef2019-12-13 13:28:36 +09001678func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001679 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001680 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001681 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001682 }
Jooyung Han35155c42020-02-06 17:33:20 +09001683 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001684 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001685 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 af.symlinks = cc.Symlinks()
1687 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001688}
1689
Jiyong Park1833cef2019-12-13 13:28:36 +09001690func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 dirInApex := "bin"
1692 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001693 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001694}
Jiyong Park1833cef2019-12-13 13:28:36 +09001695func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001696 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001697 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1698 if err != nil {
1699 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001700 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001701 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001702 fileToCopy := android.PathForOutput(ctx, s)
1703 // NB: Since go binaries are static we don't need the module for anything here, which is
1704 // good since the go tool is a blueprint.Module not an android.Module like we would
1705 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001706 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001707}
1708
Jiyong Park1833cef2019-12-13 13:28:36 +09001709func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001710 dirInApex := filepath.Join("bin", sh.SubDir())
1711 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001712 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001713 af.symlinks = sh.Symlinks()
1714 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001715}
1716
Jooyung Han58f26ab2019-12-18 15:34:32 +09001717// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1718type javaLibrary interface {
1719 android.Module
1720 java.Dependency
1721}
1722
1723func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001724 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001725 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001726 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1727 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1728 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001729}
1730
Jiyong Park1833cef2019-12-13 13:28:36 +09001731func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001732 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1733 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001734 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001735}
1736
atrost6e126252020-01-27 17:01:16 +00001737func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1738 dirInApex := filepath.Join("etc", config.SubDir())
1739 fileToCopy := config.CompatConfig()
1740 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1741}
1742
Jiyong Park1833cef2019-12-13 13:28:36 +09001743func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001744 android.Module
1745 Privileged() bool
1746 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001747 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001748 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001749}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001750 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001751 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001752 appDir = "priv-app"
1753 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001754 dirInApex := filepath.Join(appDir, pkgName)
1755 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001756 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1757 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001758 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001759
1760 if app, ok := aapp.(interface {
1761 OverriddenManifestPackageName() string
1762 }); ok {
1763 af.overriddenPackageName = app.OverriddenManifestPackageName()
1764 }
Jiyong Park618922e2020-01-08 13:35:43 +09001765 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001766}
1767
Roland Levillain935639d2019-08-13 14:55:28 +01001768// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1769type flattenedApexContext struct {
1770 android.ModuleContext
1771}
1772
1773func (c *flattenedApexContext) InstallBypassMake() bool {
1774 return true
1775}
1776
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001777// Function called while walking an APEX's payload dependencies.
1778//
1779// Return true if the `to` module should be visited, false otherwise.
1780type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1781
Jiyong Park201cedd2020-02-07 17:25:49 +09001782// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001783func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001784 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001785 am, ok := child.(android.ApexModule)
1786 if !ok || !am.CanHaveApexVariants() {
1787 return false
1788 }
1789
1790 // Check for the direct dependencies that contribute to the payload
1791 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1792 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001793 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001794 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001795 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001796 return false
1797 }
1798
1799 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001800 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001801 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001802 }
1803
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001804 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001805 })
1806}
1807
Jooyung Han03b51852020-02-26 22:45:42 +09001808func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1809 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001810 intVer, err := android.ApiStrToNum(ctx, ver)
1811 if err != nil {
1812 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001813 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001814 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001815}
1816
Paul Duffinc5192442020-03-31 11:31:36 +01001817// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1818// a dependency tag.
1819var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1820
1821func PrettyPrintTag(tag blueprint.DependencyTag) string {
1822 // Use tag's custom String() method if available.
1823 if stringer, ok := tag.(fmt.Stringer); ok {
1824 return stringer.String()
1825 }
1826
1827 // Otherwise, get a default string representation of the tag's struct.
1828 tagString := fmt.Sprintf("%#v", tag)
1829
1830 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1831 tagString = tagCleaner.ReplaceAllString(tagString, "")
1832 return tagString
1833}
1834
Jiyong Park201cedd2020-02-07 17:25:49 +09001835// Ensures that the dependencies are marked as available for this APEX
1836func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1837 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1838 if ctx.Host() || a.testApex || a.vndkApex {
1839 return
1840 }
1841
Jiyong Park58d10902020-03-28 14:43:19 +09001842 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1843 // Requiring them and their transitive depencies with apex_available is not right
1844 // because they just add noise.
1845 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1846 return
1847 }
1848
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001849 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1850 if externalDep {
1851 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1852 return false
1853 }
1854
Jiyong Park201cedd2020-02-07 17:25:49 +09001855 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001856 fromName := ctx.OtherModuleName(from)
1857 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001858
1859 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1860 // do any of its dependencies.
1861 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1862 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1863 return false
1864 }
1865
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001866 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1867 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001868 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001869 message := ""
Paul Duffinc5192442020-03-31 11:31:36 +01001870 tagPath := ctx.GetTagPath()
1871 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1872 walkPath := ctx.GetWalkPath()[1:]
1873 for i, m := range walkPath {
1874 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffindf915ff2020-03-30 17:58:21 +01001875 }
1876 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 +01001877 // Visit this module's dependencies to check and report any issues with their availability.
1878 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001879 })
1880}
1881
Jiyong Park678c8812020-02-07 17:25:49 +09001882// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1883func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1884 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001885 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001886 if from.Name() == to.Name() {
1887 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001888 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1889 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001890 }
1891
1892 if info, exists := a.depInfos[to.Name()]; exists {
1893 if !android.InList(from.Name(), info.from) {
1894 info.from = append(info.from, from.Name())
1895 }
1896 info.isExternal = info.isExternal && externalDep
1897 a.depInfos[to.Name()] = info
1898 } else {
1899 a.depInfos[to.Name()] = depInfo{
1900 to: to.Name(),
1901 from: []string{from.Name()},
1902 isExternal: externalDep,
1903 }
1904 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001905
1906 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1907 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001908 })
1909}
1910
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001911func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001912 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1913 switch a.properties.ApexType {
1914 case imageApex:
1915 if buildFlattenedAsDefault {
1916 a.suffix = imageApexSuffix
1917 } else {
1918 a.suffix = ""
1919 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001920
1921 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001922 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001923 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001924 }
1925 case zipApex:
1926 if proptools.String(a.properties.Payload_type) == "zip" {
1927 a.suffix = ""
1928 a.primaryApexType = true
1929 } else {
1930 a.suffix = zipApexSuffix
1931 }
1932 case flattenedApex:
1933 if buildFlattenedAsDefault {
1934 a.suffix = ""
1935 a.primaryApexType = true
1936 } else {
1937 a.suffix = flattenedSuffix
1938 }
Alex Light5098a612018-11-29 17:12:15 -08001939 }
1940
Roland Levillain630846d2019-06-26 12:48:34 +01001941 if len(a.properties.Tests) > 0 && !a.testApex {
1942 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1943 return
1944 }
1945
Jiyong Park0f80c182020-01-31 02:49:53 +09001946 a.checkApexAvailability(ctx)
1947
Jiyong Park678c8812020-02-07 17:25:49 +09001948 a.collectDepsInfo(ctx)
1949
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001950 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1951
Jooyung Hane1633032019-08-01 17:41:43 +09001952 // native lib dependencies
1953 var provideNativeLibs []string
1954 var requireNativeLibs []string
1955
Jooyung Han5c998b92019-06-27 11:30:33 +09001956 // Check if "uses" requirements are met with dependent apexBundles
1957 var providedNativeSharedLibs []string
1958 useVendor := proptools.Bool(a.properties.Use_vendor)
1959 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1960 if ctx.OtherModuleDependencyTag(m) != usesTag {
1961 return
1962 }
1963 otherName := ctx.OtherModuleName(m)
1964 other, ok := m.(*apexBundle)
1965 if !ok {
1966 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1967 return
1968 }
1969 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1970 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1971 return
1972 }
1973 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1974 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1975 return
1976 }
1977 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1978 })
1979
Jiyong Parkf653b052019-11-18 15:39:01 +09001980 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001981 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001982 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001983 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001984 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1985 return false
1986 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001987 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001988 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001989 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001990 case sharedLibTag, jniLibTag:
1991 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001992 if c, ok := child.(*cc.Module); ok {
1993 // bootstrap bionic libs are treated as provided by system
1994 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1995 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001996 }
Jooyung Han643adc42020-02-27 13:50:06 +09001997 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1998 fi.isJniLib = isJniLib
1999 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002000 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002001 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002002 propertyName := "native_shared_libs"
2003 if isJniLib {
2004 propertyName = "jni_libs"
2005 }
2006 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002007 }
2008 case executableTag:
2009 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002010 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002011 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002012 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002013 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002014 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002015 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002016 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002017 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002018 } else {
Alex Light778127a2019-02-27 14:19:50 -08002019 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 +09002020 }
2021 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002022 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002023 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002024 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002025 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2026 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002027 filesInfo = append(filesInfo, af)
2028 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002029 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002030 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2031 af := apexFileForJavaLibrary(ctx, sdkLib)
2032 if !af.Ok() {
2033 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2034 return false
2035 }
2036 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002037 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002038 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002039 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002040 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002041 case androidAppTag:
2042 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2043 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002044 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002045 return true // track transitive dependencies
2046 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002047 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002048 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2049 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002050 } else {
2051 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2052 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002053 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002054 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002055 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002056 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2057 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002058 } else {
atrost6e126252020-01-27 17:01:16 +00002059 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002060 }
Roland Levillain630846d2019-06-26 12:48:34 +01002061 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002062 if ccTest, ok := child.(*cc.Module); ok {
2063 if ccTest.IsTestPerSrcAllTestsVariation() {
2064 // Multiple-output test module (where `test_per_src: true`).
2065 //
2066 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2067 // We do not add this variation to `filesInfo`, as it has no output;
2068 // however, we do add the other variations of this module as indirect
2069 // dependencies (see below).
2070 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002071 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002072 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002073 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002074 af.class = nativeTest
2075 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002076 }
Roland Levillain630846d2019-06-26 12:48:34 +01002077 } else {
2078 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2079 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002080 case keyTag:
2081 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002082 a.private_key_file = key.private_key_file
2083 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002084 } else {
2085 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002086 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002087 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002088 case certificateTag:
2089 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002090 a.container_certificate_file = dep.Certificate.Pem
2091 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002092 } else {
2093 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2094 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002095 case android.PrebuiltDepTag:
2096 // If the prebuilt is force disabled, remember to delete the prebuilt file
2097 // that might have been installed in the previous builds
2098 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2099 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2100 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002101 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002102 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002103 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002104 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002105 // We cannot use a switch statement on `depTag` here as the checked
2106 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002107 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002108 if cc, ok := child.(*cc.Module); ok {
2109 if android.InList(cc.Name(), providedNativeSharedLibs) {
2110 // If we're using a shared library which is provided from other APEX,
2111 // don't include it in this APEX
2112 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002113 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002114 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002115 // If the dependency is a stubs lib, don't include it in this APEX,
2116 // but make sure that the lib is installed on the device.
2117 // In case no APEX is having the lib, the lib is installed to the system
2118 // partition.
2119 //
2120 // Always include if we are a host-apex however since those won't have any
2121 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002122 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2123 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002124 }
Jooyung Hane1633032019-08-01 17:41:43 +09002125 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002126 // Don't track further
2127 return false
2128 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002129 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002130 af.transitiveDep = true
2131 filesInfo = append(filesInfo, af)
2132 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002133 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002134 } else if cc.IsTestPerSrcDepTag(depTag) {
2135 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002136 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002137 // Handle modules created as `test_per_src` variations of a single test module:
2138 // use the name of the generated test binary (`fileToCopy`) instead of the name
2139 // of the original test module (`depName`, shared by all `test_per_src`
2140 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002141 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002142 // these are not considered transitive dep
2143 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002144 filesInfo = append(filesInfo, af)
2145 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002146 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002147 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002148 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2149 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002150 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2151 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2152 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2153 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002154 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffindddd5462020-04-07 15:25:44 +01002155 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002156 }
2157 }
2158 }
2159 return false
2160 })
2161
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002162 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2163 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2164 // via the global boot image config.
2165 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002166 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002167 dirInApex := filepath.Join("javalib", arch.String())
2168 for _, f := range files {
2169 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002170 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002171 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002172 }
2173 }
2174 }
2175
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002176 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002177 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2178 return
2179 }
2180
Jiyong Park8fd61922018-11-08 02:50:25 +09002181 // remove duplicates in filesInfo
2182 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002183 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002184 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002185 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002186 if e, ok := encountered[dest]; !ok {
2187 encountered[dest] = f
2188 } else {
2189 // If a module is directly included and also transitively depended on
2190 // consider it as directly included.
2191 e.transitiveDep = e.transitiveDep && f.transitiveDep
2192 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002193 }
2194 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002195 var result []apexFile
2196 for _, v := range encountered {
2197 result = append(result, v)
2198 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002199 return result
2200 }
2201 filesInfo = removeDup(filesInfo)
2202
2203 // to have consistent build rules
2204 sort.Slice(filesInfo, func(i, j int) bool {
2205 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2206 })
2207
Jiyong Park8fd61922018-11-08 02:50:25 +09002208 a.installDir = android.PathForModuleInstall(ctx, "apex")
2209 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002210
Jooyung Han54aca7b2019-11-20 02:26:02 +09002211 if a.properties.ApexType != zipApex {
2212 if a.properties.File_contexts == nil {
2213 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2214 } else {
2215 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2216 if a.Platform() {
2217 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2218 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2219 }
2220 }
2221 }
2222 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2223 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2224 return
2225 }
2226 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002227 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2228 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2229 // the same library in the system partition, thus effectively sharing the same libraries
2230 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2231 // in the APEX.
2232 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2233 a.installable() &&
2234 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002235
Jiyong Park9d677202020-02-19 16:29:35 +09002236 // We don't need the optimization for updatable APEXes, as it might give false signal
2237 // to the system health when the APEXes are still bundled (b/149805758)
2238 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2239 a.linkToSystemLib = false
2240 }
2241
Jiyong Park638d30e2020-02-26 18:27:19 +09002242 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2243 if ctx.Host() {
2244 a.linkToSystemLib = false
2245 }
2246
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002247 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002248 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2249
2250 a.setCertificateAndPrivateKey(ctx)
2251 if a.properties.ApexType == flattenedApex {
2252 a.buildFlattenedApex(ctx)
2253 } else {
2254 a.buildUnflattenedApex(ctx)
2255 }
2256
Jooyung Han002ab682020-01-08 01:57:58 +09002257 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002258
2259 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002260}
2261
Jooyung Han5e9013b2020-03-10 06:23:13 +09002262func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002263 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002264 moduleName = normalizeModuleName(moduleName)
2265
2266 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2267 return true
2268 }
2269
2270 key = android.AvailableToAnyApex
2271 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2272 return true
2273 }
2274
2275 return false
2276}
2277
2278func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002279 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2280 // system. Trim the prefix for the check since they are confusing
2281 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2282 if strings.HasPrefix(moduleName, "libclang_rt.") {
2283 // This module has many arch variants that depend on the product being built.
2284 // We don't want to list them all
2285 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002286 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002287 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002288}
2289
Jooyung Han344d5432019-08-23 11:17:39 +09002290func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002291 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002292 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002293 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002294 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002295 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002296 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2297 })
Alex Light5098a612018-11-29 17:12:15 -08002298 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002299 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002300 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002301 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002302 return module
2303}
Jiyong Park30ca9372019-02-07 16:27:23 +09002304
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002305func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002306 bundle := newApexBundle()
2307 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002308 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002309 return bundle
2310}
2311
Jiyong Parkfce0b422020-02-11 03:56:06 +09002312// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2313// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002314func testApexBundleFactory() android.Module {
2315 bundle := newApexBundle()
2316 bundle.testApex = true
2317 return bundle
2318}
2319
Jiyong Parkfce0b422020-02-11 03:56:06 +09002320// apex packages other modules into an APEX file which is a packaging format for system-level
2321// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002322func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002323 return newApexBundle()
2324}
2325
Jiyong Park30ca9372019-02-07 16:27:23 +09002326//
2327// Defaults
2328//
2329type Defaults struct {
2330 android.ModuleBase
2331 android.DefaultsModuleBase
2332}
2333
Jiyong Park30ca9372019-02-07 16:27:23 +09002334func defaultsFactory() android.Module {
2335 return DefaultsFactory()
2336}
2337
2338func DefaultsFactory(props ...interface{}) android.Module {
2339 module := &Defaults{}
2340
2341 module.AddProperties(props...)
2342 module.AddProperties(
2343 &apexBundleProperties{},
2344 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002345 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002346 )
2347
2348 android.InitDefaultsModule(module)
2349 return module
2350}
Jiyong Park5d790c32019-11-15 18:40:32 +09002351
2352//
2353// OverrideApex
2354//
2355type OverrideApex struct {
2356 android.ModuleBase
2357 android.OverrideModuleBase
2358}
2359
2360func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2361 // All the overrides happen in the base module.
2362}
2363
2364// override_apex is used to create an apex module based on another apex module
2365// by overriding some of its properties.
2366func overrideApexFactory() android.Module {
2367 m := &OverrideApex{}
2368 m.AddProperties(&overridableProperties{})
2369
2370 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2371 android.InitOverrideModule(m)
2372 return m
2373}