blob: cd86eeae38d37ad4c34d17c0c92818599fa5c592 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinf0207962020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Parkfa899442020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
56 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000064 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin404db3f2020-03-06 12:30:13 +000065
66 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067)
68
Paul Duffin404db3f2020-03-06 12:30:13 +000069// Transform the map of apex -> modules to module -> apexes.
70func invertApexWhiteList(m map[string][]string) map[string][]string {
71 r := make(map[string][]string)
72 for apex, modules := range m {
73 for _, module := range modules {
74 r[module] = append(r[module], apex)
75 }
76 }
77 return r
78}
79
80// Retrieve the while list of apexes to which the supplied module belongs.
81func WhitelistedApexAvailable(moduleName string) []string {
82 return inverseApexAvailWl[normalizeModuleName(moduleName)]
83}
84
Anton Hansson5053c292020-01-10 15:12:39 +000085// This is a map from apex to modules, which overrides the
86// apex_available setting for that particular module to make
87// it available for the apex regardless of its setting.
88// TODO(b/147364041): remove this
89func makeApexAvailableWhitelist() map[string][]string {
90 // The "Module separator"s below are employed to minimize merge conflicts.
91 m := make(map[string][]string)
92 //
93 // Module separator
94 //
Paul Duffinc23d9f62020-03-10 13:44:19 +000095 artApexContents := []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090096 "art_cmdlineparser_headers",
97 "art_disassembler_headers",
98 "art_libartbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +090099 "bionic_libc_platform_headers",
100 "core-repackaged-icu4j",
101 "cpp-define-generator-asm-support",
102 "cpp-define-generator-definitions",
103 "crtbegin_dynamic",
104 "crtbegin_dynamic1",
105 "crtbegin_so1",
106 "crtbrand",
Jiyong Parkfa899442020-01-31 02:49:53 +0900107 "dex2oat_headers",
108 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900109 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900110 "javavm_headers",
111 "jni_platform_headers",
112 "libPlatformProperties",
113 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000114 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900115 "libandroidicuinit",
116 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000117 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900118 "libdexfile_all_headers",
119 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000120 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900121 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000122 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900123 "libfdlibm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900124 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000125 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900126 "libicuuc_headers",
127 "libicuuc_stubdata",
128 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900129 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000130 "liblzma",
131 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900132 "libnativebridge-headers",
133 "libnativehelper_header_only",
134 "libnativeloader-headers",
135 "libnpt_headers",
136 "libopenjdkjvmti_headers",
137 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000138 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900139 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000140 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900141 "libv8",
142 "libv8base",
143 "libv8gen",
144 "libv8platform",
145 "libv8sampler",
146 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000147 "libvixl",
148 "libvixld",
149 "libz",
150 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900151 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000152 }
Paul Duffinc23d9f62020-03-10 13:44:19 +0000153 m["com.android.art.debug"] = artApexContents
154 m["com.android.art.release"] = artApexContents
Anton Hansson5053c292020-01-10 15:12:39 +0000155 //
156 // Module separator
157 //
158 m["com.android.bluetooth.updatable"] = []string{
159 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000160 "android.hardware.bluetooth.a2dp@1.0",
161 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900162 "android.hardware.bluetooth@1.0",
163 "android.hardware.bluetooth@1.1",
164 "android.hardware.graphics.bufferqueue@1.0",
165 "android.hardware.graphics.bufferqueue@2.0",
166 "android.hardware.graphics.common@1.0",
167 "android.hardware.graphics.common@1.1",
168 "android.hardware.graphics.common@1.2",
169 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000170 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "android.hidl.token@1.0",
172 "android.hidl.token@1.0-utils",
173 "avrcp-target-service",
174 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900175 "bluetooth-protos-lite",
176 "bluetooth.mapsapi",
177 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900178 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900179 "ipmemorystore-aidl-interfaces-V5-java",
180 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900181 "internal_include_headers",
182 "lib-bt-packets",
183 "lib-bt-packets-avrcp",
184 "lib-bt-packets-base",
185 "libFraunhoferAAC",
186 "libaudio-a2dp-hw-utils",
187 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900188 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000189 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900190 "libbluetooth-types",
191 "libbluetooth-types-header",
192 "libbluetooth_gd",
193 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000194 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 "libbt-audio-hal-interface",
196 "libbt-bta",
197 "libbt-common",
198 "libbt-hci",
199 "libbt-platform-protos-lite",
200 "libbt-protos-lite",
201 "libbt-sbc-decoder",
202 "libbt-sbc-encoder",
203 "libbt-stack",
204 "libbt-utils",
205 "libbtcore",
206 "libbtdevice",
207 "libbte",
208 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000209 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000210 "libevent",
211 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900212 "libg722codec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900213 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900214 "libmedia_headers",
215 "libmodpb64",
216 "libosi",
Jiyong Parkfa899442020-01-31 02:49:53 +0900217 "libstagefright_foundation_headers",
218 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000219 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900220 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000221 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900222 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000223 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900224 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900225 "net-utils-services-common",
226 "netd_aidl_interface-unstable-java",
227 "netd_event_listener_interface-java",
228 "netlink-client",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900229 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900230 "sap-api-java-static",
231 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000232 }
233 //
234 // Module separator
235 //
236 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
237 //
238 // Module separator
239 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900240 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900241 "libnativehelper_header_only",
Jiyong Parkfa899442020-01-31 02:49:53 +0900242 }
Anton Hansson5053c292020-01-10 15:12:39 +0000243 //
244 // Module separator
245 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900246 m["com.android.extservices"] = []string{
247 "flatbuffer_headers",
248 "liblua",
249 "libtextclassifier",
250 "libtextclassifier_hash_static",
251 "libtflite_static",
252 "libutf",
253 "libz_current",
254 "tensorflow_headers",
255 }
256 //
257 // Module separator
258 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900259 m["com.android.neuralnetworks"] = []string{
260 "android.hardware.neuralnetworks@1.0",
261 "android.hardware.neuralnetworks@1.1",
262 "android.hardware.neuralnetworks@1.2",
263 "android.hardware.neuralnetworks@1.3",
264 "android.hidl.allocator@1.0",
265 "android.hidl.memory.token@1.0",
266 "android.hidl.memory@1.0",
267 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900268 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900269 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900270 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900271 "libprocpartition",
272 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900273 }
Anton Hansson5053c292020-01-10 15:12:39 +0000274 //
275 // Module separator
276 //
Anton Hansson5053c292020-01-10 15:12:39 +0000277 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900278 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000279 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900280 "android.hardware.cas@1.0",
281 "android.hardware.configstore-utils",
282 "android.hardware.configstore@1.0",
283 "android.hardware.configstore@1.1",
284 "android.hardware.graphics.allocator@2.0",
285 "android.hardware.graphics.allocator@3.0",
286 "android.hardware.graphics.bufferqueue@1.0",
287 "android.hardware.graphics.bufferqueue@2.0",
288 "android.hardware.graphics.common@1.0",
289 "android.hardware.graphics.common@1.1",
290 "android.hardware.graphics.common@1.2",
291 "android.hardware.graphics.mapper@2.0",
292 "android.hardware.graphics.mapper@2.1",
293 "android.hardware.graphics.mapper@3.0",
294 "android.hardware.media.omx@1.0",
295 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000296 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000297 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900298 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000299 "android.hidl.token@1.0",
300 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900301 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900302 "gl_headers",
303 "libEGL",
304 "libEGL_blobCache",
305 "libEGL_getProcAddress",
306 "libFLAC",
307 "libFLAC-config",
308 "libFLAC-headers",
309 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000310 "libaacextractor",
311 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900312 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900313 "libaudio_system_headers",
314 "libaudioclient",
315 "libaudioclient_headers",
316 "libaudiofoundation",
317 "libaudiofoundation_headers",
318 "libaudiomanager",
319 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000320 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900321 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900322 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900323 "libbluetooth-types-header",
324 "libbufferhub",
325 "libbufferhub_headers",
326 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900327 "libc_malloc_debug_backtrace",
328 "libcamera_client",
329 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900330 "libdexfile_external_headers",
331 "libdexfile_support",
332 "libdvr_headers",
333 "libexpat",
334 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000335 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900336 "libgrallocusage",
337 "libgraphicsenv",
338 "libgui",
339 "libgui_headers",
340 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900341 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900342 "liblzma",
343 "libmath",
344 "libmedia",
345 "libmedia_codeclist",
346 "libmedia_headers",
347 "libmedia_helper",
348 "libmedia_helper_headers",
349 "libmedia_midiiowrapper",
350 "libmedia_omx",
351 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000352 "libmidiextractor",
353 "libmkvextractor",
354 "libmp3extractor",
355 "libmp4extractor",
356 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900357 "libnativebase_headers",
358 "libnativebridge-headers",
359 "libnativebridge_lazy",
360 "libnativeloader-headers",
361 "libnativeloader_lazy",
362 "libnativewindow_headers",
363 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000364 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900365 "libpackagelistparser",
Jiyong Parkfa899442020-01-31 02:49:53 +0900366 "libpdx",
367 "libpdx_default_transport",
368 "libpdx_headers",
369 "libpdx_uds",
Jiyong Parkfa899442020-01-31 02:49:53 +0900370 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000371 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900372 "libspeexresampler",
373 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000374 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900375 "libstagefright_flacdec",
376 "libstagefright_foundation",
377 "libstagefright_foundation_headers",
378 "libstagefright_foundation_without_imemory",
379 "libstagefright_headers",
380 "libstagefright_id3",
381 "libstagefright_metadatautils",
382 "libstagefright_mpeg2extractor",
383 "libstagefright_mpeg2support",
384 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900385 "libui",
386 "libui_headers",
387 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900388 "libvibrator",
389 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000390 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900391 "libwebm",
392 "media_ndk_headers",
393 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000394 "updatable-media",
395 }
396 //
397 // Module separator
398 //
399 m["com.android.media.swcodec"] = []string{
400 "android.frameworks.bufferhub@1.0",
401 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900402 "android.hardware.configstore-utils",
403 "android.hardware.configstore@1.0",
404 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000405 "android.hardware.graphics.allocator@2.0",
406 "android.hardware.graphics.allocator@3.0",
407 "android.hardware.graphics.allocator@4.0",
408 "android.hardware.graphics.bufferqueue@1.0",
409 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900410 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000411 "android.hardware.graphics.common@1.0",
412 "android.hardware.graphics.common@1.1",
413 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000414 "android.hardware.graphics.mapper@2.0",
415 "android.hardware.graphics.mapper@2.1",
416 "android.hardware.graphics.mapper@3.0",
417 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000418 "android.hardware.media.bufferpool@2.0",
419 "android.hardware.media.c2@1.0",
420 "android.hardware.media.c2@1.1",
421 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900422 "android.hardware.media@1.0",
423 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000424 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900425 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000426 "android.hidl.safe_union@1.0",
427 "android.hidl.token@1.0",
428 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900429 "libEGL",
430 "libFLAC",
431 "libFLAC-config",
432 "libFLAC-headers",
433 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900434 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900435 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000437 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900438 "libaudioutils",
439 "libaudioutils_fixedfft",
440 "libavcdec",
441 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000442 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900443 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900444 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900445 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900446 "libbluetooth-types-header",
447 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900448 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000449 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900450 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000451 "libcodec2_hidl@1.0",
452 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900453 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000454 "libcodec2_soft_aacdec",
455 "libcodec2_soft_aacenc",
456 "libcodec2_soft_amrnbdec",
457 "libcodec2_soft_amrnbenc",
458 "libcodec2_soft_amrwbdec",
459 "libcodec2_soft_amrwbenc",
460 "libcodec2_soft_av1dec_gav1",
461 "libcodec2_soft_avcdec",
462 "libcodec2_soft_avcenc",
463 "libcodec2_soft_common",
464 "libcodec2_soft_flacdec",
465 "libcodec2_soft_flacenc",
466 "libcodec2_soft_g711alawdec",
467 "libcodec2_soft_g711mlawdec",
468 "libcodec2_soft_gsmdec",
469 "libcodec2_soft_h263dec",
470 "libcodec2_soft_h263enc",
471 "libcodec2_soft_hevcdec",
472 "libcodec2_soft_hevcenc",
473 "libcodec2_soft_mp3dec",
474 "libcodec2_soft_mpeg2dec",
475 "libcodec2_soft_mpeg4dec",
476 "libcodec2_soft_mpeg4enc",
477 "libcodec2_soft_opusdec",
478 "libcodec2_soft_opusenc",
479 "libcodec2_soft_rawdec",
480 "libcodec2_soft_vorbisdec",
481 "libcodec2_soft_vp8dec",
482 "libcodec2_soft_vp8enc",
483 "libcodec2_soft_vp9dec",
484 "libcodec2_soft_vp9enc",
485 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900486 "libdexfile_support",
487 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000488 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900489 "libfmq",
490 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000491 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900492 "libgrallocusage",
493 "libgraphicsenv",
494 "libgsm",
495 "libgui_bufferqueue_static",
496 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000497 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900498 "libhardware_headers",
499 "libhevcdec",
500 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000501 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900502 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900503 "liblzma",
504 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000505 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900506 "libmedia_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900507 "libmpeg2dec",
508 "libnativebase_headers",
509 "libnativebridge_lazy",
510 "libnativeloader_lazy",
511 "libnativewindow_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900512 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000513 "libscudo_wrapper",
514 "libsfplugin_ccodec_utils",
515 "libspeexresampler",
516 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900517 "libstagefright_amrnbdec",
518 "libstagefright_amrnbenc",
519 "libstagefright_amrwbdec",
520 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000521 "libstagefright_bufferpool@2.0.1",
522 "libstagefright_bufferqueue_helper",
523 "libstagefright_enc_common",
524 "libstagefright_flacdec",
525 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900526 "libstagefright_foundation_headers",
527 "libstagefright_headers",
528 "libstagefright_m4vh263dec",
529 "libstagefright_m4vh263enc",
530 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000531 "libsync",
532 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900533 "libui_headers",
534 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000535 "libvorbisidec",
536 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900537 "libyuv",
538 "libyuv_static",
539 "media_ndk_headers",
540 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000541 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000542 }
543 //
544 // Module separator
545 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900546 m["com.android.mediaprovider"] = []string{
547 "MediaProvider",
548 "MediaProviderGoogle",
549 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900550 "libbase_ndk",
551 "libfuse",
552 "libfuse_jni",
553 "libnativehelper_header_only",
554 }
555 //
556 // Module separator
557 //
558 m["com.android.permission"] = []string{
559 "androidx.annotation_annotation",
560 "androidx.annotation_annotation-nodeps",
561 "androidx.lifecycle_lifecycle-common",
562 "androidx.lifecycle_lifecycle-common-java8",
563 "androidx.lifecycle_lifecycle-common-java8-nodeps",
564 "androidx.lifecycle_lifecycle-common-nodeps",
565 "kotlin-annotations",
566 "kotlin-stdlib",
567 "kotlin-stdlib-jdk7",
568 "kotlin-stdlib-jdk8",
569 "kotlinx-coroutines-android",
570 "kotlinx-coroutines-android-nodeps",
571 "kotlinx-coroutines-core",
572 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900574 "GooglePermissionController",
575 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900576 }
Anton Hansson5053c292020-01-10 15:12:39 +0000577 //
578 // Module separator
579 //
Anton Hansson5053c292020-01-10 15:12:39 +0000580 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900581 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900582 "libarm-optimized-routines-math",
Jiyong Parkfa899442020-01-31 02:49:53 +0900583 "libc_aeabi",
584 "libc_bionic",
585 "libc_bionic_ndk",
586 "libc_bootstrap",
587 "libc_common",
588 "libc_common_shared",
589 "libc_common_static",
590 "libc_dns",
591 "libc_dynamic_dispatch",
592 "libc_fortify",
593 "libc_freebsd",
594 "libc_freebsd_large_stack",
595 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900596 "libc_init_dynamic",
597 "libc_init_static",
598 "libc_jemalloc_wrapper",
599 "libc_netbsd",
600 "libc_nomalloc",
601 "libc_nopthread",
602 "libc_openbsd",
603 "libc_openbsd_large_stack",
604 "libc_openbsd_ndk",
605 "libc_pthread",
606 "libc_static_dispatch",
607 "libc_syscalls",
608 "libc_tzcode",
609 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900610 "libdebuggerd",
611 "libdebuggerd_common_headers",
612 "libdebuggerd_handler_core",
613 "libdebuggerd_handler_fallback",
614 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000615 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900616 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900617 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900618 "libjemalloc5",
619 "liblinker_main",
620 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900621 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000622 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900623 "libprocinfo",
624 "libpropertyinfoparser",
625 "libscudo",
626 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900627 "libsystemproperties",
628 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000629 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900630 "libz",
631 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000632 }
633 //
634 // Module separator
635 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900636 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "libnativehelper_compat_libc++",
638 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900639 "libcgrouprc",
640 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900641 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900642 "libvndksupport",
643 "tethering-aidl-interfaces-java",
644 }
Anton Hansson5053c292020-01-10 15:12:39 +0000645 //
646 // Module separator
647 //
648 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900649 "PlatformProperties",
650 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900651 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900652 "android.hardware.wifi-V1.1-java",
653 "android.hardware.wifi-V1.2-java",
654 "android.hardware.wifi-V1.3-java",
655 "android.hardware.wifi-V1.4-java",
656 "android.hardware.wifi.hostapd-V1.0-java",
657 "android.hardware.wifi.hostapd-V1.1-java",
658 "android.hardware.wifi.hostapd-V1.2-java",
659 "android.hardware.wifi.supplicant-V1.0-java",
660 "android.hardware.wifi.supplicant-V1.1-java",
661 "android.hardware.wifi.supplicant-V1.2-java",
662 "android.hardware.wifi.supplicant-V1.3-java",
663 "android.hidl.base-V1.0-java",
664 "android.hidl.manager-V1.0-java",
665 "android.hidl.manager-V1.1-java",
666 "android.hidl.manager-V1.2-java",
667 "androidx.annotation_annotation",
668 "androidx.annotation_annotation-nodeps",
669 "bouncycastle-unbundled",
670 "dnsresolver_aidl_interface-V2-java",
671 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900672 "framework-wifi-pre-jarjar",
673 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900674 "ipmemorystore-aidl-interfaces-V3-java",
675 "ipmemorystore-aidl-interfaces-java",
676 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900677 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000678 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900679 "net-utils-services-common",
680 "netd_aidl_interface-V2-java",
681 "netd_aidl_interface-unstable-java",
682 "netd_event_listener_interface-java",
683 "netlink-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900684 "networkstack-client",
685 "services.net",
686 "wifi-lite-protos",
687 "wifi-nano-protos",
688 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000689 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900690 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000691 }
692 //
693 // Module separator
694 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900695 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 Parkfa899442020-01-31 02:49:53 +0900704 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900705 }
706 //
707 // Module separator
708 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000709 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900710 "libatomic",
Jiyong Parkfa899442020-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 Parkfa899442020-01-31 02:49:53 +0900718 }
Anton Hansson5053c292020-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 Park6a9ddc32020-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 Han40b286c2020-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 Han40b286c2020-04-17 13:43:10 +0900762 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900763 ApexName: mctx.ModuleName(),
764 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900765 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900766 directDep = true
767 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800768 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900769 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900770 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900771
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800772 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900773 return
774 }
775
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100776 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900777
Jiyong Parkf760cae2020-02-12 07:53:12 +0900778 mctx.VisitDirectDeps(func(child android.Module) {
779 depName := mctx.OtherModuleName(child)
780 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100781 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800782 android.UpdateApexDependency(apexBundles, depName, directDep)
783 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900784 }
785 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900786}
787
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900788// mark if a module cannot be available to platform. A module cannot be available
789// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
790// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
791func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
792 // Host and recovery are not considered as platform
793 if mctx.Host() || mctx.Module().InstallInRecovery() {
794 return
795 }
796
797 if am, ok := mctx.Module().(android.ApexModule); ok {
798 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
799
800 // In a rare case when a lib is marked as available only to an apex
801 // but the apex doesn't exist. This can happen in a partial manifest branch
802 // like master-art. Currently, libstatssocket in the stats APEX is causing
803 // this problem.
804 // Include the lib in platform because the module SDK that ought to provide
805 // it doesn't exist, so it would otherwise be left out completely.
806 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
807 // this check for libraries provided by SDKs.
808 if !availableToPlatform && !android.InAnyApex(am.Name()) {
809 availableToPlatform = true
810 }
811
812 // If any of the dep is not available to platform, this module is also considered
813 // as being not available to platform even if it has "//apex_available:platform"
814 mctx.VisitDirectDeps(func(child android.Module) {
815 if !am.DepIsInSameApex(mctx, child) {
816 // if the dependency crosses apex boundary, don't consider it
817 return
818 }
819 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
820 availableToPlatform = false
821 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
822 }
823 })
824
825 // Exception 1: stub libraries and native bridge libraries are always available to platform
826 if cc, ok := mctx.Module().(*cc.Module); ok &&
827 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
828 availableToPlatform = true
829 }
830
831 // Exception 2: bootstrap bionic libraries are also always available to platform
832 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
833 availableToPlatform = true
834 }
835
836 if !availableToPlatform {
837 am.SetNotAvailableForPlatform()
838 }
839 }
840}
841
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100842// If a module in an APEX depends on a module from an SDK then it needs an APEX
843// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
844func inAnySdk(module android.Module) bool {
845 if sa, ok := module.(android.SdkAware); ok {
846 return sa.IsInAnySdk()
847 }
848
849 return false
850}
851
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900852// Create apex variations if a module is included in APEX(s).
853func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900854 if !mctx.Module().Enabled() {
855 return
856 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900857 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900858 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000859 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900860 // apex bundle itself is mutated so that it and its modules have same
861 // apex variant.
862 apexBundleName := mctx.ModuleName()
863 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900864 } else if o, ok := mctx.Module().(*OverrideApex); ok {
865 apexBundleName := o.GetOverriddenModuleName()
866 if apexBundleName == "" {
867 mctx.ModuleErrorf("base property is not set")
868 return
869 }
870 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900871 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900872
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900873}
Sundong Ahne9b55722019-09-06 17:37:42 +0900874
Jooyung Han7a78a922019-10-08 21:59:58 +0900875var (
876 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
877 apexFileContextsInfosMutex sync.Mutex
878)
879
880func apexFileContextsInfos(config android.Config) *[]string {
881 return config.Once(apexFileContextsInfosKey, func() interface{} {
882 return &[]string{}
883 }).(*[]string)
884}
885
Jooyung Han54aca7b2019-11-20 02:26:02 +0900886func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900887 apexFileContextsInfosMutex.Lock()
888 defer apexFileContextsInfosMutex.Unlock()
889 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900890 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900891}
892
Sundong Ahne9b55722019-09-06 17:37:42 +0900893func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900894 if !mctx.Module().Enabled() {
895 return
896 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900897 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900898 var variants []string
899 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
900 case "image":
901 variants = append(variants, imageApexType, flattenedApexType)
902 case "zip":
903 variants = append(variants, zipApexType)
904 case "both":
905 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
906 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900907 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900908 return
909 }
910
911 modules := mctx.CreateLocalVariations(variants...)
912
913 for i, v := range variants {
914 switch v {
915 case imageApexType:
916 modules[i].(*apexBundle).properties.ApexType = imageApex
917 case zipApexType:
918 modules[i].(*apexBundle).properties.ApexType = zipApex
919 case flattenedApexType:
920 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900921 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900922 modules[i].(*apexBundle).MakeAsSystemExt()
923 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900924 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900925 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900926 } else if _, ok := mctx.Module().(*OverrideApex); ok {
927 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900928 }
929}
930
Jooyung Han5c998b92019-06-27 11:30:33 +0900931func apexUsesMutator(mctx android.BottomUpMutatorContext) {
932 if ab, ok := mctx.Module().(*apexBundle); ok {
933 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
934 }
935}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900936
Jooyung Handc782442019-11-01 03:14:38 +0900937var (
938 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
939)
940
941// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
942// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
943// which may cause compatibility issues. (e.g. libbinder)
944// Even though libbinder restricts its availability via 'apex_available' property and relies on
945// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
946// to avoid similar problems.
947func useVendorWhitelist(config android.Config) []string {
948 return config.Once(useVendorWhitelistKey, func() interface{} {
949 return []string{
950 // swcodec uses "vendor" variants for smaller size
951 "com.android.media.swcodec",
952 "test_com.android.media.swcodec",
953 }
954 }).([]string)
955}
956
957// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
958// called before the first call to useVendorWhitelist()
959func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
960 config.Once(useVendorWhitelistKey, func() interface{} {
961 return whitelist
962 })
963}
964
Alex Light9670d332019-01-29 18:07:33 -0800965type apexNativeDependencies struct {
966 // List of native libraries
967 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900968
Alex Light9670d332019-01-29 18:07:33 -0800969 // List of native executables
970 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900971
Roland Levillain630846d2019-06-26 12:48:34 +0100972 // List of native tests
973 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800974}
Jooyung Han344d5432019-08-23 11:17:39 +0900975
Alex Light9670d332019-01-29 18:07:33 -0800976type apexMultilibProperties struct {
977 // Native dependencies whose compile_multilib is "first"
978 First apexNativeDependencies
979
980 // Native dependencies whose compile_multilib is "both"
981 Both apexNativeDependencies
982
983 // Native dependencies whose compile_multilib is "prefer32"
984 Prefer32 apexNativeDependencies
985
986 // Native dependencies whose compile_multilib is "32"
987 Lib32 apexNativeDependencies
988
989 // Native dependencies whose compile_multilib is "64"
990 Lib64 apexNativeDependencies
991}
992
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900993type apexBundleProperties struct {
994 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000995 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800996 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900997
Jiyong Park40e26a22019-02-08 02:53:06 +0900998 // AndroidManifest.xml file used for the zip container of this APEX bundle.
999 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001000 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001001
Roland Levillain411c5842019-09-19 16:37:20 +01001002 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1003 // device (/apex/<apex_name>).
1004 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001005 Apex_name *string
1006
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001007 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001008 // For platform APEXes, this should points to a file under /system/sepolicy
1009 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1010 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001011
1012 // List of native shared libs that are embedded inside this APEX bundle
1013 Native_shared_libs []string
1014
Roland Levillain630846d2019-06-26 12:48:34 +01001015 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001016 Binaries []string
1017
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
Roland Levillain630846d2019-06-26 12:48:34 +01001024 // List of tests that are embedded inside this APEX bundle
1025 Tests []string
1026
Jiyong Parkff1458f2018-10-12 21:49:38 +09001027 // Name of the apex_key module that provides the private key to sign APEX
1028 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001029
Alex Light5098a612018-11-29 17:12:15 -08001030 // The type of APEX to build. Controls what the APEX payload is. Either
1031 // 'image', 'zip' or 'both'. Default: 'image'.
1032 Payload_type *string
1033
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001034 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1035 // or an android_app_certificate module name in the form ":module".
1036 Certificate *string
1037
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001038 // Whether this APEX is installable to one of the partitions. Default: true.
1039 Installable *bool
1040
Jiyong Parkda6eb592018-12-19 17:12:36 +09001041 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1042 // Default is false.
1043 Use_vendor *bool
1044
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001045 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1046 Ignore_system_library_special_case *bool
1047
Alex Light9670d332019-01-29 18:07:33 -08001048 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001049
Jiyong Parkf97782b2019-02-13 20:28:58 +09001050 // List of sanitizer names that this APEX is enabled for
1051 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001052
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001053 PreventInstall bool `blueprint:"mutated"`
1054
1055 HideFromMake bool `blueprint:"mutated"`
1056
Jooyung Han5c998b92019-06-27 11:30:33 +09001057 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1058 Provide_cpp_shared_libs *bool
1059
1060 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1061 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001062
1063 // A txt file containing list of files that are whitelisted to be included in this APEX.
1064 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001065
Sundong Ahnabb64432019-10-22 13:58:29 +09001066 // package format of this apex variant; could be non-flattened, flattened, or zip.
1067 // imageApex, zipApex or flattened
1068 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001069
Jiyong Parkd1063c12019-07-17 20:08:41 +09001070 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1071 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1072 // is implied. This value affects all modules included in this APEX. In other words, they are
1073 // also built with the SDKs specified here.
1074 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001075
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001076 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1077 // Should be only used in tests#.
1078 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001079
Dario Freni98410fd2020-04-27 18:21:11 +01001080 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1081 // Should be only used in tests#.
1082 Test_only_unsigned_payload *bool
1083
Jiyong Park956305c2020-01-09 12:32:06 +09001084 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001085
1086 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Hanced674e2020-04-27 12:10:30 +09001087 // rules for making sure that the APEX is truly updatable.
1088 // - To be updatable, min_sdk_version should be set as well
1089 // This will also disable the size optimizations like symlinking to the system libs.
1090 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001091 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001092
1093 // The minimum SDK version that this apex must be compatible with.
1094 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001095}
1096
1097type apexTargetBundleProperties struct {
1098 Target struct {
1099 // Multilib properties only for android.
1100 Android struct {
1101 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001102 }
Jooyung Han344d5432019-08-23 11:17:39 +09001103
Alex Light9670d332019-01-29 18:07:33 -08001104 // Multilib properties only for host.
1105 Host struct {
1106 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001107 }
Jooyung Han344d5432019-08-23 11:17:39 +09001108
Alex Light9670d332019-01-29 18:07:33 -08001109 // Multilib properties only for host linux_bionic.
1110 Linux_bionic struct {
1111 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001112 }
Jooyung Han344d5432019-08-23 11:17:39 +09001113
Alex Light9670d332019-01-29 18:07:33 -08001114 // Multilib properties only for host linux_glibc.
1115 Linux_glibc struct {
1116 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001117 }
1118 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001119}
1120
Jiyong Park5d790c32019-11-15 18:40:32 +09001121type overridableProperties struct {
1122 // List of APKs to package inside APEX
1123 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001124
1125 // 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 Uddincb6aa122020-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 Parkaf8998c2020-02-28 16:51:07 +09001229 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001230}
1231
Jiyong Park1833cef2019-12-13 13:28:36 +09001232func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1233 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001234 builtFile: builtFile,
1235 moduleName: moduleName,
1236 installDir: installDir,
1237 class: class,
1238 module: module,
1239 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001240 if module != nil {
1241 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001242 ret.requiredModuleNames = module.RequiredModuleNames()
1243 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1244 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001245 }
1246 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001247}
1248
1249func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001250 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001251}
1252
Jiyong Park7cd10e32020-01-14 09:22:18 +09001253// Path() returns path of this apex file relative to the APEX root
1254func (af *apexFile) Path() string {
1255 return filepath.Join(af.installDir, af.builtFile.Base())
1256}
1257
1258// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1259func (af *apexFile) SymlinkPaths() []string {
1260 var ret []string
1261 for _, symlink := range af.symlinks {
1262 ret = append(ret, filepath.Join(af.installDir, symlink))
1263 }
1264 return ret
1265}
1266
1267func (af *apexFile) AvailableToPlatform() bool {
1268 if af.module == nil {
1269 return false
1270 }
1271 if am, ok := af.module.(android.ApexModule); ok {
1272 return am.AvailableFor(android.AvailableToPlatform)
1273 }
1274 return false
1275}
1276
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001277type apexBundle struct {
1278 android.ModuleBase
1279 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001280 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001281 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001282
Jiyong Park5d790c32019-11-15 18:40:32 +09001283 properties apexBundleProperties
1284 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001285 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001286
Jooyung Hanf21c7972019-12-16 22:32:06 +09001287 // specific to apex_vndk modules
1288 vndkProperties apexVndkProperties
1289
Colin Crossa4925902018-11-16 11:36:28 -08001290 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001291 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001292 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001293
Jiyong Park03b68dd2019-07-26 23:20:40 +09001294 prebuiltFileToDelete string
1295
Jiyong Park42cca6c2019-04-01 11:15:50 +09001296 public_key_file android.Path
1297 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001298
1299 container_certificate_file android.Path
1300 container_private_key_file android.Path
1301
Jooyung Han54aca7b2019-11-20 02:26:02 +09001302 fileContexts android.Path
1303
Jiyong Park8fd61922018-11-08 02:50:25 +09001304 // list of files to be included in this apex
1305 filesInfo []apexFile
1306
Jiyong Park956305c2020-01-09 12:32:06 +09001307 // list of module names that should be installed along with this APEX
1308 requiredDeps []string
1309
Jiyong Park956305c2020-01-09 12:32:06 +09001310 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev334b5172020-04-27 17:08:37 +01001311 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001312
Sundong Ahnabb64432019-10-22 13:58:29 +09001313 testApex bool
1314 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001315 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001316 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001317
Jooyung Han214bf372019-11-12 13:03:50 +09001318 manifestJsonOut android.WritablePath
1319 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001320
Jooyung Han002ab682020-01-08 01:57:58 +09001321 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001322 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001323 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001324 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1325 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001326
1327 // Suffix of module name in Android.mk
1328 // ".flattened", ".apex", ".zipapex", or ""
1329 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001330
1331 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001332
1333 // Whether to create symlink to the system file instead of having a file
1334 // inside the apex or not
1335 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001336
1337 // Struct holding the merged notice file paths in different formats
1338 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001339}
1340
Jiyong Park397e55e2018-10-24 21:09:55 +09001341func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001342 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001343 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001344 // Use *FarVariation* to be able to depend on modules having
1345 // conflicting variations with this module. This is required since
1346 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1347 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001348 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001349 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001350 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001351 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001352 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001353
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001354 ctx.AddFarVariationDependencies(append(target.Variations(),
1355 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1356 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001357
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001358 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001359 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001360 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001361 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001362}
1363
Alex Light9670d332019-01-29 18:07:33 -08001364func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1365 if ctx.Os().Class == android.Device {
1366 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1367 } else {
1368 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1369 if ctx.Os().Bionic() {
1370 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1371 } else {
1372 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1373 }
1374 }
1375}
1376
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001377func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001378 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1379 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1380 }
1381
Jiyong Park397e55e2018-10-24 21:09:55 +09001382 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001383 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001384
1385 a.combineProperties(ctx)
1386
Jiyong Park397e55e2018-10-24 21:09:55 +09001387 has32BitTarget := false
1388 for _, target := range targets {
1389 if target.Arch.ArchType.Multilib == "lib32" {
1390 has32BitTarget = true
1391 }
1392 }
1393 for i, target := range targets {
1394 // When multilib.* is omitted for native_shared_libs, it implies
1395 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001396 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001397 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001398 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001399 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001400
Roland Levillain630846d2019-06-26 12:48:34 +01001401 // When multilib.* is omitted for tests, it implies
1402 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001403 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001404 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001405 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001406 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001407
Jiyong Park397e55e2018-10-24 21:09:55 +09001408 // Add native modules targetting both ABIs
1409 addDependenciesForNativeModules(ctx,
1410 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001411 a.properties.Multilib.Both.Binaries,
1412 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001413 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001414 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001415
Alex Light3d673592019-01-18 14:37:31 -08001416 isPrimaryAbi := i == 0
1417 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001418 // When multilib.* is omitted for binaries, it implies
1419 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001420 ctx.AddFarVariationDependencies(append(target.Variations(),
1421 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1422 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001423
1424 // Add native modules targetting the first ABI
1425 addDependenciesForNativeModules(ctx,
1426 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001427 a.properties.Multilib.First.Binaries,
1428 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001429 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001430 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001431 }
1432
1433 switch target.Arch.ArchType.Multilib {
1434 case "lib32":
1435 // Add native modules targetting 32-bit ABI
1436 addDependenciesForNativeModules(ctx,
1437 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001438 a.properties.Multilib.Lib32.Binaries,
1439 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001440 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001441 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001442
1443 addDependenciesForNativeModules(ctx,
1444 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001445 a.properties.Multilib.Prefer32.Binaries,
1446 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001447 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001448 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001449 case "lib64":
1450 // Add native modules targetting 64-bit ABI
1451 addDependenciesForNativeModules(ctx,
1452 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001453 a.properties.Multilib.Lib64.Binaries,
1454 a.properties.Multilib.Lib64.Tests,
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,
1460 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001461 a.properties.Multilib.Prefer32.Binaries,
1462 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001463 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001464 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001465 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001466
1467 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1468 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1469 if sanitizer == "hwaddress" {
1470 addDependenciesForNativeModules(ctx,
1471 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001472 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001473 break
1474 }
1475 }
1476 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001477 }
1478
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001479 }
1480
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001481 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1482 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1483 // b/144532908
1484 archForPrebuiltEtc := config.Arches()[0]
1485 for _, arch := range config.Arches() {
1486 // Prefer 64-bit arch if there is any
1487 if arch.ArchType.Multilib == "lib64" {
1488 archForPrebuiltEtc = arch
1489 break
1490 }
1491 }
1492 ctx.AddFarVariationDependencies([]blueprint.Variation{
1493 {Mutator: "os", Variation: ctx.Os().String()},
1494 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1495 }, prebuiltTag, a.properties.Prebuilts...)
1496
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001497 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1498 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001499
Ulya Trafimovich44561882020-01-03 13:25:54 +00001500 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1501 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1502 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1503 javaLibTag, "jacocoagent")
1504 }
1505
Jiyong Park23c52b02019-02-02 13:13:47 +09001506 if String(a.properties.Key) == "" {
1507 ctx.ModuleErrorf("key is missing")
1508 return
1509 }
1510 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001511
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001512 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001513 if cert != "" {
1514 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001515 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001516
1517 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1518 if len(a.properties.Uses_sdks) > 0 {
1519 sdkRefs := []android.SdkRef{}
1520 for _, str := range a.properties.Uses_sdks {
1521 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1522 sdkRefs = append(sdkRefs, parsed)
1523 }
1524 a.BuildWithSdks(sdkRefs)
1525 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001526}
1527
Jiyong Park5d790c32019-11-15 18:40:32 +09001528func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1529 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1530 androidAppTag, a.overridableProperties.Apps...)
1531}
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 Freni98410fd2020-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 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001635 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001636 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001637 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001638 }
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 {
Jiyong Parkf653b052019-11-18 15:39:01 +09001658 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
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 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001662 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001663 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001664 af.symlinks = cc.Symlinks()
1665 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001666}
1667
Jiyong Park1833cef2019-12-13 13:28:36 +09001668func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001669 dirInApex := "bin"
1670 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001671 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001672}
Jiyong Park1833cef2019-12-13 13:28:36 +09001673func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001674 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001675 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1676 if err != nil {
1677 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001678 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001679 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 fileToCopy := android.PathForOutput(ctx, s)
1681 // NB: Since go binaries are static we don't need the module for anything here, which is
1682 // good since the go tool is a blueprint.Module not an android.Module like we would
1683 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001684 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001685}
1686
Jiyong Park1833cef2019-12-13 13:28:36 +09001687func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 dirInApex := filepath.Join("bin", sh.SubDir())
1689 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001690 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 af.symlinks = sh.Symlinks()
1692 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001693}
1694
Paul Duffinf299cbe2020-05-14 20:49:32 +01001695func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib java.Dependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001696 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001697 fileToCopy := lib.DexJar()
Paul Duffinf299cbe2020-05-14 20:49:32 +01001698 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001699 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1700 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001701}
1702
Jiyong Park1833cef2019-12-13 13:28:36 +09001703func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001704 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1705 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001706 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001707}
1708
atrost6e126252020-01-27 17:01:16 +00001709func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1710 dirInApex := filepath.Join("etc", config.SubDir())
1711 fileToCopy := config.CompatConfig()
1712 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1713}
1714
Jiyong Park1833cef2019-12-13 13:28:36 +09001715func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001716 android.Module
1717 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001718 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001719 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001720 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001721 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001722}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001723 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001724 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001725 appDir = "priv-app"
1726 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001727 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001728 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001729 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1730 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001731 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001732
1733 if app, ok := aapp.(interface {
1734 OverriddenManifestPackageName() string
1735 }); ok {
1736 af.overriddenPackageName = app.OverriddenManifestPackageName()
1737 }
Jiyong Park618922e2020-01-08 13:35:43 +09001738 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001739}
1740
Roland Levillain935639d2019-08-13 14:55:28 +01001741// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1742type flattenedApexContext struct {
1743 android.ModuleContext
1744}
1745
1746func (c *flattenedApexContext) InstallBypassMake() bool {
1747 return true
1748}
1749
Paul Duffin133608f2020-03-30 15:54:08 +01001750// Function called while walking an APEX's payload dependencies.
1751//
1752// Return true if the `to` module should be visited, false otherwise.
1753type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1754
Jiyong Park201cedd2020-02-07 17:25:49 +09001755// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001756func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001757 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001758 am, ok := child.(android.ApexModule)
1759 if !ok || !am.CanHaveApexVariants() {
1760 return false
1761 }
1762
1763 // Check for the direct dependencies that contribute to the payload
1764 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1765 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001766 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001767 }
Paul Duffin133608f2020-03-30 15:54:08 +01001768 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001769 return false
1770 }
1771
1772 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001773 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001774 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001775 }
1776
Paul Duffin133608f2020-03-30 15:54:08 +01001777 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001778 })
1779}
1780
Jooyung Han0c4e0162020-02-26 22:45:42 +09001781func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1782 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001783 intVer, err := android.ApiStrToNum(ctx, ver)
1784 if err != nil {
1785 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001786 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001787 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001788}
1789
Paul Duffinf0207962020-03-31 11:31:36 +01001790// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1791// a dependency tag.
1792var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1793
1794func PrettyPrintTag(tag blueprint.DependencyTag) string {
1795 // Use tag's custom String() method if available.
1796 if stringer, ok := tag.(fmt.Stringer); ok {
1797 return stringer.String()
1798 }
1799
1800 // Otherwise, get a default string representation of the tag's struct.
1801 tagString := fmt.Sprintf("%#v", tag)
1802
1803 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1804 tagString = tagCleaner.ReplaceAllString(tagString, "")
1805 return tagString
1806}
1807
Jiyong Park201cedd2020-02-07 17:25:49 +09001808// Ensures that the dependencies are marked as available for this APEX
1809func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1810 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1811 if ctx.Host() || a.testApex || a.vndkApex {
1812 return
1813 }
1814
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001815 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1816 // Requiring them and their transitive depencies with apex_available is not right
1817 // because they just add noise.
1818 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1819 return
1820 }
1821
Paul Duffin133608f2020-03-30 15:54:08 +01001822 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1823 if externalDep {
1824 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1825 return false
1826 }
1827
Jiyong Park201cedd2020-02-07 17:25:49 +09001828 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001829 fromName := ctx.OtherModuleName(from)
1830 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001831
1832 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1833 // do any of its dependencies.
1834 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1835 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1836 return false
1837 }
1838
Paul Duffin133608f2020-03-30 15:54:08 +01001839 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1840 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001841 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001842 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001843 tagPath := ctx.GetTagPath()
1844 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1845 walkPath := ctx.GetWalkPath()[1:]
1846 for i, m := range walkPath {
1847 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001848 }
1849 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffin133608f2020-03-30 15:54:08 +01001850 // Visit this module's dependencies to check and report any issues with their availability.
1851 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001852 })
1853}
1854
Jooyung Hanced674e2020-04-27 12:10:30 +09001855func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1856 if proptools.Bool(a.properties.Updatable) {
1857 if String(a.properties.Min_sdk_version) == "" {
1858 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1859 }
Artur Satayev2eedf622020-04-15 17:29:42 +01001860
1861 a.checkJavaStableSdkVersion(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001862 }
1863}
1864
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001865func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001866 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1867 switch a.properties.ApexType {
1868 case imageApex:
1869 if buildFlattenedAsDefault {
1870 a.suffix = imageApexSuffix
1871 } else {
1872 a.suffix = ""
1873 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001874
1875 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001876 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001877 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001878 }
1879 case zipApex:
1880 if proptools.String(a.properties.Payload_type) == "zip" {
1881 a.suffix = ""
1882 a.primaryApexType = true
1883 } else {
1884 a.suffix = zipApexSuffix
1885 }
1886 case flattenedApex:
1887 if buildFlattenedAsDefault {
1888 a.suffix = ""
1889 a.primaryApexType = true
1890 } else {
1891 a.suffix = flattenedSuffix
1892 }
Alex Light5098a612018-11-29 17:12:15 -08001893 }
1894
Roland Levillain630846d2019-06-26 12:48:34 +01001895 if len(a.properties.Tests) > 0 && !a.testApex {
1896 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1897 return
1898 }
1899
Jiyong Parkfa899442020-01-31 02:49:53 +09001900 a.checkApexAvailability(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001901 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001902
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001903 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1904
Jooyung Hane1633032019-08-01 17:41:43 +09001905 // native lib dependencies
1906 var provideNativeLibs []string
1907 var requireNativeLibs []string
1908
Jooyung Han5c998b92019-06-27 11:30:33 +09001909 // Check if "uses" requirements are met with dependent apexBundles
1910 var providedNativeSharedLibs []string
1911 useVendor := proptools.Bool(a.properties.Use_vendor)
1912 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1913 if ctx.OtherModuleDependencyTag(m) != usesTag {
1914 return
1915 }
1916 otherName := ctx.OtherModuleName(m)
1917 other, ok := m.(*apexBundle)
1918 if !ok {
1919 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1920 return
1921 }
1922 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1923 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1924 return
1925 }
1926 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1927 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1928 return
1929 }
1930 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1931 })
1932
Jiyong Parkf653b052019-11-18 15:39:01 +09001933 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001934 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001935 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001936 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01001937 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1938 return false
1939 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001940 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001941 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001942 switch depTag {
1943 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001944 if c, ok := child.(*cc.Module); ok {
1945 // bootstrap bionic libs are treated as provided by system
1946 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1947 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001948 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001949 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001950 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001951 } else {
1952 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001953 }
1954 case executableTag:
1955 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001956 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001957 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001958 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001959 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001960 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001961 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001962 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001963 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001964 } else {
Alex Light778127a2019-02-27 14:19:50 -08001965 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 +09001966 }
1967 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001968 if javaLib, ok := child.(*java.Library); ok {
Paul Duffinf299cbe2020-05-14 20:49:32 +01001969 af := apexFileForJavaLibrary(ctx, javaLib, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001970 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001971 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1972 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001973 filesInfo = append(filesInfo, af)
1974 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001975 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001976 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
Paul Duffinf299cbe2020-05-14 20:49:32 +01001977 af := apexFileForJavaLibrary(ctx, sdkLib, sdkLib)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001978 if !af.Ok() {
1979 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1980 return false
1981 }
1982 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001983 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001984 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001985 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001986 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001987 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001988 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001989 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001990 return true // track transitive dependencies
1991 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001992 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001993 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001994 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001995 } else {
1996 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1997 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001998 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001999 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002000 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002001 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2002 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002003 } else {
atrost6e126252020-01-27 17:01:16 +00002004 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002005 }
Roland Levillain630846d2019-06-26 12:48:34 +01002006 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002007 if ccTest, ok := child.(*cc.Module); ok {
2008 if ccTest.IsTestPerSrcAllTestsVariation() {
2009 // Multiple-output test module (where `test_per_src: true`).
2010 //
2011 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2012 // We do not add this variation to `filesInfo`, as it has no output;
2013 // however, we do add the other variations of this module as indirect
2014 // dependencies (see below).
2015 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002016 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002017 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002018 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002019 af.class = nativeTest
2020 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002021 }
Roland Levillain630846d2019-06-26 12:48:34 +01002022 } else {
2023 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2024 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002025 case keyTag:
2026 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002027 a.private_key_file = key.private_key_file
2028 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002029 } else {
2030 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002031 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002032 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002033 case certificateTag:
2034 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002035 a.container_certificate_file = dep.Certificate.Pem
2036 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002037 } else {
2038 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2039 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002040 case android.PrebuiltDepTag:
2041 // If the prebuilt is force disabled, remember to delete the prebuilt file
2042 // that might have been installed in the previous builds
2043 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2044 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2045 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002046 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002047 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002048 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002049 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002050 // We cannot use a switch statement on `depTag` here as the checked
2051 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002052 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002053 if cc, ok := child.(*cc.Module); ok {
2054 if android.InList(cc.Name(), providedNativeSharedLibs) {
2055 // If we're using a shared library which is provided from other APEX,
2056 // don't include it in this APEX
2057 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002058 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002059 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002060 // If the dependency is a stubs lib, don't include it in this APEX,
2061 // but make sure that the lib is installed on the device.
2062 // In case no APEX is having the lib, the lib is installed to the system
2063 // partition.
2064 //
2065 // Always include if we are a host-apex however since those won't have any
2066 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002067 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2068 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002069 }
Jooyung Hane1633032019-08-01 17:41:43 +09002070 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002071 // Don't track further
2072 return false
2073 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002074 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002075 af.transitiveDep = true
2076 filesInfo = append(filesInfo, af)
2077 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002078 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002079 } else if cc.IsTestPerSrcDepTag(depTag) {
2080 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002081 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002082 // Handle modules created as `test_per_src` variations of a single test module:
2083 // use the name of the generated test binary (`fileToCopy`) instead of the name
2084 // of the original test module (`depName`, shared by all `test_per_src`
2085 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002086 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002087 // these are not considered transitive dep
2088 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002089 filesInfo = append(filesInfo, af)
2090 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002091 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002092 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002093 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2094 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002095 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2096 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2097 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2098 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002099 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002100 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002101 }
2102 }
2103 }
2104 return false
2105 })
2106
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002107 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2108 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2109 // via the global boot image config.
2110 if a.artApex {
2111 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2112 dirInApex := filepath.Join("javalib", arch.String())
2113 for _, f := range files {
2114 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002115 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002116 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002117 }
2118 }
2119 }
2120
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002121 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002122 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2123 return
2124 }
2125
Jiyong Park8fd61922018-11-08 02:50:25 +09002126 // remove duplicates in filesInfo
2127 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002128 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002129 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002130 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002131 if e, ok := encountered[dest]; !ok {
2132 encountered[dest] = f
2133 } else {
2134 // If a module is directly included and also transitively depended on
2135 // consider it as directly included.
2136 e.transitiveDep = e.transitiveDep && f.transitiveDep
2137 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002138 }
2139 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002140 var result []apexFile
2141 for _, v := range encountered {
2142 result = append(result, v)
2143 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002144 return result
2145 }
2146 filesInfo = removeDup(filesInfo)
2147
2148 // to have consistent build rules
2149 sort.Slice(filesInfo, func(i, j int) bool {
2150 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2151 })
2152
Jiyong Park8fd61922018-11-08 02:50:25 +09002153 a.installDir = android.PathForModuleInstall(ctx, "apex")
2154 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002155
Jooyung Han54aca7b2019-11-20 02:26:02 +09002156 if a.properties.ApexType != zipApex {
2157 if a.properties.File_contexts == nil {
2158 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2159 } else {
2160 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2161 if a.Platform() {
2162 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2163 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2164 }
2165 }
2166 }
2167 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2168 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2169 return
2170 }
2171 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002172 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2173 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2174 // the same library in the system partition, thus effectively sharing the same libraries
2175 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2176 // in the APEX.
2177 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2178 a.installable() &&
2179 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002180
Jiyong Park9d677202020-02-19 16:29:35 +09002181 // We don't need the optimization for updatable APEXes, as it might give false signal
2182 // to the system health when the APEXes are still bundled (b/149805758)
2183 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2184 a.linkToSystemLib = false
2185 }
2186
Jiyong Park9b964182020-02-26 18:27:19 +09002187 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2188 if ctx.Host() {
2189 a.linkToSystemLib = false
2190 }
2191
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002192 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002193 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2194
2195 a.setCertificateAndPrivateKey(ctx)
2196 if a.properties.ApexType == flattenedApex {
2197 a.buildFlattenedApex(ctx)
2198 } else {
2199 a.buildUnflattenedApex(ctx)
2200 }
2201
Jooyung Han002ab682020-01-08 01:57:58 +09002202 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002203
2204 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002205}
2206
Artur Satayev2eedf622020-04-15 17:29:42 +01002207// Enforce that Java deps of the apex are using stable SDKs to compile
2208func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2209 // Visit direct deps only. As long as we guarantee top-level deps are using
2210 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2211 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2212 tag := ctx.OtherModuleDependencyTag(module)
2213 switch tag {
2214 case javaLibTag, androidAppTag:
2215 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2216 if err := m.CheckStableSdkVersion(); err != nil {
2217 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2218 }
2219 }
2220 }
2221 })
2222}
2223
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002224func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002225 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002226 moduleName = normalizeModuleName(moduleName)
2227
2228 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2229 return true
2230 }
2231
2232 key = android.AvailableToAnyApex
2233 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2234 return true
2235 }
2236
2237 return false
2238}
2239
2240func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002241 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2242 // system. Trim the prefix for the check since they are confusing
2243 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2244 if strings.HasPrefix(moduleName, "libclang_rt.") {
2245 // This module has many arch variants that depend on the product being built.
2246 // We don't want to list them all
2247 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002248 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002249 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002250}
2251
Jooyung Han344d5432019-08-23 11:17:39 +09002252func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002253 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002254 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002255 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002256 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002257 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002258 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2259 })
Alex Light5098a612018-11-29 17:12:15 -08002260 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002261 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002262 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002263 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002264 return module
2265}
Jiyong Park30ca9372019-02-07 16:27:23 +09002266
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002267func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002268 bundle := newApexBundle()
2269 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002270 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002271 return bundle
2272}
2273
Jiyong Parkfce0b422020-02-11 03:56:06 +09002274// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2275// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002276func testApexBundleFactory() android.Module {
2277 bundle := newApexBundle()
2278 bundle.testApex = true
2279 return bundle
2280}
2281
Jiyong Parkfce0b422020-02-11 03:56:06 +09002282// apex packages other modules into an APEX file which is a packaging format for system-level
2283// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002284func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002285 return newApexBundle()
2286}
2287
Jiyong Park30ca9372019-02-07 16:27:23 +09002288//
2289// Defaults
2290//
2291type Defaults struct {
2292 android.ModuleBase
2293 android.DefaultsModuleBase
2294}
2295
Jiyong Park30ca9372019-02-07 16:27:23 +09002296func defaultsFactory() android.Module {
2297 return DefaultsFactory()
2298}
2299
2300func DefaultsFactory(props ...interface{}) android.Module {
2301 module := &Defaults{}
2302
2303 module.AddProperties(props...)
2304 module.AddProperties(
2305 &apexBundleProperties{},
2306 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002307 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002308 )
2309
2310 android.InitDefaultsModule(module)
2311 return module
2312}
Jiyong Park5d790c32019-11-15 18:40:32 +09002313
2314//
2315// OverrideApex
2316//
2317type OverrideApex struct {
2318 android.ModuleBase
2319 android.OverrideModuleBase
2320}
2321
2322func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2323 // All the overrides happen in the base module.
2324}
2325
2326// override_apex is used to create an apex module based on another apex module
2327// by overriding some of its properties.
2328func overrideApexFactory() android.Module {
2329 m := &OverrideApex{}
2330 m.AddProperties(&overridableProperties{})
2331
2332 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2333 android.InitOverrideModule(m)
2334 return m
2335}