blob: d196e95e9e0bda36e7f711dba5f7c56ed28074c4 [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 Park89e850a2020-04-07 16:37:39 +0900750 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900751}
752
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900753// Mark the direct and transitive dependencies of apex bundles so that they
754// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900755func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900756 if !mctx.Module().Enabled() {
757 return
758 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800759 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900760 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000761 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900762 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900763 ApexName: mctx.ModuleName(),
764 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100765 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900766 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900767 directDep = true
768 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800769 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900770 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900771 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900772
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800773 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900774 return
775 }
776
Paul Duffin923e8a52020-03-30 15:33:32 +0100777 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900778
Jiyong Parkf760cae2020-02-12 07:53:12 +0900779 mctx.VisitDirectDeps(func(child android.Module) {
780 depName := mctx.OtherModuleName(child)
781 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100782 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800783 android.UpdateApexDependency(apexBundles, depName, directDep)
784 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900785 }
786 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900787}
788
Jiyong Park89e850a2020-04-07 16:37:39 +0900789// mark if a module cannot be available to platform. A module cannot be available
790// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
791// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
792func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
793 // Host and recovery are not considered as platform
794 if mctx.Host() || mctx.Module().InstallInRecovery() {
795 return
796 }
797
798 if am, ok := mctx.Module().(android.ApexModule); ok {
799 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
800
801 // In a rare case when a lib is marked as available only to an apex
802 // but the apex doesn't exist. This can happen in a partial manifest branch
803 // like master-art. Currently, libstatssocket in the stats APEX is causing
804 // this problem.
805 // Include the lib in platform because the module SDK that ought to provide
806 // it doesn't exist, so it would otherwise be left out completely.
807 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
808 // this check for libraries provided by SDKs.
809 if !availableToPlatform && !android.InAnyApex(am.Name()) {
810 availableToPlatform = true
811 }
812
813 // If any of the dep is not available to platform, this module is also considered
814 // as being not available to platform even if it has "//apex_available:platform"
815 mctx.VisitDirectDeps(func(child android.Module) {
816 if !am.DepIsInSameApex(mctx, child) {
817 // if the dependency crosses apex boundary, don't consider it
818 return
819 }
820 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
821 availableToPlatform = false
822 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
823 }
824 })
825
826 // Exception 1: stub libraries and native bridge libraries are always available to platform
827 if cc, ok := mctx.Module().(*cc.Module); ok &&
828 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
829 availableToPlatform = true
830 }
831
832 // Exception 2: bootstrap bionic libraries are also always available to platform
833 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
834 availableToPlatform = true
835 }
836
837 if !availableToPlatform {
838 am.SetNotAvailableForPlatform()
839 }
840 }
841}
842
Paul Duffin65347702020-03-31 15:23:40 +0100843// If a module in an APEX depends on a module from an SDK then it needs an APEX
844// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
845func inAnySdk(module android.Module) bool {
846 if sa, ok := module.(android.SdkAware); ok {
847 return sa.IsInAnySdk()
848 }
849
850 return false
851}
852
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900853// Create apex variations if a module is included in APEX(s).
854func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900855 if !mctx.Module().Enabled() {
856 return
857 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900858 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900859 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000860 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900861 // apex bundle itself is mutated so that it and its modules have same
862 // apex variant.
863 apexBundleName := mctx.ModuleName()
864 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900865 } else if o, ok := mctx.Module().(*OverrideApex); ok {
866 apexBundleName := o.GetOverriddenModuleName()
867 if apexBundleName == "" {
868 mctx.ModuleErrorf("base property is not set")
869 return
870 }
871 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900872 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900873
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900874}
Sundong Ahne9b55722019-09-06 17:37:42 +0900875
Jooyung Han7a78a922019-10-08 21:59:58 +0900876var (
877 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
878 apexFileContextsInfosMutex sync.Mutex
879)
880
881func apexFileContextsInfos(config android.Config) *[]string {
882 return config.Once(apexFileContextsInfosKey, func() interface{} {
883 return &[]string{}
884 }).(*[]string)
885}
886
Jooyung Han54aca7b2019-11-20 02:26:02 +0900887func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900888 apexFileContextsInfosMutex.Lock()
889 defer apexFileContextsInfosMutex.Unlock()
890 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900891 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900892}
893
Sundong Ahne9b55722019-09-06 17:37:42 +0900894func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900895 if !mctx.Module().Enabled() {
896 return
897 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900898 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900899 var variants []string
900 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
901 case "image":
902 variants = append(variants, imageApexType, flattenedApexType)
903 case "zip":
904 variants = append(variants, zipApexType)
905 case "both":
906 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
907 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900908 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900909 return
910 }
911
912 modules := mctx.CreateLocalVariations(variants...)
913
914 for i, v := range variants {
915 switch v {
916 case imageApexType:
917 modules[i].(*apexBundle).properties.ApexType = imageApex
918 case zipApexType:
919 modules[i].(*apexBundle).properties.ApexType = zipApex
920 case flattenedApexType:
921 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900922 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900923 modules[i].(*apexBundle).MakeAsSystemExt()
924 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900925 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900926 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900927 } else if _, ok := mctx.Module().(*OverrideApex); ok {
928 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900929 }
930}
931
Jooyung Han5c998b92019-06-27 11:30:33 +0900932func apexUsesMutator(mctx android.BottomUpMutatorContext) {
933 if ab, ok := mctx.Module().(*apexBundle); ok {
934 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
935 }
936}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900937
Jooyung Handc782442019-11-01 03:14:38 +0900938var (
939 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
940)
941
942// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
943// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
944// which may cause compatibility issues. (e.g. libbinder)
945// Even though libbinder restricts its availability via 'apex_available' property and relies on
946// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
947// to avoid similar problems.
948func useVendorWhitelist(config android.Config) []string {
949 return config.Once(useVendorWhitelistKey, func() interface{} {
950 return []string{
951 // swcodec uses "vendor" variants for smaller size
952 "com.android.media.swcodec",
953 "test_com.android.media.swcodec",
954 }
955 }).([]string)
956}
957
958// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
959// called before the first call to useVendorWhitelist()
960func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
961 config.Once(useVendorWhitelistKey, func() interface{} {
962 return whitelist
963 })
964}
965
Jooyung Han01a868d2020-02-27 13:40:44 +0900966type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800967 // List of native libraries
968 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900969
Jooyung Han643adc42020-02-27 13:50:06 +0900970 // List of JNI libraries
971 Jni_libs []string
972
Alex Light9670d332019-01-29 18:07:33 -0800973 // List of native executables
974 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900975
Roland Levillain630846d2019-06-26 12:48:34 +0100976 // List of native tests
977 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800978}
Jooyung Han344d5432019-08-23 11:17:39 +0900979
Alex Light9670d332019-01-29 18:07:33 -0800980type apexMultilibProperties struct {
981 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900982 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800983
984 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900985 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800986
987 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900988 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800989
990 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900991 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800992
993 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900994 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800995}
996
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900997type apexBundleProperties struct {
998 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000999 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001000 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001001
Jiyong Park40e26a22019-02-08 02:53:06 +09001002 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1003 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001004 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001005
Roland Levillain411c5842019-09-19 16:37:20 +01001006 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1007 // device (/apex/<apex_name>).
1008 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001009 Apex_name *string
1010
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001011 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001012 // For platform APEXes, this should points to a file under /system/sepolicy
1013 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1014 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001015
Jooyung Han01a868d2020-02-27 13:40:44 +09001016 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001017
1018 // List of java libraries that are embedded inside this APEX bundle
1019 Java_libs []string
1020
1021 // List of prebuilt files that are embedded inside this APEX bundle
1022 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001023
1024 // Name of the apex_key module that provides the private key to sign APEX
1025 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001026
Alex Light5098a612018-11-29 17:12:15 -08001027 // The type of APEX to build. Controls what the APEX payload is. Either
1028 // 'image', 'zip' or 'both'. Default: 'image'.
1029 Payload_type *string
1030
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001031 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1032 // or an android_app_certificate module name in the form ":module".
1033 Certificate *string
1034
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001035 // Whether this APEX is installable to one of the partitions. Default: true.
1036 Installable *bool
1037
Jiyong Parkda6eb592018-12-19 17:12:36 +09001038 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1039 // Default is false.
1040 Use_vendor *bool
1041
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001042 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1043 Ignore_system_library_special_case *bool
1044
Alex Light9670d332019-01-29 18:07:33 -08001045 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001046
Jiyong Parkf97782b2019-02-13 20:28:58 +09001047 // List of sanitizer names that this APEX is enabled for
1048 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001049
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001050 PreventInstall bool `blueprint:"mutated"`
1051
1052 HideFromMake bool `blueprint:"mutated"`
1053
Jooyung Han5c998b92019-06-27 11:30:33 +09001054 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1055 Provide_cpp_shared_libs *bool
1056
1057 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1058 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001059
1060 // A txt file containing list of files that are whitelisted to be included in this APEX.
1061 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001062
Sundong Ahnabb64432019-10-22 13:58:29 +09001063 // package format of this apex variant; could be non-flattened, flattened, or zip.
1064 // imageApex, zipApex or flattened
1065 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001066
Jiyong Parkd1063c12019-07-17 20:08:41 +09001067 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1068 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1069 // is implied. This value affects all modules included in this APEX. In other words, they are
1070 // also built with the SDKs specified here.
1071 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001072
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001073 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1074 // Should be only used in tests#.
1075 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001076
Dario Frenica913392020-04-27 18:21:11 +01001077 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1078 // Should be only used in tests#.
1079 Test_only_unsigned_payload *bool
1080
Jiyong Park956305c2020-01-09 12:32:06 +09001081 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001082
1083 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001084 // rules for making sure that the APEX is truly updatable.
1085 // - To be updatable, min_sdk_version should be set as well
1086 // This will also disable the size optimizations like symlinking to the system libs.
1087 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001088 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001089
1090 // The minimum SDK version that this apex must be compatibile with.
1091 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001092}
1093
1094type apexTargetBundleProperties struct {
1095 Target struct {
1096 // Multilib properties only for android.
1097 Android struct {
1098 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001099 }
Jooyung Han344d5432019-08-23 11:17:39 +09001100
Alex Light9670d332019-01-29 18:07:33 -08001101 // Multilib properties only for host.
1102 Host struct {
1103 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001104 }
Jooyung Han344d5432019-08-23 11:17:39 +09001105
Alex Light9670d332019-01-29 18:07:33 -08001106 // Multilib properties only for host linux_bionic.
1107 Linux_bionic struct {
1108 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001109 }
Jooyung Han344d5432019-08-23 11:17:39 +09001110
Alex Light9670d332019-01-29 18:07:33 -08001111 // Multilib properties only for host linux_glibc.
1112 Linux_glibc struct {
1113 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001114 }
1115 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001116}
1117
Jiyong Park5d790c32019-11-15 18:40:32 +09001118type overridableProperties struct {
1119 // List of APKs to package inside APEX
1120 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001121
Jiyong Park69aeba92020-04-24 21:16:36 +09001122 // List of runtime resource overlays (RROs) inside APEX
1123 Rros []string
1124
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001125 // Names of modules to be overridden. Listed modules can only be other binaries
1126 // (in Make or Soong).
1127 // This does not completely prevent installation of the overridden binaries, but if both
1128 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1129 // from PRODUCT_PACKAGES.
1130 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001131
1132 // Logging Parent value
1133 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001134
1135 // Apex Container Package Name.
1136 // Override value for attribute package:name in AndroidManifest.xml
1137 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001138}
1139
Alex Light5098a612018-11-29 17:12:15 -08001140type apexPackaging int
1141
1142const (
1143 imageApex apexPackaging = iota
1144 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001145 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001146)
1147
Sundong Ahnabb64432019-10-22 13:58:29 +09001148// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001149func (a apexPackaging) suffix() string {
1150 switch a {
1151 case imageApex:
1152 return imageApexSuffix
1153 case zipApex:
1154 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001155 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001156 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001157 }
1158}
1159
1160func (a apexPackaging) name() string {
1161 switch a {
1162 case imageApex:
1163 return imageApexType
1164 case zipApex:
1165 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001166 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001167 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001168 }
1169}
1170
Jiyong Parkf653b052019-11-18 15:39:01 +09001171type apexFileClass int
1172
1173const (
1174 etc apexFileClass = iota
1175 nativeSharedLib
1176 nativeExecutable
1177 shBinary
1178 pyBinary
1179 goBinary
1180 javaSharedLib
1181 nativeTest
1182 app
1183)
1184
Jiyong Park8fd61922018-11-08 02:50:25 +09001185func (class apexFileClass) NameInMake() string {
1186 switch class {
1187 case etc:
1188 return "ETC"
1189 case nativeSharedLib:
1190 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001191 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001192 return "EXECUTABLES"
1193 case javaSharedLib:
1194 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001195 case nativeTest:
1196 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001197 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001198 // b/142537672 Why isn't this APP? We want to have full control over
1199 // the paths and file names of the apk file under the flattend APEX.
1200 // If this is set to APP, then the paths and file names are modified
1201 // by the Make build system. For example, it is installed to
1202 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1203 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1204 // appends module name (which is <apexname>.<Appname> to the path.
1205 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001206 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001207 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001208 }
1209}
1210
Jiyong Parkf653b052019-11-18 15:39:01 +09001211// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001212type apexFile struct {
1213 builtFile android.Path
1214 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001215 installDir string
1216 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001217 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001218 // list of symlinks that will be created in installDir that point to this apexFile
1219 symlinks []string
1220 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001221 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001222
1223 requiredModuleNames []string
1224 targetRequiredModuleNames []string
1225 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001226
Colin Cross503c1d02020-01-28 14:00:53 -08001227 jacocoReportClassesFile android.Path // only for javalibs and apps
1228 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001229 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001230
1231 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001232}
1233
Jiyong Park1833cef2019-12-13 13:28:36 +09001234func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1235 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001236 builtFile: builtFile,
1237 moduleName: moduleName,
1238 installDir: installDir,
1239 class: class,
1240 module: module,
1241 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001242 if module != nil {
1243 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001244 ret.requiredModuleNames = module.RequiredModuleNames()
1245 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1246 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001247 }
1248 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001249}
1250
1251func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001252 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001253}
1254
Jiyong Park7cd10e32020-01-14 09:22:18 +09001255// Path() returns path of this apex file relative to the APEX root
1256func (af *apexFile) Path() string {
1257 return filepath.Join(af.installDir, af.builtFile.Base())
1258}
1259
1260// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1261func (af *apexFile) SymlinkPaths() []string {
1262 var ret []string
1263 for _, symlink := range af.symlinks {
1264 ret = append(ret, filepath.Join(af.installDir, symlink))
1265 }
1266 return ret
1267}
1268
1269func (af *apexFile) AvailableToPlatform() bool {
1270 if af.module == nil {
1271 return false
1272 }
1273 if am, ok := af.module.(android.ApexModule); ok {
1274 return am.AvailableFor(android.AvailableToPlatform)
1275 }
1276 return false
1277}
1278
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001279type apexBundle struct {
1280 android.ModuleBase
1281 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001282 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001283 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001284
Jiyong Park5d790c32019-11-15 18:40:32 +09001285 properties apexBundleProperties
1286 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001287 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001288
Jooyung Hanf21c7972019-12-16 22:32:06 +09001289 // specific to apex_vndk modules
1290 vndkProperties apexVndkProperties
1291
Colin Crossa4925902018-11-16 11:36:28 -08001292 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001293 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001294 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001295
Jiyong Park03b68dd2019-07-26 23:20:40 +09001296 prebuiltFileToDelete string
1297
Jiyong Park42cca6c2019-04-01 11:15:50 +09001298 public_key_file android.Path
1299 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001300
1301 container_certificate_file android.Path
1302 container_private_key_file android.Path
1303
Jooyung Han54aca7b2019-11-20 02:26:02 +09001304 fileContexts android.Path
1305
Jiyong Park8fd61922018-11-08 02:50:25 +09001306 // list of files to be included in this apex
1307 filesInfo []apexFile
1308
Jiyong Park956305c2020-01-09 12:32:06 +09001309 // list of module names that should be installed along with this APEX
1310 requiredDeps []string
1311
Jiyong Park956305c2020-01-09 12:32:06 +09001312 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001313 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001314
Sundong Ahnabb64432019-10-22 13:58:29 +09001315 testApex bool
1316 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001317 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001318 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001319
Jooyung Han214bf372019-11-12 13:03:50 +09001320 manifestJsonOut android.WritablePath
1321 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001322
Jooyung Han002ab682020-01-08 01:57:58 +09001323 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001324 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001325 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001326 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1327 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001328
1329 // Suffix of module name in Android.mk
1330 // ".flattened", ".apex", ".zipapex", or ""
1331 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001332
1333 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001334
1335 // Whether to create symlink to the system file instead of having a file
1336 // inside the apex or not
1337 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001338
1339 // Struct holding the merged notice file paths in different formats
1340 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001341}
1342
Jiyong Park397e55e2018-10-24 21:09:55 +09001343func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001344 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001345 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001346 // Use *FarVariation* to be able to depend on modules having
1347 // conflicting variations with this module. This is required since
1348 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1349 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001350 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001351 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001352 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001353 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001354 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001355
Jooyung Han643adc42020-02-27 13:50:06 +09001356 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1357 {Mutator: "image", Variation: imageVariation},
1358 {Mutator: "link", Variation: "shared"},
1359 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1360 }...), jniLibTag, nativeModules.Jni_libs...)
1361
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001362 ctx.AddFarVariationDependencies(append(target.Variations(),
1363 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001364 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001365
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001366 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001367 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001368 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001369 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001370}
1371
Alex Light9670d332019-01-29 18:07:33 -08001372func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1373 if ctx.Os().Class == android.Device {
1374 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1375 } else {
1376 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1377 if ctx.Os().Bionic() {
1378 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1379 } else {
1380 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1381 }
1382 }
1383}
1384
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001385func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001386 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1387 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1388 }
1389
Jiyong Park397e55e2018-10-24 21:09:55 +09001390 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001391 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001392
1393 a.combineProperties(ctx)
1394
Jiyong Park397e55e2018-10-24 21:09:55 +09001395 has32BitTarget := false
1396 for _, target := range targets {
1397 if target.Arch.ArchType.Multilib == "lib32" {
1398 has32BitTarget = true
1399 }
1400 }
1401 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001402 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001403 // multilib.both
1404 addDependenciesForNativeModules(ctx,
1405 ApexNativeDependencies{
1406 Native_shared_libs: a.properties.Native_shared_libs,
1407 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001408 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001409 Binaries: nil,
1410 },
1411 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001412
Jiyong Park397e55e2018-10-24 21:09:55 +09001413 // Add native modules targetting both ABIs
1414 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001415 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001416 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001417 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001418
Alex Light3d673592019-01-18 14:37:31 -08001419 isPrimaryAbi := i == 0
1420 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001421 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001422 // multilib.first
1423 addDependenciesForNativeModules(ctx,
1424 ApexNativeDependencies{
1425 Native_shared_libs: nil,
1426 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001427 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001428 Binaries: a.properties.Binaries,
1429 },
1430 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001431
1432 // Add native modules targetting the first ABI
1433 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001434 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001435 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001436 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001437 }
1438
1439 switch target.Arch.ArchType.Multilib {
1440 case "lib32":
1441 // Add native modules targetting 32-bit ABI
1442 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001443 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001444 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001445 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001446
1447 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001448 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001449 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001450 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001451 case "lib64":
1452 // Add native modules targetting 64-bit ABI
1453 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001454 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001455 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001456 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001457
1458 if !has32BitTarget {
1459 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001460 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001461 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001462 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001463 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001464
1465 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1466 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1467 if sanitizer == "hwaddress" {
1468 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001469 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001470 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001471 break
1472 }
1473 }
1474 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001475 }
1476
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001477 }
1478
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001479 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1480 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1481 // b/144532908
1482 archForPrebuiltEtc := config.Arches()[0]
1483 for _, arch := range config.Arches() {
1484 // Prefer 64-bit arch if there is any
1485 if arch.ArchType.Multilib == "lib64" {
1486 archForPrebuiltEtc = arch
1487 break
1488 }
1489 }
1490 ctx.AddFarVariationDependencies([]blueprint.Variation{
1491 {Mutator: "os", Variation: ctx.Os().String()},
1492 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1493 }, prebuiltTag, a.properties.Prebuilts...)
1494
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001495 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1496 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001497
Ulya Trafimovich44561882020-01-03 13:25:54 +00001498 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1499 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1500 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1501 javaLibTag, "jacocoagent")
1502 }
1503
Jiyong Park23c52b02019-02-02 13:13:47 +09001504 if String(a.properties.Key) == "" {
1505 ctx.ModuleErrorf("key is missing")
1506 return
1507 }
1508 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001509
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001510 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001511 if cert != "" {
1512 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001513 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001514
1515 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1516 if len(a.properties.Uses_sdks) > 0 {
1517 sdkRefs := []android.SdkRef{}
1518 for _, str := range a.properties.Uses_sdks {
1519 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1520 sdkRefs = append(sdkRefs, parsed)
1521 }
1522 a.BuildWithSdks(sdkRefs)
1523 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001524}
1525
Jiyong Park5d790c32019-11-15 18:40:32 +09001526func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1527 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1528 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001529 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1530 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001531}
1532
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001533func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1534 // direct deps of an APEX bundle are all part of the APEX bundle
1535 return true
1536}
1537
Colin Cross0ea8ba82019-06-06 14:33:29 -07001538func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001539 moduleName := ctx.ModuleName()
1540 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1541 // we check with the pseudo module name to see if its certificate is overridden.
1542 if a.vndkApex {
1543 moduleName = vndkApexName
1544 }
1545 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001546 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001547 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001548 }
1549 return String(a.properties.Certificate)
1550}
1551
Colin Cross41955e82019-05-29 14:40:35 -07001552func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1553 switch tag {
1554 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001555 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001556 default:
1557 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001558 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001559}
1560
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001561func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001562 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001563}
1564
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001565func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1566 return proptools.Bool(a.properties.Test_only_no_hashtree)
1567}
1568
Dario Frenica913392020-04-27 18:21:11 +01001569func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1570 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1571}
1572
Jiyong Park7c1dc612019-01-05 11:15:24 +09001573func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001574 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001575 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001576 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001577 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001578 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001579 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001580 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001581 }
1582}
1583
Jiyong Parkf97782b2019-02-13 20:28:58 +09001584func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1585 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1586 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1587 }
1588}
1589
Jiyong Park388ef3f2019-01-28 19:47:32 +09001590func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001591 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1592 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001593 }
1594
1595 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001596 globalSanitizerNames := []string{}
1597 if a.Host() {
1598 globalSanitizerNames = ctx.Config().SanitizeHost()
1599 } else {
1600 arches := ctx.Config().SanitizeDeviceArch()
1601 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1602 globalSanitizerNames = ctx.Config().SanitizeDevice()
1603 }
1604 }
1605 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001606}
1607
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001608func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001609 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001610}
1611
1612func (a *apexBundle) PreventInstall() {
1613 a.properties.PreventInstall = true
1614}
1615
1616func (a *apexBundle) HideFromMake() {
1617 a.properties.HideFromMake = true
1618}
1619
Jiyong Park956305c2020-01-09 12:32:06 +09001620func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1621 a.properties.IsCoverageVariant = coverage
1622}
1623
Jiyong Parkf653b052019-11-18 15:39:01 +09001624// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001625func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001626 // Decide the APEX-local directory by the multilib of the library
1627 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001628 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001629 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001630 case "lib32":
1631 dirInApex = "lib"
1632 case "lib64":
1633 dirInApex = "lib64"
1634 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001635 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001636 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001637 }
Jooyung Han35155c42020-02-06 17:33:20 +09001638 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001639 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001640 // Special case for Bionic libs and other libs installed with them. This is
1641 // to prevent those libs from being included in the search path
1642 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1643 // those libs in the Runtime APEX are available via the legacy paths in
1644 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1645 // to the legacy paths and thus will be loaded into the default linker
1646 // namespace (aka "platform" namespace). If the libs are directly in
1647 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1648 // into the runtime linker namespace, which will result in double loading of
1649 // them, which isn't supported.
1650 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001651 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001652
Jiyong Parkf653b052019-11-18 15:39:01 +09001653 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001654 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001655}
1656
Jiyong Park1833cef2019-12-13 13:28:36 +09001657func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001658 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001659 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001660 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001661 }
Jooyung Han35155c42020-02-06 17:33:20 +09001662 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001663 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001664 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001665 af.symlinks = cc.Symlinks()
1666 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001667}
1668
Jiyong Park1833cef2019-12-13 13:28:36 +09001669func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001670 dirInApex := "bin"
1671 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001672 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001673}
Jiyong Park1833cef2019-12-13 13:28:36 +09001674func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001675 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001676 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1677 if err != nil {
1678 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001679 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001680 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001681 fileToCopy := android.PathForOutput(ctx, s)
1682 // NB: Since go binaries are static we don't need the module for anything here, which is
1683 // good since the go tool is a blueprint.Module not an android.Module like we would
1684 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001685 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001686}
1687
Jiyong Park1833cef2019-12-13 13:28:36 +09001688func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001689 dirInApex := filepath.Join("bin", sh.SubDir())
1690 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001691 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001692 af.symlinks = sh.Symlinks()
1693 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001694}
1695
Jooyung Han58f26ab2019-12-18 15:34:32 +09001696// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1697type javaLibrary interface {
1698 android.Module
1699 java.Dependency
1700}
1701
1702func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001703 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001704 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001705 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1706 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1707 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001708}
1709
Jiyong Park1833cef2019-12-13 13:28:36 +09001710func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001711 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1712 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001713 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001714}
1715
atrost6e126252020-01-27 17:01:16 +00001716func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1717 dirInApex := filepath.Join("etc", config.SubDir())
1718 fileToCopy := config.CompatConfig()
1719 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1720}
1721
Jiyong Park1833cef2019-12-13 13:28:36 +09001722func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001723 android.Module
1724 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001725 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001726 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001727 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001728 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001729}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001730 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001731 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001732 appDir = "priv-app"
1733 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001734 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001735 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001736 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1737 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001738 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001739
1740 if app, ok := aapp.(interface {
1741 OverriddenManifestPackageName() string
1742 }); ok {
1743 af.overriddenPackageName = app.OverriddenManifestPackageName()
1744 }
Jiyong Park618922e2020-01-08 13:35:43 +09001745 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001746}
1747
Jiyong Park69aeba92020-04-24 21:16:36 +09001748func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1749 rroDir := "overlay"
1750 dirInApex := filepath.Join(rroDir, rro.Theme())
1751 fileToCopy := rro.OutputFile()
1752 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1753 af.certificate = rro.Certificate()
1754
1755 if a, ok := rro.(interface {
1756 OverriddenManifestPackageName() string
1757 }); ok {
1758 af.overriddenPackageName = a.OverriddenManifestPackageName()
1759 }
1760 return af
1761}
1762
Roland Levillain935639d2019-08-13 14:55:28 +01001763// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1764type flattenedApexContext struct {
1765 android.ModuleContext
1766}
1767
1768func (c *flattenedApexContext) InstallBypassMake() bool {
1769 return true
1770}
1771
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001772// Function called while walking an APEX's payload dependencies.
1773//
1774// Return true if the `to` module should be visited, false otherwise.
1775type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1776
Jiyong Park201cedd2020-02-07 17:25:49 +09001777// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001778func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001779 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001780 am, ok := child.(android.ApexModule)
1781 if !ok || !am.CanHaveApexVariants() {
1782 return false
1783 }
1784
1785 // Check for the direct dependencies that contribute to the payload
1786 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1787 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001788 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001789 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001790 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001791 return false
1792 }
1793
1794 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001795 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001796 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001797 }
1798
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001799 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001800 })
1801}
1802
Jooyung Han03b51852020-02-26 22:45:42 +09001803func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1804 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001805 intVer, err := android.ApiStrToNum(ctx, ver)
1806 if err != nil {
1807 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001808 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001809 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001810}
1811
Paul Duffinc5192442020-03-31 11:31:36 +01001812// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1813// a dependency tag.
1814var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1815
1816func PrettyPrintTag(tag blueprint.DependencyTag) string {
1817 // Use tag's custom String() method if available.
1818 if stringer, ok := tag.(fmt.Stringer); ok {
1819 return stringer.String()
1820 }
1821
1822 // Otherwise, get a default string representation of the tag's struct.
1823 tagString := fmt.Sprintf("%#v", tag)
1824
1825 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1826 tagString = tagCleaner.ReplaceAllString(tagString, "")
1827 return tagString
1828}
1829
Jiyong Park201cedd2020-02-07 17:25:49 +09001830// Ensures that the dependencies are marked as available for this APEX
1831func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1832 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1833 if ctx.Host() || a.testApex || a.vndkApex {
1834 return
1835 }
1836
Jiyong Park58d10902020-03-28 14:43:19 +09001837 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1838 // Requiring them and their transitive depencies with apex_available is not right
1839 // because they just add noise.
1840 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1841 return
1842 }
1843
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001844 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1845 if externalDep {
1846 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1847 return false
1848 }
1849
Jiyong Park201cedd2020-02-07 17:25:49 +09001850 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001851 fromName := ctx.OtherModuleName(from)
1852 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001853
1854 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1855 // do any of its dependencies.
1856 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1857 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1858 return false
1859 }
1860
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001861 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1862 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001863 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001864 message := ""
Paul Duffinc5192442020-03-31 11:31:36 +01001865 tagPath := ctx.GetTagPath()
1866 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1867 walkPath := ctx.GetWalkPath()[1:]
1868 for i, m := range walkPath {
1869 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffindf915ff2020-03-30 17:58:21 +01001870 }
1871 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 +01001872 // Visit this module's dependencies to check and report any issues with their availability.
1873 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001874 })
1875}
1876
Jooyung Han548640b2020-04-27 12:10:30 +09001877func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1878 if proptools.Bool(a.properties.Updatable) {
1879 if String(a.properties.Min_sdk_version) == "" {
1880 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1881 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001882
1883 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001884 }
1885}
1886
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001887func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001888 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1889 switch a.properties.ApexType {
1890 case imageApex:
1891 if buildFlattenedAsDefault {
1892 a.suffix = imageApexSuffix
1893 } else {
1894 a.suffix = ""
1895 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001896
1897 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001898 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001899 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001900 }
1901 case zipApex:
1902 if proptools.String(a.properties.Payload_type) == "zip" {
1903 a.suffix = ""
1904 a.primaryApexType = true
1905 } else {
1906 a.suffix = zipApexSuffix
1907 }
1908 case flattenedApex:
1909 if buildFlattenedAsDefault {
1910 a.suffix = ""
1911 a.primaryApexType = true
1912 } else {
1913 a.suffix = flattenedSuffix
1914 }
Alex Light5098a612018-11-29 17:12:15 -08001915 }
1916
Roland Levillain630846d2019-06-26 12:48:34 +01001917 if len(a.properties.Tests) > 0 && !a.testApex {
1918 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1919 return
1920 }
1921
Jiyong Park0f80c182020-01-31 02:49:53 +09001922 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001923 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001924
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001925 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1926
Jooyung Hane1633032019-08-01 17:41:43 +09001927 // native lib dependencies
1928 var provideNativeLibs []string
1929 var requireNativeLibs []string
1930
Jooyung Han5c998b92019-06-27 11:30:33 +09001931 // Check if "uses" requirements are met with dependent apexBundles
1932 var providedNativeSharedLibs []string
1933 useVendor := proptools.Bool(a.properties.Use_vendor)
1934 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1935 if ctx.OtherModuleDependencyTag(m) != usesTag {
1936 return
1937 }
1938 otherName := ctx.OtherModuleName(m)
1939 other, ok := m.(*apexBundle)
1940 if !ok {
1941 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1942 return
1943 }
1944 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1945 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1946 return
1947 }
1948 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1949 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1950 return
1951 }
1952 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1953 })
1954
Jiyong Parkf653b052019-11-18 15:39:01 +09001955 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001956 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001957 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001958 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001959 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1960 return false
1961 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001962 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001963 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001964 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001965 case sharedLibTag, jniLibTag:
1966 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001967 if c, ok := child.(*cc.Module); ok {
1968 // bootstrap bionic libs are treated as provided by system
1969 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1970 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001971 }
Jooyung Han643adc42020-02-27 13:50:06 +09001972 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1973 fi.isJniLib = isJniLib
1974 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001975 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001976 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001977 propertyName := "native_shared_libs"
1978 if isJniLib {
1979 propertyName = "jni_libs"
1980 }
1981 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001982 }
1983 case executableTag:
1984 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001985 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001986 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001987 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001988 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001989 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001990 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001991 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001992 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001993 } else {
Alex Light778127a2019-02-27 14:19:50 -08001994 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 +09001995 }
1996 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001997 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001998 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001999 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002000 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2001 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002002 filesInfo = append(filesInfo, af)
2003 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002004 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002005 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2006 af := apexFileForJavaLibrary(ctx, sdkLib)
2007 if !af.Ok() {
2008 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2009 return false
2010 }
2011 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002012 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002013 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002014 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002015 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002016 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002017 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002018 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002019 return true // track transitive dependencies
2020 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002021 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002022 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002023 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002024 } else {
2025 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2026 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002027 case rroTag:
2028 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2029 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2030 } else {
2031 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2032 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002033 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002034 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002035 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002036 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2037 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002038 } else {
atrost6e126252020-01-27 17:01:16 +00002039 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002040 }
Roland Levillain630846d2019-06-26 12:48:34 +01002041 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002042 if ccTest, ok := child.(*cc.Module); ok {
2043 if ccTest.IsTestPerSrcAllTestsVariation() {
2044 // Multiple-output test module (where `test_per_src: true`).
2045 //
2046 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2047 // We do not add this variation to `filesInfo`, as it has no output;
2048 // however, we do add the other variations of this module as indirect
2049 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002050 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002051 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002052 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002053 af.class = nativeTest
2054 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002055 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002056 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002057 } else {
2058 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2059 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002060 case keyTag:
2061 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002062 a.private_key_file = key.private_key_file
2063 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002064 } else {
2065 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002066 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002067 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002068 case certificateTag:
2069 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002070 a.container_certificate_file = dep.Certificate.Pem
2071 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002072 } else {
2073 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2074 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002075 case android.PrebuiltDepTag:
2076 // If the prebuilt is force disabled, remember to delete the prebuilt file
2077 // that might have been installed in the previous builds
2078 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2079 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2080 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002081 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002082 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002083 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002084 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002085 // We cannot use a switch statement on `depTag` here as the checked
2086 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002087 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002088 if cc, ok := child.(*cc.Module); ok {
2089 if android.InList(cc.Name(), providedNativeSharedLibs) {
2090 // If we're using a shared library which is provided from other APEX,
2091 // don't include it in this APEX
2092 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002093 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002094 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002095 // If the dependency is a stubs lib, don't include it in this APEX,
2096 // but make sure that the lib is installed on the device.
2097 // In case no APEX is having the lib, the lib is installed to the system
2098 // partition.
2099 //
2100 // Always include if we are a host-apex however since those won't have any
2101 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002102 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2103 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002104 }
Jooyung Hane1633032019-08-01 17:41:43 +09002105 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002106 // Don't track further
2107 return false
2108 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002109 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002110 af.transitiveDep = true
2111 filesInfo = append(filesInfo, af)
2112 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002113 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002114 } else if cc.IsTestPerSrcDepTag(depTag) {
2115 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002116 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002117 // Handle modules created as `test_per_src` variations of a single test module:
2118 // use the name of the generated test binary (`fileToCopy`) instead of the name
2119 // of the original test module (`depName`, shared by all `test_per_src`
2120 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002121 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002122 // these are not considered transitive dep
2123 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002124 filesInfo = append(filesInfo, af)
2125 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002126 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002127 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002128 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2129 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002130 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2131 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2132 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2133 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002134 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffindddd5462020-04-07 15:25:44 +01002135 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002136 }
2137 }
2138 }
2139 return false
2140 })
2141
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002142 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2143 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2144 // via the global boot image config.
2145 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002146 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002147 dirInApex := filepath.Join("javalib", arch.String())
2148 for _, f := range files {
2149 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002150 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002151 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002152 }
2153 }
2154 }
2155
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002156 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002157 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2158 return
2159 }
2160
Jiyong Park8fd61922018-11-08 02:50:25 +09002161 // remove duplicates in filesInfo
2162 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002163 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002164 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002165 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002166 if e, ok := encountered[dest]; !ok {
2167 encountered[dest] = f
2168 } else {
2169 // If a module is directly included and also transitively depended on
2170 // consider it as directly included.
2171 e.transitiveDep = e.transitiveDep && f.transitiveDep
2172 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002173 }
2174 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002175 var result []apexFile
2176 for _, v := range encountered {
2177 result = append(result, v)
2178 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002179 return result
2180 }
2181 filesInfo = removeDup(filesInfo)
2182
2183 // to have consistent build rules
2184 sort.Slice(filesInfo, func(i, j int) bool {
2185 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2186 })
2187
Jiyong Park8fd61922018-11-08 02:50:25 +09002188 a.installDir = android.PathForModuleInstall(ctx, "apex")
2189 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002190
Jooyung Han54aca7b2019-11-20 02:26:02 +09002191 if a.properties.ApexType != zipApex {
2192 if a.properties.File_contexts == nil {
2193 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2194 } else {
2195 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2196 if a.Platform() {
2197 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2198 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2199 }
2200 }
2201 }
2202 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2203 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2204 return
2205 }
2206 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002207 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2208 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2209 // the same library in the system partition, thus effectively sharing the same libraries
2210 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2211 // in the APEX.
2212 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2213 a.installable() &&
2214 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002215
Jiyong Park9d677202020-02-19 16:29:35 +09002216 // We don't need the optimization for updatable APEXes, as it might give false signal
2217 // to the system health when the APEXes are still bundled (b/149805758)
2218 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2219 a.linkToSystemLib = false
2220 }
2221
Jiyong Park638d30e2020-02-26 18:27:19 +09002222 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2223 if ctx.Host() {
2224 a.linkToSystemLib = false
2225 }
2226
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002227 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002228 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2229
2230 a.setCertificateAndPrivateKey(ctx)
2231 if a.properties.ApexType == flattenedApex {
2232 a.buildFlattenedApex(ctx)
2233 } else {
2234 a.buildUnflattenedApex(ctx)
2235 }
2236
Jooyung Han002ab682020-01-08 01:57:58 +09002237 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002238
2239 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002240}
2241
Artur Satayev8cf899a2020-04-15 17:29:42 +01002242// Enforce that Java deps of the apex are using stable SDKs to compile
2243func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2244 // Visit direct deps only. As long as we guarantee top-level deps are using
2245 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2246 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2247 tag := ctx.OtherModuleDependencyTag(module)
2248 switch tag {
2249 case javaLibTag, androidAppTag:
2250 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2251 if err := m.CheckStableSdkVersion(); err != nil {
2252 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2253 }
2254 }
2255 }
2256 })
2257}
2258
Jooyung Han5e9013b2020-03-10 06:23:13 +09002259func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002260 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002261 moduleName = normalizeModuleName(moduleName)
2262
2263 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2264 return true
2265 }
2266
2267 key = android.AvailableToAnyApex
2268 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2269 return true
2270 }
2271
2272 return false
2273}
2274
2275func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002276 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2277 // system. Trim the prefix for the check since they are confusing
2278 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2279 if strings.HasPrefix(moduleName, "libclang_rt.") {
2280 // This module has many arch variants that depend on the product being built.
2281 // We don't want to list them all
2282 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002283 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002284 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002285}
2286
Jooyung Han344d5432019-08-23 11:17:39 +09002287func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002288 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002289 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002290 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002291 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002292 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002293 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2294 })
Alex Light5098a612018-11-29 17:12:15 -08002295 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002296 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002297 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002298 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002299 return module
2300}
Jiyong Park30ca9372019-02-07 16:27:23 +09002301
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002302func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002303 bundle := newApexBundle()
2304 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002305 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002306 return bundle
2307}
2308
Jiyong Parkfce0b422020-02-11 03:56:06 +09002309// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2310// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002311func testApexBundleFactory() android.Module {
2312 bundle := newApexBundle()
2313 bundle.testApex = true
2314 return bundle
2315}
2316
Jiyong Parkfce0b422020-02-11 03:56:06 +09002317// apex packages other modules into an APEX file which is a packaging format for system-level
2318// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002319func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002320 return newApexBundle()
2321}
2322
Jiyong Park30ca9372019-02-07 16:27:23 +09002323//
2324// Defaults
2325//
2326type Defaults struct {
2327 android.ModuleBase
2328 android.DefaultsModuleBase
2329}
2330
Jiyong Park30ca9372019-02-07 16:27:23 +09002331func defaultsFactory() android.Module {
2332 return DefaultsFactory()
2333}
2334
2335func DefaultsFactory(props ...interface{}) android.Module {
2336 module := &Defaults{}
2337
2338 module.AddProperties(props...)
2339 module.AddProperties(
2340 &apexBundleProperties{},
2341 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002342 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002343 )
2344
2345 android.InitDefaultsModule(module)
2346 return module
2347}
Jiyong Park5d790c32019-11-15 18:40:32 +09002348
2349//
2350// OverrideApex
2351//
2352type OverrideApex struct {
2353 android.ModuleBase
2354 android.OverrideModuleBase
2355}
2356
2357func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2358 // All the overrides happen in the base module.
2359}
2360
2361// override_apex is used to create an apex module based on another apex module
2362// by overriding some of its properties.
2363func overrideApexFactory() android.Module {
2364 m := &OverrideApex{}
2365 m.AddProperties(&overridableProperties{})
2366
2367 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2368 android.InitOverrideModule(m)
2369 return m
2370}