blob: 07253c1cf255ec27d50fb40ccfc18554ad6e98af [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 Duffinf0207962020-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 Parkfa899442020-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 Parkfa899442020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
56 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000064 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin404db3f2020-03-06 12:30:13 +000065
66 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067)
68
Paul Duffin404db3f2020-03-06 12:30:13 +000069// Transform the map of apex -> modules to module -> apexes.
70func invertApexWhiteList(m map[string][]string) map[string][]string {
71 r := make(map[string][]string)
72 for apex, modules := range m {
73 for _, module := range modules {
74 r[module] = append(r[module], apex)
75 }
76 }
77 return r
78}
79
80// Retrieve the while list of apexes to which the supplied module belongs.
81func WhitelistedApexAvailable(moduleName string) []string {
82 return inverseApexAvailWl[normalizeModuleName(moduleName)]
83}
84
Anton Hansson5053c292020-01-10 15:12:39 +000085// This is a map from apex to modules, which overrides the
86// apex_available setting for that particular module to make
87// it available for the apex regardless of its setting.
88// TODO(b/147364041): remove this
89func makeApexAvailableWhitelist() map[string][]string {
90 // The "Module separator"s below are employed to minimize merge conflicts.
91 m := make(map[string][]string)
92 //
93 // Module separator
94 //
Jiyong Parkfa899442020-01-31 02:49:53 +090095 m["com.android.adbd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090096 "libadbd_auth",
Jiyong Parkfa899442020-01-31 02:49:53 +090097 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +090098 "libcap",
Jiyong Parkfa899442020-01-31 02:49:53 +090099 "libmdnssd",
100 "libminijail",
101 "libminijail_gen_constants",
102 "libminijail_gen_constants_obj",
103 "libminijail_gen_syscall",
104 "libminijail_gen_syscall_obj",
105 "libminijail_generated",
106 "libpackagelistparser",
107 "libpcre2",
108 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900109 }
110 //
111 // Module separator
112 //
Paul Duffinc23d9f62020-03-10 13:44:19 +0000113 artApexContents := []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900114 "art_cmdlineparser_headers",
115 "art_disassembler_headers",
116 "art_libartbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900117 "bionic_libc_platform_headers",
118 "core-repackaged-icu4j",
119 "cpp-define-generator-asm-support",
120 "cpp-define-generator-definitions",
121 "crtbegin_dynamic",
122 "crtbegin_dynamic1",
123 "crtbegin_so1",
124 "crtbrand",
Jiyong Parkfa899442020-01-31 02:49:53 +0900125 "dex2oat_headers",
126 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900127 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900128 "javavm_headers",
129 "jni_platform_headers",
130 "libPlatformProperties",
131 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000132 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900133 "libandroidicuinit",
134 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000135 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900136 "libasync_safe",
Jiyong Parkfa899442020-01-31 02:49:53 +0900137 "libdexfile_all_headers",
138 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000139 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900140 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000141 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900142 "libfdlibm",
143 "libgtest_prod",
144 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000145 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900146 "libicuuc_headers",
147 "libicuuc_stubdata",
148 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900149 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000150 "liblzma",
151 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900152 "libnativebridge-headers",
153 "libnativehelper_header_only",
154 "libnativeloader-headers",
155 "libnpt_headers",
156 "libopenjdkjvmti_headers",
157 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000158 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900159 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000160 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900161 "libv8",
162 "libv8base",
163 "libv8gen",
164 "libv8platform",
165 "libv8sampler",
166 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000167 "libvixl",
168 "libvixld",
169 "libz",
170 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000172 }
Paul Duffinc23d9f62020-03-10 13:44:19 +0000173 m["com.android.art.debug"] = artApexContents
174 m["com.android.art.release"] = artApexContents
Anton Hansson5053c292020-01-10 15:12:39 +0000175 //
176 // Module separator
177 //
178 m["com.android.bluetooth.updatable"] = []string{
179 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000180 "android.hardware.bluetooth.a2dp@1.0",
181 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900182 "android.hardware.bluetooth@1.0",
183 "android.hardware.bluetooth@1.1",
184 "android.hardware.graphics.bufferqueue@1.0",
185 "android.hardware.graphics.bufferqueue@2.0",
186 "android.hardware.graphics.common@1.0",
187 "android.hardware.graphics.common@1.1",
188 "android.hardware.graphics.common@1.2",
189 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000190 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900191 "android.hidl.token@1.0",
192 "android.hidl.token@1.0-utils",
193 "avrcp-target-service",
194 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 "bluetooth-protos-lite",
196 "bluetooth.mapsapi",
197 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900198 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900199 "ipmemorystore-aidl-interfaces-V5-java",
200 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900201 "internal_include_headers",
202 "lib-bt-packets",
203 "lib-bt-packets-avrcp",
204 "lib-bt-packets-base",
205 "libFraunhoferAAC",
206 "libaudio-a2dp-hw-utils",
207 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900208 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000209 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900210 "libbluetooth-types",
211 "libbluetooth-types-header",
212 "libbluetooth_gd",
213 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000214 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libbt-audio-hal-interface",
216 "libbt-bta",
217 "libbt-common",
218 "libbt-hci",
219 "libbt-platform-protos-lite",
220 "libbt-protos-lite",
221 "libbt-sbc-decoder",
222 "libbt-sbc-encoder",
223 "libbt-stack",
224 "libbt-utils",
225 "libbtcore",
226 "libbtdevice",
227 "libbte",
228 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000229 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000230 "libevent",
231 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900232 "libg722codec",
233 "libgtest_prod",
234 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900235 "libmedia_headers",
236 "libmodpb64",
237 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000238 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900239 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900240 "libstagefright_foundation_headers",
241 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000242 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900243 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000244 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900245 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000246 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900247 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900248 "net-utils-services-common",
249 "netd_aidl_interface-unstable-java",
250 "netd_event_listener_interface-java",
251 "netlink-client",
252 "networkstack-aidl-interfaces-unstable-java",
253 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900254 "sap-api-java-static",
255 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000256 }
257 //
258 // Module separator
259 //
260 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
261 //
262 // Module separator
263 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900264 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900265 "boringssl_self_test",
Jiyong Parkfa899442020-01-31 02:49:53 +0900266 "libnativehelper_header_only",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900267 "unsupportedappusage",
Jiyong Parkfa899442020-01-31 02:49:53 +0900268 }
Anton Hansson5053c292020-01-10 15:12:39 +0000269 //
270 // Module separator
271 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900272 m["com.android.extservices"] = []string{
273 "flatbuffer_headers",
274 "liblua",
275 "libtextclassifier",
276 "libtextclassifier_hash_static",
277 "libtflite_static",
278 "libutf",
279 "libz_current",
280 "tensorflow_headers",
281 }
282 //
283 // Module separator
284 //
285 m["com.android.cronet"] = []string{
286 "cronet_impl_common_java",
287 "cronet_impl_native_java",
288 "cronet_impl_platform_java",
289 "libcronet.80.0.3986.0",
290 "org.chromium.net.cronet",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900291 "org.chromium.net.cronet.xml",
Jiyong Parkfa899442020-01-31 02:49:53 +0900292 "prebuilt_libcronet.80.0.3986.0",
293 }
294 //
295 // Module separator
296 //
297 m["com.android.neuralnetworks"] = []string{
298 "android.hardware.neuralnetworks@1.0",
299 "android.hardware.neuralnetworks@1.1",
300 "android.hardware.neuralnetworks@1.2",
301 "android.hardware.neuralnetworks@1.3",
302 "android.hidl.allocator@1.0",
303 "android.hidl.memory.token@1.0",
304 "android.hidl.memory@1.0",
305 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900306 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900307 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900308 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900309 "libprocessgroup",
310 "libprocessgroup_headers",
311 "libprocpartition",
312 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900313 }
Anton Hansson5053c292020-01-10 15:12:39 +0000314 //
315 // Module separator
316 //
Anton Hansson5053c292020-01-10 15:12:39 +0000317 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900318 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000319 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900320 "android.hardware.cas@1.0",
321 "android.hardware.configstore-utils",
322 "android.hardware.configstore@1.0",
323 "android.hardware.configstore@1.1",
324 "android.hardware.graphics.allocator@2.0",
325 "android.hardware.graphics.allocator@3.0",
326 "android.hardware.graphics.bufferqueue@1.0",
327 "android.hardware.graphics.bufferqueue@2.0",
328 "android.hardware.graphics.common@1.0",
329 "android.hardware.graphics.common@1.1",
330 "android.hardware.graphics.common@1.2",
331 "android.hardware.graphics.mapper@2.0",
332 "android.hardware.graphics.mapper@2.1",
333 "android.hardware.graphics.mapper@3.0",
334 "android.hardware.media.omx@1.0",
335 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000336 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000337 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900338 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000339 "android.hidl.token@1.0",
340 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900341 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900342 "gl_headers",
343 "libEGL",
344 "libEGL_blobCache",
345 "libEGL_getProcAddress",
346 "libFLAC",
347 "libFLAC-config",
348 "libFLAC-headers",
349 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000350 "libaacextractor",
351 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900352 "libarect",
353 "libasync_safe",
354 "libaudio_system_headers",
355 "libaudioclient",
356 "libaudioclient_headers",
357 "libaudiofoundation",
358 "libaudiofoundation_headers",
359 "libaudiomanager",
360 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000361 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900362 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900363 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900364 "libbluetooth-types-header",
365 "libbufferhub",
366 "libbufferhub_headers",
367 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900368 "libc_malloc_debug_backtrace",
369 "libcamera_client",
370 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900371 "libdexfile_external_headers",
372 "libdexfile_support",
373 "libdvr_headers",
374 "libexpat",
375 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000376 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900377 "libgrallocusage",
378 "libgraphicsenv",
379 "libgui",
380 "libgui_headers",
381 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900382 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900383 "liblzma",
384 "libmath",
385 "libmedia",
386 "libmedia_codeclist",
387 "libmedia_headers",
388 "libmedia_helper",
389 "libmedia_helper_headers",
390 "libmedia_midiiowrapper",
391 "libmedia_omx",
392 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000393 "libmidiextractor",
394 "libmkvextractor",
395 "libmp3extractor",
396 "libmp4extractor",
397 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900398 "libnativebase_headers",
399 "libnativebridge-headers",
400 "libnativebridge_lazy",
401 "libnativeloader-headers",
402 "libnativeloader_lazy",
403 "libnativewindow_headers",
404 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000405 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900406 "libpackagelistparser",
407 "libpcre2",
408 "libpdx",
409 "libpdx_default_transport",
410 "libpdx_headers",
411 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000412 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900413 "libprocessgroup_headers",
414 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900415 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000416 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900417 "libspeexresampler",
418 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000419 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900420 "libstagefright_flacdec",
421 "libstagefright_foundation",
422 "libstagefright_foundation_headers",
423 "libstagefright_foundation_without_imemory",
424 "libstagefright_headers",
425 "libstagefright_id3",
426 "libstagefright_metadatautils",
427 "libstagefright_mpeg2extractor",
428 "libstagefright_mpeg2support",
429 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900430 "libui",
431 "libui_headers",
432 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900433 "libvibrator",
434 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000435 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libwebm",
437 "media_ndk_headers",
438 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000439 "updatable-media",
440 }
441 //
442 // Module separator
443 //
444 m["com.android.media.swcodec"] = []string{
445 "android.frameworks.bufferhub@1.0",
446 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900447 "android.hardware.configstore-utils",
448 "android.hardware.configstore@1.0",
449 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000450 "android.hardware.graphics.allocator@2.0",
451 "android.hardware.graphics.allocator@3.0",
452 "android.hardware.graphics.allocator@4.0",
453 "android.hardware.graphics.bufferqueue@1.0",
454 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900455 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000456 "android.hardware.graphics.common@1.0",
457 "android.hardware.graphics.common@1.1",
458 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000459 "android.hardware.graphics.mapper@2.0",
460 "android.hardware.graphics.mapper@2.1",
461 "android.hardware.graphics.mapper@3.0",
462 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000463 "android.hardware.media.bufferpool@2.0",
464 "android.hardware.media.c2@1.0",
465 "android.hardware.media.c2@1.1",
466 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900467 "android.hardware.media@1.0",
468 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000469 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900470 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000471 "android.hidl.safe_union@1.0",
472 "android.hidl.token@1.0",
473 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900474 "libEGL",
475 "libFLAC",
476 "libFLAC-config",
477 "libFLAC-headers",
478 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900479 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900480 "libarect",
481 "libasync_safe",
482 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000483 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900484 "libaudioutils",
485 "libaudioutils_fixedfft",
486 "libavcdec",
487 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000488 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900489 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900490 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900491 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900492 "libbluetooth-types-header",
493 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900494 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000495 "libcap",
496 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900497 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000498 "libcodec2_hidl@1.0",
499 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900500 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000501 "libcodec2_soft_aacdec",
502 "libcodec2_soft_aacenc",
503 "libcodec2_soft_amrnbdec",
504 "libcodec2_soft_amrnbenc",
505 "libcodec2_soft_amrwbdec",
506 "libcodec2_soft_amrwbenc",
507 "libcodec2_soft_av1dec_gav1",
508 "libcodec2_soft_avcdec",
509 "libcodec2_soft_avcenc",
510 "libcodec2_soft_common",
511 "libcodec2_soft_flacdec",
512 "libcodec2_soft_flacenc",
513 "libcodec2_soft_g711alawdec",
514 "libcodec2_soft_g711mlawdec",
515 "libcodec2_soft_gsmdec",
516 "libcodec2_soft_h263dec",
517 "libcodec2_soft_h263enc",
518 "libcodec2_soft_hevcdec",
519 "libcodec2_soft_hevcenc",
520 "libcodec2_soft_mp3dec",
521 "libcodec2_soft_mpeg2dec",
522 "libcodec2_soft_mpeg4dec",
523 "libcodec2_soft_mpeg4enc",
524 "libcodec2_soft_opusdec",
525 "libcodec2_soft_opusenc",
526 "libcodec2_soft_rawdec",
527 "libcodec2_soft_vorbisdec",
528 "libcodec2_soft_vp8dec",
529 "libcodec2_soft_vp8enc",
530 "libcodec2_soft_vp9dec",
531 "libcodec2_soft_vp9enc",
532 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900533 "libdexfile_support",
534 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000535 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900536 "libfmq",
537 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000538 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900539 "libgrallocusage",
540 "libgraphicsenv",
541 "libgsm",
542 "libgui_bufferqueue_static",
543 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000544 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900545 "libhardware_headers",
546 "libhevcdec",
547 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000548 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900549 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900550 "liblzma",
551 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000552 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900553 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000554 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900555 "libminijail_gen_constants",
556 "libminijail_gen_constants_obj",
557 "libminijail_gen_syscall",
558 "libminijail_gen_syscall_obj",
559 "libminijail_generated",
560 "libmpeg2dec",
561 "libnativebase_headers",
562 "libnativebridge_lazy",
563 "libnativeloader_lazy",
564 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000565 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900566 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000567 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900568 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000569 "libscudo_wrapper",
570 "libsfplugin_ccodec_utils",
571 "libspeexresampler",
572 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "libstagefright_amrnbdec",
574 "libstagefright_amrnbenc",
575 "libstagefright_amrwbdec",
576 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000577 "libstagefright_bufferpool@2.0.1",
578 "libstagefright_bufferqueue_helper",
579 "libstagefright_enc_common",
580 "libstagefright_flacdec",
581 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900582 "libstagefright_foundation_headers",
583 "libstagefright_headers",
584 "libstagefright_m4vh263dec",
585 "libstagefright_m4vh263enc",
586 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000587 "libsync",
588 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900589 "libui_headers",
590 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000591 "libvorbisidec",
592 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900593 "libyuv",
594 "libyuv_static",
595 "media_ndk_headers",
596 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000597 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000598 }
599 //
600 // Module separator
601 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900602 m["com.android.mediaprovider"] = []string{
603 "MediaProvider",
604 "MediaProviderGoogle",
605 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900606 "libbase_ndk",
607 "libfuse",
608 "libfuse_jni",
609 "libnativehelper_header_only",
610 }
611 //
612 // Module separator
613 //
614 m["com.android.permission"] = []string{
615 "androidx.annotation_annotation",
616 "androidx.annotation_annotation-nodeps",
617 "androidx.lifecycle_lifecycle-common",
618 "androidx.lifecycle_lifecycle-common-java8",
619 "androidx.lifecycle_lifecycle-common-java8-nodeps",
620 "androidx.lifecycle_lifecycle-common-nodeps",
621 "kotlin-annotations",
622 "kotlin-stdlib",
623 "kotlin-stdlib-jdk7",
624 "kotlin-stdlib-jdk8",
625 "kotlinx-coroutines-android",
626 "kotlinx-coroutines-android-nodeps",
627 "kotlinx-coroutines-core",
628 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900629 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900630 "GooglePermissionController",
631 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900632 }
Anton Hansson5053c292020-01-10 15:12:39 +0000633 //
634 // Module separator
635 //
Anton Hansson5053c292020-01-10 15:12:39 +0000636 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900638 "libarm-optimized-routines-math",
639 "libasync_safe",
640 "libasync_safe_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900641 "libc_aeabi",
642 "libc_bionic",
643 "libc_bionic_ndk",
644 "libc_bootstrap",
645 "libc_common",
646 "libc_common_shared",
647 "libc_common_static",
648 "libc_dns",
649 "libc_dynamic_dispatch",
650 "libc_fortify",
651 "libc_freebsd",
652 "libc_freebsd_large_stack",
653 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900654 "libc_init_dynamic",
655 "libc_init_static",
656 "libc_jemalloc_wrapper",
657 "libc_netbsd",
658 "libc_nomalloc",
659 "libc_nopthread",
660 "libc_openbsd",
661 "libc_openbsd_large_stack",
662 "libc_openbsd_ndk",
663 "libc_pthread",
664 "libc_static_dispatch",
665 "libc_syscalls",
666 "libc_tzcode",
667 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900668 "libdebuggerd",
669 "libdebuggerd_common_headers",
670 "libdebuggerd_handler_core",
671 "libdebuggerd_handler_fallback",
672 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000673 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900674 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900675 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900676 "libgtest_prod",
677 "libjemalloc5",
678 "liblinker_main",
679 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900680 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000681 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900682 "libprocessgroup_headers",
683 "libprocinfo",
684 "libpropertyinfoparser",
685 "libscudo",
686 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900687 "libsystemproperties",
688 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000689 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900690 "libz",
691 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000692 }
693 //
694 // Module separator
695 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900696 m["com.android.resolv"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 "libgtest_prod",
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 "libnativehelper_header_only",
700 "libnetd_client_headers",
701 "libnetd_resolv",
702 "libnetdutils",
703 "libprocessgroup",
704 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900705 "libstatslog_resolv",
706 "libstatspush_compat",
707 "libstatssocket",
708 "libstatssocket_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900709 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900710 "netd_event_listener_interface-ndk_platform",
711 "server_configurable_flags",
712 "stats_proto",
713 }
Anton Hansson5053c292020-01-10 15:12:39 +0000714 //
715 // Module separator
716 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900717 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900718 "libnativehelper_compat_libc++",
719 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900720 "libcgrouprc",
721 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900722 "libprocessgroup",
723 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900724 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900725 "libvndksupport",
726 "tethering-aidl-interfaces-java",
727 }
Anton Hansson5053c292020-01-10 15:12:39 +0000728 //
729 // Module separator
730 //
731 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900732 "PlatformProperties",
733 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900734 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900735 "android.hardware.wifi-V1.1-java",
736 "android.hardware.wifi-V1.2-java",
737 "android.hardware.wifi-V1.3-java",
738 "android.hardware.wifi-V1.4-java",
739 "android.hardware.wifi.hostapd-V1.0-java",
740 "android.hardware.wifi.hostapd-V1.1-java",
741 "android.hardware.wifi.hostapd-V1.2-java",
742 "android.hardware.wifi.supplicant-V1.0-java",
743 "android.hardware.wifi.supplicant-V1.1-java",
744 "android.hardware.wifi.supplicant-V1.2-java",
745 "android.hardware.wifi.supplicant-V1.3-java",
746 "android.hidl.base-V1.0-java",
747 "android.hidl.manager-V1.0-java",
748 "android.hidl.manager-V1.1-java",
749 "android.hidl.manager-V1.2-java",
750 "androidx.annotation_annotation",
751 "androidx.annotation_annotation-nodeps",
752 "bouncycastle-unbundled",
753 "dnsresolver_aidl_interface-V2-java",
754 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900755 "framework-wifi-pre-jarjar",
756 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900757 "ipmemorystore-aidl-interfaces-V3-java",
758 "ipmemorystore-aidl-interfaces-java",
759 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900760 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000761 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900762 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000763 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900764 "net-utils-services-common",
765 "netd_aidl_interface-V2-java",
766 "netd_aidl_interface-unstable-java",
767 "netd_event_listener_interface-java",
768 "netlink-client",
769 "networkstack-aidl-interfaces-unstable-java",
770 "networkstack-client",
771 "services.net",
772 "wifi-lite-protos",
773 "wifi-nano-protos",
774 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000775 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900776 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000777 }
778 //
779 // Module separator
780 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900781 m["com.android.sdkext"] = []string{
782 "fmtlib_ndk",
783 "libbase_ndk",
784 "libprotobuf-cpp-lite-ndk",
785 }
786 //
787 // Module separator
788 //
789 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900790 "libprocessgroup_headers",
791 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900792 }
793 //
794 // Module separator
795 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000796 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900797 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900798 "libclang_rt",
799 "libgcc_stripped",
800 "libprofile-clang-extras",
801 "libprofile-clang-extras_ndk",
802 "libprofile-extras",
803 "libprofile-extras_ndk",
804 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900805 }
Anton Hansson5053c292020-01-10 15:12:39 +0000806 return m
807}
808
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900809func init() {
Jooyung Hane17caa62020-04-08 14:13:04 +0900810 android.AddNeverAllowRules(android.NeverAllow().
811 ModuleType("apex").
812 With("updatable", "true").
813 With("min_sdk_version", "").
814 Because("All updatable apexes should set min_sdk_version."))
815
Jiyong Parkd1063c12019-07-17 20:08:41 +0900816 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800817 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900818 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900819 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700820 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900821 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900822
Jooyung Han31c470b2019-10-18 16:26:59 +0900823 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900824 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900825
826 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
827 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
828 sort.Strings(*apexFileContextsInfos)
829 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
830 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900831}
832
Jooyung Han31c470b2019-10-18 16:26:59 +0900833func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
834 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
835 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
836}
837
Jiyong Parkd1063c12019-07-17 20:08:41 +0900838func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900839 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900840 ctx.BottomUp("apex", apexMutator).Parallel()
841 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
842 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900843}
844
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900845// Mark the direct and transitive dependencies of apex bundles so that they
846// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900847func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800848 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900849 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000850 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900851 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900852 ApexName: mctx.ModuleName(),
853 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900854 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900855 directDep = true
856 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800857 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900858 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900859 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900860
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800861 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900862 return
863 }
864
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100865 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900866
Jiyong Parkf760cae2020-02-12 07:53:12 +0900867 mctx.VisitDirectDeps(func(child android.Module) {
868 depName := mctx.OtherModuleName(child)
869 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100870 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800871 android.UpdateApexDependency(apexBundles, depName, directDep)
872 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900873 }
874 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900875}
876
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100877// If a module in an APEX depends on a module from an SDK then it needs an APEX
878// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
879func inAnySdk(module android.Module) bool {
880 if sa, ok := module.(android.SdkAware); ok {
881 return sa.IsInAnySdk()
882 }
883
884 return false
885}
886
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900887// Create apex variations if a module is included in APEX(s).
888func apexMutator(mctx android.BottomUpMutatorContext) {
889 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900890 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000891 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900892 // apex bundle itself is mutated so that it and its modules have same
893 // apex variant.
894 apexBundleName := mctx.ModuleName()
895 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900896 } else if o, ok := mctx.Module().(*OverrideApex); ok {
897 apexBundleName := o.GetOverriddenModuleName()
898 if apexBundleName == "" {
899 mctx.ModuleErrorf("base property is not set")
900 return
901 }
902 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900903 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900904
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900905}
Sundong Ahne9b55722019-09-06 17:37:42 +0900906
Jooyung Han7a78a922019-10-08 21:59:58 +0900907var (
908 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
909 apexFileContextsInfosMutex sync.Mutex
910)
911
912func apexFileContextsInfos(config android.Config) *[]string {
913 return config.Once(apexFileContextsInfosKey, func() interface{} {
914 return &[]string{}
915 }).(*[]string)
916}
917
Jooyung Han54aca7b2019-11-20 02:26:02 +0900918func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900919 apexFileContextsInfosMutex.Lock()
920 defer apexFileContextsInfosMutex.Unlock()
921 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900922 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900923}
924
Sundong Ahne9b55722019-09-06 17:37:42 +0900925func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900926 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900927 var variants []string
928 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
929 case "image":
930 variants = append(variants, imageApexType, flattenedApexType)
931 case "zip":
932 variants = append(variants, zipApexType)
933 case "both":
934 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
935 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900936 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900937 return
938 }
939
940 modules := mctx.CreateLocalVariations(variants...)
941
942 for i, v := range variants {
943 switch v {
944 case imageApexType:
945 modules[i].(*apexBundle).properties.ApexType = imageApex
946 case zipApexType:
947 modules[i].(*apexBundle).properties.ApexType = zipApex
948 case flattenedApexType:
949 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900950 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900951 modules[i].(*apexBundle).MakeAsSystemExt()
952 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900953 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900954 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900955 } else if _, ok := mctx.Module().(*OverrideApex); ok {
956 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900957 }
958}
959
Jooyung Han5c998b92019-06-27 11:30:33 +0900960func apexUsesMutator(mctx android.BottomUpMutatorContext) {
961 if ab, ok := mctx.Module().(*apexBundle); ok {
962 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
963 }
964}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900965
Jooyung Handc782442019-11-01 03:14:38 +0900966var (
967 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
968)
969
970// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
971// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
972// which may cause compatibility issues. (e.g. libbinder)
973// Even though libbinder restricts its availability via 'apex_available' property and relies on
974// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
975// to avoid similar problems.
976func useVendorWhitelist(config android.Config) []string {
977 return config.Once(useVendorWhitelistKey, func() interface{} {
978 return []string{
979 // swcodec uses "vendor" variants for smaller size
980 "com.android.media.swcodec",
981 "test_com.android.media.swcodec",
982 }
983 }).([]string)
984}
985
986// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
987// called before the first call to useVendorWhitelist()
988func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
989 config.Once(useVendorWhitelistKey, func() interface{} {
990 return whitelist
991 })
992}
993
Alex Light9670d332019-01-29 18:07:33 -0800994type apexNativeDependencies struct {
995 // List of native libraries
996 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900997
Alex Light9670d332019-01-29 18:07:33 -0800998 // List of native executables
999 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001000
Roland Levillain630846d2019-06-26 12:48:34 +01001001 // List of native tests
1002 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001003}
Jooyung Han344d5432019-08-23 11:17:39 +09001004
Alex Light9670d332019-01-29 18:07:33 -08001005type apexMultilibProperties struct {
1006 // Native dependencies whose compile_multilib is "first"
1007 First apexNativeDependencies
1008
1009 // Native dependencies whose compile_multilib is "both"
1010 Both apexNativeDependencies
1011
1012 // Native dependencies whose compile_multilib is "prefer32"
1013 Prefer32 apexNativeDependencies
1014
1015 // Native dependencies whose compile_multilib is "32"
1016 Lib32 apexNativeDependencies
1017
1018 // Native dependencies whose compile_multilib is "64"
1019 Lib64 apexNativeDependencies
1020}
1021
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001022type apexBundleProperties struct {
1023 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001024 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001025 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001026
Jiyong Park40e26a22019-02-08 02:53:06 +09001027 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1028 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001029 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001030
Roland Levillain411c5842019-09-19 16:37:20 +01001031 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1032 // device (/apex/<apex_name>).
1033 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001034 Apex_name *string
1035
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001036 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001037 // For platform APEXes, this should points to a file under /system/sepolicy
1038 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1039 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001040
1041 // List of native shared libs that are embedded inside this APEX bundle
1042 Native_shared_libs []string
1043
Roland Levillain630846d2019-06-26 12:48:34 +01001044 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001045 Binaries []string
1046
1047 // List of java libraries that are embedded inside this APEX bundle
1048 Java_libs []string
1049
1050 // List of prebuilt files that are embedded inside this APEX bundle
1051 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001052
Roland Levillain630846d2019-06-26 12:48:34 +01001053 // List of tests that are embedded inside this APEX bundle
1054 Tests []string
1055
Jiyong Parkff1458f2018-10-12 21:49:38 +09001056 // Name of the apex_key module that provides the private key to sign APEX
1057 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001058
Alex Light5098a612018-11-29 17:12:15 -08001059 // The type of APEX to build. Controls what the APEX payload is. Either
1060 // 'image', 'zip' or 'both'. Default: 'image'.
1061 Payload_type *string
1062
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001063 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1064 // or an android_app_certificate module name in the form ":module".
1065 Certificate *string
1066
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001067 // Whether this APEX is installable to one of the partitions. Default: true.
1068 Installable *bool
1069
Jiyong Parkda6eb592018-12-19 17:12:36 +09001070 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1071 // Default is false.
1072 Use_vendor *bool
1073
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001074 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1075 Ignore_system_library_special_case *bool
1076
Alex Light9670d332019-01-29 18:07:33 -08001077 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001078
Jiyong Parkf97782b2019-02-13 20:28:58 +09001079 // List of sanitizer names that this APEX is enabled for
1080 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001081
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001082 PreventInstall bool `blueprint:"mutated"`
1083
1084 HideFromMake bool `blueprint:"mutated"`
1085
Jooyung Han5c998b92019-06-27 11:30:33 +09001086 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1087 Provide_cpp_shared_libs *bool
1088
1089 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1090 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001091
1092 // A txt file containing list of files that are whitelisted to be included in this APEX.
1093 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001094
Sundong Ahnabb64432019-10-22 13:58:29 +09001095 // package format of this apex variant; could be non-flattened, flattened, or zip.
1096 // imageApex, zipApex or flattened
1097 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001098
Jiyong Parkd1063c12019-07-17 20:08:41 +09001099 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1100 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1101 // is implied. This value affects all modules included in this APEX. In other words, they are
1102 // also built with the SDKs specified here.
1103 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001104
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001105 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1106 // Should be only used in tests#.
1107 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001108
Jiyong Park956305c2020-01-09 12:32:06 +09001109 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001110
1111 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1112 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1113 // like symlinking to the system libs. Default is false.
1114 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001115
1116 // The minimum SDK version that this apex must be compatible with.
1117 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001118}
1119
1120type apexTargetBundleProperties struct {
1121 Target struct {
1122 // Multilib properties only for android.
1123 Android struct {
1124 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001125 }
Jooyung Han344d5432019-08-23 11:17:39 +09001126
Alex Light9670d332019-01-29 18:07:33 -08001127 // Multilib properties only for host.
1128 Host struct {
1129 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001130 }
Jooyung Han344d5432019-08-23 11:17:39 +09001131
Alex Light9670d332019-01-29 18:07:33 -08001132 // Multilib properties only for host linux_bionic.
1133 Linux_bionic struct {
1134 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001135 }
Jooyung Han344d5432019-08-23 11:17:39 +09001136
Alex Light9670d332019-01-29 18:07:33 -08001137 // Multilib properties only for host linux_glibc.
1138 Linux_glibc struct {
1139 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001140 }
1141 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001142}
1143
Jiyong Park5d790c32019-11-15 18:40:32 +09001144type overridableProperties struct {
1145 // List of APKs to package inside APEX
1146 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001147
1148 // Names of modules to be overridden. Listed modules can only be other binaries
1149 // (in Make or Soong).
1150 // This does not completely prevent installation of the overridden binaries, but if both
1151 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1152 // from PRODUCT_PACKAGES.
1153 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001154
1155 // Logging Parent value
1156 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001157
1158 // Apex Container Package Name.
1159 // Override value for attribute package:name in AndroidManifest.xml
1160 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001161}
1162
Alex Light5098a612018-11-29 17:12:15 -08001163type apexPackaging int
1164
1165const (
1166 imageApex apexPackaging = iota
1167 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001168 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001169)
1170
Sundong Ahnabb64432019-10-22 13:58:29 +09001171// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001172func (a apexPackaging) suffix() string {
1173 switch a {
1174 case imageApex:
1175 return imageApexSuffix
1176 case zipApex:
1177 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001178 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001179 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001180 }
1181}
1182
1183func (a apexPackaging) name() string {
1184 switch a {
1185 case imageApex:
1186 return imageApexType
1187 case zipApex:
1188 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001189 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001190 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001191 }
1192}
1193
Jiyong Parkf653b052019-11-18 15:39:01 +09001194type apexFileClass int
1195
1196const (
1197 etc apexFileClass = iota
1198 nativeSharedLib
1199 nativeExecutable
1200 shBinary
1201 pyBinary
1202 goBinary
1203 javaSharedLib
1204 nativeTest
1205 app
1206)
1207
Jiyong Park8fd61922018-11-08 02:50:25 +09001208func (class apexFileClass) NameInMake() string {
1209 switch class {
1210 case etc:
1211 return "ETC"
1212 case nativeSharedLib:
1213 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001214 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001215 return "EXECUTABLES"
1216 case javaSharedLib:
1217 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001218 case nativeTest:
1219 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001220 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001221 // b/142537672 Why isn't this APP? We want to have full control over
1222 // the paths and file names of the apk file under the flattend APEX.
1223 // If this is set to APP, then the paths and file names are modified
1224 // by the Make build system. For example, it is installed to
1225 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1226 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1227 // appends module name (which is <apexname>.<Appname> to the path.
1228 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001229 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001230 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001231 }
1232}
1233
Jiyong Parkf653b052019-11-18 15:39:01 +09001234// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001235type apexFile struct {
1236 builtFile android.Path
1237 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001238 installDir string
1239 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001240 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001241 // list of symlinks that will be created in installDir that point to this apexFile
1242 symlinks []string
1243 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001244 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001245
1246 requiredModuleNames []string
1247 targetRequiredModuleNames []string
1248 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001249
Colin Cross503c1d02020-01-28 14:00:53 -08001250 jacocoReportClassesFile android.Path // only for javalibs and apps
1251 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001252 overriddenPackageName string // only for apps
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,
Roland Levillain630846d2019-06-26 12:48:34 +01001371 native_shared_libs []string, binaries []string, tests []string,
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
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001381 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001382
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001383 ctx.AddFarVariationDependencies(append(target.Variations(),
1384 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1385 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001386
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001387 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001388 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001389 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001390 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001391}
1392
Alex Light9670d332019-01-29 18:07:33 -08001393func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1394 if ctx.Os().Class == android.Device {
1395 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1396 } else {
1397 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1398 if ctx.Os().Bionic() {
1399 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1400 } else {
1401 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1402 }
1403 }
1404}
1405
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001406func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001407 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1408 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1409 }
1410
Jiyong Park397e55e2018-10-24 21:09:55 +09001411 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001412 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001413
1414 a.combineProperties(ctx)
1415
Jiyong Park397e55e2018-10-24 21:09:55 +09001416 has32BitTarget := false
1417 for _, target := range targets {
1418 if target.Arch.ArchType.Multilib == "lib32" {
1419 has32BitTarget = true
1420 }
1421 }
1422 for i, target := range targets {
1423 // When multilib.* is omitted for native_shared_libs, it implies
1424 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001425 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001426 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001427 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001428 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001429
Roland Levillain630846d2019-06-26 12:48:34 +01001430 // When multilib.* is omitted for tests, it implies
1431 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001432 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001433 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001434 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001435 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001436
Jiyong Park397e55e2018-10-24 21:09:55 +09001437 // Add native modules targetting both ABIs
1438 addDependenciesForNativeModules(ctx,
1439 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001440 a.properties.Multilib.Both.Binaries,
1441 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001442 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001443 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001444
Alex Light3d673592019-01-18 14:37:31 -08001445 isPrimaryAbi := i == 0
1446 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001447 // When multilib.* is omitted for binaries, it implies
1448 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001449 ctx.AddFarVariationDependencies(append(target.Variations(),
1450 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1451 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001452
1453 // Add native modules targetting the first ABI
1454 addDependenciesForNativeModules(ctx,
1455 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001456 a.properties.Multilib.First.Binaries,
1457 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001458 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001459 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001460 }
1461
1462 switch target.Arch.ArchType.Multilib {
1463 case "lib32":
1464 // Add native modules targetting 32-bit ABI
1465 addDependenciesForNativeModules(ctx,
1466 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001467 a.properties.Multilib.Lib32.Binaries,
1468 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001469 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001470 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001471
1472 addDependenciesForNativeModules(ctx,
1473 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001474 a.properties.Multilib.Prefer32.Binaries,
1475 a.properties.Multilib.Prefer32.Tests,
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,
1481 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001482 a.properties.Multilib.Lib64.Binaries,
1483 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001484 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001485 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001486
1487 if !has32BitTarget {
1488 addDependenciesForNativeModules(ctx,
1489 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001490 a.properties.Multilib.Prefer32.Binaries,
1491 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001492 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001493 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001494 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001495
1496 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1497 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1498 if sanitizer == "hwaddress" {
1499 addDependenciesForNativeModules(ctx,
1500 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001501 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001502 break
1503 }
1504 }
1505 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001506 }
1507
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001508 }
1509
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001510 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1511 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1512 // b/144532908
1513 archForPrebuiltEtc := config.Arches()[0]
1514 for _, arch := range config.Arches() {
1515 // Prefer 64-bit arch if there is any
1516 if arch.ArchType.Multilib == "lib64" {
1517 archForPrebuiltEtc = arch
1518 break
1519 }
1520 }
1521 ctx.AddFarVariationDependencies([]blueprint.Variation{
1522 {Mutator: "os", Variation: ctx.Os().String()},
1523 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1524 }, prebuiltTag, a.properties.Prebuilts...)
1525
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001526 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1527 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001528
Ulya Trafimovich44561882020-01-03 13:25:54 +00001529 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1530 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1531 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1532 javaLibTag, "jacocoagent")
1533 }
1534
Jiyong Park23c52b02019-02-02 13:13:47 +09001535 if String(a.properties.Key) == "" {
1536 ctx.ModuleErrorf("key is missing")
1537 return
1538 }
1539 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001540
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001541 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001542 if cert != "" {
1543 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001544 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001545
1546 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1547 if len(a.properties.Uses_sdks) > 0 {
1548 sdkRefs := []android.SdkRef{}
1549 for _, str := range a.properties.Uses_sdks {
1550 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1551 sdkRefs = append(sdkRefs, parsed)
1552 }
1553 a.BuildWithSdks(sdkRefs)
1554 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001555}
1556
Jiyong Park5d790c32019-11-15 18:40:32 +09001557func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1558 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1559 androidAppTag, a.overridableProperties.Apps...)
1560}
1561
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001562func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1563 // direct deps of an APEX bundle are all part of the APEX bundle
1564 return true
1565}
1566
Colin Cross0ea8ba82019-06-06 14:33:29 -07001567func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001568 moduleName := ctx.ModuleName()
1569 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1570 // we check with the pseudo module name to see if its certificate is overridden.
1571 if a.vndkApex {
1572 moduleName = vndkApexName
1573 }
1574 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001575 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001576 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001577 }
1578 return String(a.properties.Certificate)
1579}
1580
Colin Cross41955e82019-05-29 14:40:35 -07001581func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1582 switch tag {
1583 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001584 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001585 default:
1586 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001587 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001588}
1589
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001590func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001591 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001592}
1593
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001594func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1595 return proptools.Bool(a.properties.Test_only_no_hashtree)
1596}
1597
Jiyong Park7c1dc612019-01-05 11:15:24 +09001598func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001599 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001600 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001601 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001602 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001603 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001604 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001605 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001606 }
1607}
1608
Jiyong Parkf97782b2019-02-13 20:28:58 +09001609func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1610 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1611 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1612 }
1613}
1614
Jiyong Park388ef3f2019-01-28 19:47:32 +09001615func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001616 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1617 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001618 }
1619
1620 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001621 globalSanitizerNames := []string{}
1622 if a.Host() {
1623 globalSanitizerNames = ctx.Config().SanitizeHost()
1624 } else {
1625 arches := ctx.Config().SanitizeDeviceArch()
1626 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1627 globalSanitizerNames = ctx.Config().SanitizeDevice()
1628 }
1629 }
1630 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001631}
1632
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001633func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001634 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001635}
1636
1637func (a *apexBundle) PreventInstall() {
1638 a.properties.PreventInstall = true
1639}
1640
1641func (a *apexBundle) HideFromMake() {
1642 a.properties.HideFromMake = true
1643}
1644
Jiyong Park956305c2020-01-09 12:32:06 +09001645func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1646 a.properties.IsCoverageVariant = coverage
1647}
1648
Jiyong Parkf653b052019-11-18 15:39:01 +09001649// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001650func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001651 // Decide the APEX-local directory by the multilib of the library
1652 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001653 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001654 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001655 case "lib32":
1656 dirInApex = "lib"
1657 case "lib64":
1658 dirInApex = "lib64"
1659 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001660 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001661 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001662 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001663 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001664 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001665 // Special case for Bionic libs and other libs installed with them. This is
1666 // to prevent those libs from being included in the search path
1667 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1668 // those libs in the Runtime APEX are available via the legacy paths in
1669 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1670 // to the legacy paths and thus will be loaded into the default linker
1671 // namespace (aka "platform" namespace). If the libs are directly in
1672 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1673 // into the runtime linker namespace, which will result in double loading of
1674 // them, which isn't supported.
1675 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001676 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001677
Jiyong Parkf653b052019-11-18 15:39:01 +09001678 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001679 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001680}
1681
Jiyong Park1833cef2019-12-13 13:28:36 +09001682func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001683 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001684 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001685 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001686 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001687 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001688 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001689 af.symlinks = cc.Symlinks()
1690 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001691}
1692
Jiyong Park1833cef2019-12-13 13:28:36 +09001693func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001694 dirInApex := "bin"
1695 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001696 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001697}
Jiyong Park1833cef2019-12-13 13:28:36 +09001698func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001699 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001700 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1701 if err != nil {
1702 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001703 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001704 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001705 fileToCopy := android.PathForOutput(ctx, s)
1706 // NB: Since go binaries are static we don't need the module for anything here, which is
1707 // good since the go tool is a blueprint.Module not an android.Module like we would
1708 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001709 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001710}
1711
Jiyong Park1833cef2019-12-13 13:28:36 +09001712func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001713 dirInApex := filepath.Join("bin", sh.SubDir())
1714 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001715 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001716 af.symlinks = sh.Symlinks()
1717 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001718}
1719
Jooyung Han58f26ab2019-12-18 15:34:32 +09001720// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1721type javaLibrary interface {
1722 android.Module
1723 java.Dependency
1724}
1725
1726func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001727 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001728 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001729 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1730 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1731 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001732}
1733
Jiyong Park1833cef2019-12-13 13:28:36 +09001734func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001735 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1736 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001737 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001738}
1739
atrost6e126252020-01-27 17:01:16 +00001740func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1741 dirInApex := filepath.Join("etc", config.SubDir())
1742 fileToCopy := config.CompatConfig()
1743 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1744}
1745
Jiyong Park1833cef2019-12-13 13:28:36 +09001746func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001747 android.Module
1748 Privileged() bool
1749 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001750 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001751 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001752}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001753 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001754 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001755 appDir = "priv-app"
1756 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001757 dirInApex := filepath.Join(appDir, pkgName)
1758 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001759 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1760 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001761 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001762
1763 if app, ok := aapp.(interface {
1764 OverriddenManifestPackageName() string
1765 }); ok {
1766 af.overriddenPackageName = app.OverriddenManifestPackageName()
1767 }
Jiyong Park618922e2020-01-08 13:35:43 +09001768 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001769}
1770
Roland Levillain935639d2019-08-13 14:55:28 +01001771// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1772type flattenedApexContext struct {
1773 android.ModuleContext
1774}
1775
1776func (c *flattenedApexContext) InstallBypassMake() bool {
1777 return true
1778}
1779
Paul Duffin133608f2020-03-30 15:54:08 +01001780// Function called while walking an APEX's payload dependencies.
1781//
1782// Return true if the `to` module should be visited, false otherwise.
1783type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1784
Jiyong Park201cedd2020-02-07 17:25:49 +09001785// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001786func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001787 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001788 am, ok := child.(android.ApexModule)
1789 if !ok || !am.CanHaveApexVariants() {
1790 return false
1791 }
1792
1793 // Check for the direct dependencies that contribute to the payload
1794 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1795 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001796 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001797 }
Paul Duffin133608f2020-03-30 15:54:08 +01001798 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001799 return false
1800 }
1801
1802 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001803 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001804 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001805 }
1806
Paul Duffin133608f2020-03-30 15:54:08 +01001807 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001808 })
1809}
1810
Jooyung Han0c4e0162020-02-26 22:45:42 +09001811func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1812 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001813 intVer, err := android.ApiStrToNum(ctx, ver)
1814 if err != nil {
1815 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001816 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001817 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001818}
1819
Paul Duffinf0207962020-03-31 11:31:36 +01001820// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1821// a dependency tag.
1822var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1823
1824func PrettyPrintTag(tag blueprint.DependencyTag) string {
1825 // Use tag's custom String() method if available.
1826 if stringer, ok := tag.(fmt.Stringer); ok {
1827 return stringer.String()
1828 }
1829
1830 // Otherwise, get a default string representation of the tag's struct.
1831 tagString := fmt.Sprintf("%#v", tag)
1832
1833 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1834 tagString = tagCleaner.ReplaceAllString(tagString, "")
1835 return tagString
1836}
1837
Jiyong Park201cedd2020-02-07 17:25:49 +09001838// Ensures that the dependencies are marked as available for this APEX
1839func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1840 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1841 if ctx.Host() || a.testApex || a.vndkApex {
1842 return
1843 }
1844
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001845 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1846 // Requiring them and their transitive depencies with apex_available is not right
1847 // because they just add noise.
1848 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1849 return
1850 }
1851
Paul Duffin133608f2020-03-30 15:54:08 +01001852 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1853 if externalDep {
1854 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1855 return false
1856 }
1857
Jiyong Park201cedd2020-02-07 17:25:49 +09001858 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001859 fromName := ctx.OtherModuleName(from)
1860 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001861
1862 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1863 // do any of its dependencies.
1864 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1865 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1866 return false
1867 }
1868
Paul Duffin133608f2020-03-30 15:54:08 +01001869 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1870 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001871 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001872 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001873 tagPath := ctx.GetTagPath()
1874 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1875 walkPath := ctx.GetWalkPath()[1:]
1876 for i, m := range walkPath {
1877 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001878 }
1879 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffin133608f2020-03-30 15:54:08 +01001880 // Visit this module's dependencies to check and report any issues with their availability.
1881 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001882 })
1883}
1884
Jiyong Park678c8812020-02-07 17:25:49 +09001885// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1886func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1887 a.depInfos = make(map[string]depInfo)
Paul Duffin133608f2020-03-30 15:54:08 +01001888 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001889 if from.Name() == to.Name() {
1890 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffin133608f2020-03-30 15:54:08 +01001891 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1892 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001893 }
1894
1895 if info, exists := a.depInfos[to.Name()]; exists {
1896 if !android.InList(from.Name(), info.from) {
1897 info.from = append(info.from, from.Name())
1898 }
1899 info.isExternal = info.isExternal && externalDep
1900 a.depInfos[to.Name()] = info
1901 } else {
1902 a.depInfos[to.Name()] = depInfo{
1903 to: to.Name(),
1904 from: []string{from.Name()},
1905 isExternal: externalDep,
1906 }
1907 }
Paul Duffin133608f2020-03-30 15:54:08 +01001908
1909 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1910 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001911 })
1912}
1913
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001914func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001915 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1916 switch a.properties.ApexType {
1917 case imageApex:
1918 if buildFlattenedAsDefault {
1919 a.suffix = imageApexSuffix
1920 } else {
1921 a.suffix = ""
1922 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001923
1924 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001925 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001926 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001927 }
1928 case zipApex:
1929 if proptools.String(a.properties.Payload_type) == "zip" {
1930 a.suffix = ""
1931 a.primaryApexType = true
1932 } else {
1933 a.suffix = zipApexSuffix
1934 }
1935 case flattenedApex:
1936 if buildFlattenedAsDefault {
1937 a.suffix = ""
1938 a.primaryApexType = true
1939 } else {
1940 a.suffix = flattenedSuffix
1941 }
Alex Light5098a612018-11-29 17:12:15 -08001942 }
1943
Roland Levillain630846d2019-06-26 12:48:34 +01001944 if len(a.properties.Tests) > 0 && !a.testApex {
1945 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1946 return
1947 }
1948
Jiyong Parkfa899442020-01-31 02:49:53 +09001949 a.checkApexAvailability(ctx)
1950
Jiyong Park678c8812020-02-07 17:25:49 +09001951 a.collectDepsInfo(ctx)
1952
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001953 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1954
Jooyung Hane1633032019-08-01 17:41:43 +09001955 // native lib dependencies
1956 var provideNativeLibs []string
1957 var requireNativeLibs []string
1958
Jooyung Han5c998b92019-06-27 11:30:33 +09001959 // Check if "uses" requirements are met with dependent apexBundles
1960 var providedNativeSharedLibs []string
1961 useVendor := proptools.Bool(a.properties.Use_vendor)
1962 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1963 if ctx.OtherModuleDependencyTag(m) != usesTag {
1964 return
1965 }
1966 otherName := ctx.OtherModuleName(m)
1967 other, ok := m.(*apexBundle)
1968 if !ok {
1969 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1970 return
1971 }
1972 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1973 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1974 return
1975 }
1976 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1977 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1978 return
1979 }
1980 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1981 })
1982
Jiyong Parkf653b052019-11-18 15:39:01 +09001983 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001984 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001985 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001986 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01001987 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1988 return false
1989 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001990 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001991 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001992 switch depTag {
1993 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001994 if c, ok := child.(*cc.Module); ok {
1995 // bootstrap bionic libs are treated as provided by system
1996 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1997 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001998 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001999 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002000 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002001 } else {
2002 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002003 }
2004 case executableTag:
2005 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002006 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002007 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002008 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002009 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002010 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002011 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002012 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002013 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002014 } else {
Alex Light778127a2019-02-27 14:19:50 -08002015 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 +09002016 }
2017 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002018 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002019 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002020 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002021 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2022 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002023 filesInfo = append(filesInfo, af)
2024 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002025 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002026 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2027 af := apexFileForJavaLibrary(ctx, sdkLib)
2028 if !af.Ok() {
2029 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2030 return false
2031 }
2032 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002033 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002034 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002035 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002036 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002037 case androidAppTag:
2038 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2039 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002040 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002041 return true // track transitive dependencies
2042 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002043 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002044 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2045 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002046 } else {
2047 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2048 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002049 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002050 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002051 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002052 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2053 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002054 } else {
atrost6e126252020-01-27 17:01:16 +00002055 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002056 }
Roland Levillain630846d2019-06-26 12:48:34 +01002057 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002058 if ccTest, ok := child.(*cc.Module); ok {
2059 if ccTest.IsTestPerSrcAllTestsVariation() {
2060 // Multiple-output test module (where `test_per_src: true`).
2061 //
2062 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2063 // We do not add this variation to `filesInfo`, as it has no output;
2064 // however, we do add the other variations of this module as indirect
2065 // dependencies (see below).
2066 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002067 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002068 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002069 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002070 af.class = nativeTest
2071 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002072 }
Roland Levillain630846d2019-06-26 12:48:34 +01002073 } else {
2074 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2075 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002076 case keyTag:
2077 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002078 a.private_key_file = key.private_key_file
2079 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002080 } else {
2081 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002082 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002083 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002084 case certificateTag:
2085 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002086 a.container_certificate_file = dep.Certificate.Pem
2087 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002088 } else {
2089 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2090 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002091 case android.PrebuiltDepTag:
2092 // If the prebuilt is force disabled, remember to delete the prebuilt file
2093 // that might have been installed in the previous builds
2094 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2095 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2096 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002097 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002098 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002099 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002100 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002101 // We cannot use a switch statement on `depTag` here as the checked
2102 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002103 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002104 if cc, ok := child.(*cc.Module); ok {
2105 if android.InList(cc.Name(), providedNativeSharedLibs) {
2106 // If we're using a shared library which is provided from other APEX,
2107 // don't include it in this APEX
2108 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002109 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002110 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002111 // If the dependency is a stubs lib, don't include it in this APEX,
2112 // but make sure that the lib is installed on the device.
2113 // In case no APEX is having the lib, the lib is installed to the system
2114 // partition.
2115 //
2116 // Always include if we are a host-apex however since those won't have any
2117 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002118 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2119 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002120 }
Jooyung Hane1633032019-08-01 17:41:43 +09002121 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002122 // Don't track further
2123 return false
2124 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002125 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002126 af.transitiveDep = true
2127 filesInfo = append(filesInfo, af)
2128 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002129 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002130 } else if cc.IsTestPerSrcDepTag(depTag) {
2131 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002132 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002133 // Handle modules created as `test_per_src` variations of a single test module:
2134 // use the name of the generated test binary (`fileToCopy`) instead of the name
2135 // of the original test module (`depName`, shared by all `test_per_src`
2136 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002137 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002138 // these are not considered transitive dep
2139 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002140 filesInfo = append(filesInfo, af)
2141 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002142 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002143 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002144 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2145 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002146 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2147 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2148 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2149 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002150 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002151 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002152 }
2153 }
2154 }
2155 return false
2156 })
2157
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002158 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2159 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2160 // via the global boot image config.
2161 if a.artApex {
2162 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2163 dirInApex := filepath.Join("javalib", arch.String())
2164 for _, f := range files {
2165 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002166 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002167 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002168 }
2169 }
2170 }
2171
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002172 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002173 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2174 return
2175 }
2176
Jiyong Park8fd61922018-11-08 02:50:25 +09002177 // remove duplicates in filesInfo
2178 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002179 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002180 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002181 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002182 if e, ok := encountered[dest]; !ok {
2183 encountered[dest] = f
2184 } else {
2185 // If a module is directly included and also transitively depended on
2186 // consider it as directly included.
2187 e.transitiveDep = e.transitiveDep && f.transitiveDep
2188 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002189 }
2190 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002191 var result []apexFile
2192 for _, v := range encountered {
2193 result = append(result, v)
2194 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002195 return result
2196 }
2197 filesInfo = removeDup(filesInfo)
2198
2199 // to have consistent build rules
2200 sort.Slice(filesInfo, func(i, j int) bool {
2201 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2202 })
2203
Jiyong Park8fd61922018-11-08 02:50:25 +09002204 a.installDir = android.PathForModuleInstall(ctx, "apex")
2205 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002206
Jooyung Han54aca7b2019-11-20 02:26:02 +09002207 if a.properties.ApexType != zipApex {
2208 if a.properties.File_contexts == nil {
2209 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2210 } else {
2211 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2212 if a.Platform() {
2213 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2214 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2215 }
2216 }
2217 }
2218 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2219 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2220 return
2221 }
2222 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002223 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2224 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2225 // the same library in the system partition, thus effectively sharing the same libraries
2226 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2227 // in the APEX.
2228 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2229 a.installable() &&
2230 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002231
Jiyong Park9d677202020-02-19 16:29:35 +09002232 // We don't need the optimization for updatable APEXes, as it might give false signal
2233 // to the system health when the APEXes are still bundled (b/149805758)
2234 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2235 a.linkToSystemLib = false
2236 }
2237
Jiyong Park9b964182020-02-26 18:27:19 +09002238 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2239 if ctx.Host() {
2240 a.linkToSystemLib = false
2241 }
2242
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002243 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002244 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2245
2246 a.setCertificateAndPrivateKey(ctx)
2247 if a.properties.ApexType == flattenedApex {
2248 a.buildFlattenedApex(ctx)
2249 } else {
2250 a.buildUnflattenedApex(ctx)
2251 }
2252
Jooyung Han002ab682020-01-08 01:57:58 +09002253 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002254
2255 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002256}
2257
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002258func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002259 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002260 moduleName = normalizeModuleName(moduleName)
2261
2262 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2263 return true
2264 }
2265
2266 key = android.AvailableToAnyApex
2267 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2268 return true
2269 }
2270
2271 return false
2272}
2273
2274func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002275 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2276 // system. Trim the prefix for the check since they are confusing
2277 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2278 if strings.HasPrefix(moduleName, "libclang_rt.") {
2279 // This module has many arch variants that depend on the product being built.
2280 // We don't want to list them all
2281 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002282 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002283 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002284}
2285
Jooyung Han344d5432019-08-23 11:17:39 +09002286func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002287 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002288 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002289 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002290 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002291 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002292 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2293 })
Alex Light5098a612018-11-29 17:12:15 -08002294 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002295 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002296 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002297 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002298 return module
2299}
Jiyong Park30ca9372019-02-07 16:27:23 +09002300
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002301func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002302 bundle := newApexBundle()
2303 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002304 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002305 return bundle
2306}
2307
Jiyong Parkfce0b422020-02-11 03:56:06 +09002308// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2309// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002310func testApexBundleFactory() android.Module {
2311 bundle := newApexBundle()
2312 bundle.testApex = true
2313 return bundle
2314}
2315
Jiyong Parkfce0b422020-02-11 03:56:06 +09002316// apex packages other modules into an APEX file which is a packaging format for system-level
2317// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002318func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002319 return newApexBundle()
2320}
2321
Jiyong Park30ca9372019-02-07 16:27:23 +09002322//
2323// Defaults
2324//
2325type Defaults struct {
2326 android.ModuleBase
2327 android.DefaultsModuleBase
2328}
2329
Jiyong Park30ca9372019-02-07 16:27:23 +09002330func defaultsFactory() android.Module {
2331 return DefaultsFactory()
2332}
2333
2334func DefaultsFactory(props ...interface{}) android.Module {
2335 module := &Defaults{}
2336
2337 module.AddProperties(props...)
2338 module.AddProperties(
2339 &apexBundleProperties{},
2340 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002341 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002342 )
2343
2344 android.InitDefaultsModule(module)
2345 return module
2346}
Jiyong Park5d790c32019-11-15 18:40:32 +09002347
2348//
2349// OverrideApex
2350//
2351type OverrideApex struct {
2352 android.ModuleBase
2353 android.OverrideModuleBase
2354}
2355
2356func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2357 // All the overrides happen in the base module.
2358}
2359
2360// override_apex is used to create an apex module based on another apex module
2361// by overriding some of its properties.
2362func overrideApexFactory() android.Module {
2363 m := &OverrideApex{}
2364 m.AddProperties(&overridableProperties{})
2365
2366 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2367 android.InitOverrideModule(m)
2368 return m
2369}