blob: 89313d441bad56d34ae9bf3cc68b42b692f104af [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",
Anton Hansson5053c292020-01-10 15:12:39 +0000415 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900416 "libspeexresampler",
417 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000418 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900419 "libstagefright_flacdec",
420 "libstagefright_foundation",
421 "libstagefright_foundation_headers",
422 "libstagefright_foundation_without_imemory",
423 "libstagefright_headers",
424 "libstagefright_id3",
425 "libstagefright_metadatautils",
426 "libstagefright_mpeg2extractor",
427 "libstagefright_mpeg2support",
428 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900429 "libui",
430 "libui_headers",
431 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900432 "libvibrator",
433 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000434 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900435 "libwebm",
436 "media_ndk_headers",
437 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000438 "updatable-media",
439 }
440 //
441 // Module separator
442 //
443 m["com.android.media.swcodec"] = []string{
444 "android.frameworks.bufferhub@1.0",
445 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900446 "android.hardware.configstore-utils",
447 "android.hardware.configstore@1.0",
448 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000449 "android.hardware.graphics.allocator@2.0",
450 "android.hardware.graphics.allocator@3.0",
451 "android.hardware.graphics.allocator@4.0",
452 "android.hardware.graphics.bufferqueue@1.0",
453 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900454 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000455 "android.hardware.graphics.common@1.0",
456 "android.hardware.graphics.common@1.1",
457 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000458 "android.hardware.graphics.mapper@2.0",
459 "android.hardware.graphics.mapper@2.1",
460 "android.hardware.graphics.mapper@3.0",
461 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000462 "android.hardware.media.bufferpool@2.0",
463 "android.hardware.media.c2@1.0",
464 "android.hardware.media.c2@1.1",
465 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900466 "android.hardware.media@1.0",
467 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000468 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900469 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000470 "android.hidl.safe_union@1.0",
471 "android.hidl.token@1.0",
472 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900473 "libEGL",
474 "libFLAC",
475 "libFLAC-config",
476 "libFLAC-headers",
477 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900478 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900479 "libarect",
480 "libasync_safe",
481 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000482 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900483 "libaudioutils",
484 "libaudioutils_fixedfft",
485 "libavcdec",
486 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000487 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900488 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900489 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900490 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900491 "libbluetooth-types-header",
492 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900493 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000494 "libcap",
495 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900496 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000497 "libcodec2_hidl@1.0",
498 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900499 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000500 "libcodec2_soft_aacdec",
501 "libcodec2_soft_aacenc",
502 "libcodec2_soft_amrnbdec",
503 "libcodec2_soft_amrnbenc",
504 "libcodec2_soft_amrwbdec",
505 "libcodec2_soft_amrwbenc",
506 "libcodec2_soft_av1dec_gav1",
507 "libcodec2_soft_avcdec",
508 "libcodec2_soft_avcenc",
509 "libcodec2_soft_common",
510 "libcodec2_soft_flacdec",
511 "libcodec2_soft_flacenc",
512 "libcodec2_soft_g711alawdec",
513 "libcodec2_soft_g711mlawdec",
514 "libcodec2_soft_gsmdec",
515 "libcodec2_soft_h263dec",
516 "libcodec2_soft_h263enc",
517 "libcodec2_soft_hevcdec",
518 "libcodec2_soft_hevcenc",
519 "libcodec2_soft_mp3dec",
520 "libcodec2_soft_mpeg2dec",
521 "libcodec2_soft_mpeg4dec",
522 "libcodec2_soft_mpeg4enc",
523 "libcodec2_soft_opusdec",
524 "libcodec2_soft_opusenc",
525 "libcodec2_soft_rawdec",
526 "libcodec2_soft_vorbisdec",
527 "libcodec2_soft_vp8dec",
528 "libcodec2_soft_vp8enc",
529 "libcodec2_soft_vp9dec",
530 "libcodec2_soft_vp9enc",
531 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900532 "libdexfile_support",
533 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000534 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900535 "libfmq",
536 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000537 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900538 "libgrallocusage",
539 "libgraphicsenv",
540 "libgsm",
541 "libgui_bufferqueue_static",
542 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000543 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900544 "libhardware_headers",
545 "libhevcdec",
546 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000547 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900548 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900549 "liblzma",
550 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000551 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900552 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000553 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900554 "libminijail_gen_constants",
555 "libminijail_gen_constants_obj",
556 "libminijail_gen_syscall",
557 "libminijail_gen_syscall_obj",
558 "libminijail_generated",
559 "libmpeg2dec",
560 "libnativebase_headers",
561 "libnativebridge_lazy",
562 "libnativeloader_lazy",
563 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000564 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900565 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000566 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900567 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000568 "libscudo_wrapper",
569 "libsfplugin_ccodec_utils",
570 "libspeexresampler",
571 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900572 "libstagefright_amrnbdec",
573 "libstagefright_amrnbenc",
574 "libstagefright_amrwbdec",
575 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000576 "libstagefright_bufferpool@2.0.1",
577 "libstagefright_bufferqueue_helper",
578 "libstagefright_enc_common",
579 "libstagefright_flacdec",
580 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900581 "libstagefright_foundation_headers",
582 "libstagefright_headers",
583 "libstagefright_m4vh263dec",
584 "libstagefright_m4vh263enc",
585 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000586 "libsync",
587 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900588 "libui_headers",
589 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000590 "libvorbisidec",
591 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900592 "libyuv",
593 "libyuv_static",
594 "media_ndk_headers",
595 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000596 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000597 }
598 //
599 // Module separator
600 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900601 m["com.android.mediaprovider"] = []string{
602 "MediaProvider",
603 "MediaProviderGoogle",
604 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900605 "libbase_ndk",
606 "libfuse",
607 "libfuse_jni",
608 "libnativehelper_header_only",
609 }
610 //
611 // Module separator
612 //
613 m["com.android.permission"] = []string{
614 "androidx.annotation_annotation",
615 "androidx.annotation_annotation-nodeps",
616 "androidx.lifecycle_lifecycle-common",
617 "androidx.lifecycle_lifecycle-common-java8",
618 "androidx.lifecycle_lifecycle-common-java8-nodeps",
619 "androidx.lifecycle_lifecycle-common-nodeps",
620 "kotlin-annotations",
621 "kotlin-stdlib",
622 "kotlin-stdlib-jdk7",
623 "kotlin-stdlib-jdk8",
624 "kotlinx-coroutines-android",
625 "kotlinx-coroutines-android-nodeps",
626 "kotlinx-coroutines-core",
627 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900628 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900629 "GooglePermissionController",
630 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900631 }
Anton Hansson5053c292020-01-10 15:12:39 +0000632 //
633 // Module separator
634 //
Anton Hansson5053c292020-01-10 15:12:39 +0000635 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900636 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "libarm-optimized-routines-math",
638 "libasync_safe",
639 "libasync_safe_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900640 "libc_aeabi",
641 "libc_bionic",
642 "libc_bionic_ndk",
643 "libc_bootstrap",
644 "libc_common",
645 "libc_common_shared",
646 "libc_common_static",
647 "libc_dns",
648 "libc_dynamic_dispatch",
649 "libc_fortify",
650 "libc_freebsd",
651 "libc_freebsd_large_stack",
652 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900653 "libc_init_dynamic",
654 "libc_init_static",
655 "libc_jemalloc_wrapper",
656 "libc_netbsd",
657 "libc_nomalloc",
658 "libc_nopthread",
659 "libc_openbsd",
660 "libc_openbsd_large_stack",
661 "libc_openbsd_ndk",
662 "libc_pthread",
663 "libc_static_dispatch",
664 "libc_syscalls",
665 "libc_tzcode",
666 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900667 "libdebuggerd",
668 "libdebuggerd_common_headers",
669 "libdebuggerd_handler_core",
670 "libdebuggerd_handler_fallback",
671 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000672 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900673 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900674 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900675 "libgtest_prod",
676 "libjemalloc5",
677 "liblinker_main",
678 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900679 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000680 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900681 "libprocessgroup_headers",
682 "libprocinfo",
683 "libpropertyinfoparser",
684 "libscudo",
685 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900686 "libsystemproperties",
687 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000688 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900689 "libz",
690 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000691 }
692 //
693 // Module separator
694 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900695 m["com.android.resolv"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900696 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 "libgtest_prod",
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 "libnativehelper_header_only",
699 "libnetd_client_headers",
700 "libnetd_resolv",
701 "libnetdutils",
702 "libprocessgroup",
703 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900704 "libstatslog_resolv",
705 "libstatspush_compat",
706 "libstatssocket",
707 "libstatssocket_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900708 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900709 "netd_event_listener_interface-ndk_platform",
710 "server_configurable_flags",
711 "stats_proto",
712 }
Anton Hansson5053c292020-01-10 15:12:39 +0000713 //
714 // Module separator
715 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900716 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900717 "libnativehelper_compat_libc++",
718 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900719 "libcgrouprc",
720 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900721 "libprocessgroup",
722 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900723 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900724 "libvndksupport",
725 "tethering-aidl-interfaces-java",
726 }
Anton Hansson5053c292020-01-10 15:12:39 +0000727 //
728 // Module separator
729 //
730 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900731 "PlatformProperties",
732 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900733 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900734 "android.hardware.wifi-V1.1-java",
735 "android.hardware.wifi-V1.2-java",
736 "android.hardware.wifi-V1.3-java",
737 "android.hardware.wifi-V1.4-java",
738 "android.hardware.wifi.hostapd-V1.0-java",
739 "android.hardware.wifi.hostapd-V1.1-java",
740 "android.hardware.wifi.hostapd-V1.2-java",
741 "android.hardware.wifi.supplicant-V1.0-java",
742 "android.hardware.wifi.supplicant-V1.1-java",
743 "android.hardware.wifi.supplicant-V1.2-java",
744 "android.hardware.wifi.supplicant-V1.3-java",
745 "android.hidl.base-V1.0-java",
746 "android.hidl.manager-V1.0-java",
747 "android.hidl.manager-V1.1-java",
748 "android.hidl.manager-V1.2-java",
749 "androidx.annotation_annotation",
750 "androidx.annotation_annotation-nodeps",
751 "bouncycastle-unbundled",
752 "dnsresolver_aidl_interface-V2-java",
753 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900754 "framework-wifi-pre-jarjar",
755 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900756 "ipmemorystore-aidl-interfaces-V3-java",
757 "ipmemorystore-aidl-interfaces-java",
758 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900759 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000760 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900761 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000762 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900763 "net-utils-services-common",
764 "netd_aidl_interface-V2-java",
765 "netd_aidl_interface-unstable-java",
766 "netd_event_listener_interface-java",
767 "netlink-client",
768 "networkstack-aidl-interfaces-unstable-java",
769 "networkstack-client",
770 "services.net",
771 "wifi-lite-protos",
772 "wifi-nano-protos",
773 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000774 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900775 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000776 }
777 //
778 // Module separator
779 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900780 m["com.android.sdkext"] = []string{
781 "fmtlib_ndk",
782 "libbase_ndk",
783 "libprotobuf-cpp-lite-ndk",
784 }
785 //
786 // Module separator
787 //
788 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900789 "libprocessgroup_headers",
790 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900791 }
792 //
793 // Module separator
794 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000795 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900796 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900797 "libclang_rt",
798 "libgcc_stripped",
799 "libprofile-clang-extras",
800 "libprofile-clang-extras_ndk",
801 "libprofile-extras",
802 "libprofile-extras_ndk",
803 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900804 }
Anton Hansson5053c292020-01-10 15:12:39 +0000805 return m
806}
807
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900808func init() {
Jooyung Hane17caa62020-04-08 14:13:04 +0900809 android.AddNeverAllowRules(android.NeverAllow().
810 ModuleType("apex").
811 With("updatable", "true").
812 With("min_sdk_version", "").
813 Because("All updatable apexes should set min_sdk_version."))
814
Jiyong Parkd1063c12019-07-17 20:08:41 +0900815 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800816 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900817 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900818 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700819 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900820 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900821
Jooyung Han31c470b2019-10-18 16:26:59 +0900822 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900823 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900824
825 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
826 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
827 sort.Strings(*apexFileContextsInfos)
828 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
829 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900830}
831
Jooyung Han31c470b2019-10-18 16:26:59 +0900832func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
833 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
834 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
835}
836
Jiyong Parkd1063c12019-07-17 20:08:41 +0900837func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900838 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900839 ctx.BottomUp("apex", apexMutator).Parallel()
840 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
841 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900842}
843
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900844// Mark the direct and transitive dependencies of apex bundles so that they
845// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900846func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900847 if !mctx.Module().Enabled() {
848 return
849 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800850 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900851 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000852 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900853 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900854 ApexName: mctx.ModuleName(),
855 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900856 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900857 directDep = true
858 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800859 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900860 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900861 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900862
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800863 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900864 return
865 }
866
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100867 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900868
Jiyong Parkf760cae2020-02-12 07:53:12 +0900869 mctx.VisitDirectDeps(func(child android.Module) {
870 depName := mctx.OtherModuleName(child)
871 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100872 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800873 android.UpdateApexDependency(apexBundles, depName, directDep)
874 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900875 }
876 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877}
878
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100879// If a module in an APEX depends on a module from an SDK then it needs an APEX
880// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
881func inAnySdk(module android.Module) bool {
882 if sa, ok := module.(android.SdkAware); ok {
883 return sa.IsInAnySdk()
884 }
885
886 return false
887}
888
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900889// Create apex variations if a module is included in APEX(s).
890func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900891 if !mctx.Module().Enabled() {
892 return
893 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900894 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900895 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000896 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900897 // apex bundle itself is mutated so that it and its modules have same
898 // apex variant.
899 apexBundleName := mctx.ModuleName()
900 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900901 } else if o, ok := mctx.Module().(*OverrideApex); ok {
902 apexBundleName := o.GetOverriddenModuleName()
903 if apexBundleName == "" {
904 mctx.ModuleErrorf("base property is not set")
905 return
906 }
907 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900908 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900909
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900910}
Sundong Ahne9b55722019-09-06 17:37:42 +0900911
Jooyung Han7a78a922019-10-08 21:59:58 +0900912var (
913 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
914 apexFileContextsInfosMutex sync.Mutex
915)
916
917func apexFileContextsInfos(config android.Config) *[]string {
918 return config.Once(apexFileContextsInfosKey, func() interface{} {
919 return &[]string{}
920 }).(*[]string)
921}
922
Jooyung Han54aca7b2019-11-20 02:26:02 +0900923func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900924 apexFileContextsInfosMutex.Lock()
925 defer apexFileContextsInfosMutex.Unlock()
926 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900927 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900928}
929
Sundong Ahne9b55722019-09-06 17:37:42 +0900930func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900931 if !mctx.Module().Enabled() {
932 return
933 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900934 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900935 var variants []string
936 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
937 case "image":
938 variants = append(variants, imageApexType, flattenedApexType)
939 case "zip":
940 variants = append(variants, zipApexType)
941 case "both":
942 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
943 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900944 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900945 return
946 }
947
948 modules := mctx.CreateLocalVariations(variants...)
949
950 for i, v := range variants {
951 switch v {
952 case imageApexType:
953 modules[i].(*apexBundle).properties.ApexType = imageApex
954 case zipApexType:
955 modules[i].(*apexBundle).properties.ApexType = zipApex
956 case flattenedApexType:
957 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900958 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900959 modules[i].(*apexBundle).MakeAsSystemExt()
960 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900961 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900962 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900963 } else if _, ok := mctx.Module().(*OverrideApex); ok {
964 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900965 }
966}
967
Jooyung Han5c998b92019-06-27 11:30:33 +0900968func apexUsesMutator(mctx android.BottomUpMutatorContext) {
969 if ab, ok := mctx.Module().(*apexBundle); ok {
970 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
971 }
972}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900973
Jooyung Handc782442019-11-01 03:14:38 +0900974var (
975 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
976)
977
978// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
979// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
980// which may cause compatibility issues. (e.g. libbinder)
981// Even though libbinder restricts its availability via 'apex_available' property and relies on
982// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
983// to avoid similar problems.
984func useVendorWhitelist(config android.Config) []string {
985 return config.Once(useVendorWhitelistKey, func() interface{} {
986 return []string{
987 // swcodec uses "vendor" variants for smaller size
988 "com.android.media.swcodec",
989 "test_com.android.media.swcodec",
990 }
991 }).([]string)
992}
993
994// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
995// called before the first call to useVendorWhitelist()
996func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
997 config.Once(useVendorWhitelistKey, func() interface{} {
998 return whitelist
999 })
1000}
1001
Alex Light9670d332019-01-29 18:07:33 -08001002type apexNativeDependencies struct {
1003 // List of native libraries
1004 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001005
Alex Light9670d332019-01-29 18:07:33 -08001006 // List of native executables
1007 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001008
Roland Levillain630846d2019-06-26 12:48:34 +01001009 // List of native tests
1010 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001011}
Jooyung Han344d5432019-08-23 11:17:39 +09001012
Alex Light9670d332019-01-29 18:07:33 -08001013type apexMultilibProperties struct {
1014 // Native dependencies whose compile_multilib is "first"
1015 First apexNativeDependencies
1016
1017 // Native dependencies whose compile_multilib is "both"
1018 Both apexNativeDependencies
1019
1020 // Native dependencies whose compile_multilib is "prefer32"
1021 Prefer32 apexNativeDependencies
1022
1023 // Native dependencies whose compile_multilib is "32"
1024 Lib32 apexNativeDependencies
1025
1026 // Native dependencies whose compile_multilib is "64"
1027 Lib64 apexNativeDependencies
1028}
1029
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001030type apexBundleProperties struct {
1031 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001032 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001033 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001034
Jiyong Park40e26a22019-02-08 02:53:06 +09001035 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1036 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001037 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001038
Roland Levillain411c5842019-09-19 16:37:20 +01001039 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1040 // device (/apex/<apex_name>).
1041 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001042 Apex_name *string
1043
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001044 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001045 // For platform APEXes, this should points to a file under /system/sepolicy
1046 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1047 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001048
1049 // List of native shared libs that are embedded inside this APEX bundle
1050 Native_shared_libs []string
1051
Roland Levillain630846d2019-06-26 12:48:34 +01001052 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001053 Binaries []string
1054
1055 // List of java libraries that are embedded inside this APEX bundle
1056 Java_libs []string
1057
1058 // List of prebuilt files that are embedded inside this APEX bundle
1059 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001060
Roland Levillain630846d2019-06-26 12:48:34 +01001061 // List of tests that are embedded inside this APEX bundle
1062 Tests []string
1063
Jiyong Parkff1458f2018-10-12 21:49:38 +09001064 // Name of the apex_key module that provides the private key to sign APEX
1065 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001066
Alex Light5098a612018-11-29 17:12:15 -08001067 // The type of APEX to build. Controls what the APEX payload is. Either
1068 // 'image', 'zip' or 'both'. Default: 'image'.
1069 Payload_type *string
1070
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001071 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1072 // or an android_app_certificate module name in the form ":module".
1073 Certificate *string
1074
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001075 // Whether this APEX is installable to one of the partitions. Default: true.
1076 Installable *bool
1077
Jiyong Parkda6eb592018-12-19 17:12:36 +09001078 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1079 // Default is false.
1080 Use_vendor *bool
1081
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001082 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1083 Ignore_system_library_special_case *bool
1084
Alex Light9670d332019-01-29 18:07:33 -08001085 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001086
Jiyong Parkf97782b2019-02-13 20:28:58 +09001087 // List of sanitizer names that this APEX is enabled for
1088 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001089
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001090 PreventInstall bool `blueprint:"mutated"`
1091
1092 HideFromMake bool `blueprint:"mutated"`
1093
Jooyung Han5c998b92019-06-27 11:30:33 +09001094 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1095 Provide_cpp_shared_libs *bool
1096
1097 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1098 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001099
1100 // A txt file containing list of files that are whitelisted to be included in this APEX.
1101 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001102
Sundong Ahnabb64432019-10-22 13:58:29 +09001103 // package format of this apex variant; could be non-flattened, flattened, or zip.
1104 // imageApex, zipApex or flattened
1105 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001106
Jiyong Parkd1063c12019-07-17 20:08:41 +09001107 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1108 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1109 // is implied. This value affects all modules included in this APEX. In other words, they are
1110 // also built with the SDKs specified here.
1111 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001112
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001113 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1114 // Should be only used in tests#.
1115 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001116
Jiyong Park956305c2020-01-09 12:32:06 +09001117 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001118
1119 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1120 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1121 // like symlinking to the system libs. Default is false.
1122 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001123
1124 // The minimum SDK version that this apex must be compatible with.
1125 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001126}
1127
1128type apexTargetBundleProperties struct {
1129 Target struct {
1130 // Multilib properties only for android.
1131 Android struct {
1132 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001133 }
Jooyung Han344d5432019-08-23 11:17:39 +09001134
Alex Light9670d332019-01-29 18:07:33 -08001135 // Multilib properties only for host.
1136 Host struct {
1137 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001138 }
Jooyung Han344d5432019-08-23 11:17:39 +09001139
Alex Light9670d332019-01-29 18:07:33 -08001140 // Multilib properties only for host linux_bionic.
1141 Linux_bionic struct {
1142 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001143 }
Jooyung Han344d5432019-08-23 11:17:39 +09001144
Alex Light9670d332019-01-29 18:07:33 -08001145 // Multilib properties only for host linux_glibc.
1146 Linux_glibc struct {
1147 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001148 }
1149 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001150}
1151
Jiyong Park5d790c32019-11-15 18:40:32 +09001152type overridableProperties struct {
1153 // List of APKs to package inside APEX
1154 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001155
1156 // Names of modules to be overridden. Listed modules can only be other binaries
1157 // (in Make or Soong).
1158 // This does not completely prevent installation of the overridden binaries, but if both
1159 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1160 // from PRODUCT_PACKAGES.
1161 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001162
1163 // Logging Parent value
1164 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001165
1166 // Apex Container Package Name.
1167 // Override value for attribute package:name in AndroidManifest.xml
1168 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001169}
1170
Alex Light5098a612018-11-29 17:12:15 -08001171type apexPackaging int
1172
1173const (
1174 imageApex apexPackaging = iota
1175 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001176 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001177)
1178
Sundong Ahnabb64432019-10-22 13:58:29 +09001179// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001180func (a apexPackaging) suffix() string {
1181 switch a {
1182 case imageApex:
1183 return imageApexSuffix
1184 case zipApex:
1185 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001186 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001187 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001188 }
1189}
1190
1191func (a apexPackaging) name() string {
1192 switch a {
1193 case imageApex:
1194 return imageApexType
1195 case zipApex:
1196 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001197 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001198 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001199 }
1200}
1201
Jiyong Parkf653b052019-11-18 15:39:01 +09001202type apexFileClass int
1203
1204const (
1205 etc apexFileClass = iota
1206 nativeSharedLib
1207 nativeExecutable
1208 shBinary
1209 pyBinary
1210 goBinary
1211 javaSharedLib
1212 nativeTest
1213 app
1214)
1215
Jiyong Park8fd61922018-11-08 02:50:25 +09001216func (class apexFileClass) NameInMake() string {
1217 switch class {
1218 case etc:
1219 return "ETC"
1220 case nativeSharedLib:
1221 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001222 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001223 return "EXECUTABLES"
1224 case javaSharedLib:
1225 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001226 case nativeTest:
1227 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001228 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001229 // b/142537672 Why isn't this APP? We want to have full control over
1230 // the paths and file names of the apk file under the flattend APEX.
1231 // If this is set to APP, then the paths and file names are modified
1232 // by the Make build system. For example, it is installed to
1233 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1234 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1235 // appends module name (which is <apexname>.<Appname> to the path.
1236 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001237 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001238 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001239 }
1240}
1241
Jiyong Parkf653b052019-11-18 15:39:01 +09001242// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001243type apexFile struct {
1244 builtFile android.Path
1245 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001246 installDir string
1247 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001248 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001249 // list of symlinks that will be created in installDir that point to this apexFile
1250 symlinks []string
1251 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001252 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001253
1254 requiredModuleNames []string
1255 targetRequiredModuleNames []string
1256 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001257
Colin Cross503c1d02020-01-28 14:00:53 -08001258 jacocoReportClassesFile android.Path // only for javalibs and apps
1259 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001260 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001261}
1262
Jiyong Park1833cef2019-12-13 13:28:36 +09001263func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1264 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001265 builtFile: builtFile,
1266 moduleName: moduleName,
1267 installDir: installDir,
1268 class: class,
1269 module: module,
1270 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001271 if module != nil {
1272 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001273 ret.requiredModuleNames = module.RequiredModuleNames()
1274 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1275 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001276 }
1277 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001278}
1279
1280func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001281 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001282}
1283
Jiyong Park7cd10e32020-01-14 09:22:18 +09001284// Path() returns path of this apex file relative to the APEX root
1285func (af *apexFile) Path() string {
1286 return filepath.Join(af.installDir, af.builtFile.Base())
1287}
1288
1289// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1290func (af *apexFile) SymlinkPaths() []string {
1291 var ret []string
1292 for _, symlink := range af.symlinks {
1293 ret = append(ret, filepath.Join(af.installDir, symlink))
1294 }
1295 return ret
1296}
1297
1298func (af *apexFile) AvailableToPlatform() bool {
1299 if af.module == nil {
1300 return false
1301 }
1302 if am, ok := af.module.(android.ApexModule); ok {
1303 return am.AvailableFor(android.AvailableToPlatform)
1304 }
1305 return false
1306}
1307
Jiyong Park678c8812020-02-07 17:25:49 +09001308type depInfo struct {
1309 to string
1310 from []string
1311 isExternal bool
1312}
1313
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001314type apexBundle struct {
1315 android.ModuleBase
1316 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001317 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001318 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001319
Jiyong Park5d790c32019-11-15 18:40:32 +09001320 properties apexBundleProperties
1321 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001322 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001323
Jooyung Hanf21c7972019-12-16 22:32:06 +09001324 // specific to apex_vndk modules
1325 vndkProperties apexVndkProperties
1326
Colin Crossa4925902018-11-16 11:36:28 -08001327 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001328 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001329 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001330
Jiyong Park03b68dd2019-07-26 23:20:40 +09001331 prebuiltFileToDelete string
1332
Jiyong Park42cca6c2019-04-01 11:15:50 +09001333 public_key_file android.Path
1334 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001335
1336 container_certificate_file android.Path
1337 container_private_key_file android.Path
1338
Jooyung Han54aca7b2019-11-20 02:26:02 +09001339 fileContexts android.Path
1340
Jiyong Park8fd61922018-11-08 02:50:25 +09001341 // list of files to be included in this apex
1342 filesInfo []apexFile
1343
Jiyong Park956305c2020-01-09 12:32:06 +09001344 // list of module names that should be installed along with this APEX
1345 requiredDeps []string
1346
Jiyong Park956305c2020-01-09 12:32:06 +09001347 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001348 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001349
Sundong Ahnabb64432019-10-22 13:58:29 +09001350 testApex bool
1351 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001352 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001353 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001354
Jooyung Han214bf372019-11-12 13:03:50 +09001355 manifestJsonOut android.WritablePath
1356 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001357
Jooyung Han002ab682020-01-08 01:57:58 +09001358 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001359 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001360 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001361 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1362 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001363
1364 // Suffix of module name in Android.mk
1365 // ".flattened", ".apex", ".zipapex", or ""
1366 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001367
1368 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001369
1370 // Whether to create symlink to the system file instead of having a file
1371 // inside the apex or not
1372 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001373
1374 // Struct holding the merged notice file paths in different formats
1375 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001376}
1377
Jiyong Park397e55e2018-10-24 21:09:55 +09001378func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001379 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001380 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001381 // Use *FarVariation* to be able to depend on modules having
1382 // conflicting variations with this module. This is required since
1383 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1384 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001385 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001386 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001387 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001388 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001389 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001390
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001391 ctx.AddFarVariationDependencies(append(target.Variations(),
1392 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1393 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001394
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001395 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001396 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001397 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001398 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001399}
1400
Alex Light9670d332019-01-29 18:07:33 -08001401func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1402 if ctx.Os().Class == android.Device {
1403 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1404 } else {
1405 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1406 if ctx.Os().Bionic() {
1407 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1408 } else {
1409 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1410 }
1411 }
1412}
1413
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001414func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001415 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1416 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1417 }
1418
Jiyong Park397e55e2018-10-24 21:09:55 +09001419 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001420 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001421
1422 a.combineProperties(ctx)
1423
Jiyong Park397e55e2018-10-24 21:09:55 +09001424 has32BitTarget := false
1425 for _, target := range targets {
1426 if target.Arch.ArchType.Multilib == "lib32" {
1427 has32BitTarget = true
1428 }
1429 }
1430 for i, target := range targets {
1431 // When multilib.* is omitted for native_shared_libs, it implies
1432 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001433 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001434 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001435 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001436 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001437
Roland Levillain630846d2019-06-26 12:48:34 +01001438 // When multilib.* is omitted for tests, it implies
1439 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001440 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001441 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001442 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001443 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001444
Jiyong Park397e55e2018-10-24 21:09:55 +09001445 // Add native modules targetting both ABIs
1446 addDependenciesForNativeModules(ctx,
1447 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001448 a.properties.Multilib.Both.Binaries,
1449 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001450 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001451 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001452
Alex Light3d673592019-01-18 14:37:31 -08001453 isPrimaryAbi := i == 0
1454 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001455 // When multilib.* is omitted for binaries, it implies
1456 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001457 ctx.AddFarVariationDependencies(append(target.Variations(),
1458 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1459 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001460
1461 // Add native modules targetting the first ABI
1462 addDependenciesForNativeModules(ctx,
1463 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001464 a.properties.Multilib.First.Binaries,
1465 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001466 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001467 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001468 }
1469
1470 switch target.Arch.ArchType.Multilib {
1471 case "lib32":
1472 // Add native modules targetting 32-bit ABI
1473 addDependenciesForNativeModules(ctx,
1474 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001475 a.properties.Multilib.Lib32.Binaries,
1476 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001477 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001478 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001479
1480 addDependenciesForNativeModules(ctx,
1481 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001482 a.properties.Multilib.Prefer32.Binaries,
1483 a.properties.Multilib.Prefer32.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 case "lib64":
1487 // Add native modules targetting 64-bit ABI
1488 addDependenciesForNativeModules(ctx,
1489 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001490 a.properties.Multilib.Lib64.Binaries,
1491 a.properties.Multilib.Lib64.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
1495 if !has32BitTarget {
1496 addDependenciesForNativeModules(ctx,
1497 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001498 a.properties.Multilib.Prefer32.Binaries,
1499 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001500 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001501 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001502 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001503
1504 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1505 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1506 if sanitizer == "hwaddress" {
1507 addDependenciesForNativeModules(ctx,
1508 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001509 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001510 break
1511 }
1512 }
1513 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001514 }
1515
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001516 }
1517
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001518 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1519 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1520 // b/144532908
1521 archForPrebuiltEtc := config.Arches()[0]
1522 for _, arch := range config.Arches() {
1523 // Prefer 64-bit arch if there is any
1524 if arch.ArchType.Multilib == "lib64" {
1525 archForPrebuiltEtc = arch
1526 break
1527 }
1528 }
1529 ctx.AddFarVariationDependencies([]blueprint.Variation{
1530 {Mutator: "os", Variation: ctx.Os().String()},
1531 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1532 }, prebuiltTag, a.properties.Prebuilts...)
1533
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001534 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1535 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001536
Ulya Trafimovich44561882020-01-03 13:25:54 +00001537 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1538 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1539 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1540 javaLibTag, "jacocoagent")
1541 }
1542
Jiyong Park23c52b02019-02-02 13:13:47 +09001543 if String(a.properties.Key) == "" {
1544 ctx.ModuleErrorf("key is missing")
1545 return
1546 }
1547 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001548
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001549 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001550 if cert != "" {
1551 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001552 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001553
1554 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1555 if len(a.properties.Uses_sdks) > 0 {
1556 sdkRefs := []android.SdkRef{}
1557 for _, str := range a.properties.Uses_sdks {
1558 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1559 sdkRefs = append(sdkRefs, parsed)
1560 }
1561 a.BuildWithSdks(sdkRefs)
1562 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001563}
1564
Jiyong Park5d790c32019-11-15 18:40:32 +09001565func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1566 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1567 androidAppTag, a.overridableProperties.Apps...)
1568}
1569
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001570func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1571 // direct deps of an APEX bundle are all part of the APEX bundle
1572 return true
1573}
1574
Colin Cross0ea8ba82019-06-06 14:33:29 -07001575func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001576 moduleName := ctx.ModuleName()
1577 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1578 // we check with the pseudo module name to see if its certificate is overridden.
1579 if a.vndkApex {
1580 moduleName = vndkApexName
1581 }
1582 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001583 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001584 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001585 }
1586 return String(a.properties.Certificate)
1587}
1588
Colin Cross41955e82019-05-29 14:40:35 -07001589func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1590 switch tag {
1591 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001592 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001593 default:
1594 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001595 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001596}
1597
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001598func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001599 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001600}
1601
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001602func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1603 return proptools.Bool(a.properties.Test_only_no_hashtree)
1604}
1605
Jiyong Park7c1dc612019-01-05 11:15:24 +09001606func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001607 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001608 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001609 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001610 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001611 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001612 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001613 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001614 }
1615}
1616
Jiyong Parkf97782b2019-02-13 20:28:58 +09001617func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1618 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1619 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1620 }
1621}
1622
Jiyong Park388ef3f2019-01-28 19:47:32 +09001623func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001624 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1625 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001626 }
1627
1628 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001629 globalSanitizerNames := []string{}
1630 if a.Host() {
1631 globalSanitizerNames = ctx.Config().SanitizeHost()
1632 } else {
1633 arches := ctx.Config().SanitizeDeviceArch()
1634 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1635 globalSanitizerNames = ctx.Config().SanitizeDevice()
1636 }
1637 }
1638 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001639}
1640
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001641func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001642 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001643}
1644
1645func (a *apexBundle) PreventInstall() {
1646 a.properties.PreventInstall = true
1647}
1648
1649func (a *apexBundle) HideFromMake() {
1650 a.properties.HideFromMake = true
1651}
1652
Jiyong Park956305c2020-01-09 12:32:06 +09001653func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1654 a.properties.IsCoverageVariant = coverage
1655}
1656
Jiyong Parkf653b052019-11-18 15:39:01 +09001657// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001658func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001659 // Decide the APEX-local directory by the multilib of the library
1660 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001661 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001662 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001663 case "lib32":
1664 dirInApex = "lib"
1665 case "lib64":
1666 dirInApex = "lib64"
1667 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001668 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001669 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001670 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001671 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001672 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001673 // Special case for Bionic libs and other libs installed with them. This is
1674 // to prevent those libs from being included in the search path
1675 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1676 // those libs in the Runtime APEX are available via the legacy paths in
1677 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1678 // to the legacy paths and thus will be loaded into the default linker
1679 // namespace (aka "platform" namespace). If the libs are directly in
1680 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1681 // into the runtime linker namespace, which will result in double loading of
1682 // them, which isn't supported.
1683 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001684 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001685
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001687 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001688}
1689
Jiyong Park1833cef2019-12-13 13:28:36 +09001690func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001692 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001693 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001694 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001695 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001696 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001697 af.symlinks = cc.Symlinks()
1698 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001699}
1700
Jiyong Park1833cef2019-12-13 13:28:36 +09001701func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001702 dirInApex := "bin"
1703 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001704 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001705}
Jiyong Park1833cef2019-12-13 13:28:36 +09001706func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001707 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001708 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1709 if err != nil {
1710 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001711 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001712 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001713 fileToCopy := android.PathForOutput(ctx, s)
1714 // NB: Since go binaries are static we don't need the module for anything here, which is
1715 // good since the go tool is a blueprint.Module not an android.Module like we would
1716 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001717 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001718}
1719
Jiyong Park1833cef2019-12-13 13:28:36 +09001720func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001721 dirInApex := filepath.Join("bin", sh.SubDir())
1722 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001723 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001724 af.symlinks = sh.Symlinks()
1725 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001726}
1727
Jooyung Han58f26ab2019-12-18 15:34:32 +09001728// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1729type javaLibrary interface {
1730 android.Module
1731 java.Dependency
1732}
1733
1734func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001735 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001736 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001737 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1738 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1739 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001740}
1741
Jiyong Park1833cef2019-12-13 13:28:36 +09001742func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001743 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1744 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001745 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001746}
1747
atrost6e126252020-01-27 17:01:16 +00001748func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1749 dirInApex := filepath.Join("etc", config.SubDir())
1750 fileToCopy := config.CompatConfig()
1751 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1752}
1753
Jiyong Park1833cef2019-12-13 13:28:36 +09001754func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001755 android.Module
1756 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001757 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001758 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001759 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001760 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001761}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001762 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001763 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001764 appDir = "priv-app"
1765 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001766 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001767 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001768 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1769 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001770 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001771
1772 if app, ok := aapp.(interface {
1773 OverriddenManifestPackageName() string
1774 }); ok {
1775 af.overriddenPackageName = app.OverriddenManifestPackageName()
1776 }
Jiyong Park618922e2020-01-08 13:35:43 +09001777 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001778}
1779
Roland Levillain935639d2019-08-13 14:55:28 +01001780// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1781type flattenedApexContext struct {
1782 android.ModuleContext
1783}
1784
1785func (c *flattenedApexContext) InstallBypassMake() bool {
1786 return true
1787}
1788
Paul Duffin133608f2020-03-30 15:54:08 +01001789// Function called while walking an APEX's payload dependencies.
1790//
1791// Return true if the `to` module should be visited, false otherwise.
1792type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1793
Jiyong Park201cedd2020-02-07 17:25:49 +09001794// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001795func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001796 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001797 am, ok := child.(android.ApexModule)
1798 if !ok || !am.CanHaveApexVariants() {
1799 return false
1800 }
1801
1802 // Check for the direct dependencies that contribute to the payload
1803 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1804 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001805 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001806 }
Paul Duffin133608f2020-03-30 15:54:08 +01001807 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001808 return false
1809 }
1810
1811 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001812 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001813 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001814 }
1815
Paul Duffin133608f2020-03-30 15:54:08 +01001816 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001817 })
1818}
1819
Jooyung Han0c4e0162020-02-26 22:45:42 +09001820func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1821 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001822 intVer, err := android.ApiStrToNum(ctx, ver)
1823 if err != nil {
1824 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001825 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001826 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001827}
1828
Paul Duffinf0207962020-03-31 11:31:36 +01001829// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1830// a dependency tag.
1831var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1832
1833func PrettyPrintTag(tag blueprint.DependencyTag) string {
1834 // Use tag's custom String() method if available.
1835 if stringer, ok := tag.(fmt.Stringer); ok {
1836 return stringer.String()
1837 }
1838
1839 // Otherwise, get a default string representation of the tag's struct.
1840 tagString := fmt.Sprintf("%#v", tag)
1841
1842 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1843 tagString = tagCleaner.ReplaceAllString(tagString, "")
1844 return tagString
1845}
1846
Jiyong Park201cedd2020-02-07 17:25:49 +09001847// Ensures that the dependencies are marked as available for this APEX
1848func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1849 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1850 if ctx.Host() || a.testApex || a.vndkApex {
1851 return
1852 }
1853
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001854 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1855 // Requiring them and their transitive depencies with apex_available is not right
1856 // because they just add noise.
1857 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1858 return
1859 }
1860
Paul Duffin133608f2020-03-30 15:54:08 +01001861 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1862 if externalDep {
1863 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1864 return false
1865 }
1866
Jiyong Park201cedd2020-02-07 17:25:49 +09001867 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001868 fromName := ctx.OtherModuleName(from)
1869 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001870
1871 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1872 // do any of its dependencies.
1873 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1874 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1875 return false
1876 }
1877
Paul Duffin133608f2020-03-30 15:54:08 +01001878 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1879 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001880 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001881 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001882 tagPath := ctx.GetTagPath()
1883 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1884 walkPath := ctx.GetWalkPath()[1:]
1885 for i, m := range walkPath {
1886 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001887 }
1888 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 +01001889 // Visit this module's dependencies to check and report any issues with their availability.
1890 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001891 })
1892}
1893
Jiyong Park678c8812020-02-07 17:25:49 +09001894// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1895func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1896 a.depInfos = make(map[string]depInfo)
Paul Duffin133608f2020-03-30 15:54:08 +01001897 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001898 if from.Name() == to.Name() {
1899 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffin133608f2020-03-30 15:54:08 +01001900 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1901 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001902 }
1903
1904 if info, exists := a.depInfos[to.Name()]; exists {
1905 if !android.InList(from.Name(), info.from) {
1906 info.from = append(info.from, from.Name())
1907 }
1908 info.isExternal = info.isExternal && externalDep
1909 a.depInfos[to.Name()] = info
1910 } else {
1911 a.depInfos[to.Name()] = depInfo{
1912 to: to.Name(),
1913 from: []string{from.Name()},
1914 isExternal: externalDep,
1915 }
1916 }
Paul Duffin133608f2020-03-30 15:54:08 +01001917
1918 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1919 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001920 })
1921}
1922
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001923func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001924 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1925 switch a.properties.ApexType {
1926 case imageApex:
1927 if buildFlattenedAsDefault {
1928 a.suffix = imageApexSuffix
1929 } else {
1930 a.suffix = ""
1931 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001932
1933 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001934 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001935 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001936 }
1937 case zipApex:
1938 if proptools.String(a.properties.Payload_type) == "zip" {
1939 a.suffix = ""
1940 a.primaryApexType = true
1941 } else {
1942 a.suffix = zipApexSuffix
1943 }
1944 case flattenedApex:
1945 if buildFlattenedAsDefault {
1946 a.suffix = ""
1947 a.primaryApexType = true
1948 } else {
1949 a.suffix = flattenedSuffix
1950 }
Alex Light5098a612018-11-29 17:12:15 -08001951 }
1952
Roland Levillain630846d2019-06-26 12:48:34 +01001953 if len(a.properties.Tests) > 0 && !a.testApex {
1954 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1955 return
1956 }
1957
Jiyong Parkfa899442020-01-31 02:49:53 +09001958 a.checkApexAvailability(ctx)
1959
Jiyong Park678c8812020-02-07 17:25:49 +09001960 a.collectDepsInfo(ctx)
1961
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001962 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1963
Jooyung Hane1633032019-08-01 17:41:43 +09001964 // native lib dependencies
1965 var provideNativeLibs []string
1966 var requireNativeLibs []string
1967
Jooyung Han5c998b92019-06-27 11:30:33 +09001968 // Check if "uses" requirements are met with dependent apexBundles
1969 var providedNativeSharedLibs []string
1970 useVendor := proptools.Bool(a.properties.Use_vendor)
1971 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1972 if ctx.OtherModuleDependencyTag(m) != usesTag {
1973 return
1974 }
1975 otherName := ctx.OtherModuleName(m)
1976 other, ok := m.(*apexBundle)
1977 if !ok {
1978 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1979 return
1980 }
1981 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1982 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1983 return
1984 }
1985 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1986 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1987 return
1988 }
1989 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1990 })
1991
Jiyong Parkf653b052019-11-18 15:39:01 +09001992 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001993 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001994 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001995 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01001996 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1997 return false
1998 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001999 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002000 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002001 switch depTag {
2002 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002003 if c, ok := child.(*cc.Module); ok {
2004 // bootstrap bionic libs are treated as provided by system
2005 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2006 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002007 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002008 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002009 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002010 } else {
2011 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002012 }
2013 case executableTag:
2014 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002015 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002016 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002017 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002018 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002019 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002020 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002021 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002022 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002023 } else {
Alex Light778127a2019-02-27 14:19:50 -08002024 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 +09002025 }
2026 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002027 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002028 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002029 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002030 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2031 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002032 filesInfo = append(filesInfo, af)
2033 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002034 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002035 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2036 af := apexFileForJavaLibrary(ctx, sdkLib)
2037 if !af.Ok() {
2038 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2039 return false
2040 }
2041 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002042 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002043 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002044 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002045 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002046 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002047 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002048 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002049 return true // track transitive dependencies
2050 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002051 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002052 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002053 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002054 } else {
2055 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2056 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002057 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002058 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002059 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002060 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2061 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002062 } else {
atrost6e126252020-01-27 17:01:16 +00002063 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002064 }
Roland Levillain630846d2019-06-26 12:48:34 +01002065 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002066 if ccTest, ok := child.(*cc.Module); ok {
2067 if ccTest.IsTestPerSrcAllTestsVariation() {
2068 // Multiple-output test module (where `test_per_src: true`).
2069 //
2070 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2071 // We do not add this variation to `filesInfo`, as it has no output;
2072 // however, we do add the other variations of this module as indirect
2073 // dependencies (see below).
2074 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002075 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002076 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002077 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002078 af.class = nativeTest
2079 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002080 }
Roland Levillain630846d2019-06-26 12:48:34 +01002081 } else {
2082 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2083 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002084 case keyTag:
2085 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002086 a.private_key_file = key.private_key_file
2087 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002088 } else {
2089 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002090 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002091 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002092 case certificateTag:
2093 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002094 a.container_certificate_file = dep.Certificate.Pem
2095 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002096 } else {
2097 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2098 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002099 case android.PrebuiltDepTag:
2100 // If the prebuilt is force disabled, remember to delete the prebuilt file
2101 // that might have been installed in the previous builds
2102 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2103 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2104 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002105 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002106 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002107 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002108 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002109 // We cannot use a switch statement on `depTag` here as the checked
2110 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002111 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002112 if cc, ok := child.(*cc.Module); ok {
2113 if android.InList(cc.Name(), providedNativeSharedLibs) {
2114 // If we're using a shared library which is provided from other APEX,
2115 // don't include it in this APEX
2116 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002117 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002118 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002119 // If the dependency is a stubs lib, don't include it in this APEX,
2120 // but make sure that the lib is installed on the device.
2121 // In case no APEX is having the lib, the lib is installed to the system
2122 // partition.
2123 //
2124 // Always include if we are a host-apex however since those won't have any
2125 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002126 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2127 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002128 }
Jooyung Hane1633032019-08-01 17:41:43 +09002129 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002130 // Don't track further
2131 return false
2132 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002133 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002134 af.transitiveDep = true
2135 filesInfo = append(filesInfo, af)
2136 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002137 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002138 } else if cc.IsTestPerSrcDepTag(depTag) {
2139 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002140 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002141 // Handle modules created as `test_per_src` variations of a single test module:
2142 // use the name of the generated test binary (`fileToCopy`) instead of the name
2143 // of the original test module (`depName`, shared by all `test_per_src`
2144 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002145 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002146 // these are not considered transitive dep
2147 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002148 filesInfo = append(filesInfo, af)
2149 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002150 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002151 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002152 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2153 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002154 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2155 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2156 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2157 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002158 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002159 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002160 }
2161 }
2162 }
2163 return false
2164 })
2165
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002166 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2167 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2168 // via the global boot image config.
2169 if a.artApex {
2170 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2171 dirInApex := filepath.Join("javalib", arch.String())
2172 for _, f := range files {
2173 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002174 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002175 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002176 }
2177 }
2178 }
2179
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002180 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002181 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2182 return
2183 }
2184
Jiyong Park8fd61922018-11-08 02:50:25 +09002185 // remove duplicates in filesInfo
2186 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002187 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002188 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002189 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002190 if e, ok := encountered[dest]; !ok {
2191 encountered[dest] = f
2192 } else {
2193 // If a module is directly included and also transitively depended on
2194 // consider it as directly included.
2195 e.transitiveDep = e.transitiveDep && f.transitiveDep
2196 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002197 }
2198 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002199 var result []apexFile
2200 for _, v := range encountered {
2201 result = append(result, v)
2202 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002203 return result
2204 }
2205 filesInfo = removeDup(filesInfo)
2206
2207 // to have consistent build rules
2208 sort.Slice(filesInfo, func(i, j int) bool {
2209 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2210 })
2211
Jiyong Park8fd61922018-11-08 02:50:25 +09002212 a.installDir = android.PathForModuleInstall(ctx, "apex")
2213 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002214
Jooyung Han54aca7b2019-11-20 02:26:02 +09002215 if a.properties.ApexType != zipApex {
2216 if a.properties.File_contexts == nil {
2217 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2218 } else {
2219 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2220 if a.Platform() {
2221 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2222 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2223 }
2224 }
2225 }
2226 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2227 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2228 return
2229 }
2230 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002231 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2232 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2233 // the same library in the system partition, thus effectively sharing the same libraries
2234 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2235 // in the APEX.
2236 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2237 a.installable() &&
2238 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002239
Jiyong Park9d677202020-02-19 16:29:35 +09002240 // We don't need the optimization for updatable APEXes, as it might give false signal
2241 // to the system health when the APEXes are still bundled (b/149805758)
2242 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2243 a.linkToSystemLib = false
2244 }
2245
Jiyong Park9b964182020-02-26 18:27:19 +09002246 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2247 if ctx.Host() {
2248 a.linkToSystemLib = false
2249 }
2250
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002251 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002252 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2253
2254 a.setCertificateAndPrivateKey(ctx)
2255 if a.properties.ApexType == flattenedApex {
2256 a.buildFlattenedApex(ctx)
2257 } else {
2258 a.buildUnflattenedApex(ctx)
2259 }
2260
Jooyung Han002ab682020-01-08 01:57:58 +09002261 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002262
2263 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002264}
2265
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002266func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002267 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002268 moduleName = normalizeModuleName(moduleName)
2269
2270 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2271 return true
2272 }
2273
2274 key = android.AvailableToAnyApex
2275 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2276 return true
2277 }
2278
2279 return false
2280}
2281
2282func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002283 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2284 // system. Trim the prefix for the check since they are confusing
2285 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2286 if strings.HasPrefix(moduleName, "libclang_rt.") {
2287 // This module has many arch variants that depend on the product being built.
2288 // We don't want to list them all
2289 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002290 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002291 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002292}
2293
Jooyung Han344d5432019-08-23 11:17:39 +09002294func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002295 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002296 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002297 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002298 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002299 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002300 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2301 })
Alex Light5098a612018-11-29 17:12:15 -08002302 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002303 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002304 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002305 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002306 return module
2307}
Jiyong Park30ca9372019-02-07 16:27:23 +09002308
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002309func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002310 bundle := newApexBundle()
2311 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002312 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002313 return bundle
2314}
2315
Jiyong Parkfce0b422020-02-11 03:56:06 +09002316// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2317// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002318func testApexBundleFactory() android.Module {
2319 bundle := newApexBundle()
2320 bundle.testApex = true
2321 return bundle
2322}
2323
Jiyong Parkfce0b422020-02-11 03:56:06 +09002324// apex packages other modules into an APEX file which is a packaging format for system-level
2325// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002326func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002327 return newApexBundle()
2328}
2329
Jiyong Park30ca9372019-02-07 16:27:23 +09002330//
2331// Defaults
2332//
2333type Defaults struct {
2334 android.ModuleBase
2335 android.DefaultsModuleBase
2336}
2337
Jiyong Park30ca9372019-02-07 16:27:23 +09002338func defaultsFactory() android.Module {
2339 return DefaultsFactory()
2340}
2341
2342func DefaultsFactory(props ...interface{}) android.Module {
2343 module := &Defaults{}
2344
2345 module.AddProperties(props...)
2346 module.AddProperties(
2347 &apexBundleProperties{},
2348 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002349 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002350 )
2351
2352 android.InitDefaultsModule(module)
2353 return module
2354}
Jiyong Park5d790c32019-11-15 18:40:32 +09002355
2356//
2357// OverrideApex
2358//
2359type OverrideApex struct {
2360 android.ModuleBase
2361 android.OverrideModuleBase
2362}
2363
2364func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2365 // All the overrides happen in the base module.
2366}
2367
2368// override_apex is used to create an apex module based on another apex module
2369// by overriding some of its properties.
2370func overrideApexFactory() android.Module {
2371 m := &OverrideApex{}
2372 m.AddProperties(&overridableProperties{})
2373
2374 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2375 android.InitOverrideModule(m)
2376 return m
2377}