blob: fa71ffa5c4678dd09745c3533a15c3828766abda [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090048
49 // determines if the dependent will be part of the APEX payload
50 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090051}
52
53var (
Jiyong Park0f80c182020-01-31 02:49:53 +090054 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090055 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090056 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 Park0f80c182020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090064 rroTag = dependencyTag{name: "rro", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Paul Duffin50cbefd2020-03-10 13:44:19 +000096 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090097 "art_cmdlineparser_headers",
98 "art_disassembler_headers",
99 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "bionic_libc_platform_headers",
101 "core-repackaged-icu4j",
102 "cpp-define-generator-asm-support",
103 "cpp-define-generator-definitions",
104 "crtbegin_dynamic",
105 "crtbegin_dynamic1",
106 "crtbegin_so1",
107 "crtbrand",
Jiyong Park0f80c182020-01-31 02:49:53 +0900108 "dex2oat_headers",
109 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900110 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 "javavm_headers",
112 "jni_platform_headers",
113 "libPlatformProperties",
114 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000115 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900116 "libandroidicuinit",
117 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000118 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900119 "libdexfile_all_headers",
120 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000121 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900122 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000123 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900124 "libfdlibm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900125 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000126 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900127 "libicuuc_headers",
128 "libicuuc_stubdata",
129 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000131 "liblzma",
132 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900133 "libnativebridge-headers",
134 "libnativehelper_header_only",
135 "libnativeloader-headers",
136 "libnpt_headers",
137 "libopenjdkjvmti_headers",
138 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000139 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900140 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000141 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900142 "libv8",
143 "libv8base",
144 "libv8gen",
145 "libv8platform",
146 "libv8sampler",
147 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000148 "libvixl",
149 "libvixld",
150 "libz",
151 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000153 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000154 m["com.android.art.debug"] = artApexContents
155 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000156 //
157 // Module separator
158 //
159 m["com.android.bluetooth.updatable"] = []string{
160 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "android.hardware.bluetooth.a2dp@1.0",
162 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900163 "android.hardware.bluetooth@1.0",
164 "android.hardware.bluetooth@1.1",
165 "android.hardware.graphics.bufferqueue@1.0",
166 "android.hardware.graphics.bufferqueue@2.0",
167 "android.hardware.graphics.common@1.0",
168 "android.hardware.graphics.common@1.1",
169 "android.hardware.graphics.common@1.2",
170 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000171 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900172 "android.hidl.token@1.0",
173 "android.hidl.token@1.0-utils",
174 "avrcp-target-service",
175 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 "bluetooth-protos-lite",
177 "bluetooth.mapsapi",
178 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900179 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900180 "ipmemorystore-aidl-interfaces-V5-java",
181 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900182 "internal_include_headers",
183 "lib-bt-packets",
184 "lib-bt-packets-avrcp",
185 "lib-bt-packets-base",
186 "libFraunhoferAAC",
187 "libaudio-a2dp-hw-utils",
188 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900189 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000190 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900191 "libbluetooth-types",
192 "libbluetooth-types-header",
193 "libbluetooth_gd",
194 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000195 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "libbt-audio-hal-interface",
197 "libbt-bta",
198 "libbt-common",
199 "libbt-hci",
200 "libbt-platform-protos-lite",
201 "libbt-protos-lite",
202 "libbt-sbc-decoder",
203 "libbt-sbc-encoder",
204 "libbt-stack",
205 "libbt-utils",
206 "libbtcore",
207 "libbtdevice",
208 "libbte",
209 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000210 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000211 "libevent",
212 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900213 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900214 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900215 "libmedia_headers",
216 "libmodpb64",
217 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900218 "libstagefright_foundation_headers",
219 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000220 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900221 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000222 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900223 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000224 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900225 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900226 "net-utils-services-common",
227 "netd_aidl_interface-unstable-java",
228 "netd_event_listener_interface-java",
229 "netlink-client",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900230 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900231 "sap-api-java-static",
232 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000233 }
234 //
235 // Module separator
236 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900237 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000238 //
239 // Module separator
240 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libnativehelper_header_only",
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 }
244 //
245 // Module separator
246 //
247 m["com.android.extservices"] = []string{
248 "flatbuffer_headers",
249 "liblua",
250 "libtextclassifier",
251 "libtextclassifier_hash_static",
252 "libtflite_static",
253 "libutf",
254 "libz_current",
255 "tensorflow_headers",
256 }
257 //
258 // Module separator
259 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900260 m["com.android.neuralnetworks"] = []string{
261 "android.hardware.neuralnetworks@1.0",
262 "android.hardware.neuralnetworks@1.1",
263 "android.hardware.neuralnetworks@1.2",
264 "android.hardware.neuralnetworks@1.3",
265 "android.hidl.allocator@1.0",
266 "android.hidl.memory.token@1.0",
267 "android.hidl.memory@1.0",
268 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900269 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900270 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900272 "libprocpartition",
273 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900274 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000275 //
276 // Module separator
277 //
278 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000279 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900280 "android.hardware.cas.native@1.0",
281 "android.hardware.cas@1.0",
282 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000283 "android.hardware.configstore@1.0",
284 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000285 "android.hardware.graphics.allocator@2.0",
286 "android.hardware.graphics.allocator@3.0",
287 "android.hardware.graphics.bufferqueue@1.0",
288 "android.hardware.graphics.bufferqueue@2.0",
289 "android.hardware.graphics.common@1.0",
290 "android.hardware.graphics.common@1.1",
291 "android.hardware.graphics.common@1.2",
292 "android.hardware.graphics.mapper@2.0",
293 "android.hardware.graphics.mapper@2.1",
294 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000296 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900297 "android.hidl.allocator@1.0",
298 "android.hidl.memory.token@1.0",
299 "android.hidl.memory@1.0",
300 "android.hidl.token@1.0",
301 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900302 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900303 "gl_headers",
304 "libEGL",
305 "libEGL_blobCache",
306 "libEGL_getProcAddress",
307 "libFLAC",
308 "libFLAC-config",
309 "libFLAC-headers",
310 "libGLESv2",
311 "libaacextractor",
312 "libamrextractor",
313 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900314 "libaudio_system_headers",
315 "libaudioclient",
316 "libaudioclient_headers",
317 "libaudiofoundation",
318 "libaudiofoundation_headers",
319 "libaudiomanager",
320 "libaudiopolicy",
321 "libaudioutils",
322 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900323 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900324 "libbluetooth-types-header",
325 "libbufferhub",
326 "libbufferhub_headers",
327 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900328 "libc_malloc_debug_backtrace",
329 "libcamera_client",
330 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900331 "libdexfile_external_headers",
332 "libdexfile_support",
333 "libdvr_headers",
334 "libexpat",
335 "libfifo",
336 "libflacextractor",
337 "libgrallocusage",
338 "libgraphicsenv",
339 "libgui",
340 "libgui_headers",
341 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900342 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900343 "liblzma",
344 "libmath",
345 "libmedia",
346 "libmedia_codeclist",
347 "libmedia_headers",
348 "libmedia_helper",
349 "libmedia_helper_headers",
350 "libmedia_midiiowrapper",
351 "libmedia_omx",
352 "libmediautils",
353 "libmidiextractor",
354 "libmkvextractor",
355 "libmp3extractor",
356 "libmp4extractor",
357 "libmpeg2extractor",
358 "libnativebase_headers",
359 "libnativebridge-headers",
360 "libnativebridge_lazy",
361 "libnativeloader-headers",
362 "libnativeloader_lazy",
363 "libnativewindow_headers",
364 "libnblog",
365 "liboggextractor",
366 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900367 "libpdx",
368 "libpdx_default_transport",
369 "libpdx_headers",
370 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900371 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900372 "libsonivox",
373 "libspeexresampler",
374 "libspeexresampler",
375 "libstagefright_esds",
376 "libstagefright_flacdec",
377 "libstagefright_flacdec",
378 "libstagefright_foundation",
379 "libstagefright_foundation_headers",
380 "libstagefright_foundation_without_imemory",
381 "libstagefright_headers",
382 "libstagefright_id3",
383 "libstagefright_metadatautils",
384 "libstagefright_mpeg2extractor",
385 "libstagefright_mpeg2support",
386 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900387 "libui",
388 "libui_headers",
389 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900390 "libvibrator",
391 "libvorbisidec",
392 "libwavextractor",
393 "libwebm",
394 "media_ndk_headers",
395 "media_plugin_headers",
396 "updatable-media",
397 }
398 //
399 // Module separator
400 //
401 m["com.android.media.swcodec"] = []string{
402 "android.frameworks.bufferhub@1.0",
403 "android.hardware.common-ndk_platform",
404 "android.hardware.configstore-utils",
405 "android.hardware.configstore@1.0",
406 "android.hardware.configstore@1.1",
407 "android.hardware.graphics.allocator@2.0",
408 "android.hardware.graphics.allocator@3.0",
409 "android.hardware.graphics.bufferqueue@1.0",
410 "android.hardware.graphics.bufferqueue@2.0",
411 "android.hardware.graphics.common-ndk_platform",
412 "android.hardware.graphics.common@1.0",
413 "android.hardware.graphics.common@1.1",
414 "android.hardware.graphics.common@1.2",
415 "android.hardware.graphics.mapper@2.0",
416 "android.hardware.graphics.mapper@2.1",
417 "android.hardware.graphics.mapper@3.0",
418 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000419 "android.hardware.media.bufferpool@2.0",
420 "android.hardware.media.c2@1.0",
421 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900422 "android.hardware.media@1.0",
423 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000424 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900425 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000426 "android.hidl.safe_union@1.0",
427 "android.hidl.token@1.0",
428 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900429 "libEGL",
430 "libFLAC",
431 "libFLAC-config",
432 "libFLAC-headers",
433 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900434 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900435 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900436 "libaudio_system_headers",
437 "libaudioutils",
438 "libaudioutils",
439 "libaudioutils_fixedfft",
440 "libavcdec",
441 "libavcenc",
442 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000443 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900444 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900445 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900446 "libbluetooth-types-header",
447 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900448 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000449 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900450 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000451 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900452 "libcodec2_hidl@1.1",
453 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000454 "libcodec2_soft_aacdec",
455 "libcodec2_soft_aacenc",
456 "libcodec2_soft_amrnbdec",
457 "libcodec2_soft_amrnbenc",
458 "libcodec2_soft_amrwbdec",
459 "libcodec2_soft_amrwbenc",
460 "libcodec2_soft_av1dec_gav1",
461 "libcodec2_soft_avcdec",
462 "libcodec2_soft_avcenc",
463 "libcodec2_soft_common",
464 "libcodec2_soft_flacdec",
465 "libcodec2_soft_flacenc",
466 "libcodec2_soft_g711alawdec",
467 "libcodec2_soft_g711mlawdec",
468 "libcodec2_soft_gsmdec",
469 "libcodec2_soft_h263dec",
470 "libcodec2_soft_h263enc",
471 "libcodec2_soft_hevcdec",
472 "libcodec2_soft_hevcenc",
473 "libcodec2_soft_mp3dec",
474 "libcodec2_soft_mpeg2dec",
475 "libcodec2_soft_mpeg4dec",
476 "libcodec2_soft_mpeg4enc",
477 "libcodec2_soft_opusdec",
478 "libcodec2_soft_opusenc",
479 "libcodec2_soft_rawdec",
480 "libcodec2_soft_vorbisdec",
481 "libcodec2_soft_vp8dec",
482 "libcodec2_soft_vp8enc",
483 "libcodec2_soft_vp9dec",
484 "libcodec2_soft_vp9enc",
485 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000486 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900487 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000488 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900489 "libfmq",
490 "libgav1",
491 "libgralloctypes",
492 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000493 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900494 "libgsm",
495 "libgui_bufferqueue_static",
496 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000497 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900498 "libhardware_headers",
499 "libhevcdec",
500 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000501 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900502 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000503 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900504 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000505 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900506 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900507 "libmpeg2dec",
508 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000509 "libnativebridge_lazy",
510 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900511 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900512 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000513 "libscudo_wrapper",
514 "libsfplugin_ccodec_utils",
515 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900516 "libstagefright_amrnbdec",
517 "libstagefright_amrnbenc",
518 "libstagefright_amrwbdec",
519 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000520 "libstagefright_bufferpool@2.0.1",
521 "libstagefright_bufferqueue_helper",
522 "libstagefright_enc_common",
523 "libstagefright_flacdec",
524 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900525 "libstagefright_foundation_headers",
526 "libstagefright_headers",
527 "libstagefright_m4vh263dec",
528 "libstagefright_m4vh263enc",
529 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000530 "libsync",
531 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900532 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000533 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000534 "libvorbisidec",
535 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900536 "libyuv",
537 "libyuv_static",
538 "media_ndk_headers",
539 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000540 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900541 }
542 //
543 // Module separator
544 //
545 m["com.android.mediaprovider"] = []string{
546 "MediaProvider",
547 "MediaProviderGoogle",
548 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900549 "libbase_ndk",
550 "libfuse",
551 "libfuse_jni",
552 "libnativehelper_header_only",
553 }
554 //
555 // Module separator
556 //
557 m["com.android.permission"] = []string{
558 "androidx.annotation_annotation",
559 "androidx.annotation_annotation-nodeps",
560 "androidx.lifecycle_lifecycle-common",
561 "androidx.lifecycle_lifecycle-common-java8",
562 "androidx.lifecycle_lifecycle-common-java8-nodeps",
563 "androidx.lifecycle_lifecycle-common-nodeps",
564 "kotlin-annotations",
565 "kotlin-stdlib",
566 "kotlin-stdlib-jdk7",
567 "kotlin-stdlib-jdk8",
568 "kotlinx-coroutines-android",
569 "kotlinx-coroutines-android-nodeps",
570 "kotlinx-coroutines-core",
571 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900572 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000573 }
574 //
575 // Module separator
576 //
577 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900578 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900579 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "libc_aeabi",
581 "libc_bionic",
582 "libc_bionic_ndk",
583 "libc_bootstrap",
584 "libc_common",
585 "libc_common_shared",
586 "libc_common_static",
587 "libc_dns",
588 "libc_dynamic_dispatch",
589 "libc_fortify",
590 "libc_freebsd",
591 "libc_freebsd_large_stack",
592 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900593 "libc_init_dynamic",
594 "libc_init_static",
595 "libc_jemalloc_wrapper",
596 "libc_netbsd",
597 "libc_nomalloc",
598 "libc_nopthread",
599 "libc_openbsd",
600 "libc_openbsd_large_stack",
601 "libc_openbsd_ndk",
602 "libc_pthread",
603 "libc_static_dispatch",
604 "libc_syscalls",
605 "libc_tzcode",
606 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900607 "libdebuggerd",
608 "libdebuggerd_common_headers",
609 "libdebuggerd_handler_core",
610 "libdebuggerd_handler_fallback",
611 "libdexfile_external_headers",
612 "libdexfile_support",
613 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900614 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900615 "libjemalloc5",
616 "liblinker_main",
617 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900618 "liblz4",
619 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900620 "libprocinfo",
621 "libpropertyinfoparser",
622 "libscudo",
623 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900624 "libsystemproperties",
625 "libtombstoned_client_static",
626 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900627 "libz",
628 "libziparchive",
629 }
630 //
631 // Module separator
632 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900633 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900634 "libnativehelper_compat_libc++",
635 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900636 "libcgrouprc",
637 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900638 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900639 "libvndksupport",
640 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000641 }
642 //
643 // Module separator
644 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900645 m["com.android.wifi"] = []string{
646 "PlatformProperties",
647 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900648 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900649 "android.hardware.wifi-V1.1-java",
650 "android.hardware.wifi-V1.2-java",
651 "android.hardware.wifi-V1.3-java",
652 "android.hardware.wifi-V1.4-java",
653 "android.hardware.wifi.hostapd-V1.0-java",
654 "android.hardware.wifi.hostapd-V1.1-java",
655 "android.hardware.wifi.hostapd-V1.2-java",
656 "android.hardware.wifi.supplicant-V1.0-java",
657 "android.hardware.wifi.supplicant-V1.1-java",
658 "android.hardware.wifi.supplicant-V1.2-java",
659 "android.hardware.wifi.supplicant-V1.3-java",
660 "android.hidl.base-V1.0-java",
661 "android.hidl.manager-V1.0-java",
662 "android.hidl.manager-V1.1-java",
663 "android.hidl.manager-V1.2-java",
664 "androidx.annotation_annotation",
665 "androidx.annotation_annotation-nodeps",
666 "bouncycastle-unbundled",
667 "dnsresolver_aidl_interface-V2-java",
668 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900669 "framework-wifi-pre-jarjar",
670 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900671 "ipmemorystore-aidl-interfaces-V3-java",
672 "ipmemorystore-aidl-interfaces-java",
673 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900674 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900675 "libwifi-jni",
676 "net-utils-services-common",
677 "netd_aidl_interface-V2-java",
678 "netd_aidl_interface-unstable-java",
679 "netd_event_listener_interface-java",
680 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900681 "networkstack-client",
682 "services.net",
683 "wifi-lite-protos",
684 "wifi-nano-protos",
685 "wifi-service-pre-jarjar",
686 "wifi-service-resources",
687 "prebuilt_androidx.annotation_annotation-nodeps",
688 }
689 //
690 // Module separator
691 //
692 m["com.android.sdkext"] = []string{
693 "fmtlib_ndk",
694 "libbase_ndk",
695 "libprotobuf-cpp-lite-ndk",
696 }
697 //
698 // Module separator
699 //
700 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900701 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900702 }
703 //
704 // Module separator
705 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000706 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900708 "libclang_rt",
709 "libgcc_stripped",
710 "libprofile-clang-extras",
711 "libprofile-clang-extras_ndk",
712 "libprofile-extras",
713 "libprofile-extras_ndk",
714 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900715 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000716 return m
717}
718
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900719func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900720 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800721 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900722 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900723 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700724 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900725 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900726
Jooyung Han31c470b2019-10-18 16:26:59 +0900727 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900728 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900729
730 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
731 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
732 sort.Strings(*apexFileContextsInfos)
733 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
734 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900735}
736
Jooyung Han31c470b2019-10-18 16:26:59 +0900737func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
738 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
739 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
740}
741
Jiyong Parkd1063c12019-07-17 20:08:41 +0900742func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900743 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900744 ctx.BottomUp("apex", apexMutator).Parallel()
745 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
746 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900747 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900748}
749
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900750// Mark the direct and transitive dependencies of apex bundles so that they
751// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900752func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900753 if !mctx.Module().Enabled() {
754 return
755 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800756 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900757 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000758 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900759 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900760 ApexName: mctx.ModuleName(),
761 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100762 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900763 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900764 directDep = true
765 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800766 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900767 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900768 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900769
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800770 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900771 return
772 }
773
Paul Duffin923e8a52020-03-30 15:33:32 +0100774 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900775
Jiyong Parkf760cae2020-02-12 07:53:12 +0900776 mctx.VisitDirectDeps(func(child android.Module) {
777 depName := mctx.OtherModuleName(child)
778 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100779 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800780 android.UpdateApexDependency(apexBundles, depName, directDep)
781 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900782 }
783 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900784}
785
Jiyong Park89e850a2020-04-07 16:37:39 +0900786// mark if a module cannot be available to platform. A module cannot be available
787// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
788// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
789func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
790 // Host and recovery are not considered as platform
791 if mctx.Host() || mctx.Module().InstallInRecovery() {
792 return
793 }
794
795 if am, ok := mctx.Module().(android.ApexModule); ok {
796 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
797
798 // In a rare case when a lib is marked as available only to an apex
799 // but the apex doesn't exist. This can happen in a partial manifest branch
800 // like master-art. Currently, libstatssocket in the stats APEX is causing
801 // this problem.
802 // Include the lib in platform because the module SDK that ought to provide
803 // it doesn't exist, so it would otherwise be left out completely.
804 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
805 // this check for libraries provided by SDKs.
806 if !availableToPlatform && !android.InAnyApex(am.Name()) {
807 availableToPlatform = true
808 }
809
810 // If any of the dep is not available to platform, this module is also considered
811 // as being not available to platform even if it has "//apex_available:platform"
812 mctx.VisitDirectDeps(func(child android.Module) {
813 if !am.DepIsInSameApex(mctx, child) {
814 // if the dependency crosses apex boundary, don't consider it
815 return
816 }
817 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
818 availableToPlatform = false
819 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
820 }
821 })
822
823 // Exception 1: stub libraries and native bridge libraries are always available to platform
824 if cc, ok := mctx.Module().(*cc.Module); ok &&
825 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
826 availableToPlatform = true
827 }
828
829 // Exception 2: bootstrap bionic libraries are also always available to platform
830 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
831 availableToPlatform = true
832 }
833
834 if !availableToPlatform {
835 am.SetNotAvailableForPlatform()
836 }
837 }
838}
839
Paul Duffin65347702020-03-31 15:23:40 +0100840// If a module in an APEX depends on a module from an SDK then it needs an APEX
841// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
842func inAnySdk(module android.Module) bool {
843 if sa, ok := module.(android.SdkAware); ok {
844 return sa.IsInAnySdk()
845 }
846
847 return false
848}
849
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900850// Create apex variations if a module is included in APEX(s).
851func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900852 if !mctx.Module().Enabled() {
853 return
854 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900855 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900856 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000857 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900858 // apex bundle itself is mutated so that it and its modules have same
859 // apex variant.
860 apexBundleName := mctx.ModuleName()
861 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900862 } else if o, ok := mctx.Module().(*OverrideApex); ok {
863 apexBundleName := o.GetOverriddenModuleName()
864 if apexBundleName == "" {
865 mctx.ModuleErrorf("base property is not set")
866 return
867 }
868 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900869 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900870
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900871}
Sundong Ahne9b55722019-09-06 17:37:42 +0900872
Jooyung Han7a78a922019-10-08 21:59:58 +0900873var (
874 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
875 apexFileContextsInfosMutex sync.Mutex
876)
877
878func apexFileContextsInfos(config android.Config) *[]string {
879 return config.Once(apexFileContextsInfosKey, func() interface{} {
880 return &[]string{}
881 }).(*[]string)
882}
883
Jooyung Han54aca7b2019-11-20 02:26:02 +0900884func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900885 apexFileContextsInfosMutex.Lock()
886 defer apexFileContextsInfosMutex.Unlock()
887 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900888 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900889}
890
Sundong Ahne9b55722019-09-06 17:37:42 +0900891func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900892 if !mctx.Module().Enabled() {
893 return
894 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900895 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900896 var variants []string
897 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
898 case "image":
899 variants = append(variants, imageApexType, flattenedApexType)
900 case "zip":
901 variants = append(variants, zipApexType)
902 case "both":
903 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
904 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900905 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900906 return
907 }
908
909 modules := mctx.CreateLocalVariations(variants...)
910
911 for i, v := range variants {
912 switch v {
913 case imageApexType:
914 modules[i].(*apexBundle).properties.ApexType = imageApex
915 case zipApexType:
916 modules[i].(*apexBundle).properties.ApexType = zipApex
917 case flattenedApexType:
918 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900919 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900920 modules[i].(*apexBundle).MakeAsSystemExt()
921 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900922 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900923 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900924 } else if _, ok := mctx.Module().(*OverrideApex); ok {
925 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900926 }
927}
928
Jooyung Han5c998b92019-06-27 11:30:33 +0900929func apexUsesMutator(mctx android.BottomUpMutatorContext) {
930 if ab, ok := mctx.Module().(*apexBundle); ok {
931 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
932 }
933}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900934
Jooyung Handc782442019-11-01 03:14:38 +0900935var (
936 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
937)
938
939// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
940// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
941// which may cause compatibility issues. (e.g. libbinder)
942// Even though libbinder restricts its availability via 'apex_available' property and relies on
943// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
944// to avoid similar problems.
945func useVendorWhitelist(config android.Config) []string {
946 return config.Once(useVendorWhitelistKey, func() interface{} {
947 return []string{
948 // swcodec uses "vendor" variants for smaller size
949 "com.android.media.swcodec",
950 "test_com.android.media.swcodec",
951 }
952 }).([]string)
953}
954
955// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
956// called before the first call to useVendorWhitelist()
957func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
958 config.Once(useVendorWhitelistKey, func() interface{} {
959 return whitelist
960 })
961}
962
Jooyung Han01a868d2020-02-27 13:40:44 +0900963type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800964 // List of native libraries
965 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900966
Jooyung Han643adc42020-02-27 13:50:06 +0900967 // List of JNI libraries
968 Jni_libs []string
969
Alex Light9670d332019-01-29 18:07:33 -0800970 // List of native executables
971 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900972
Roland Levillain630846d2019-06-26 12:48:34 +0100973 // List of native tests
974 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800975}
Jooyung Han344d5432019-08-23 11:17:39 +0900976
Alex Light9670d332019-01-29 18:07:33 -0800977type apexMultilibProperties struct {
978 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900979 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800980
981 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900982 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800983
984 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900985 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800986
987 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900988 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800989
990 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900991 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800992}
993
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900994type apexBundleProperties struct {
995 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000996 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800997 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900998
Jiyong Park40e26a22019-02-08 02:53:06 +0900999 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1000 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001001 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001002
Roland Levillain411c5842019-09-19 16:37:20 +01001003 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1004 // device (/apex/<apex_name>).
1005 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001006 Apex_name *string
1007
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001008 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001009 // For platform APEXes, this should points to a file under /system/sepolicy
1010 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1011 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001012
Jooyung Han01a868d2020-02-27 13:40:44 +09001013 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001014
1015 // List of java libraries that are embedded inside this APEX bundle
1016 Java_libs []string
1017
1018 // List of prebuilt files that are embedded inside this APEX bundle
1019 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001020
1021 // Name of the apex_key module that provides the private key to sign APEX
1022 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001023
Alex Light5098a612018-11-29 17:12:15 -08001024 // The type of APEX to build. Controls what the APEX payload is. Either
1025 // 'image', 'zip' or 'both'. Default: 'image'.
1026 Payload_type *string
1027
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001028 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1029 // or an android_app_certificate module name in the form ":module".
1030 Certificate *string
1031
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001032 // Whether this APEX is installable to one of the partitions. Default: true.
1033 Installable *bool
1034
Jiyong Parkda6eb592018-12-19 17:12:36 +09001035 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1036 // Default is false.
1037 Use_vendor *bool
1038
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001039 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1040 Ignore_system_library_special_case *bool
1041
Alex Light9670d332019-01-29 18:07:33 -08001042 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001043
Jiyong Parkf97782b2019-02-13 20:28:58 +09001044 // List of sanitizer names that this APEX is enabled for
1045 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001046
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001047 PreventInstall bool `blueprint:"mutated"`
1048
1049 HideFromMake bool `blueprint:"mutated"`
1050
Jooyung Han5c998b92019-06-27 11:30:33 +09001051 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1052 Provide_cpp_shared_libs *bool
1053
1054 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1055 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001056
1057 // A txt file containing list of files that are whitelisted to be included in this APEX.
1058 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001059
Sundong Ahnabb64432019-10-22 13:58:29 +09001060 // package format of this apex variant; could be non-flattened, flattened, or zip.
1061 // imageApex, zipApex or flattened
1062 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001063
Jiyong Parkd1063c12019-07-17 20:08:41 +09001064 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1065 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1066 // is implied. This value affects all modules included in this APEX. In other words, they are
1067 // also built with the SDKs specified here.
1068 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001069
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001070 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1071 // Should be only used in tests#.
1072 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001073
Dario Frenica913392020-04-27 18:21:11 +01001074 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1075 // Should be only used in tests#.
1076 Test_only_unsigned_payload *bool
1077
Jiyong Park956305c2020-01-09 12:32:06 +09001078 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001079
1080 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001081 // rules for making sure that the APEX is truly updatable.
1082 // - To be updatable, min_sdk_version should be set as well
1083 // This will also disable the size optimizations like symlinking to the system libs.
1084 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001085 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001086
1087 // The minimum SDK version that this apex must be compatibile with.
1088 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001089}
1090
1091type apexTargetBundleProperties struct {
1092 Target struct {
1093 // Multilib properties only for android.
1094 Android struct {
1095 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001096 }
Jooyung Han344d5432019-08-23 11:17:39 +09001097
Alex Light9670d332019-01-29 18:07:33 -08001098 // Multilib properties only for host.
1099 Host struct {
1100 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001101 }
Jooyung Han344d5432019-08-23 11:17:39 +09001102
Alex Light9670d332019-01-29 18:07:33 -08001103 // Multilib properties only for host linux_bionic.
1104 Linux_bionic struct {
1105 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001106 }
Jooyung Han344d5432019-08-23 11:17:39 +09001107
Alex Light9670d332019-01-29 18:07:33 -08001108 // Multilib properties only for host linux_glibc.
1109 Linux_glibc struct {
1110 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001111 }
1112 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001113}
1114
Jiyong Park5d790c32019-11-15 18:40:32 +09001115type overridableProperties struct {
1116 // List of APKs to package inside APEX
1117 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001118
Jiyong Park69aeba92020-04-24 21:16:36 +09001119 // List of runtime resource overlays (RROs) inside APEX
1120 Rros []string
1121
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001122 // Names of modules to be overridden. Listed modules can only be other binaries
1123 // (in Make or Soong).
1124 // This does not completely prevent installation of the overridden binaries, but if both
1125 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1126 // from PRODUCT_PACKAGES.
1127 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001128
1129 // Logging Parent value
1130 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001131
1132 // Apex Container Package Name.
1133 // Override value for attribute package:name in AndroidManifest.xml
1134 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001135}
1136
Alex Light5098a612018-11-29 17:12:15 -08001137type apexPackaging int
1138
1139const (
1140 imageApex apexPackaging = iota
1141 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001142 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001143)
1144
Sundong Ahnabb64432019-10-22 13:58:29 +09001145// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001146func (a apexPackaging) suffix() string {
1147 switch a {
1148 case imageApex:
1149 return imageApexSuffix
1150 case zipApex:
1151 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001152 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001153 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001154 }
1155}
1156
1157func (a apexPackaging) name() string {
1158 switch a {
1159 case imageApex:
1160 return imageApexType
1161 case zipApex:
1162 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001163 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001164 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001165 }
1166}
1167
Jiyong Parkf653b052019-11-18 15:39:01 +09001168type apexFileClass int
1169
1170const (
1171 etc apexFileClass = iota
1172 nativeSharedLib
1173 nativeExecutable
1174 shBinary
1175 pyBinary
1176 goBinary
1177 javaSharedLib
1178 nativeTest
1179 app
1180)
1181
Jiyong Park8fd61922018-11-08 02:50:25 +09001182func (class apexFileClass) NameInMake() string {
1183 switch class {
1184 case etc:
1185 return "ETC"
1186 case nativeSharedLib:
1187 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001188 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001189 return "EXECUTABLES"
1190 case javaSharedLib:
1191 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001192 case nativeTest:
1193 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001194 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001195 // b/142537672 Why isn't this APP? We want to have full control over
1196 // the paths and file names of the apk file under the flattend APEX.
1197 // If this is set to APP, then the paths and file names are modified
1198 // by the Make build system. For example, it is installed to
1199 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1200 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1201 // appends module name (which is <apexname>.<Appname> to the path.
1202 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001203 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001204 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001205 }
1206}
1207
Jiyong Parkf653b052019-11-18 15:39:01 +09001208// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001209type apexFile struct {
1210 builtFile android.Path
1211 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001212 installDir string
1213 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001214 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001215 // list of symlinks that will be created in installDir that point to this apexFile
1216 symlinks []string
1217 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001218 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001219
1220 requiredModuleNames []string
1221 targetRequiredModuleNames []string
1222 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001223
Colin Cross503c1d02020-01-28 14:00:53 -08001224 jacocoReportClassesFile android.Path // only for javalibs and apps
1225 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001226 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001227
1228 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001229}
1230
Jiyong Park1833cef2019-12-13 13:28:36 +09001231func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1232 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001233 builtFile: builtFile,
1234 moduleName: moduleName,
1235 installDir: installDir,
1236 class: class,
1237 module: module,
1238 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001239 if module != nil {
1240 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001241 ret.requiredModuleNames = module.RequiredModuleNames()
1242 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1243 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001244 }
1245 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001246}
1247
1248func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001249 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001250}
1251
Jiyong Park7cd10e32020-01-14 09:22:18 +09001252// Path() returns path of this apex file relative to the APEX root
1253func (af *apexFile) Path() string {
1254 return filepath.Join(af.installDir, af.builtFile.Base())
1255}
1256
1257// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1258func (af *apexFile) SymlinkPaths() []string {
1259 var ret []string
1260 for _, symlink := range af.symlinks {
1261 ret = append(ret, filepath.Join(af.installDir, symlink))
1262 }
1263 return ret
1264}
1265
1266func (af *apexFile) AvailableToPlatform() bool {
1267 if af.module == nil {
1268 return false
1269 }
1270 if am, ok := af.module.(android.ApexModule); ok {
1271 return am.AvailableFor(android.AvailableToPlatform)
1272 }
1273 return false
1274}
1275
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001276type apexBundle struct {
1277 android.ModuleBase
1278 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001279 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001280 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001281
Jiyong Park5d790c32019-11-15 18:40:32 +09001282 properties apexBundleProperties
1283 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001284 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001285
Jooyung Hanf21c7972019-12-16 22:32:06 +09001286 // specific to apex_vndk modules
1287 vndkProperties apexVndkProperties
1288
Colin Crossa4925902018-11-16 11:36:28 -08001289 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001290 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001291 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001292
Jiyong Park03b68dd2019-07-26 23:20:40 +09001293 prebuiltFileToDelete string
1294
Jiyong Park42cca6c2019-04-01 11:15:50 +09001295 public_key_file android.Path
1296 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001297
1298 container_certificate_file android.Path
1299 container_private_key_file android.Path
1300
Jooyung Han54aca7b2019-11-20 02:26:02 +09001301 fileContexts android.Path
1302
Jiyong Park8fd61922018-11-08 02:50:25 +09001303 // list of files to be included in this apex
1304 filesInfo []apexFile
1305
Jiyong Park956305c2020-01-09 12:32:06 +09001306 // list of module names that should be installed along with this APEX
1307 requiredDeps []string
1308
Jiyong Park956305c2020-01-09 12:32:06 +09001309 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001310 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001311
Sundong Ahnabb64432019-10-22 13:58:29 +09001312 testApex bool
1313 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001314 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001315 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001316
Jooyung Han214bf372019-11-12 13:03:50 +09001317 manifestJsonOut android.WritablePath
1318 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001319
Jooyung Han002ab682020-01-08 01:57:58 +09001320 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001321 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001322 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001323 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1324 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001325
1326 // Suffix of module name in Android.mk
1327 // ".flattened", ".apex", ".zipapex", or ""
1328 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001329
1330 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001331
1332 // Whether to create symlink to the system file instead of having a file
1333 // inside the apex or not
1334 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001335
1336 // Struct holding the merged notice file paths in different formats
1337 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001338}
1339
Jiyong Park397e55e2018-10-24 21:09:55 +09001340func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001341 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001342 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001343 // Use *FarVariation* to be able to depend on modules having
1344 // conflicting variations with this module. This is required since
1345 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1346 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001347 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001348 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001349 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001350 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001351 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001352
Jooyung Han643adc42020-02-27 13:50:06 +09001353 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1354 {Mutator: "image", Variation: imageVariation},
1355 {Mutator: "link", Variation: "shared"},
1356 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1357 }...), jniLibTag, nativeModules.Jni_libs...)
1358
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001359 ctx.AddFarVariationDependencies(append(target.Variations(),
1360 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001361 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001362
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001363 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001364 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001365 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001366 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001367}
1368
Alex Light9670d332019-01-29 18:07:33 -08001369func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1370 if ctx.Os().Class == android.Device {
1371 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1372 } else {
1373 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1374 if ctx.Os().Bionic() {
1375 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1376 } else {
1377 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1378 }
1379 }
1380}
1381
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001382func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001383 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1384 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1385 }
1386
Jiyong Park397e55e2018-10-24 21:09:55 +09001387 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001388 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001389
1390 a.combineProperties(ctx)
1391
Jiyong Park397e55e2018-10-24 21:09:55 +09001392 has32BitTarget := false
1393 for _, target := range targets {
1394 if target.Arch.ArchType.Multilib == "lib32" {
1395 has32BitTarget = true
1396 }
1397 }
1398 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001399 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001400 // multilib.both
1401 addDependenciesForNativeModules(ctx,
1402 ApexNativeDependencies{
1403 Native_shared_libs: a.properties.Native_shared_libs,
1404 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001405 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001406 Binaries: nil,
1407 },
1408 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001409
Jiyong Park397e55e2018-10-24 21:09:55 +09001410 // Add native modules targetting both ABIs
1411 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001412 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001413 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001414 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001415
Alex Light3d673592019-01-18 14:37:31 -08001416 isPrimaryAbi := i == 0
1417 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001418 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001419 // multilib.first
1420 addDependenciesForNativeModules(ctx,
1421 ApexNativeDependencies{
1422 Native_shared_libs: nil,
1423 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001424 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001425 Binaries: a.properties.Binaries,
1426 },
1427 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001428
1429 // Add native modules targetting the first ABI
1430 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001431 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001432 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001433 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001434 }
1435
1436 switch target.Arch.ArchType.Multilib {
1437 case "lib32":
1438 // Add native modules targetting 32-bit ABI
1439 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001440 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001441 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001442 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001443
1444 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001445 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001446 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001447 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001448 case "lib64":
1449 // Add native modules targetting 64-bit ABI
1450 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001451 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001452 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001453 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001454
1455 if !has32BitTarget {
1456 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001457 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001458 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001459 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001460 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001461
1462 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1463 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1464 if sanitizer == "hwaddress" {
1465 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001466 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001467 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001468 break
1469 }
1470 }
1471 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001472 }
1473
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001474 }
1475
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001476 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1477 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1478 // b/144532908
1479 archForPrebuiltEtc := config.Arches()[0]
1480 for _, arch := range config.Arches() {
1481 // Prefer 64-bit arch if there is any
1482 if arch.ArchType.Multilib == "lib64" {
1483 archForPrebuiltEtc = arch
1484 break
1485 }
1486 }
1487 ctx.AddFarVariationDependencies([]blueprint.Variation{
1488 {Mutator: "os", Variation: ctx.Os().String()},
1489 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1490 }, prebuiltTag, a.properties.Prebuilts...)
1491
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001492 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1493 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001494
Ulya Trafimovich44561882020-01-03 13:25:54 +00001495 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1496 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1497 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1498 javaLibTag, "jacocoagent")
1499 }
1500
Jiyong Park23c52b02019-02-02 13:13:47 +09001501 if String(a.properties.Key) == "" {
1502 ctx.ModuleErrorf("key is missing")
1503 return
1504 }
1505 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001506
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001507 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001508 if cert != "" {
1509 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001510 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001511
1512 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1513 if len(a.properties.Uses_sdks) > 0 {
1514 sdkRefs := []android.SdkRef{}
1515 for _, str := range a.properties.Uses_sdks {
1516 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1517 sdkRefs = append(sdkRefs, parsed)
1518 }
1519 a.BuildWithSdks(sdkRefs)
1520 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001521}
1522
Jiyong Park5d790c32019-11-15 18:40:32 +09001523func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1524 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1525 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001526 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1527 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001528}
1529
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001530func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1531 // direct deps of an APEX bundle are all part of the APEX bundle
1532 return true
1533}
1534
Colin Cross0ea8ba82019-06-06 14:33:29 -07001535func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001536 moduleName := ctx.ModuleName()
1537 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1538 // we check with the pseudo module name to see if its certificate is overridden.
1539 if a.vndkApex {
1540 moduleName = vndkApexName
1541 }
1542 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001543 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001544 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001545 }
1546 return String(a.properties.Certificate)
1547}
1548
Colin Cross41955e82019-05-29 14:40:35 -07001549func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1550 switch tag {
1551 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001552 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001553 default:
1554 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001555 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001556}
1557
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001558func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001559 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001560}
1561
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001562func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1563 return proptools.Bool(a.properties.Test_only_no_hashtree)
1564}
1565
Dario Frenica913392020-04-27 18:21:11 +01001566func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1567 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1568}
1569
Jiyong Park7c1dc612019-01-05 11:15:24 +09001570func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001571 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001572 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001573 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001574 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001575 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001576 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001577 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001578 }
1579}
1580
Jiyong Parkf97782b2019-02-13 20:28:58 +09001581func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1582 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1583 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1584 }
1585}
1586
Jiyong Park388ef3f2019-01-28 19:47:32 +09001587func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001588 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1589 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001590 }
1591
1592 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001593 globalSanitizerNames := []string{}
1594 if a.Host() {
1595 globalSanitizerNames = ctx.Config().SanitizeHost()
1596 } else {
1597 arches := ctx.Config().SanitizeDeviceArch()
1598 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1599 globalSanitizerNames = ctx.Config().SanitizeDevice()
1600 }
1601 }
1602 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001603}
1604
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001605var _ cc.Coverage = (*apexBundle)(nil)
1606
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001607func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001608 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001609}
1610
1611func (a *apexBundle) PreventInstall() {
1612 a.properties.PreventInstall = true
1613}
1614
1615func (a *apexBundle) HideFromMake() {
1616 a.properties.HideFromMake = true
1617}
1618
Jiyong Park956305c2020-01-09 12:32:06 +09001619func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1620 a.properties.IsCoverageVariant = coverage
1621}
1622
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001623func (a *apexBundle) EnableCoverageIfNeeded() {}
1624
Jiyong Parkf653b052019-11-18 15:39:01 +09001625// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001626func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001627 // Decide the APEX-local directory by the multilib of the library
1628 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001629 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001630 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001631 case "lib32":
1632 dirInApex = "lib"
1633 case "lib64":
1634 dirInApex = "lib64"
1635 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001636 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001637 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001638 }
Jooyung Han35155c42020-02-06 17:33:20 +09001639 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001640 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001641 // Special case for Bionic libs and other libs installed with them. This is
1642 // to prevent those libs from being included in the search path
1643 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1644 // those libs in the Runtime APEX are available via the legacy paths in
1645 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1646 // to the legacy paths and thus will be loaded into the default linker
1647 // namespace (aka "platform" namespace). If the libs are directly in
1648 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1649 // into the runtime linker namespace, which will result in double loading of
1650 // them, which isn't supported.
1651 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001652 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001653
Jiyong Parkf653b052019-11-18 15:39:01 +09001654 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001655 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001656}
1657
Jiyong Park1833cef2019-12-13 13:28:36 +09001658func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001659 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001660 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001661 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001662 }
Jooyung Han35155c42020-02-06 17:33:20 +09001663 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001664 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001665 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001666 af.symlinks = cc.Symlinks()
1667 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001668}
1669
Jiyong Park1833cef2019-12-13 13:28:36 +09001670func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001671 dirInApex := "bin"
1672 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001673 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001674}
Jiyong Park1833cef2019-12-13 13:28:36 +09001675func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001676 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001677 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1678 if err != nil {
1679 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001681 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001682 fileToCopy := android.PathForOutput(ctx, s)
1683 // NB: Since go binaries are static we don't need the module for anything here, which is
1684 // good since the go tool is a blueprint.Module not an android.Module like we would
1685 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001686 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001687}
1688
Jiyong Park1833cef2019-12-13 13:28:36 +09001689func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001690 dirInApex := filepath.Join("bin", sh.SubDir())
1691 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001692 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001693 af.symlinks = sh.Symlinks()
1694 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001695}
1696
Jooyung Han58f26ab2019-12-18 15:34:32 +09001697// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1698type javaLibrary interface {
1699 android.Module
1700 java.Dependency
1701}
1702
1703func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001704 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001705 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001706 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1707 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1708 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001709}
1710
Jiyong Park1833cef2019-12-13 13:28:36 +09001711func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001712 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1713 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001714 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001715}
1716
atrost6e126252020-01-27 17:01:16 +00001717func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1718 dirInApex := filepath.Join("etc", config.SubDir())
1719 fileToCopy := config.CompatConfig()
1720 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1721}
1722
Jiyong Park1833cef2019-12-13 13:28:36 +09001723func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001724 android.Module
1725 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001726 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001727 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001728 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001729 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001730}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001731 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001732 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001733 appDir = "priv-app"
1734 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001735 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001736 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001737 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1738 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001739 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001740
1741 if app, ok := aapp.(interface {
1742 OverriddenManifestPackageName() string
1743 }); ok {
1744 af.overriddenPackageName = app.OverriddenManifestPackageName()
1745 }
Jiyong Park618922e2020-01-08 13:35:43 +09001746 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001747}
1748
Jiyong Park69aeba92020-04-24 21:16:36 +09001749func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1750 rroDir := "overlay"
1751 dirInApex := filepath.Join(rroDir, rro.Theme())
1752 fileToCopy := rro.OutputFile()
1753 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1754 af.certificate = rro.Certificate()
1755
1756 if a, ok := rro.(interface {
1757 OverriddenManifestPackageName() string
1758 }); ok {
1759 af.overriddenPackageName = a.OverriddenManifestPackageName()
1760 }
1761 return af
1762}
1763
Roland Levillain935639d2019-08-13 14:55:28 +01001764// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1765type flattenedApexContext struct {
1766 android.ModuleContext
1767}
1768
1769func (c *flattenedApexContext) InstallBypassMake() bool {
1770 return true
1771}
1772
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001773// Function called while walking an APEX's payload dependencies.
1774//
1775// Return true if the `to` module should be visited, false otherwise.
1776type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1777
Jiyong Park201cedd2020-02-07 17:25:49 +09001778// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001779func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001780 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001781 am, ok := child.(android.ApexModule)
1782 if !ok || !am.CanHaveApexVariants() {
1783 return false
1784 }
1785
1786 // Check for the direct dependencies that contribute to the payload
1787 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1788 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001789 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001790 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001791 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001792 return false
1793 }
1794
1795 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001796 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001797 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001798 }
1799
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001800 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001801 })
1802}
1803
Jooyung Han03b51852020-02-26 22:45:42 +09001804func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1805 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001806 intVer, err := android.ApiStrToNum(ctx, ver)
1807 if err != nil {
1808 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001809 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001810 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001811}
1812
Jiyong Park201cedd2020-02-07 17:25:49 +09001813// Ensures that the dependencies are marked as available for this APEX
1814func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1815 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1816 if ctx.Host() || a.testApex || a.vndkApex {
1817 return
1818 }
1819
Jiyong Park58d10902020-03-28 14:43:19 +09001820 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1821 // Requiring them and their transitive depencies with apex_available is not right
1822 // because they just add noise.
1823 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1824 return
1825 }
1826
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001827 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1828 if externalDep {
1829 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1830 return false
1831 }
1832
Jiyong Park201cedd2020-02-07 17:25:49 +09001833 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001834 fromName := ctx.OtherModuleName(from)
1835 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001836
1837 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1838 // do any of its dependencies.
1839 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1840 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1841 return false
1842 }
1843
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001844 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1845 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001846 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001847 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, ctx.GetPathString(true))
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001848 // Visit this module's dependencies to check and report any issues with their availability.
1849 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001850 })
1851}
1852
Jooyung Han548640b2020-04-27 12:10:30 +09001853func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1854 if proptools.Bool(a.properties.Updatable) {
1855 if String(a.properties.Min_sdk_version) == "" {
1856 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1857 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001858
1859 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001860 }
1861}
1862
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001863func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001864 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1865 switch a.properties.ApexType {
1866 case imageApex:
1867 if buildFlattenedAsDefault {
1868 a.suffix = imageApexSuffix
1869 } else {
1870 a.suffix = ""
1871 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001872
1873 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001874 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001875 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001876 }
1877 case zipApex:
1878 if proptools.String(a.properties.Payload_type) == "zip" {
1879 a.suffix = ""
1880 a.primaryApexType = true
1881 } else {
1882 a.suffix = zipApexSuffix
1883 }
1884 case flattenedApex:
1885 if buildFlattenedAsDefault {
1886 a.suffix = ""
1887 a.primaryApexType = true
1888 } else {
1889 a.suffix = flattenedSuffix
1890 }
Alex Light5098a612018-11-29 17:12:15 -08001891 }
1892
Roland Levillain630846d2019-06-26 12:48:34 +01001893 if len(a.properties.Tests) > 0 && !a.testApex {
1894 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1895 return
1896 }
1897
Jiyong Park0f80c182020-01-31 02:49:53 +09001898 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001899 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001900
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001901 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1902
Jooyung Hane1633032019-08-01 17:41:43 +09001903 // native lib dependencies
1904 var provideNativeLibs []string
1905 var requireNativeLibs []string
1906
Jooyung Han5c998b92019-06-27 11:30:33 +09001907 // Check if "uses" requirements are met with dependent apexBundles
1908 var providedNativeSharedLibs []string
1909 useVendor := proptools.Bool(a.properties.Use_vendor)
1910 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1911 if ctx.OtherModuleDependencyTag(m) != usesTag {
1912 return
1913 }
1914 otherName := ctx.OtherModuleName(m)
1915 other, ok := m.(*apexBundle)
1916 if !ok {
1917 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1918 return
1919 }
1920 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1921 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1922 return
1923 }
1924 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1925 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1926 return
1927 }
1928 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1929 })
1930
Jiyong Parkf653b052019-11-18 15:39:01 +09001931 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001932 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001933 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001934 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001935 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1936 return false
1937 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001938 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001939 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001940 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001941 case sharedLibTag, jniLibTag:
1942 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001943 if c, ok := child.(*cc.Module); ok {
1944 // bootstrap bionic libs are treated as provided by system
1945 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1946 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001947 }
Jooyung Han643adc42020-02-27 13:50:06 +09001948 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1949 fi.isJniLib = isJniLib
1950 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001951 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001952 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001953 propertyName := "native_shared_libs"
1954 if isJniLib {
1955 propertyName = "jni_libs"
1956 }
1957 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001958 }
1959 case executableTag:
1960 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001961 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001962 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001963 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001964 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001965 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001966 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001967 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001968 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001969 } else {
Alex Light778127a2019-02-27 14:19:50 -08001970 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 +09001971 }
1972 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001973 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001974 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001975 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001976 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1977 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001978 filesInfo = append(filesInfo, af)
1979 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001980 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001981 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1982 af := apexFileForJavaLibrary(ctx, sdkLib)
1983 if !af.Ok() {
1984 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1985 return false
1986 }
1987 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001988 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001989 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001990 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001991 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001992 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001993 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001994 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001995 return true // track transitive dependencies
1996 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001997 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001998 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001999 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002000 } else {
2001 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2002 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002003 case rroTag:
2004 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2005 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2006 } else {
2007 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2008 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002009 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002010 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002011 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002012 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2013 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002014 } else {
atrost6e126252020-01-27 17:01:16 +00002015 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002016 }
Roland Levillain630846d2019-06-26 12:48:34 +01002017 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002018 if ccTest, ok := child.(*cc.Module); ok {
2019 if ccTest.IsTestPerSrcAllTestsVariation() {
2020 // Multiple-output test module (where `test_per_src: true`).
2021 //
2022 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2023 // We do not add this variation to `filesInfo`, as it has no output;
2024 // however, we do add the other variations of this module as indirect
2025 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002026 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002027 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002028 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002029 af.class = nativeTest
2030 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002031 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002032 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002033 } else {
2034 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2035 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002036 case keyTag:
2037 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002038 a.private_key_file = key.private_key_file
2039 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002040 } else {
2041 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002042 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002043 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002044 case certificateTag:
2045 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002046 a.container_certificate_file = dep.Certificate.Pem
2047 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002048 } else {
2049 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2050 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002051 case android.PrebuiltDepTag:
2052 // If the prebuilt is force disabled, remember to delete the prebuilt file
2053 // that might have been installed in the previous builds
2054 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2055 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2056 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002057 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002058 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002059 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002060 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002061 // We cannot use a switch statement on `depTag` here as the checked
2062 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002063 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002064 if cc, ok := child.(*cc.Module); ok {
2065 if android.InList(cc.Name(), providedNativeSharedLibs) {
2066 // If we're using a shared library which is provided from other APEX,
2067 // don't include it in this APEX
2068 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002069 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002070 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002071 // If the dependency is a stubs lib, don't include it in this APEX,
2072 // but make sure that the lib is installed on the device.
2073 // In case no APEX is having the lib, the lib is installed to the system
2074 // partition.
2075 //
2076 // Always include if we are a host-apex however since those won't have any
2077 // system libraries.
Yo Chiang29555d52020-05-06 15:59:59 +08002078 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.BaseModuleName(), a.requiredDeps) {
2079 a.requiredDeps = append(a.requiredDeps, cc.BaseModuleName())
Roland Levillainf89cd092019-07-29 16:22:59 +01002080 }
Jooyung Hane1633032019-08-01 17:41:43 +09002081 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002082 // Don't track further
2083 return false
2084 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002085 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002086 af.transitiveDep = true
2087 filesInfo = append(filesInfo, af)
2088 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002089 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002090 } else if cc.IsTestPerSrcDepTag(depTag) {
2091 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002092 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002093 // Handle modules created as `test_per_src` variations of a single test module:
2094 // use the name of the generated test binary (`fileToCopy`) instead of the name
2095 // of the original test module (`depName`, shared by all `test_per_src`
2096 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002097 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002098 // these are not considered transitive dep
2099 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002100 filesInfo = append(filesInfo, af)
2101 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002102 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002103 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002104 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2105 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002106 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2107 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2108 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2109 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002110 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002111 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002112 }
2113 }
2114 }
2115 return false
2116 })
2117
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002118 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2119 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2120 // via the global boot image config.
2121 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002122 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002123 dirInApex := filepath.Join("javalib", arch.String())
2124 for _, f := range files {
2125 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002126 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002127 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002128 }
2129 }
2130 }
2131
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002132 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002133 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2134 return
2135 }
2136
Jiyong Park8fd61922018-11-08 02:50:25 +09002137 // remove duplicates in filesInfo
2138 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002139 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002140 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002141 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002142 if e, ok := encountered[dest]; !ok {
2143 encountered[dest] = f
2144 } else {
2145 // If a module is directly included and also transitively depended on
2146 // consider it as directly included.
2147 e.transitiveDep = e.transitiveDep && f.transitiveDep
2148 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002149 }
2150 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002151 var result []apexFile
2152 for _, v := range encountered {
2153 result = append(result, v)
2154 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002155 return result
2156 }
2157 filesInfo = removeDup(filesInfo)
2158
2159 // to have consistent build rules
2160 sort.Slice(filesInfo, func(i, j int) bool {
2161 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2162 })
2163
Jiyong Park8fd61922018-11-08 02:50:25 +09002164 a.installDir = android.PathForModuleInstall(ctx, "apex")
2165 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002166
Jooyung Han54aca7b2019-11-20 02:26:02 +09002167 if a.properties.ApexType != zipApex {
2168 if a.properties.File_contexts == nil {
2169 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2170 } else {
2171 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2172 if a.Platform() {
2173 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2174 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2175 }
2176 }
2177 }
2178 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2179 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2180 return
2181 }
2182 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002183 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2184 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2185 // the same library in the system partition, thus effectively sharing the same libraries
2186 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2187 // in the APEX.
2188 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2189 a.installable() &&
2190 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002191
Jiyong Park9d677202020-02-19 16:29:35 +09002192 // We don't need the optimization for updatable APEXes, as it might give false signal
2193 // to the system health when the APEXes are still bundled (b/149805758)
2194 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2195 a.linkToSystemLib = false
2196 }
2197
Jiyong Park638d30e2020-02-26 18:27:19 +09002198 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2199 if ctx.Host() {
2200 a.linkToSystemLib = false
2201 }
2202
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002203 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002204 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2205
2206 a.setCertificateAndPrivateKey(ctx)
2207 if a.properties.ApexType == flattenedApex {
2208 a.buildFlattenedApex(ctx)
2209 } else {
2210 a.buildUnflattenedApex(ctx)
2211 }
2212
Jooyung Han002ab682020-01-08 01:57:58 +09002213 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002214
2215 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002216}
2217
Artur Satayev8cf899a2020-04-15 17:29:42 +01002218// Enforce that Java deps of the apex are using stable SDKs to compile
2219func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2220 // Visit direct deps only. As long as we guarantee top-level deps are using
2221 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2222 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2223 tag := ctx.OtherModuleDependencyTag(module)
2224 switch tag {
2225 case javaLibTag, androidAppTag:
2226 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2227 if err := m.CheckStableSdkVersion(); err != nil {
2228 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2229 }
2230 }
2231 }
2232 })
2233}
2234
Jooyung Han5e9013b2020-03-10 06:23:13 +09002235func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002236 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002237 moduleName = normalizeModuleName(moduleName)
2238
2239 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2240 return true
2241 }
2242
2243 key = android.AvailableToAnyApex
2244 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2245 return true
2246 }
2247
2248 return false
2249}
2250
2251func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002252 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2253 // system. Trim the prefix for the check since they are confusing
2254 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2255 if strings.HasPrefix(moduleName, "libclang_rt.") {
2256 // This module has many arch variants that depend on the product being built.
2257 // We don't want to list them all
2258 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002259 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002260 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002261}
2262
Jooyung Han344d5432019-08-23 11:17:39 +09002263func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002264 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002265 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002266 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002267 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002268 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002269 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2270 })
Alex Light5098a612018-11-29 17:12:15 -08002271 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002272 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002273 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002274 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002275 return module
2276}
Jiyong Park30ca9372019-02-07 16:27:23 +09002277
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002278func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002279 bundle := newApexBundle()
2280 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002281 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002282 return bundle
2283}
2284
Jiyong Parkfce0b422020-02-11 03:56:06 +09002285// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2286// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002287func testApexBundleFactory() android.Module {
2288 bundle := newApexBundle()
2289 bundle.testApex = true
2290 return bundle
2291}
2292
Jiyong Parkfce0b422020-02-11 03:56:06 +09002293// apex packages other modules into an APEX file which is a packaging format for system-level
2294// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002295func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002296 return newApexBundle()
2297}
2298
Jiyong Park30ca9372019-02-07 16:27:23 +09002299//
2300// Defaults
2301//
2302type Defaults struct {
2303 android.ModuleBase
2304 android.DefaultsModuleBase
2305}
2306
Jiyong Park30ca9372019-02-07 16:27:23 +09002307func defaultsFactory() android.Module {
2308 return DefaultsFactory()
2309}
2310
2311func DefaultsFactory(props ...interface{}) android.Module {
2312 module := &Defaults{}
2313
2314 module.AddProperties(props...)
2315 module.AddProperties(
2316 &apexBundleProperties{},
2317 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002318 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002319 )
2320
2321 android.InitDefaultsModule(module)
2322 return module
2323}
Jiyong Park5d790c32019-11-15 18:40:32 +09002324
2325//
2326// OverrideApex
2327//
2328type OverrideApex struct {
2329 android.ModuleBase
2330 android.OverrideModuleBase
2331}
2332
2333func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2334 // All the overrides happen in the base module.
2335}
2336
2337// override_apex is used to create an apex module based on another apex module
2338// by overriding some of its properties.
2339func overrideApexFactory() android.Module {
2340 m := &OverrideApex{}
2341 m.AddProperties(&overridableProperties{})
2342
2343 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2344 android.InitOverrideModule(m)
2345 return m
2346}