blob: 13f660ef44deff82c0e30071fa20696684879207 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinc5192442020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090065 rroTag = dependencyTag{name: "rro", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000066 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000067
68 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069)
70
Paul Duffin7d74e7b2020-03-06 12:30:13 +000071// Transform the map of apex -> modules to module -> apexes.
72func invertApexWhiteList(m map[string][]string) map[string][]string {
73 r := make(map[string][]string)
74 for apex, modules := range m {
75 for _, module := range modules {
76 r[module] = append(r[module], apex)
77 }
78 }
79 return r
80}
81
82// Retrieve the while list of apexes to which the supplied module belongs.
83func WhitelistedApexAvailable(moduleName string) []string {
84 return inverseApexAvailWl[normalizeModuleName(moduleName)]
85}
86
Anton Hanssoneec79eb2020-01-10 15:12:39 +000087// This is a map from apex to modules, which overrides the
88// apex_available setting for that particular module to make
89// it available for the apex regardless of its setting.
90// TODO(b/147364041): remove this
91func makeApexAvailableWhitelist() map[string][]string {
92 // The "Module separator"s below are employed to minimize merge conflicts.
93 m := make(map[string][]string)
94 //
95 // Module separator
96 //
Paul Duffin50cbefd2020-03-10 13:44:19 +000097 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "art_cmdlineparser_headers",
99 "art_disassembler_headers",
100 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900101 "bionic_libc_platform_headers",
102 "core-repackaged-icu4j",
103 "cpp-define-generator-asm-support",
104 "cpp-define-generator-definitions",
105 "crtbegin_dynamic",
106 "crtbegin_dynamic1",
107 "crtbegin_so1",
108 "crtbrand",
Jiyong Park0f80c182020-01-31 02:49:53 +0900109 "dex2oat_headers",
110 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900112 "javavm_headers",
113 "jni_platform_headers",
114 "libPlatformProperties",
115 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000116 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900117 "libandroidicuinit",
118 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000119 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900120 "libdexfile_all_headers",
121 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000122 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900123 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000124 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900125 "libfdlibm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900126 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000127 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900128 "libicuuc_headers",
129 "libicuuc_stubdata",
130 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900131 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000132 "liblzma",
133 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900134 "libnativebridge-headers",
135 "libnativehelper_header_only",
136 "libnativeloader-headers",
137 "libnpt_headers",
138 "libopenjdkjvmti_headers",
139 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000140 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900141 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000142 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900143 "libv8",
144 "libv8base",
145 "libv8gen",
146 "libv8platform",
147 "libv8sampler",
148 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000149 "libvixl",
150 "libvixld",
151 "libz",
152 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900153 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000154 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000155 m["com.android.art.debug"] = artApexContents
156 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000157 //
158 // Module separator
159 //
160 m["com.android.bluetooth.updatable"] = []string{
161 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000162 "android.hardware.bluetooth.a2dp@1.0",
163 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "android.hardware.bluetooth@1.0",
165 "android.hardware.bluetooth@1.1",
166 "android.hardware.graphics.bufferqueue@1.0",
167 "android.hardware.graphics.bufferqueue@2.0",
168 "android.hardware.graphics.common@1.0",
169 "android.hardware.graphics.common@1.1",
170 "android.hardware.graphics.common@1.2",
171 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000172 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900173 "android.hidl.token@1.0",
174 "android.hidl.token@1.0-utils",
175 "avrcp-target-service",
176 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900177 "bluetooth-protos-lite",
178 "bluetooth.mapsapi",
179 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900180 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900181 "ipmemorystore-aidl-interfaces-V5-java",
182 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900183 "internal_include_headers",
184 "lib-bt-packets",
185 "lib-bt-packets-avrcp",
186 "lib-bt-packets-base",
187 "libFraunhoferAAC",
188 "libaudio-a2dp-hw-utils",
189 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900190 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000191 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900192 "libbluetooth-types",
193 "libbluetooth-types-header",
194 "libbluetooth_gd",
195 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000196 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900197 "libbt-audio-hal-interface",
198 "libbt-bta",
199 "libbt-common",
200 "libbt-hci",
201 "libbt-platform-protos-lite",
202 "libbt-protos-lite",
203 "libbt-sbc-decoder",
204 "libbt-sbc-encoder",
205 "libbt-stack",
206 "libbt-utils",
207 "libbtcore",
208 "libbtdevice",
209 "libbte",
210 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000211 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000212 "libevent",
213 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900214 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900215 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900216 "libmedia_headers",
217 "libmodpb64",
218 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900219 "libstagefright_foundation_headers",
220 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000221 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900222 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000223 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900224 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000225 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900226 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900227 "net-utils-services-common",
228 "netd_aidl_interface-unstable-java",
229 "netd_event_listener_interface-java",
230 "netlink-client",
231 "networkstack-aidl-interfaces-unstable-java",
232 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900233 "sap-api-java-static",
234 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000235 }
236 //
237 // Module separator
238 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900239 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000240 //
241 // Module separator
242 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900244 "libnativehelper_header_only",
Jiyong Park0f80c182020-01-31 02:49:53 +0900245 }
246 //
247 // Module separator
248 //
249 m["com.android.extservices"] = []string{
250 "flatbuffer_headers",
251 "liblua",
252 "libtextclassifier",
253 "libtextclassifier_hash_static",
254 "libtflite_static",
255 "libutf",
256 "libz_current",
257 "tensorflow_headers",
258 }
259 //
260 // Module separator
261 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900262 m["com.android.neuralnetworks"] = []string{
263 "android.hardware.neuralnetworks@1.0",
264 "android.hardware.neuralnetworks@1.1",
265 "android.hardware.neuralnetworks@1.2",
266 "android.hardware.neuralnetworks@1.3",
267 "android.hidl.allocator@1.0",
268 "android.hidl.memory.token@1.0",
269 "android.hidl.memory@1.0",
270 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900272 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900273 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900274 "libprocpartition",
275 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900276 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000277 //
278 // Module separator
279 //
280 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000281 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900282 "android.hardware.cas.native@1.0",
283 "android.hardware.cas@1.0",
284 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000285 "android.hardware.configstore@1.0",
286 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000287 "android.hardware.graphics.allocator@2.0",
288 "android.hardware.graphics.allocator@3.0",
289 "android.hardware.graphics.bufferqueue@1.0",
290 "android.hardware.graphics.bufferqueue@2.0",
291 "android.hardware.graphics.common@1.0",
292 "android.hardware.graphics.common@1.1",
293 "android.hardware.graphics.common@1.2",
294 "android.hardware.graphics.mapper@2.0",
295 "android.hardware.graphics.mapper@2.1",
296 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900297 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000298 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900299 "android.hidl.allocator@1.0",
300 "android.hidl.memory.token@1.0",
301 "android.hidl.memory@1.0",
302 "android.hidl.token@1.0",
303 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900304 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900305 "gl_headers",
306 "libEGL",
307 "libEGL_blobCache",
308 "libEGL_getProcAddress",
309 "libFLAC",
310 "libFLAC-config",
311 "libFLAC-headers",
312 "libGLESv2",
313 "libaacextractor",
314 "libamrextractor",
315 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900316 "libaudio_system_headers",
317 "libaudioclient",
318 "libaudioclient_headers",
319 "libaudiofoundation",
320 "libaudiofoundation_headers",
321 "libaudiomanager",
322 "libaudiopolicy",
323 "libaudioutils",
324 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900325 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900326 "libbluetooth-types-header",
327 "libbufferhub",
328 "libbufferhub_headers",
329 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900330 "libc_malloc_debug_backtrace",
331 "libcamera_client",
332 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900333 "libdexfile_external_headers",
334 "libdexfile_support",
335 "libdvr_headers",
336 "libexpat",
337 "libfifo",
338 "libflacextractor",
339 "libgrallocusage",
340 "libgraphicsenv",
341 "libgui",
342 "libgui_headers",
343 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900344 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900345 "liblzma",
346 "libmath",
347 "libmedia",
348 "libmedia_codeclist",
349 "libmedia_headers",
350 "libmedia_helper",
351 "libmedia_helper_headers",
352 "libmedia_midiiowrapper",
353 "libmedia_omx",
354 "libmediautils",
355 "libmidiextractor",
356 "libmkvextractor",
357 "libmp3extractor",
358 "libmp4extractor",
359 "libmpeg2extractor",
360 "libnativebase_headers",
361 "libnativebridge-headers",
362 "libnativebridge_lazy",
363 "libnativeloader-headers",
364 "libnativeloader_lazy",
365 "libnativewindow_headers",
366 "libnblog",
367 "liboggextractor",
368 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900369 "libpdx",
370 "libpdx_default_transport",
371 "libpdx_headers",
372 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900373 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900374 "libsonivox",
375 "libspeexresampler",
376 "libspeexresampler",
377 "libstagefright_esds",
378 "libstagefright_flacdec",
379 "libstagefright_flacdec",
380 "libstagefright_foundation",
381 "libstagefright_foundation_headers",
382 "libstagefright_foundation_without_imemory",
383 "libstagefright_headers",
384 "libstagefright_id3",
385 "libstagefright_metadatautils",
386 "libstagefright_mpeg2extractor",
387 "libstagefright_mpeg2support",
388 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900389 "libui",
390 "libui_headers",
391 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900392 "libvibrator",
393 "libvorbisidec",
394 "libwavextractor",
395 "libwebm",
396 "media_ndk_headers",
397 "media_plugin_headers",
398 "updatable-media",
399 }
400 //
401 // Module separator
402 //
403 m["com.android.media.swcodec"] = []string{
404 "android.frameworks.bufferhub@1.0",
405 "android.hardware.common-ndk_platform",
406 "android.hardware.configstore-utils",
407 "android.hardware.configstore@1.0",
408 "android.hardware.configstore@1.1",
409 "android.hardware.graphics.allocator@2.0",
410 "android.hardware.graphics.allocator@3.0",
411 "android.hardware.graphics.bufferqueue@1.0",
412 "android.hardware.graphics.bufferqueue@2.0",
413 "android.hardware.graphics.common-ndk_platform",
414 "android.hardware.graphics.common@1.0",
415 "android.hardware.graphics.common@1.1",
416 "android.hardware.graphics.common@1.2",
417 "android.hardware.graphics.mapper@2.0",
418 "android.hardware.graphics.mapper@2.1",
419 "android.hardware.graphics.mapper@3.0",
420 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000421 "android.hardware.media.bufferpool@2.0",
422 "android.hardware.media.c2@1.0",
423 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900424 "android.hardware.media@1.0",
425 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000426 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900427 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000428 "android.hidl.safe_union@1.0",
429 "android.hidl.token@1.0",
430 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900431 "libEGL",
432 "libFLAC",
433 "libFLAC-config",
434 "libFLAC-headers",
435 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900436 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900437 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900438 "libaudio_system_headers",
439 "libaudioutils",
440 "libaudioutils",
441 "libaudioutils_fixedfft",
442 "libavcdec",
443 "libavcenc",
444 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000445 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900446 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900447 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900448 "libbluetooth-types-header",
449 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900450 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000451 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900452 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000453 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900454 "libcodec2_hidl@1.1",
455 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000456 "libcodec2_soft_aacdec",
457 "libcodec2_soft_aacenc",
458 "libcodec2_soft_amrnbdec",
459 "libcodec2_soft_amrnbenc",
460 "libcodec2_soft_amrwbdec",
461 "libcodec2_soft_amrwbenc",
462 "libcodec2_soft_av1dec_gav1",
463 "libcodec2_soft_avcdec",
464 "libcodec2_soft_avcenc",
465 "libcodec2_soft_common",
466 "libcodec2_soft_flacdec",
467 "libcodec2_soft_flacenc",
468 "libcodec2_soft_g711alawdec",
469 "libcodec2_soft_g711mlawdec",
470 "libcodec2_soft_gsmdec",
471 "libcodec2_soft_h263dec",
472 "libcodec2_soft_h263enc",
473 "libcodec2_soft_hevcdec",
474 "libcodec2_soft_hevcenc",
475 "libcodec2_soft_mp3dec",
476 "libcodec2_soft_mpeg2dec",
477 "libcodec2_soft_mpeg4dec",
478 "libcodec2_soft_mpeg4enc",
479 "libcodec2_soft_opusdec",
480 "libcodec2_soft_opusenc",
481 "libcodec2_soft_rawdec",
482 "libcodec2_soft_vorbisdec",
483 "libcodec2_soft_vp8dec",
484 "libcodec2_soft_vp8enc",
485 "libcodec2_soft_vp9dec",
486 "libcodec2_soft_vp9enc",
487 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000488 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900489 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000490 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900491 "libfmq",
492 "libgav1",
493 "libgralloctypes",
494 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000495 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900496 "libgsm",
497 "libgui_bufferqueue_static",
498 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000499 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900500 "libhardware_headers",
501 "libhevcdec",
502 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000503 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900504 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000505 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900506 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000507 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900508 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900509 "libmpeg2dec",
510 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000511 "libnativebridge_lazy",
512 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900513 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900514 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000515 "libscudo_wrapper",
516 "libsfplugin_ccodec_utils",
517 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900518 "libstagefright_amrnbdec",
519 "libstagefright_amrnbenc",
520 "libstagefright_amrwbdec",
521 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000522 "libstagefright_bufferpool@2.0.1",
523 "libstagefright_bufferqueue_helper",
524 "libstagefright_enc_common",
525 "libstagefright_flacdec",
526 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900527 "libstagefright_foundation_headers",
528 "libstagefright_headers",
529 "libstagefright_m4vh263dec",
530 "libstagefright_m4vh263enc",
531 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000532 "libsync",
533 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900534 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000535 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000536 "libvorbisidec",
537 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900538 "libyuv",
539 "libyuv_static",
540 "media_ndk_headers",
541 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000542 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900543 }
544 //
545 // Module separator
546 //
547 m["com.android.mediaprovider"] = []string{
548 "MediaProvider",
549 "MediaProviderGoogle",
550 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900551 "libbase_ndk",
552 "libfuse",
553 "libfuse_jni",
554 "libnativehelper_header_only",
555 }
556 //
557 // Module separator
558 //
559 m["com.android.permission"] = []string{
560 "androidx.annotation_annotation",
561 "androidx.annotation_annotation-nodeps",
562 "androidx.lifecycle_lifecycle-common",
563 "androidx.lifecycle_lifecycle-common-java8",
564 "androidx.lifecycle_lifecycle-common-java8-nodeps",
565 "androidx.lifecycle_lifecycle-common-nodeps",
566 "kotlin-annotations",
567 "kotlin-stdlib",
568 "kotlin-stdlib-jdk7",
569 "kotlin-stdlib-jdk8",
570 "kotlinx-coroutines-android",
571 "kotlinx-coroutines-android-nodeps",
572 "kotlinx-coroutines-core",
573 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900574 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000575 }
576 //
577 // Module separator
578 //
579 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900582 "libc_aeabi",
583 "libc_bionic",
584 "libc_bionic_ndk",
585 "libc_bootstrap",
586 "libc_common",
587 "libc_common_shared",
588 "libc_common_static",
589 "libc_dns",
590 "libc_dynamic_dispatch",
591 "libc_fortify",
592 "libc_freebsd",
593 "libc_freebsd_large_stack",
594 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900595 "libc_init_dynamic",
596 "libc_init_static",
597 "libc_jemalloc_wrapper",
598 "libc_netbsd",
599 "libc_nomalloc",
600 "libc_nopthread",
601 "libc_openbsd",
602 "libc_openbsd_large_stack",
603 "libc_openbsd_ndk",
604 "libc_pthread",
605 "libc_static_dispatch",
606 "libc_syscalls",
607 "libc_tzcode",
608 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900609 "libdebuggerd",
610 "libdebuggerd_common_headers",
611 "libdebuggerd_handler_core",
612 "libdebuggerd_handler_fallback",
613 "libdexfile_external_headers",
614 "libdexfile_support",
615 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900616 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900617 "libjemalloc5",
618 "liblinker_main",
619 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900620 "liblz4",
621 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900622 "libprocinfo",
623 "libpropertyinfoparser",
624 "libscudo",
625 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900626 "libsystemproperties",
627 "libtombstoned_client_static",
628 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900629 "libz",
630 "libziparchive",
631 }
632 //
633 // Module separator
634 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900635 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900636 "libnativehelper_compat_libc++",
637 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900638 "libcgrouprc",
639 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900640 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900641 "libvndksupport",
642 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000643 }
644 //
645 // Module separator
646 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 m["com.android.wifi"] = []string{
648 "PlatformProperties",
649 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900650 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900651 "android.hardware.wifi-V1.1-java",
652 "android.hardware.wifi-V1.2-java",
653 "android.hardware.wifi-V1.3-java",
654 "android.hardware.wifi-V1.4-java",
655 "android.hardware.wifi.hostapd-V1.0-java",
656 "android.hardware.wifi.hostapd-V1.1-java",
657 "android.hardware.wifi.hostapd-V1.2-java",
658 "android.hardware.wifi.supplicant-V1.0-java",
659 "android.hardware.wifi.supplicant-V1.1-java",
660 "android.hardware.wifi.supplicant-V1.2-java",
661 "android.hardware.wifi.supplicant-V1.3-java",
662 "android.hidl.base-V1.0-java",
663 "android.hidl.manager-V1.0-java",
664 "android.hidl.manager-V1.1-java",
665 "android.hidl.manager-V1.2-java",
666 "androidx.annotation_annotation",
667 "androidx.annotation_annotation-nodeps",
668 "bouncycastle-unbundled",
669 "dnsresolver_aidl_interface-V2-java",
670 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900671 "framework-wifi-pre-jarjar",
672 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900673 "ipmemorystore-aidl-interfaces-V3-java",
674 "ipmemorystore-aidl-interfaces-java",
675 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900676 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900677 "libwifi-jni",
678 "net-utils-services-common",
679 "netd_aidl_interface-V2-java",
680 "netd_aidl_interface-unstable-java",
681 "netd_event_listener_interface-java",
682 "netlink-client",
683 "networkstack-aidl-interfaces-unstable-java",
684 "networkstack-client",
685 "services.net",
686 "wifi-lite-protos",
687 "wifi-nano-protos",
688 "wifi-service-pre-jarjar",
689 "wifi-service-resources",
690 "prebuilt_androidx.annotation_annotation-nodeps",
691 }
692 //
693 // Module separator
694 //
695 m["com.android.sdkext"] = []string{
696 "fmtlib_ndk",
697 "libbase_ndk",
698 "libprotobuf-cpp-lite-ndk",
699 }
700 //
701 // Module separator
702 //
703 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900704 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900705 }
706 //
707 // Module separator
708 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000709 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900710 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900711 "libclang_rt",
712 "libgcc_stripped",
713 "libprofile-clang-extras",
714 "libprofile-clang-extras_ndk",
715 "libprofile-extras",
716 "libprofile-extras_ndk",
717 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900718 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000719 return m
720}
721
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900722func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900723 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800724 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900725 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900726 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700727 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900728 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900729
Jooyung Han31c470b2019-10-18 16:26:59 +0900730 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900731 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900732
733 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
734 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
735 sort.Strings(*apexFileContextsInfos)
736 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
737 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900738}
739
Jooyung Han31c470b2019-10-18 16:26:59 +0900740func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
741 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
742 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
743}
744
Jiyong Parkd1063c12019-07-17 20:08:41 +0900745func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900746 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900747 ctx.BottomUp("apex", apexMutator).Parallel()
748 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
749 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900750}
751
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900752// Mark the direct and transitive dependencies of apex bundles so that they
753// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900754func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900755 if !mctx.Module().Enabled() {
756 return
757 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800758 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900759 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000760 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900761 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900762 ApexName: mctx.ModuleName(),
763 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100764 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900765 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900766 directDep = true
767 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800768 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900769 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900770 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900771
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800772 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900773 return
774 }
775
Paul Duffin923e8a52020-03-30 15:33:32 +0100776 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900777
Jiyong Parkf760cae2020-02-12 07:53:12 +0900778 mctx.VisitDirectDeps(func(child android.Module) {
779 depName := mctx.OtherModuleName(child)
780 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100781 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800782 android.UpdateApexDependency(apexBundles, depName, directDep)
783 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900784 }
785 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900786}
787
Paul Duffin65347702020-03-31 15:23:40 +0100788// If a module in an APEX depends on a module from an SDK then it needs an APEX
789// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
790func inAnySdk(module android.Module) bool {
791 if sa, ok := module.(android.SdkAware); ok {
792 return sa.IsInAnySdk()
793 }
794
795 return false
796}
797
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900798// Create apex variations if a module is included in APEX(s).
799func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900800 if !mctx.Module().Enabled() {
801 return
802 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900803 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900804 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000805 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900806 // apex bundle itself is mutated so that it and its modules have same
807 // apex variant.
808 apexBundleName := mctx.ModuleName()
809 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900810 } else if o, ok := mctx.Module().(*OverrideApex); ok {
811 apexBundleName := o.GetOverriddenModuleName()
812 if apexBundleName == "" {
813 mctx.ModuleErrorf("base property is not set")
814 return
815 }
816 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900817 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900818
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900819}
Sundong Ahne9b55722019-09-06 17:37:42 +0900820
Jooyung Han7a78a922019-10-08 21:59:58 +0900821var (
822 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
823 apexFileContextsInfosMutex sync.Mutex
824)
825
826func apexFileContextsInfos(config android.Config) *[]string {
827 return config.Once(apexFileContextsInfosKey, func() interface{} {
828 return &[]string{}
829 }).(*[]string)
830}
831
Jooyung Han54aca7b2019-11-20 02:26:02 +0900832func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900833 apexFileContextsInfosMutex.Lock()
834 defer apexFileContextsInfosMutex.Unlock()
835 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900836 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900837}
838
Sundong Ahne9b55722019-09-06 17:37:42 +0900839func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900840 if !mctx.Module().Enabled() {
841 return
842 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900843 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900844 var variants []string
845 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
846 case "image":
847 variants = append(variants, imageApexType, flattenedApexType)
848 case "zip":
849 variants = append(variants, zipApexType)
850 case "both":
851 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
852 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900853 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900854 return
855 }
856
857 modules := mctx.CreateLocalVariations(variants...)
858
859 for i, v := range variants {
860 switch v {
861 case imageApexType:
862 modules[i].(*apexBundle).properties.ApexType = imageApex
863 case zipApexType:
864 modules[i].(*apexBundle).properties.ApexType = zipApex
865 case flattenedApexType:
866 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900867 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900868 modules[i].(*apexBundle).MakeAsSystemExt()
869 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900870 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900871 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900872 } else if _, ok := mctx.Module().(*OverrideApex); ok {
873 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900874 }
875}
876
Jooyung Han5c998b92019-06-27 11:30:33 +0900877func apexUsesMutator(mctx android.BottomUpMutatorContext) {
878 if ab, ok := mctx.Module().(*apexBundle); ok {
879 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
880 }
881}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900882
Jooyung Handc782442019-11-01 03:14:38 +0900883var (
884 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
885)
886
887// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
888// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
889// which may cause compatibility issues. (e.g. libbinder)
890// Even though libbinder restricts its availability via 'apex_available' property and relies on
891// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
892// to avoid similar problems.
893func useVendorWhitelist(config android.Config) []string {
894 return config.Once(useVendorWhitelistKey, func() interface{} {
895 return []string{
896 // swcodec uses "vendor" variants for smaller size
897 "com.android.media.swcodec",
898 "test_com.android.media.swcodec",
899 }
900 }).([]string)
901}
902
903// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
904// called before the first call to useVendorWhitelist()
905func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
906 config.Once(useVendorWhitelistKey, func() interface{} {
907 return whitelist
908 })
909}
910
Jooyung Han01a868d2020-02-27 13:40:44 +0900911type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800912 // List of native libraries
913 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900914
Jooyung Han643adc42020-02-27 13:50:06 +0900915 // List of JNI libraries
916 Jni_libs []string
917
Alex Light9670d332019-01-29 18:07:33 -0800918 // List of native executables
919 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900920
Roland Levillain630846d2019-06-26 12:48:34 +0100921 // List of native tests
922 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800923}
Jooyung Han344d5432019-08-23 11:17:39 +0900924
Alex Light9670d332019-01-29 18:07:33 -0800925type apexMultilibProperties struct {
926 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900927 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800928
929 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900930 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800931
932 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900933 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800934
935 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900936 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800937
938 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900939 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800940}
941
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900942type apexBundleProperties struct {
943 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000944 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800945 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900946
Jiyong Park40e26a22019-02-08 02:53:06 +0900947 // AndroidManifest.xml file used for the zip container of this APEX bundle.
948 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800949 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900950
Roland Levillain411c5842019-09-19 16:37:20 +0100951 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
952 // device (/apex/<apex_name>).
953 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900954 Apex_name *string
955
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900956 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900957 // For platform APEXes, this should points to a file under /system/sepolicy
958 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
959 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900960
Jooyung Han01a868d2020-02-27 13:40:44 +0900961 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900962
963 // List of java libraries that are embedded inside this APEX bundle
964 Java_libs []string
965
966 // List of prebuilt files that are embedded inside this APEX bundle
967 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900968
969 // Name of the apex_key module that provides the private key to sign APEX
970 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900971
Alex Light5098a612018-11-29 17:12:15 -0800972 // The type of APEX to build. Controls what the APEX payload is. Either
973 // 'image', 'zip' or 'both'. Default: 'image'.
974 Payload_type *string
975
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900976 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
977 // or an android_app_certificate module name in the form ":module".
978 Certificate *string
979
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900980 // Whether this APEX is installable to one of the partitions. Default: true.
981 Installable *bool
982
Jiyong Parkda6eb592018-12-19 17:12:36 +0900983 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
984 // Default is false.
985 Use_vendor *bool
986
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800987 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
988 Ignore_system_library_special_case *bool
989
Alex Light9670d332019-01-29 18:07:33 -0800990 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900991
Jiyong Parkf97782b2019-02-13 20:28:58 +0900992 // List of sanitizer names that this APEX is enabled for
993 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900994
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900995 PreventInstall bool `blueprint:"mutated"`
996
997 HideFromMake bool `blueprint:"mutated"`
998
Jooyung Han5c998b92019-06-27 11:30:33 +0900999 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1000 Provide_cpp_shared_libs *bool
1001
1002 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1003 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001004
1005 // A txt file containing list of files that are whitelisted to be included in this APEX.
1006 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001007
Sundong Ahnabb64432019-10-22 13:58:29 +09001008 // package format of this apex variant; could be non-flattened, flattened, or zip.
1009 // imageApex, zipApex or flattened
1010 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001011
Jiyong Parkd1063c12019-07-17 20:08:41 +09001012 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1013 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1014 // is implied. This value affects all modules included in this APEX. In other words, they are
1015 // also built with the SDKs specified here.
1016 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001017
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001018 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1019 // Should be only used in tests#.
1020 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001021
Jiyong Park956305c2020-01-09 12:32:06 +09001022 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001023
1024 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1025 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1026 // like symlinking to the system libs. Default is false.
1027 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001028
1029 // The minimum SDK version that this apex must be compatibile with.
1030 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001031}
1032
1033type apexTargetBundleProperties struct {
1034 Target struct {
1035 // Multilib properties only for android.
1036 Android struct {
1037 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001038 }
Jooyung Han344d5432019-08-23 11:17:39 +09001039
Alex Light9670d332019-01-29 18:07:33 -08001040 // Multilib properties only for host.
1041 Host struct {
1042 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001043 }
Jooyung Han344d5432019-08-23 11:17:39 +09001044
Alex Light9670d332019-01-29 18:07:33 -08001045 // Multilib properties only for host linux_bionic.
1046 Linux_bionic struct {
1047 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001048 }
Jooyung Han344d5432019-08-23 11:17:39 +09001049
Alex Light9670d332019-01-29 18:07:33 -08001050 // Multilib properties only for host linux_glibc.
1051 Linux_glibc struct {
1052 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001053 }
1054 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001055}
1056
Jiyong Park5d790c32019-11-15 18:40:32 +09001057type overridableProperties struct {
1058 // List of APKs to package inside APEX
1059 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001060
Jiyong Park69aeba92020-04-24 21:16:36 +09001061 // List of runtime resource overlays (RROs) inside APEX
1062 Rros []string
1063
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001064 // Names of modules to be overridden. Listed modules can only be other binaries
1065 // (in Make or Soong).
1066 // This does not completely prevent installation of the overridden binaries, but if both
1067 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1068 // from PRODUCT_PACKAGES.
1069 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001070
1071 // Logging Parent value
1072 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001073
1074 // Apex Container Package Name.
1075 // Override value for attribute package:name in AndroidManifest.xml
1076 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001077}
1078
Alex Light5098a612018-11-29 17:12:15 -08001079type apexPackaging int
1080
1081const (
1082 imageApex apexPackaging = iota
1083 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001084 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001085)
1086
Sundong Ahnabb64432019-10-22 13:58:29 +09001087// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001088func (a apexPackaging) suffix() string {
1089 switch a {
1090 case imageApex:
1091 return imageApexSuffix
1092 case zipApex:
1093 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001094 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001095 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001096 }
1097}
1098
1099func (a apexPackaging) name() string {
1100 switch a {
1101 case imageApex:
1102 return imageApexType
1103 case zipApex:
1104 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001105 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001106 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001107 }
1108}
1109
Jiyong Parkf653b052019-11-18 15:39:01 +09001110type apexFileClass int
1111
1112const (
1113 etc apexFileClass = iota
1114 nativeSharedLib
1115 nativeExecutable
1116 shBinary
1117 pyBinary
1118 goBinary
1119 javaSharedLib
1120 nativeTest
1121 app
1122)
1123
Jiyong Park8fd61922018-11-08 02:50:25 +09001124func (class apexFileClass) NameInMake() string {
1125 switch class {
1126 case etc:
1127 return "ETC"
1128 case nativeSharedLib:
1129 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001130 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001131 return "EXECUTABLES"
1132 case javaSharedLib:
1133 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001134 case nativeTest:
1135 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001136 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001137 // b/142537672 Why isn't this APP? We want to have full control over
1138 // the paths and file names of the apk file under the flattend APEX.
1139 // If this is set to APP, then the paths and file names are modified
1140 // by the Make build system. For example, it is installed to
1141 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1142 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1143 // appends module name (which is <apexname>.<Appname> to the path.
1144 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001145 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001146 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001147 }
1148}
1149
Jiyong Parkf653b052019-11-18 15:39:01 +09001150// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001151type apexFile struct {
1152 builtFile android.Path
1153 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001154 installDir string
1155 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001156 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001157 // list of symlinks that will be created in installDir that point to this apexFile
1158 symlinks []string
1159 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001160 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001161
1162 requiredModuleNames []string
1163 targetRequiredModuleNames []string
1164 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001165
Colin Cross503c1d02020-01-28 14:00:53 -08001166 jacocoReportClassesFile android.Path // only for javalibs and apps
1167 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001168 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001169
1170 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001171}
1172
Jiyong Park1833cef2019-12-13 13:28:36 +09001173func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1174 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001175 builtFile: builtFile,
1176 moduleName: moduleName,
1177 installDir: installDir,
1178 class: class,
1179 module: module,
1180 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001181 if module != nil {
1182 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001183 ret.requiredModuleNames = module.RequiredModuleNames()
1184 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1185 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001186 }
1187 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001188}
1189
1190func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001191 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001192}
1193
Jiyong Park7cd10e32020-01-14 09:22:18 +09001194// Path() returns path of this apex file relative to the APEX root
1195func (af *apexFile) Path() string {
1196 return filepath.Join(af.installDir, af.builtFile.Base())
1197}
1198
1199// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1200func (af *apexFile) SymlinkPaths() []string {
1201 var ret []string
1202 for _, symlink := range af.symlinks {
1203 ret = append(ret, filepath.Join(af.installDir, symlink))
1204 }
1205 return ret
1206}
1207
1208func (af *apexFile) AvailableToPlatform() bool {
1209 if af.module == nil {
1210 return false
1211 }
1212 if am, ok := af.module.(android.ApexModule); ok {
1213 return am.AvailableFor(android.AvailableToPlatform)
1214 }
1215 return false
1216}
1217
Jiyong Park678c8812020-02-07 17:25:49 +09001218type depInfo struct {
1219 to string
1220 from []string
1221 isExternal bool
1222}
1223
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001224type apexBundle struct {
1225 android.ModuleBase
1226 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001227 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001228 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001229
Jiyong Park5d790c32019-11-15 18:40:32 +09001230 properties apexBundleProperties
1231 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001232 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001233
Jooyung Hanf21c7972019-12-16 22:32:06 +09001234 // specific to apex_vndk modules
1235 vndkProperties apexVndkProperties
1236
Colin Crossa4925902018-11-16 11:36:28 -08001237 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001238 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001239 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001240
Jiyong Park03b68dd2019-07-26 23:20:40 +09001241 prebuiltFileToDelete string
1242
Jiyong Park42cca6c2019-04-01 11:15:50 +09001243 public_key_file android.Path
1244 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001245
1246 container_certificate_file android.Path
1247 container_private_key_file android.Path
1248
Jooyung Han54aca7b2019-11-20 02:26:02 +09001249 fileContexts android.Path
1250
Jiyong Park8fd61922018-11-08 02:50:25 +09001251 // list of files to be included in this apex
1252 filesInfo []apexFile
1253
Jiyong Park956305c2020-01-09 12:32:06 +09001254 // list of module names that should be installed along with this APEX
1255 requiredDeps []string
1256
Jiyong Park956305c2020-01-09 12:32:06 +09001257 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001258 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001259
Sundong Ahnabb64432019-10-22 13:58:29 +09001260 testApex bool
1261 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001262 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001263 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001264
Jooyung Han214bf372019-11-12 13:03:50 +09001265 manifestJsonOut android.WritablePath
1266 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001267
Jooyung Han002ab682020-01-08 01:57:58 +09001268 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001269 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001270 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001271 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1272 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001273
1274 // Suffix of module name in Android.mk
1275 // ".flattened", ".apex", ".zipapex", or ""
1276 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001277
1278 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001279
1280 // Whether to create symlink to the system file instead of having a file
1281 // inside the apex or not
1282 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001283
1284 // Struct holding the merged notice file paths in different formats
1285 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001286}
1287
Jiyong Park397e55e2018-10-24 21:09:55 +09001288func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001289 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001290 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001291 // Use *FarVariation* to be able to depend on modules having
1292 // conflicting variations with this module. This is required since
1293 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1294 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001295 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001296 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001297 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001298 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001299 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001300
Jooyung Han643adc42020-02-27 13:50:06 +09001301 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1302 {Mutator: "image", Variation: imageVariation},
1303 {Mutator: "link", Variation: "shared"},
1304 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1305 }...), jniLibTag, nativeModules.Jni_libs...)
1306
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001307 ctx.AddFarVariationDependencies(append(target.Variations(),
1308 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001309 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001310
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001311 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001312 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001313 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001314 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001315}
1316
Alex Light9670d332019-01-29 18:07:33 -08001317func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1318 if ctx.Os().Class == android.Device {
1319 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1320 } else {
1321 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1322 if ctx.Os().Bionic() {
1323 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1324 } else {
1325 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1326 }
1327 }
1328}
1329
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001330func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001331 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1332 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1333 }
1334
Jiyong Park397e55e2018-10-24 21:09:55 +09001335 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001336 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001337
1338 a.combineProperties(ctx)
1339
Jiyong Park397e55e2018-10-24 21:09:55 +09001340 has32BitTarget := false
1341 for _, target := range targets {
1342 if target.Arch.ArchType.Multilib == "lib32" {
1343 has32BitTarget = true
1344 }
1345 }
1346 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001347 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001348 // multilib.both
1349 addDependenciesForNativeModules(ctx,
1350 ApexNativeDependencies{
1351 Native_shared_libs: a.properties.Native_shared_libs,
1352 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001353 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001354 Binaries: nil,
1355 },
1356 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001357
Jiyong Park397e55e2018-10-24 21:09:55 +09001358 // Add native modules targetting both ABIs
1359 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001360 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001361 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001362 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001363
Alex Light3d673592019-01-18 14:37:31 -08001364 isPrimaryAbi := i == 0
1365 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001366 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001367 // multilib.first
1368 addDependenciesForNativeModules(ctx,
1369 ApexNativeDependencies{
1370 Native_shared_libs: nil,
1371 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001372 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001373 Binaries: a.properties.Binaries,
1374 },
1375 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001376
1377 // Add native modules targetting the first ABI
1378 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001379 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001380 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001381 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001382 }
1383
1384 switch target.Arch.ArchType.Multilib {
1385 case "lib32":
1386 // Add native modules targetting 32-bit ABI
1387 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001388 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001389 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001390 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001391
1392 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001393 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001394 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001395 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001396 case "lib64":
1397 // Add native modules targetting 64-bit ABI
1398 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001399 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001400 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001401 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001402
1403 if !has32BitTarget {
1404 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001405 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001406 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001407 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001408 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001409
1410 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1411 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1412 if sanitizer == "hwaddress" {
1413 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001414 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001415 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001416 break
1417 }
1418 }
1419 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001420 }
1421
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001422 }
1423
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001424 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1425 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1426 // b/144532908
1427 archForPrebuiltEtc := config.Arches()[0]
1428 for _, arch := range config.Arches() {
1429 // Prefer 64-bit arch if there is any
1430 if arch.ArchType.Multilib == "lib64" {
1431 archForPrebuiltEtc = arch
1432 break
1433 }
1434 }
1435 ctx.AddFarVariationDependencies([]blueprint.Variation{
1436 {Mutator: "os", Variation: ctx.Os().String()},
1437 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1438 }, prebuiltTag, a.properties.Prebuilts...)
1439
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001440 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1441 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001442
Ulya Trafimovich44561882020-01-03 13:25:54 +00001443 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1444 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1445 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1446 javaLibTag, "jacocoagent")
1447 }
1448
Jiyong Park23c52b02019-02-02 13:13:47 +09001449 if String(a.properties.Key) == "" {
1450 ctx.ModuleErrorf("key is missing")
1451 return
1452 }
1453 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001454
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001455 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001456 if cert != "" {
1457 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001458 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001459
1460 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1461 if len(a.properties.Uses_sdks) > 0 {
1462 sdkRefs := []android.SdkRef{}
1463 for _, str := range a.properties.Uses_sdks {
1464 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1465 sdkRefs = append(sdkRefs, parsed)
1466 }
1467 a.BuildWithSdks(sdkRefs)
1468 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001469}
1470
Jiyong Park5d790c32019-11-15 18:40:32 +09001471func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1472 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1473 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001474 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1475 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001476}
1477
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001478func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1479 // direct deps of an APEX bundle are all part of the APEX bundle
1480 return true
1481}
1482
Colin Cross0ea8ba82019-06-06 14:33:29 -07001483func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001484 moduleName := ctx.ModuleName()
1485 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1486 // we check with the pseudo module name to see if its certificate is overridden.
1487 if a.vndkApex {
1488 moduleName = vndkApexName
1489 }
1490 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001491 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001492 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001493 }
1494 return String(a.properties.Certificate)
1495}
1496
Colin Cross41955e82019-05-29 14:40:35 -07001497func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1498 switch tag {
1499 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001500 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001501 default:
1502 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001503 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001504}
1505
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001506func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001507 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001508}
1509
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001510func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1511 return proptools.Bool(a.properties.Test_only_no_hashtree)
1512}
1513
Jiyong Park7c1dc612019-01-05 11:15:24 +09001514func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001515 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001516 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001517 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001518 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001519 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001520 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001521 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001522 }
1523}
1524
Jiyong Parkf97782b2019-02-13 20:28:58 +09001525func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1526 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1527 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1528 }
1529}
1530
Jiyong Park388ef3f2019-01-28 19:47:32 +09001531func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001532 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1533 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001534 }
1535
1536 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001537 globalSanitizerNames := []string{}
1538 if a.Host() {
1539 globalSanitizerNames = ctx.Config().SanitizeHost()
1540 } else {
1541 arches := ctx.Config().SanitizeDeviceArch()
1542 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1543 globalSanitizerNames = ctx.Config().SanitizeDevice()
1544 }
1545 }
1546 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001547}
1548
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001549func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001550 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001551}
1552
1553func (a *apexBundle) PreventInstall() {
1554 a.properties.PreventInstall = true
1555}
1556
1557func (a *apexBundle) HideFromMake() {
1558 a.properties.HideFromMake = true
1559}
1560
Jiyong Park956305c2020-01-09 12:32:06 +09001561func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1562 a.properties.IsCoverageVariant = coverage
1563}
1564
Jiyong Parkf653b052019-11-18 15:39:01 +09001565// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001566func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001567 // Decide the APEX-local directory by the multilib of the library
1568 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001569 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001570 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001571 case "lib32":
1572 dirInApex = "lib"
1573 case "lib64":
1574 dirInApex = "lib64"
1575 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001576 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001577 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001578 }
Jooyung Han35155c42020-02-06 17:33:20 +09001579 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001580 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001581 // Special case for Bionic libs and other libs installed with them. This is
1582 // to prevent those libs from being included in the search path
1583 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1584 // those libs in the Runtime APEX are available via the legacy paths in
1585 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1586 // to the legacy paths and thus will be loaded into the default linker
1587 // namespace (aka "platform" namespace). If the libs are directly in
1588 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1589 // into the runtime linker namespace, which will result in double loading of
1590 // them, which isn't supported.
1591 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001592 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001593
Jiyong Parkf653b052019-11-18 15:39:01 +09001594 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001595 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001596}
1597
Jiyong Park1833cef2019-12-13 13:28:36 +09001598func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001599 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001600 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001601 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001602 }
Jooyung Han35155c42020-02-06 17:33:20 +09001603 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001604 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001605 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001606 af.symlinks = cc.Symlinks()
1607 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001608}
1609
Jiyong Park1833cef2019-12-13 13:28:36 +09001610func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001611 dirInApex := "bin"
1612 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001613 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001614}
Jiyong Park1833cef2019-12-13 13:28:36 +09001615func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001616 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001617 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1618 if err != nil {
1619 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001620 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001621 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001622 fileToCopy := android.PathForOutput(ctx, s)
1623 // NB: Since go binaries are static we don't need the module for anything here, which is
1624 // good since the go tool is a blueprint.Module not an android.Module like we would
1625 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001626 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001627}
1628
Jiyong Park1833cef2019-12-13 13:28:36 +09001629func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001630 dirInApex := filepath.Join("bin", sh.SubDir())
1631 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001632 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001633 af.symlinks = sh.Symlinks()
1634 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001635}
1636
Jooyung Han58f26ab2019-12-18 15:34:32 +09001637// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1638type javaLibrary interface {
1639 android.Module
1640 java.Dependency
1641}
1642
1643func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001644 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001645 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001646 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1647 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1648 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001649}
1650
Jiyong Park1833cef2019-12-13 13:28:36 +09001651func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001652 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1653 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001654 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001655}
1656
atrost6e126252020-01-27 17:01:16 +00001657func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1658 dirInApex := filepath.Join("etc", config.SubDir())
1659 fileToCopy := config.CompatConfig()
1660 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1661}
1662
Jiyong Park1833cef2019-12-13 13:28:36 +09001663func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001664 android.Module
1665 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001666 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001667 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001668 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001669 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001670}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001671 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001672 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001673 appDir = "priv-app"
1674 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001675 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001676 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001677 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1678 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001679 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001680
1681 if app, ok := aapp.(interface {
1682 OverriddenManifestPackageName() string
1683 }); ok {
1684 af.overriddenPackageName = app.OverriddenManifestPackageName()
1685 }
Jiyong Park618922e2020-01-08 13:35:43 +09001686 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001687}
1688
Jiyong Park69aeba92020-04-24 21:16:36 +09001689func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1690 rroDir := "overlay"
1691 dirInApex := filepath.Join(rroDir, rro.Theme())
1692 fileToCopy := rro.OutputFile()
1693 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1694 af.certificate = rro.Certificate()
1695
1696 if a, ok := rro.(interface {
1697 OverriddenManifestPackageName() string
1698 }); ok {
1699 af.overriddenPackageName = a.OverriddenManifestPackageName()
1700 }
1701 return af
1702}
1703
Roland Levillain935639d2019-08-13 14:55:28 +01001704// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1705type flattenedApexContext struct {
1706 android.ModuleContext
1707}
1708
1709func (c *flattenedApexContext) InstallBypassMake() bool {
1710 return true
1711}
1712
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001713// Function called while walking an APEX's payload dependencies.
1714//
1715// Return true if the `to` module should be visited, false otherwise.
1716type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1717
Jiyong Park201cedd2020-02-07 17:25:49 +09001718// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001719func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001720 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001721 am, ok := child.(android.ApexModule)
1722 if !ok || !am.CanHaveApexVariants() {
1723 return false
1724 }
1725
1726 // Check for the direct dependencies that contribute to the payload
1727 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1728 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001729 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001730 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001731 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001732 return false
1733 }
1734
1735 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001736 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001737 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001738 }
1739
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001740 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001741 })
1742}
1743
Jooyung Han03b51852020-02-26 22:45:42 +09001744func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1745 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001746 intVer, err := android.ApiStrToNum(ctx, ver)
1747 if err != nil {
1748 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001749 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001750 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001751}
1752
Paul Duffinc5192442020-03-31 11:31:36 +01001753// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1754// a dependency tag.
1755var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1756
1757func PrettyPrintTag(tag blueprint.DependencyTag) string {
1758 // Use tag's custom String() method if available.
1759 if stringer, ok := tag.(fmt.Stringer); ok {
1760 return stringer.String()
1761 }
1762
1763 // Otherwise, get a default string representation of the tag's struct.
1764 tagString := fmt.Sprintf("%#v", tag)
1765
1766 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1767 tagString = tagCleaner.ReplaceAllString(tagString, "")
1768 return tagString
1769}
1770
Jiyong Park201cedd2020-02-07 17:25:49 +09001771// Ensures that the dependencies are marked as available for this APEX
1772func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1773 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1774 if ctx.Host() || a.testApex || a.vndkApex {
1775 return
1776 }
1777
Jiyong Park58d10902020-03-28 14:43:19 +09001778 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1779 // Requiring them and their transitive depencies with apex_available is not right
1780 // because they just add noise.
1781 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1782 return
1783 }
1784
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001785 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1786 if externalDep {
1787 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1788 return false
1789 }
1790
Jiyong Park201cedd2020-02-07 17:25:49 +09001791 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001792 fromName := ctx.OtherModuleName(from)
1793 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001794
1795 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1796 // do any of its dependencies.
1797 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1798 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1799 return false
1800 }
1801
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001802 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1803 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001804 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001805 message := ""
Paul Duffinc5192442020-03-31 11:31:36 +01001806 tagPath := ctx.GetTagPath()
1807 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1808 walkPath := ctx.GetWalkPath()[1:]
1809 for i, m := range walkPath {
1810 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffindf915ff2020-03-30 17:58:21 +01001811 }
1812 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001813 // Visit this module's dependencies to check and report any issues with their availability.
1814 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001815 })
1816}
1817
Jiyong Park678c8812020-02-07 17:25:49 +09001818// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1819func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1820 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001821 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001822 if from.Name() == to.Name() {
1823 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001824 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1825 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001826 }
1827
1828 if info, exists := a.depInfos[to.Name()]; exists {
1829 if !android.InList(from.Name(), info.from) {
1830 info.from = append(info.from, from.Name())
1831 }
1832 info.isExternal = info.isExternal && externalDep
1833 a.depInfos[to.Name()] = info
1834 } else {
1835 a.depInfos[to.Name()] = depInfo{
1836 to: to.Name(),
1837 from: []string{from.Name()},
1838 isExternal: externalDep,
1839 }
1840 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001841
1842 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1843 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001844 })
1845}
1846
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001847func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001848 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1849 switch a.properties.ApexType {
1850 case imageApex:
1851 if buildFlattenedAsDefault {
1852 a.suffix = imageApexSuffix
1853 } else {
1854 a.suffix = ""
1855 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001856
1857 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001858 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001859 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001860 }
1861 case zipApex:
1862 if proptools.String(a.properties.Payload_type) == "zip" {
1863 a.suffix = ""
1864 a.primaryApexType = true
1865 } else {
1866 a.suffix = zipApexSuffix
1867 }
1868 case flattenedApex:
1869 if buildFlattenedAsDefault {
1870 a.suffix = ""
1871 a.primaryApexType = true
1872 } else {
1873 a.suffix = flattenedSuffix
1874 }
Alex Light5098a612018-11-29 17:12:15 -08001875 }
1876
Roland Levillain630846d2019-06-26 12:48:34 +01001877 if len(a.properties.Tests) > 0 && !a.testApex {
1878 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1879 return
1880 }
1881
Jiyong Park0f80c182020-01-31 02:49:53 +09001882 a.checkApexAvailability(ctx)
1883
Jiyong Park678c8812020-02-07 17:25:49 +09001884 a.collectDepsInfo(ctx)
1885
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001886 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1887
Jooyung Hane1633032019-08-01 17:41:43 +09001888 // native lib dependencies
1889 var provideNativeLibs []string
1890 var requireNativeLibs []string
1891
Jooyung Han5c998b92019-06-27 11:30:33 +09001892 // Check if "uses" requirements are met with dependent apexBundles
1893 var providedNativeSharedLibs []string
1894 useVendor := proptools.Bool(a.properties.Use_vendor)
1895 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1896 if ctx.OtherModuleDependencyTag(m) != usesTag {
1897 return
1898 }
1899 otherName := ctx.OtherModuleName(m)
1900 other, ok := m.(*apexBundle)
1901 if !ok {
1902 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1903 return
1904 }
1905 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1906 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1907 return
1908 }
1909 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1910 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1911 return
1912 }
1913 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1914 })
1915
Jiyong Parkf653b052019-11-18 15:39:01 +09001916 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001917 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001918 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001919 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001920 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1921 return false
1922 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001923 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001924 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001925 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001926 case sharedLibTag, jniLibTag:
1927 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001928 if c, ok := child.(*cc.Module); ok {
1929 // bootstrap bionic libs are treated as provided by system
1930 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1931 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001932 }
Jooyung Han643adc42020-02-27 13:50:06 +09001933 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1934 fi.isJniLib = isJniLib
1935 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001936 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001937 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001938 propertyName := "native_shared_libs"
1939 if isJniLib {
1940 propertyName = "jni_libs"
1941 }
1942 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001943 }
1944 case executableTag:
1945 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001946 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001947 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001948 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001949 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001950 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001951 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001952 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001953 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001954 } else {
Alex Light778127a2019-02-27 14:19:50 -08001955 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 +09001956 }
1957 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001958 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001959 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001960 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001961 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1962 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001963 filesInfo = append(filesInfo, af)
1964 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001965 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001966 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1967 af := apexFileForJavaLibrary(ctx, sdkLib)
1968 if !af.Ok() {
1969 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1970 return false
1971 }
1972 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001973 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001974 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001975 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001976 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001977 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001978 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001979 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001980 return true // track transitive dependencies
1981 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001982 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001983 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001984 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001985 } else {
1986 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1987 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001988 case rroTag:
1989 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1990 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1991 } else {
1992 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
1993 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001994 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001995 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001996 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001997 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1998 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001999 } else {
atrost6e126252020-01-27 17:01:16 +00002000 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002001 }
Roland Levillain630846d2019-06-26 12:48:34 +01002002 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002003 if ccTest, ok := child.(*cc.Module); ok {
2004 if ccTest.IsTestPerSrcAllTestsVariation() {
2005 // Multiple-output test module (where `test_per_src: true`).
2006 //
2007 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2008 // We do not add this variation to `filesInfo`, as it has no output;
2009 // however, we do add the other variations of this module as indirect
2010 // dependencies (see below).
2011 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002012 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002013 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002014 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002015 af.class = nativeTest
2016 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002017 }
Roland Levillain630846d2019-06-26 12:48:34 +01002018 } else {
2019 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2020 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002021 case keyTag:
2022 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002023 a.private_key_file = key.private_key_file
2024 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002025 } else {
2026 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002027 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002028 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002029 case certificateTag:
2030 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002031 a.container_certificate_file = dep.Certificate.Pem
2032 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002033 } else {
2034 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2035 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002036 case android.PrebuiltDepTag:
2037 // If the prebuilt is force disabled, remember to delete the prebuilt file
2038 // that might have been installed in the previous builds
2039 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2040 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2041 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002042 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002043 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002044 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002045 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002046 // We cannot use a switch statement on `depTag` here as the checked
2047 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002048 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002049 if cc, ok := child.(*cc.Module); ok {
2050 if android.InList(cc.Name(), providedNativeSharedLibs) {
2051 // If we're using a shared library which is provided from other APEX,
2052 // don't include it in this APEX
2053 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002054 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002055 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002056 // If the dependency is a stubs lib, don't include it in this APEX,
2057 // but make sure that the lib is installed on the device.
2058 // In case no APEX is having the lib, the lib is installed to the system
2059 // partition.
2060 //
2061 // Always include if we are a host-apex however since those won't have any
2062 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002063 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2064 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002065 }
Jooyung Hane1633032019-08-01 17:41:43 +09002066 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002067 // Don't track further
2068 return false
2069 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002070 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002071 af.transitiveDep = true
2072 filesInfo = append(filesInfo, af)
2073 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002074 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002075 } else if cc.IsTestPerSrcDepTag(depTag) {
2076 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002077 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002078 // Handle modules created as `test_per_src` variations of a single test module:
2079 // use the name of the generated test binary (`fileToCopy`) instead of the name
2080 // of the original test module (`depName`, shared by all `test_per_src`
2081 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002082 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002083 // these are not considered transitive dep
2084 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002085 filesInfo = append(filesInfo, af)
2086 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002087 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002088 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002089 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2090 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002091 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2092 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2093 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2094 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002095 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffindddd5462020-04-07 15:25:44 +01002096 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002097 }
2098 }
2099 }
2100 return false
2101 })
2102
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002103 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2104 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2105 // via the global boot image config.
2106 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002107 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002108 dirInApex := filepath.Join("javalib", arch.String())
2109 for _, f := range files {
2110 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002111 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002112 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002113 }
2114 }
2115 }
2116
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002117 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002118 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2119 return
2120 }
2121
Jiyong Park8fd61922018-11-08 02:50:25 +09002122 // remove duplicates in filesInfo
2123 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002124 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002125 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002126 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002127 if e, ok := encountered[dest]; !ok {
2128 encountered[dest] = f
2129 } else {
2130 // If a module is directly included and also transitively depended on
2131 // consider it as directly included.
2132 e.transitiveDep = e.transitiveDep && f.transitiveDep
2133 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002134 }
2135 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002136 var result []apexFile
2137 for _, v := range encountered {
2138 result = append(result, v)
2139 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002140 return result
2141 }
2142 filesInfo = removeDup(filesInfo)
2143
2144 // to have consistent build rules
2145 sort.Slice(filesInfo, func(i, j int) bool {
2146 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2147 })
2148
Jiyong Park8fd61922018-11-08 02:50:25 +09002149 a.installDir = android.PathForModuleInstall(ctx, "apex")
2150 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002151
Jooyung Han54aca7b2019-11-20 02:26:02 +09002152 if a.properties.ApexType != zipApex {
2153 if a.properties.File_contexts == nil {
2154 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2155 } else {
2156 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2157 if a.Platform() {
2158 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2159 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2160 }
2161 }
2162 }
2163 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2164 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2165 return
2166 }
2167 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002168 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2169 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2170 // the same library in the system partition, thus effectively sharing the same libraries
2171 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2172 // in the APEX.
2173 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2174 a.installable() &&
2175 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002176
Jiyong Park9d677202020-02-19 16:29:35 +09002177 // We don't need the optimization for updatable APEXes, as it might give false signal
2178 // to the system health when the APEXes are still bundled (b/149805758)
2179 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2180 a.linkToSystemLib = false
2181 }
2182
Jiyong Park638d30e2020-02-26 18:27:19 +09002183 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2184 if ctx.Host() {
2185 a.linkToSystemLib = false
2186 }
2187
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002188 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002189 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2190
2191 a.setCertificateAndPrivateKey(ctx)
2192 if a.properties.ApexType == flattenedApex {
2193 a.buildFlattenedApex(ctx)
2194 } else {
2195 a.buildUnflattenedApex(ctx)
2196 }
2197
Jooyung Han002ab682020-01-08 01:57:58 +09002198 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002199
2200 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002201}
2202
Jooyung Han5e9013b2020-03-10 06:23:13 +09002203func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002204 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002205 moduleName = normalizeModuleName(moduleName)
2206
2207 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2208 return true
2209 }
2210
2211 key = android.AvailableToAnyApex
2212 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2213 return true
2214 }
2215
2216 return false
2217}
2218
2219func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002220 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2221 // system. Trim the prefix for the check since they are confusing
2222 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2223 if strings.HasPrefix(moduleName, "libclang_rt.") {
2224 // This module has many arch variants that depend on the product being built.
2225 // We don't want to list them all
2226 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002227 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002228 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002229}
2230
Jooyung Han344d5432019-08-23 11:17:39 +09002231func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002232 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002233 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002234 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002235 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002236 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002237 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2238 })
Alex Light5098a612018-11-29 17:12:15 -08002239 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002240 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002241 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002242 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002243 return module
2244}
Jiyong Park30ca9372019-02-07 16:27:23 +09002245
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002246func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002247 bundle := newApexBundle()
2248 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002249 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002250 return bundle
2251}
2252
Jiyong Parkfce0b422020-02-11 03:56:06 +09002253// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2254// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002255func testApexBundleFactory() android.Module {
2256 bundle := newApexBundle()
2257 bundle.testApex = true
2258 return bundle
2259}
2260
Jiyong Parkfce0b422020-02-11 03:56:06 +09002261// apex packages other modules into an APEX file which is a packaging format for system-level
2262// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002263func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002264 return newApexBundle()
2265}
2266
Jiyong Park30ca9372019-02-07 16:27:23 +09002267//
2268// Defaults
2269//
2270type Defaults struct {
2271 android.ModuleBase
2272 android.DefaultsModuleBase
2273}
2274
Jiyong Park30ca9372019-02-07 16:27:23 +09002275func defaultsFactory() android.Module {
2276 return DefaultsFactory()
2277}
2278
2279func DefaultsFactory(props ...interface{}) android.Module {
2280 module := &Defaults{}
2281
2282 module.AddProperties(props...)
2283 module.AddProperties(
2284 &apexBundleProperties{},
2285 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002286 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002287 )
2288
2289 android.InitDefaultsModule(module)
2290 return module
2291}
Jiyong Park5d790c32019-11-15 18:40:32 +09002292
2293//
2294// OverrideApex
2295//
2296type OverrideApex struct {
2297 android.ModuleBase
2298 android.OverrideModuleBase
2299}
2300
2301func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2302 // All the overrides happen in the base module.
2303}
2304
2305// override_apex is used to create an apex module based on another apex module
2306// by overriding some of its properties.
2307func overrideApexFactory() android.Module {
2308 m := &OverrideApex{}
2309 m.AddProperties(&overridableProperties{})
2310
2311 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2312 android.InitOverrideModule(m)
2313 return m
2314}