blob: 34b5595b45c8a587284328b27e6637ac9af80032 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinf0207962020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Parkfa899442020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
56 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000064 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin404db3f2020-03-06 12:30:13 +000065
66 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067)
68
Paul Duffin404db3f2020-03-06 12:30:13 +000069// Transform the map of apex -> modules to module -> apexes.
70func invertApexWhiteList(m map[string][]string) map[string][]string {
71 r := make(map[string][]string)
72 for apex, modules := range m {
73 for _, module := range modules {
74 r[module] = append(r[module], apex)
75 }
76 }
77 return r
78}
79
80// Retrieve the while list of apexes to which the supplied module belongs.
81func WhitelistedApexAvailable(moduleName string) []string {
82 return inverseApexAvailWl[normalizeModuleName(moduleName)]
83}
84
Anton Hansson5053c292020-01-10 15:12:39 +000085// This is a map from apex to modules, which overrides the
86// apex_available setting for that particular module to make
87// it available for the apex regardless of its setting.
88// TODO(b/147364041): remove this
89func makeApexAvailableWhitelist() map[string][]string {
90 // The "Module separator"s below are employed to minimize merge conflicts.
91 m := make(map[string][]string)
92 //
93 // Module separator
94 //
Jiyong Park8b399192020-04-29 22:34:13 +090095 m["com.android.appsearch"] = []string{
96 "icing-java-proto-lite",
97 "libprotobuf-java-lite",
Anton Hansson5053c292020-01-10 15:12:39 +000098 }
99 //
100 // Module separator
101 //
102 m["com.android.bluetooth.updatable"] = []string{
103 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000104 "android.hardware.bluetooth.a2dp@1.0",
105 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900106 "android.hardware.bluetooth@1.0",
107 "android.hardware.bluetooth@1.1",
108 "android.hardware.graphics.bufferqueue@1.0",
109 "android.hardware.graphics.bufferqueue@2.0",
110 "android.hardware.graphics.common@1.0",
111 "android.hardware.graphics.common@1.1",
112 "android.hardware.graphics.common@1.2",
113 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000114 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900115 "android.hidl.token@1.0",
116 "android.hidl.token@1.0-utils",
117 "avrcp-target-service",
118 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900119 "bluetooth-protos-lite",
120 "bluetooth.mapsapi",
121 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900122 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900123 "ipmemorystore-aidl-interfaces-V5-java",
124 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900125 "internal_include_headers",
126 "lib-bt-packets",
127 "lib-bt-packets-avrcp",
128 "lib-bt-packets-base",
129 "libFraunhoferAAC",
130 "libaudio-a2dp-hw-utils",
131 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900132 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000133 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900134 "libbluetooth-types",
135 "libbluetooth-types-header",
136 "libbluetooth_gd",
137 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000138 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900139 "libbt-audio-hal-interface",
140 "libbt-bta",
141 "libbt-common",
142 "libbt-hci",
143 "libbt-platform-protos-lite",
144 "libbt-protos-lite",
145 "libbt-sbc-decoder",
146 "libbt-sbc-encoder",
147 "libbt-stack",
148 "libbt-utils",
149 "libbtcore",
150 "libbtdevice",
151 "libbte",
152 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000153 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000154 "libevent",
155 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900156 "libg722codec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900157 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900158 "libmedia_headers",
159 "libmodpb64",
160 "libosi",
Jiyong Parkfa899442020-01-31 02:49:53 +0900161 "libstagefright_foundation_headers",
162 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000163 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900164 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000165 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900166 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000167 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900168 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900169 "net-utils-services-common",
170 "netd_aidl_interface-unstable-java",
171 "netd_event_listener_interface-java",
172 "netlink-client",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900173 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900174 "sap-api-java-static",
175 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000176 }
177 //
178 // Module separator
179 //
180 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
181 //
182 // Module separator
183 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900184 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900185 "libnativehelper_header_only",
Jiyong Parkfa899442020-01-31 02:49:53 +0900186 }
Anton Hansson5053c292020-01-10 15:12:39 +0000187 //
188 // Module separator
189 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900190 m["com.android.extservices"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900191 "error_prone_annotations",
192 "ExtServices-core",
193 "ExtServices",
194 "libtextclassifier-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 "libz_current",
Jooyung Han11c20932020-05-19 15:47:01 +0900196 "textclassifier-statsd",
197 "TextClassifierNotificationLibNoManifest",
198 "TextClassifierServiceLibNoManifest",
Jiyong Parkfa899442020-01-31 02:49:53 +0900199 }
200 //
201 // Module separator
202 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900203 m["com.android.neuralnetworks"] = []string{
204 "android.hardware.neuralnetworks@1.0",
205 "android.hardware.neuralnetworks@1.1",
206 "android.hardware.neuralnetworks@1.2",
207 "android.hardware.neuralnetworks@1.3",
208 "android.hidl.allocator@1.0",
209 "android.hidl.memory.token@1.0",
210 "android.hidl.memory@1.0",
211 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900212 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900213 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900214 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libprocpartition",
216 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900217 }
Anton Hansson5053c292020-01-10 15:12:39 +0000218 //
219 // Module separator
220 //
Anton Hansson5053c292020-01-10 15:12:39 +0000221 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900222 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000223 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900224 "android.hardware.cas@1.0",
225 "android.hardware.configstore-utils",
226 "android.hardware.configstore@1.0",
227 "android.hardware.configstore@1.1",
228 "android.hardware.graphics.allocator@2.0",
229 "android.hardware.graphics.allocator@3.0",
230 "android.hardware.graphics.bufferqueue@1.0",
231 "android.hardware.graphics.bufferqueue@2.0",
232 "android.hardware.graphics.common@1.0",
233 "android.hardware.graphics.common@1.1",
234 "android.hardware.graphics.common@1.2",
235 "android.hardware.graphics.mapper@2.0",
236 "android.hardware.graphics.mapper@2.1",
237 "android.hardware.graphics.mapper@3.0",
238 "android.hardware.media.omx@1.0",
239 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000240 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000241 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900242 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000243 "android.hidl.token@1.0",
244 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900245 "bionic_libc_platform_headers",
Jooyung Han11c20932020-05-19 15:47:01 +0900246 "exoplayer2-extractor",
247 "exoplayer2-extractor-annotation-stubs",
Jiyong Parkfa899442020-01-31 02:49:53 +0900248 "gl_headers",
Jooyung Han11c20932020-05-19 15:47:01 +0900249 "jsr305",
Jiyong Parkfa899442020-01-31 02:49:53 +0900250 "libEGL",
251 "libEGL_blobCache",
252 "libEGL_getProcAddress",
253 "libFLAC",
254 "libFLAC-config",
255 "libFLAC-headers",
256 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000257 "libaacextractor",
258 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900259 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900260 "libaudio_system_headers",
261 "libaudioclient",
262 "libaudioclient_headers",
263 "libaudiofoundation",
264 "libaudiofoundation_headers",
265 "libaudiomanager",
266 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000267 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900268 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900269 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900270 "libbluetooth-types-header",
271 "libbufferhub",
272 "libbufferhub_headers",
273 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900274 "libc_malloc_debug_backtrace",
275 "libcamera_client",
276 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900277 "libdexfile_external_headers",
278 "libdexfile_support",
279 "libdvr_headers",
280 "libexpat",
281 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000282 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900283 "libgrallocusage",
284 "libgraphicsenv",
285 "libgui",
286 "libgui_headers",
287 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900288 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900289 "liblzma",
290 "libmath",
291 "libmedia",
292 "libmedia_codeclist",
293 "libmedia_headers",
294 "libmedia_helper",
295 "libmedia_helper_headers",
296 "libmedia_midiiowrapper",
297 "libmedia_omx",
298 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000299 "libmidiextractor",
300 "libmkvextractor",
301 "libmp3extractor",
302 "libmp4extractor",
303 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900304 "libnativebase_headers",
305 "libnativebridge-headers",
306 "libnativebridge_lazy",
307 "libnativeloader-headers",
308 "libnativeloader_lazy",
309 "libnativewindow_headers",
310 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000311 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900312 "libpackagelistparser",
Jiyong Parkfa899442020-01-31 02:49:53 +0900313 "libpdx",
314 "libpdx_default_transport",
315 "libpdx_headers",
316 "libpdx_uds",
Jiyong Parkfa899442020-01-31 02:49:53 +0900317 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000318 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900319 "libspeexresampler",
320 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000321 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900322 "libstagefright_flacdec",
323 "libstagefright_foundation",
324 "libstagefright_foundation_headers",
325 "libstagefright_foundation_without_imemory",
326 "libstagefright_headers",
327 "libstagefright_id3",
328 "libstagefright_metadatautils",
329 "libstagefright_mpeg2extractor",
330 "libstagefright_mpeg2support",
331 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900332 "libui",
333 "libui_headers",
334 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900335 "libvibrator",
336 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000337 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900338 "libwebm",
339 "media_ndk_headers",
340 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000341 "updatable-media",
342 }
343 //
344 // Module separator
345 //
346 m["com.android.media.swcodec"] = []string{
347 "android.frameworks.bufferhub@1.0",
348 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900349 "android.hardware.configstore-utils",
350 "android.hardware.configstore@1.0",
351 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000352 "android.hardware.graphics.allocator@2.0",
353 "android.hardware.graphics.allocator@3.0",
354 "android.hardware.graphics.allocator@4.0",
355 "android.hardware.graphics.bufferqueue@1.0",
356 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900357 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000358 "android.hardware.graphics.common@1.0",
359 "android.hardware.graphics.common@1.1",
360 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000361 "android.hardware.graphics.mapper@2.0",
362 "android.hardware.graphics.mapper@2.1",
363 "android.hardware.graphics.mapper@3.0",
364 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000365 "android.hardware.media.bufferpool@2.0",
366 "android.hardware.media.c2@1.0",
367 "android.hardware.media.c2@1.1",
368 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900369 "android.hardware.media@1.0",
370 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000371 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900372 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000373 "android.hidl.safe_union@1.0",
374 "android.hidl.token@1.0",
375 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900376 "libEGL",
377 "libFLAC",
378 "libFLAC-config",
379 "libFLAC-headers",
380 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900381 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900382 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900383 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000384 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900385 "libaudioutils",
386 "libaudioutils_fixedfft",
387 "libavcdec",
388 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000389 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900390 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900391 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900392 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900393 "libbluetooth-types-header",
394 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900395 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000396 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900397 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000398 "libcodec2_hidl@1.0",
399 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900400 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000401 "libcodec2_soft_aacdec",
402 "libcodec2_soft_aacenc",
403 "libcodec2_soft_amrnbdec",
404 "libcodec2_soft_amrnbenc",
405 "libcodec2_soft_amrwbdec",
406 "libcodec2_soft_amrwbenc",
407 "libcodec2_soft_av1dec_gav1",
408 "libcodec2_soft_avcdec",
409 "libcodec2_soft_avcenc",
410 "libcodec2_soft_common",
411 "libcodec2_soft_flacdec",
412 "libcodec2_soft_flacenc",
413 "libcodec2_soft_g711alawdec",
414 "libcodec2_soft_g711mlawdec",
415 "libcodec2_soft_gsmdec",
416 "libcodec2_soft_h263dec",
417 "libcodec2_soft_h263enc",
418 "libcodec2_soft_hevcdec",
419 "libcodec2_soft_hevcenc",
420 "libcodec2_soft_mp3dec",
421 "libcodec2_soft_mpeg2dec",
422 "libcodec2_soft_mpeg4dec",
423 "libcodec2_soft_mpeg4enc",
424 "libcodec2_soft_opusdec",
425 "libcodec2_soft_opusenc",
426 "libcodec2_soft_rawdec",
427 "libcodec2_soft_vorbisdec",
428 "libcodec2_soft_vp8dec",
429 "libcodec2_soft_vp8enc",
430 "libcodec2_soft_vp9dec",
431 "libcodec2_soft_vp9enc",
432 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900433 "libdexfile_support",
434 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000435 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libfmq",
437 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000438 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900439 "libgrallocusage",
440 "libgraphicsenv",
441 "libgsm",
442 "libgui_bufferqueue_static",
443 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000444 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900445 "libhardware_headers",
446 "libhevcdec",
447 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000448 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900449 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900450 "liblzma",
451 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000452 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900453 "libmedia_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900454 "libmpeg2dec",
455 "libnativebase_headers",
456 "libnativebridge_lazy",
457 "libnativeloader_lazy",
458 "libnativewindow_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900459 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000460 "libscudo_wrapper",
461 "libsfplugin_ccodec_utils",
462 "libspeexresampler",
463 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900464 "libstagefright_amrnbdec",
465 "libstagefright_amrnbenc",
466 "libstagefright_amrwbdec",
467 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000468 "libstagefright_bufferpool@2.0.1",
469 "libstagefright_bufferqueue_helper",
470 "libstagefright_enc_common",
471 "libstagefright_flacdec",
472 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900473 "libstagefright_foundation_headers",
474 "libstagefright_headers",
475 "libstagefright_m4vh263dec",
476 "libstagefright_m4vh263enc",
477 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000478 "libsync",
479 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900480 "libui_headers",
481 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000482 "libvorbisidec",
483 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900484 "libyuv",
485 "libyuv_static",
486 "media_ndk_headers",
487 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000488 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000489 }
490 //
491 // Module separator
492 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900493 m["com.android.mediaprovider"] = []string{
494 "MediaProvider",
495 "MediaProviderGoogle",
496 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900497 "libbase_ndk",
498 "libfuse",
499 "libfuse_jni",
500 "libnativehelper_header_only",
501 }
502 //
503 // Module separator
504 //
505 m["com.android.permission"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900506 "car-ui-lib",
507 "iconloader",
Jiyong Parkfa899442020-01-31 02:49:53 +0900508 "kotlin-annotations",
509 "kotlin-stdlib",
510 "kotlin-stdlib-jdk7",
511 "kotlin-stdlib-jdk8",
512 "kotlinx-coroutines-android",
513 "kotlinx-coroutines-android-nodeps",
514 "kotlinx-coroutines-core",
515 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900516 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900517 "GooglePermissionController",
518 "PermissionController",
Jooyung Han11c20932020-05-19 15:47:01 +0900519 "SettingsLibActionBarShadow",
520 "SettingsLibAppPreference",
521 "SettingsLibBarChartPreference",
522 "SettingsLibLayoutPreference",
523 "SettingsLibProgressBar",
524 "SettingsLibSearchWidget",
525 "SettingsLibSettingsTheme",
526 "SettingsLibRestrictedLockUtils",
527 "SettingsLibHelpUtils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900528 }
Anton Hansson5053c292020-01-10 15:12:39 +0000529 //
530 // Module separator
531 //
Anton Hansson5053c292020-01-10 15:12:39 +0000532 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900533 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900534 "libarm-optimized-routines-math",
Jiyong Parkfa899442020-01-31 02:49:53 +0900535 "libc_aeabi",
536 "libc_bionic",
537 "libc_bionic_ndk",
538 "libc_bootstrap",
539 "libc_common",
540 "libc_common_shared",
541 "libc_common_static",
542 "libc_dns",
543 "libc_dynamic_dispatch",
544 "libc_fortify",
545 "libc_freebsd",
546 "libc_freebsd_large_stack",
547 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900548 "libc_init_dynamic",
549 "libc_init_static",
550 "libc_jemalloc_wrapper",
551 "libc_netbsd",
552 "libc_nomalloc",
553 "libc_nopthread",
554 "libc_openbsd",
555 "libc_openbsd_large_stack",
556 "libc_openbsd_ndk",
557 "libc_pthread",
558 "libc_static_dispatch",
559 "libc_syscalls",
560 "libc_tzcode",
561 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900562 "libdebuggerd",
563 "libdebuggerd_common_headers",
564 "libdebuggerd_handler_core",
565 "libdebuggerd_handler_fallback",
566 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000567 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900568 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900569 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900570 "libjemalloc5",
571 "liblinker_main",
572 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000574 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900575 "libprocinfo",
576 "libpropertyinfoparser",
577 "libscudo",
578 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900579 "libsystemproperties",
580 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000581 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900582 "libz",
583 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000584 }
585 //
586 // Module separator
587 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900588 m["com.android.tethering"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900589 "android.hardware.tetheroffload.config-V1.0-java",
590 "android.hardware.tetheroffload.control-V1.0-java",
591 "android.hidl.base-V1.0-java",
592 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900593 "libcgrouprc",
594 "libcgrouprc_format",
Jooyung Han11c20932020-05-19 15:47:01 +0900595 "libnativehelper_compat_libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900596 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900597 "libvndksupport",
Jooyung Han11c20932020-05-19 15:47:01 +0900598 "net-utils-framework-common",
599 "netd_aidl_interface-V3-java",
600 "netlink-client",
601 "networkstack-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900602 "tethering-aidl-interfaces-java",
Jooyung Han11c20932020-05-19 15:47:01 +0900603 "TetheringApiCurrentLib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900604 }
Anton Hansson5053c292020-01-10 15:12:39 +0000605 //
606 // Module separator
607 //
608 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900609 "PlatformProperties",
610 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900611 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900612 "android.hardware.wifi-V1.1-java",
613 "android.hardware.wifi-V1.2-java",
614 "android.hardware.wifi-V1.3-java",
615 "android.hardware.wifi-V1.4-java",
616 "android.hardware.wifi.hostapd-V1.0-java",
617 "android.hardware.wifi.hostapd-V1.1-java",
618 "android.hardware.wifi.hostapd-V1.2-java",
619 "android.hardware.wifi.supplicant-V1.0-java",
620 "android.hardware.wifi.supplicant-V1.1-java",
621 "android.hardware.wifi.supplicant-V1.2-java",
622 "android.hardware.wifi.supplicant-V1.3-java",
623 "android.hidl.base-V1.0-java",
624 "android.hidl.manager-V1.0-java",
625 "android.hidl.manager-V1.1-java",
626 "android.hidl.manager-V1.2-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900627 "bouncycastle-unbundled",
628 "dnsresolver_aidl_interface-V2-java",
629 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900630 "framework-wifi-pre-jarjar",
631 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900632 "ipmemorystore-aidl-interfaces-V3-java",
633 "ipmemorystore-aidl-interfaces-java",
634 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900635 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000636 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "net-utils-services-common",
638 "netd_aidl_interface-V2-java",
639 "netd_aidl_interface-unstable-java",
640 "netd_event_listener_interface-java",
641 "netlink-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900642 "networkstack-client",
643 "services.net",
644 "wifi-lite-protos",
645 "wifi-nano-protos",
646 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000647 "wifi-service-resources",
648 }
649 //
650 // Module separator
651 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900652 m["com.android.sdkext"] = []string{
653 "fmtlib_ndk",
654 "libbase_ndk",
655 "libprotobuf-cpp-lite-ndk",
656 }
657 //
658 // Module separator
659 //
660 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900661 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900662 }
663 //
664 // Module separator
665 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000666 m[android.AvailableToAnyApex] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900667 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
668 "androidx",
669 "androidx-constraintlayout_constraintlayout",
670 "androidx-constraintlayout_constraintlayout-nodeps",
671 "androidx-constraintlayout_constraintlayout-solver",
672 "androidx-constraintlayout_constraintlayout-solver-nodeps",
673 "com.google.android.material_material",
674 "com.google.android.material_material-nodeps",
675
Jiyong Parkfa899442020-01-31 02:49:53 +0900676 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900677 "libclang_rt",
678 "libgcc_stripped",
679 "libprofile-clang-extras",
680 "libprofile-clang-extras_ndk",
681 "libprofile-extras",
682 "libprofile-extras_ndk",
683 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900684 }
Anton Hansson5053c292020-01-10 15:12:39 +0000685 return m
686}
687
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900688func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900689 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800690 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900691 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900692 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700693 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900694 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700695 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900696
Jooyung Han31c470b2019-10-18 16:26:59 +0900697 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900698 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900699
700 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
701 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
702 sort.Strings(*apexFileContextsInfos)
703 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
704 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900705}
706
Jooyung Han31c470b2019-10-18 16:26:59 +0900707func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
708 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
709 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
710}
711
Jiyong Parkd1063c12019-07-17 20:08:41 +0900712func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900713 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900714 ctx.BottomUp("apex", apexMutator).Parallel()
715 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
716 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900717 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900718}
719
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900720// Mark the direct and transitive dependencies of apex bundles so that they
721// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900722func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900723 if !mctx.Module().Enabled() {
724 return
725 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800726 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900727 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000728 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900729 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900730 ApexName: mctx.ModuleName(),
731 MinSdkVersion: a.minSdkVersion(mctx),
Artur Satayev2b4b7bb2020-04-28 14:57:42 +0100732 Updatable: a.Updatable(),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900733 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900734 directDep = true
735 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800736 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900737 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900738 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900739
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800740 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900741 return
742 }
743
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100744 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900745
Jiyong Parkf760cae2020-02-12 07:53:12 +0900746 mctx.VisitDirectDeps(func(child android.Module) {
747 depName := mctx.OtherModuleName(child)
748 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100749 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800750 android.UpdateApexDependency(apexBundles, depName, directDep)
751 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900752 }
753 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900754}
755
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900756// mark if a module cannot be available to platform. A module cannot be available
757// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
758// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
759func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
760 // Host and recovery are not considered as platform
761 if mctx.Host() || mctx.Module().InstallInRecovery() {
762 return
763 }
764
765 if am, ok := mctx.Module().(android.ApexModule); ok {
766 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
767
768 // In a rare case when a lib is marked as available only to an apex
769 // but the apex doesn't exist. This can happen in a partial manifest branch
770 // like master-art. Currently, libstatssocket in the stats APEX is causing
771 // this problem.
772 // Include the lib in platform because the module SDK that ought to provide
773 // it doesn't exist, so it would otherwise be left out completely.
774 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
775 // this check for libraries provided by SDKs.
776 if !availableToPlatform && !android.InAnyApex(am.Name()) {
777 availableToPlatform = true
778 }
779
780 // If any of the dep is not available to platform, this module is also considered
781 // as being not available to platform even if it has "//apex_available:platform"
782 mctx.VisitDirectDeps(func(child android.Module) {
783 if !am.DepIsInSameApex(mctx, child) {
784 // if the dependency crosses apex boundary, don't consider it
785 return
786 }
787 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
788 availableToPlatform = false
789 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
790 }
791 })
792
793 // Exception 1: stub libraries and native bridge libraries are always available to platform
794 if cc, ok := mctx.Module().(*cc.Module); ok &&
795 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
796 availableToPlatform = true
797 }
798
799 // Exception 2: bootstrap bionic libraries are also always available to platform
800 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
801 availableToPlatform = true
802 }
803
804 if !availableToPlatform {
805 am.SetNotAvailableForPlatform()
806 }
807 }
808}
809
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100810// If a module in an APEX depends on a module from an SDK then it needs an APEX
811// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
812func inAnySdk(module android.Module) bool {
813 if sa, ok := module.(android.SdkAware); ok {
814 return sa.IsInAnySdk()
815 }
816
817 return false
818}
819
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900820// Create apex variations if a module is included in APEX(s).
821func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900822 if !mctx.Module().Enabled() {
823 return
824 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900825 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900826 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000827 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900828 // apex bundle itself is mutated so that it and its modules have same
829 // apex variant.
830 apexBundleName := mctx.ModuleName()
831 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900832 } else if o, ok := mctx.Module().(*OverrideApex); ok {
833 apexBundleName := o.GetOverriddenModuleName()
834 if apexBundleName == "" {
835 mctx.ModuleErrorf("base property is not set")
836 return
837 }
838 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900839 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900840
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900841}
Sundong Ahne9b55722019-09-06 17:37:42 +0900842
Jooyung Han7a78a922019-10-08 21:59:58 +0900843var (
844 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
845 apexFileContextsInfosMutex sync.Mutex
846)
847
848func apexFileContextsInfos(config android.Config) *[]string {
849 return config.Once(apexFileContextsInfosKey, func() interface{} {
850 return &[]string{}
851 }).(*[]string)
852}
853
Jooyung Han54aca7b2019-11-20 02:26:02 +0900854func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900855 apexFileContextsInfosMutex.Lock()
856 defer apexFileContextsInfosMutex.Unlock()
857 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900858 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900859}
860
Sundong Ahne9b55722019-09-06 17:37:42 +0900861func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900862 if !mctx.Module().Enabled() {
863 return
864 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900865 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900866 var variants []string
867 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
868 case "image":
869 variants = append(variants, imageApexType, flattenedApexType)
870 case "zip":
871 variants = append(variants, zipApexType)
872 case "both":
873 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
874 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900875 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900876 return
877 }
878
879 modules := mctx.CreateLocalVariations(variants...)
880
881 for i, v := range variants {
882 switch v {
883 case imageApexType:
884 modules[i].(*apexBundle).properties.ApexType = imageApex
885 case zipApexType:
886 modules[i].(*apexBundle).properties.ApexType = zipApex
887 case flattenedApexType:
888 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900889 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900890 modules[i].(*apexBundle).MakeAsSystemExt()
891 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900892 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900893 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900894 } else if _, ok := mctx.Module().(*OverrideApex); ok {
895 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900896 }
897}
898
Jooyung Han5c998b92019-06-27 11:30:33 +0900899func apexUsesMutator(mctx android.BottomUpMutatorContext) {
900 if ab, ok := mctx.Module().(*apexBundle); ok {
901 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
902 }
903}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900904
Jooyung Handc782442019-11-01 03:14:38 +0900905var (
906 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
907)
908
909// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
910// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
911// which may cause compatibility issues. (e.g. libbinder)
912// Even though libbinder restricts its availability via 'apex_available' property and relies on
913// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
914// to avoid similar problems.
915func useVendorWhitelist(config android.Config) []string {
916 return config.Once(useVendorWhitelistKey, func() interface{} {
917 return []string{
918 // swcodec uses "vendor" variants for smaller size
919 "com.android.media.swcodec",
920 "test_com.android.media.swcodec",
921 }
922 }).([]string)
923}
924
925// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
926// called before the first call to useVendorWhitelist()
927func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
928 config.Once(useVendorWhitelistKey, func() interface{} {
929 return whitelist
930 })
931}
932
Alex Light9670d332019-01-29 18:07:33 -0800933type apexNativeDependencies struct {
934 // List of native libraries
935 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900936
Alex Light9670d332019-01-29 18:07:33 -0800937 // List of native executables
938 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900939
Roland Levillain630846d2019-06-26 12:48:34 +0100940 // List of native tests
941 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800942}
Jooyung Han344d5432019-08-23 11:17:39 +0900943
Alex Light9670d332019-01-29 18:07:33 -0800944type apexMultilibProperties struct {
945 // Native dependencies whose compile_multilib is "first"
946 First apexNativeDependencies
947
948 // Native dependencies whose compile_multilib is "both"
949 Both apexNativeDependencies
950
951 // Native dependencies whose compile_multilib is "prefer32"
952 Prefer32 apexNativeDependencies
953
954 // Native dependencies whose compile_multilib is "32"
955 Lib32 apexNativeDependencies
956
957 // Native dependencies whose compile_multilib is "64"
958 Lib64 apexNativeDependencies
959}
960
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900961type apexBundleProperties struct {
962 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000963 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800964 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900965
Jiyong Park40e26a22019-02-08 02:53:06 +0900966 // AndroidManifest.xml file used for the zip container of this APEX bundle.
967 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800968 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900969
Roland Levillain411c5842019-09-19 16:37:20 +0100970 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
971 // device (/apex/<apex_name>).
972 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900973 Apex_name *string
974
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900975 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900976 // For platform APEXes, this should points to a file under /system/sepolicy
977 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
978 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900979
980 // List of native shared libs that are embedded inside this APEX bundle
981 Native_shared_libs []string
982
Roland Levillain630846d2019-06-26 12:48:34 +0100983 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900984 Binaries []string
985
986 // List of java libraries that are embedded inside this APEX bundle
987 Java_libs []string
988
989 // List of prebuilt files that are embedded inside this APEX bundle
990 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900991
Roland Levillain630846d2019-06-26 12:48:34 +0100992 // List of tests that are embedded inside this APEX bundle
993 Tests []string
994
Jiyong Parkff1458f2018-10-12 21:49:38 +0900995 // Name of the apex_key module that provides the private key to sign APEX
996 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900997
Alex Light5098a612018-11-29 17:12:15 -0800998 // The type of APEX to build. Controls what the APEX payload is. Either
999 // 'image', 'zip' or 'both'. Default: 'image'.
1000 Payload_type *string
1001
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001002 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1003 // or an android_app_certificate module name in the form ":module".
1004 Certificate *string
1005
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001006 // Whether this APEX is installable to one of the partitions. Default: true.
1007 Installable *bool
1008
Jiyong Parkda6eb592018-12-19 17:12:36 +09001009 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1010 // Default is false.
1011 Use_vendor *bool
1012
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001013 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1014 Ignore_system_library_special_case *bool
1015
Alex Light9670d332019-01-29 18:07:33 -08001016 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001017
Jiyong Parkf97782b2019-02-13 20:28:58 +09001018 // List of sanitizer names that this APEX is enabled for
1019 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001020
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001021 PreventInstall bool `blueprint:"mutated"`
1022
1023 HideFromMake bool `blueprint:"mutated"`
1024
Jooyung Han5c998b92019-06-27 11:30:33 +09001025 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1026 Provide_cpp_shared_libs *bool
1027
1028 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1029 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001030
1031 // A txt file containing list of files that are whitelisted to be included in this APEX.
1032 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001033
Sundong Ahnabb64432019-10-22 13:58:29 +09001034 // package format of this apex variant; could be non-flattened, flattened, or zip.
1035 // imageApex, zipApex or flattened
1036 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001037
Jiyong Parkd1063c12019-07-17 20:08:41 +09001038 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1039 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1040 // is implied. This value affects all modules included in this APEX. In other words, they are
1041 // also built with the SDKs specified here.
1042 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001043
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001044 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1045 // Should be only used in tests#.
1046 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001047
Dario Freni98410fd2020-04-27 18:21:11 +01001048 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1049 // Should be only used in tests#.
1050 Test_only_unsigned_payload *bool
1051
Jiyong Park956305c2020-01-09 12:32:06 +09001052 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001053
1054 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Hanced674e2020-04-27 12:10:30 +09001055 // rules for making sure that the APEX is truly updatable.
1056 // - To be updatable, min_sdk_version should be set as well
1057 // This will also disable the size optimizations like symlinking to the system libs.
1058 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001059 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001060
1061 // The minimum SDK version that this apex must be compatible with.
1062 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001063}
1064
1065type apexTargetBundleProperties struct {
1066 Target struct {
1067 // Multilib properties only for android.
1068 Android struct {
1069 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001070 }
Jooyung Han344d5432019-08-23 11:17:39 +09001071
Alex Light9670d332019-01-29 18:07:33 -08001072 // Multilib properties only for host.
1073 Host struct {
1074 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001075 }
Jooyung Han344d5432019-08-23 11:17:39 +09001076
Alex Light9670d332019-01-29 18:07:33 -08001077 // Multilib properties only for host linux_bionic.
1078 Linux_bionic struct {
1079 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001080 }
Jooyung Han344d5432019-08-23 11:17:39 +09001081
Alex Light9670d332019-01-29 18:07:33 -08001082 // Multilib properties only for host linux_glibc.
1083 Linux_glibc struct {
1084 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001085 }
1086 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001087}
1088
Jiyong Park5d790c32019-11-15 18:40:32 +09001089type overridableProperties struct {
1090 // List of APKs to package inside APEX
1091 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001092
1093 // Names of modules to be overridden. Listed modules can only be other binaries
1094 // (in Make or Soong).
1095 // This does not completely prevent installation of the overridden binaries, but if both
1096 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1097 // from PRODUCT_PACKAGES.
1098 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001099
1100 // Logging Parent value
1101 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001102
1103 // Apex Container Package Name.
1104 // Override value for attribute package:name in AndroidManifest.xml
1105 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001106}
1107
Alex Light5098a612018-11-29 17:12:15 -08001108type apexPackaging int
1109
1110const (
1111 imageApex apexPackaging = iota
1112 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001113 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001114)
1115
Sundong Ahnabb64432019-10-22 13:58:29 +09001116// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001117func (a apexPackaging) suffix() string {
1118 switch a {
1119 case imageApex:
1120 return imageApexSuffix
1121 case zipApex:
1122 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001123 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001124 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001125 }
1126}
1127
1128func (a apexPackaging) name() string {
1129 switch a {
1130 case imageApex:
1131 return imageApexType
1132 case zipApex:
1133 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001134 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001135 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001136 }
1137}
1138
Jiyong Parkf653b052019-11-18 15:39:01 +09001139type apexFileClass int
1140
1141const (
1142 etc apexFileClass = iota
1143 nativeSharedLib
1144 nativeExecutable
1145 shBinary
1146 pyBinary
1147 goBinary
1148 javaSharedLib
1149 nativeTest
1150 app
1151)
1152
Jiyong Park8fd61922018-11-08 02:50:25 +09001153func (class apexFileClass) NameInMake() string {
1154 switch class {
1155 case etc:
1156 return "ETC"
1157 case nativeSharedLib:
1158 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001159 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001160 return "EXECUTABLES"
1161 case javaSharedLib:
1162 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001163 case nativeTest:
1164 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001165 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001166 // b/142537672 Why isn't this APP? We want to have full control over
1167 // the paths and file names of the apk file under the flattend APEX.
1168 // If this is set to APP, then the paths and file names are modified
1169 // by the Make build system. For example, it is installed to
1170 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1171 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1172 // appends module name (which is <apexname>.<Appname> to the path.
1173 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001174 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001175 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001176 }
1177}
1178
Jiyong Parkf653b052019-11-18 15:39:01 +09001179// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001180type apexFile struct {
1181 builtFile android.Path
Jiyong Parked50ca82020-05-28 23:46:55 +09001182 stem string
Jiyong Park8fd61922018-11-08 02:50:25 +09001183 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001184 installDir string
1185 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001186 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001187 // list of symlinks that will be created in installDir that point to this apexFile
1188 symlinks []string
1189 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001190 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001191
1192 requiredModuleNames []string
1193 targetRequiredModuleNames []string
1194 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001195
Colin Cross503c1d02020-01-28 14:00:53 -08001196 jacocoReportClassesFile android.Path // only for javalibs and apps
1197 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001198 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001199}
1200
Jiyong Park1833cef2019-12-13 13:28:36 +09001201func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1202 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001203 builtFile: builtFile,
1204 moduleName: moduleName,
1205 installDir: installDir,
1206 class: class,
1207 module: module,
1208 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001209 if module != nil {
1210 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001211 ret.requiredModuleNames = module.RequiredModuleNames()
1212 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1213 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001214 }
1215 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001216}
1217
1218func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001219 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001220}
1221
Jiyong Parked50ca82020-05-28 23:46:55 +09001222func (af *apexFile) apexRelativePath(path string) string {
1223 return filepath.Join(af.installDir, path)
1224}
1225
Jiyong Park7cd10e32020-01-14 09:22:18 +09001226// Path() returns path of this apex file relative to the APEX root
1227func (af *apexFile) Path() string {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001228 return af.apexRelativePath(af.Stem())
1229}
1230
1231func (af *apexFile) Stem() string {
Jiyong Parked50ca82020-05-28 23:46:55 +09001232 if af.stem != "" {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001233 return af.stem
Jiyong Parked50ca82020-05-28 23:46:55 +09001234 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001235 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001236}
1237
1238// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1239func (af *apexFile) SymlinkPaths() []string {
1240 var ret []string
1241 for _, symlink := range af.symlinks {
1242 ret = append(ret, filepath.Join(af.installDir, symlink))
1243 }
1244 return ret
1245}
1246
1247func (af *apexFile) AvailableToPlatform() bool {
1248 if af.module == nil {
1249 return false
1250 }
1251 if am, ok := af.module.(android.ApexModule); ok {
1252 return am.AvailableFor(android.AvailableToPlatform)
1253 }
1254 return false
1255}
1256
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001257type apexBundle struct {
1258 android.ModuleBase
1259 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001260 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001261 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001262
Jiyong Park5d790c32019-11-15 18:40:32 +09001263 properties apexBundleProperties
1264 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001265 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001266
Jooyung Hanf21c7972019-12-16 22:32:06 +09001267 // specific to apex_vndk modules
1268 vndkProperties apexVndkProperties
1269
Colin Crossa4925902018-11-16 11:36:28 -08001270 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001271 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001272 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001273
Jiyong Park03b68dd2019-07-26 23:20:40 +09001274 prebuiltFileToDelete string
1275
Jiyong Park42cca6c2019-04-01 11:15:50 +09001276 public_key_file android.Path
1277 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001278
1279 container_certificate_file android.Path
1280 container_private_key_file android.Path
1281
Jooyung Han54aca7b2019-11-20 02:26:02 +09001282 fileContexts android.Path
1283
Jiyong Park8fd61922018-11-08 02:50:25 +09001284 // list of files to be included in this apex
1285 filesInfo []apexFile
1286
Jiyong Park956305c2020-01-09 12:32:06 +09001287 // list of module names that should be installed along with this APEX
1288 requiredDeps []string
1289
Jiyong Park956305c2020-01-09 12:32:06 +09001290 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev334b5172020-04-27 17:08:37 +01001291 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001292
Sundong Ahnabb64432019-10-22 13:58:29 +09001293 testApex bool
1294 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001295 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001296 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001297
Jooyung Han214bf372019-11-12 13:03:50 +09001298 manifestJsonOut android.WritablePath
1299 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001300
Jooyung Han002ab682020-01-08 01:57:58 +09001301 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001302 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001303 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001304 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1305 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001306
1307 // Suffix of module name in Android.mk
1308 // ".flattened", ".apex", ".zipapex", or ""
1309 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001310
1311 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001312
1313 // Whether to create symlink to the system file instead of having a file
1314 // inside the apex or not
1315 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001316
1317 // Struct holding the merged notice file paths in different formats
1318 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001319}
1320
Jiyong Park397e55e2018-10-24 21:09:55 +09001321func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001322 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001323 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001324 // Use *FarVariation* to be able to depend on modules having
1325 // conflicting variations with this module. This is required since
1326 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1327 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001328 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001329 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001330 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001331 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001332 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001333
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001334 ctx.AddFarVariationDependencies(append(target.Variations(),
1335 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1336 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001337
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001338 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001339 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001340 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001341 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001342}
1343
Alex Light9670d332019-01-29 18:07:33 -08001344func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1345 if ctx.Os().Class == android.Device {
1346 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1347 } else {
1348 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1349 if ctx.Os().Bionic() {
1350 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1351 } else {
1352 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1353 }
1354 }
1355}
1356
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001357func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001358 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1359 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1360 }
1361
Jiyong Park397e55e2018-10-24 21:09:55 +09001362 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001363 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001364
1365 a.combineProperties(ctx)
1366
Jiyong Park397e55e2018-10-24 21:09:55 +09001367 has32BitTarget := false
1368 for _, target := range targets {
1369 if target.Arch.ArchType.Multilib == "lib32" {
1370 has32BitTarget = true
1371 }
1372 }
1373 for i, target := range targets {
1374 // When multilib.* is omitted for native_shared_libs, it implies
1375 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001376 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001377 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001378 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001379 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001380
Roland Levillain630846d2019-06-26 12:48:34 +01001381 // When multilib.* is omitted for tests, it implies
1382 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001383 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001384 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001385 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001386 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001387
Jiyong Park397e55e2018-10-24 21:09:55 +09001388 // Add native modules targetting both ABIs
1389 addDependenciesForNativeModules(ctx,
1390 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001391 a.properties.Multilib.Both.Binaries,
1392 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001393 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001394 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001395
Alex Light3d673592019-01-18 14:37:31 -08001396 isPrimaryAbi := i == 0
1397 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001398 // When multilib.* is omitted for binaries, it implies
1399 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001400 ctx.AddFarVariationDependencies(append(target.Variations(),
1401 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1402 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001403
1404 // Add native modules targetting the first ABI
1405 addDependenciesForNativeModules(ctx,
1406 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001407 a.properties.Multilib.First.Binaries,
1408 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001409 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001410 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001411 }
1412
1413 switch target.Arch.ArchType.Multilib {
1414 case "lib32":
1415 // Add native modules targetting 32-bit ABI
1416 addDependenciesForNativeModules(ctx,
1417 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001418 a.properties.Multilib.Lib32.Binaries,
1419 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001420 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001421 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001422
1423 addDependenciesForNativeModules(ctx,
1424 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001425 a.properties.Multilib.Prefer32.Binaries,
1426 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001427 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001428 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001429 case "lib64":
1430 // Add native modules targetting 64-bit ABI
1431 addDependenciesForNativeModules(ctx,
1432 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001433 a.properties.Multilib.Lib64.Binaries,
1434 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001435 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001436 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001437
1438 if !has32BitTarget {
1439 addDependenciesForNativeModules(ctx,
1440 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001441 a.properties.Multilib.Prefer32.Binaries,
1442 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001443 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001444 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001445 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001446
1447 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1448 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1449 if sanitizer == "hwaddress" {
1450 addDependenciesForNativeModules(ctx,
1451 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001452 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001453 break
1454 }
1455 }
1456 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001457 }
1458
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001459 }
1460
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001461 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1462 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1463 // b/144532908
1464 archForPrebuiltEtc := config.Arches()[0]
1465 for _, arch := range config.Arches() {
1466 // Prefer 64-bit arch if there is any
1467 if arch.ArchType.Multilib == "lib64" {
1468 archForPrebuiltEtc = arch
1469 break
1470 }
1471 }
1472 ctx.AddFarVariationDependencies([]blueprint.Variation{
1473 {Mutator: "os", Variation: ctx.Os().String()},
1474 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1475 }, prebuiltTag, a.properties.Prebuilts...)
1476
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001477 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1478 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001479
Ulya Trafimovich44561882020-01-03 13:25:54 +00001480 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1481 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1482 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1483 javaLibTag, "jacocoagent")
1484 }
1485
Jiyong Park23c52b02019-02-02 13:13:47 +09001486 if String(a.properties.Key) == "" {
1487 ctx.ModuleErrorf("key is missing")
1488 return
1489 }
1490 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001491
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001492 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001493 if cert != "" {
1494 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001495 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001496
1497 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1498 if len(a.properties.Uses_sdks) > 0 {
1499 sdkRefs := []android.SdkRef{}
1500 for _, str := range a.properties.Uses_sdks {
1501 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1502 sdkRefs = append(sdkRefs, parsed)
1503 }
1504 a.BuildWithSdks(sdkRefs)
1505 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001506}
1507
Jiyong Park5d790c32019-11-15 18:40:32 +09001508func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1509 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1510 androidAppTag, a.overridableProperties.Apps...)
1511}
1512
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001513func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1514 // direct deps of an APEX bundle are all part of the APEX bundle
1515 return true
1516}
1517
Colin Cross0ea8ba82019-06-06 14:33:29 -07001518func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001519 moduleName := ctx.ModuleName()
1520 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1521 // we check with the pseudo module name to see if its certificate is overridden.
1522 if a.vndkApex {
1523 moduleName = vndkApexName
1524 }
1525 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001526 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001527 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001528 }
1529 return String(a.properties.Certificate)
1530}
1531
Colin Cross41955e82019-05-29 14:40:35 -07001532func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1533 switch tag {
1534 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001535 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001536 default:
1537 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001538 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001539}
1540
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001541func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001542 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001543}
1544
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001545func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1546 return proptools.Bool(a.properties.Test_only_no_hashtree)
1547}
1548
Dario Freni98410fd2020-04-27 18:21:11 +01001549func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1550 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1551}
1552
Jiyong Park7c1dc612019-01-05 11:15:24 +09001553func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001554 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001555 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001556 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001557 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001558 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001559 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001560 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001561 }
1562}
1563
Jiyong Parkf97782b2019-02-13 20:28:58 +09001564func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1565 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1566 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1567 }
1568}
1569
Jiyong Park388ef3f2019-01-28 19:47:32 +09001570func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001571 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1572 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001573 }
1574
1575 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001576 globalSanitizerNames := []string{}
1577 if a.Host() {
1578 globalSanitizerNames = ctx.Config().SanitizeHost()
1579 } else {
1580 arches := ctx.Config().SanitizeDeviceArch()
1581 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1582 globalSanitizerNames = ctx.Config().SanitizeDevice()
1583 }
1584 }
1585 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001586}
1587
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001588func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001589 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001590}
1591
1592func (a *apexBundle) PreventInstall() {
1593 a.properties.PreventInstall = true
1594}
1595
1596func (a *apexBundle) HideFromMake() {
1597 a.properties.HideFromMake = true
1598}
1599
Jiyong Park956305c2020-01-09 12:32:06 +09001600func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1601 a.properties.IsCoverageVariant = coverage
1602}
1603
Jiyong Parkf653b052019-11-18 15:39:01 +09001604// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001605func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001606 // Decide the APEX-local directory by the multilib of the library
1607 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001608 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001609 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001610 case "lib32":
1611 dirInApex = "lib"
1612 case "lib64":
1613 dirInApex = "lib64"
1614 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001615 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001616 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001617 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001618 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001619 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001620 // Special case for Bionic libs and other libs installed with them. This is
1621 // to prevent those libs from being included in the search path
1622 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1623 // those libs in the Runtime APEX are available via the legacy paths in
1624 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1625 // to the legacy paths and thus will be loaded into the default linker
1626 // namespace (aka "platform" namespace). If the libs are directly in
1627 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1628 // into the runtime linker namespace, which will result in double loading of
1629 // them, which isn't supported.
1630 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001631 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001632
Jiyong Parkf653b052019-11-18 15:39:01 +09001633 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001634 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001635}
1636
Jiyong Park1833cef2019-12-13 13:28:36 +09001637func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001638 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001639 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001640 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001641 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001642 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001643 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001644 af.symlinks = cc.Symlinks()
1645 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001646}
1647
Jiyong Park1833cef2019-12-13 13:28:36 +09001648func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001649 dirInApex := "bin"
1650 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001651 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001652}
Jiyong Park1833cef2019-12-13 13:28:36 +09001653func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001654 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001655 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1656 if err != nil {
1657 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001658 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001659 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001660 fileToCopy := android.PathForOutput(ctx, s)
1661 // NB: Since go binaries are static we don't need the module for anything here, which is
1662 // good since the go tool is a blueprint.Module not an android.Module like we would
1663 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001664 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001665}
1666
Jiyong Park1833cef2019-12-13 13:28:36 +09001667func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001668 dirInApex := filepath.Join("bin", sh.SubDir())
1669 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001670 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001671 af.symlinks = sh.Symlinks()
1672 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001673}
1674
Jiyong Parked50ca82020-05-28 23:46:55 +09001675type javaDependency interface {
1676 java.Dependency
1677 Stem() string
1678}
1679
1680func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001681 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001682 fileToCopy := lib.DexJar()
Paul Duffinf299cbe2020-05-14 20:49:32 +01001683 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001684 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
Jiyong Parked50ca82020-05-28 23:46:55 +09001685 af.stem = lib.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001686 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001687}
1688
Jiyong Park1833cef2019-12-13 13:28:36 +09001689func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001690 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1691 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001692 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001693}
1694
atrost6e126252020-01-27 17:01:16 +00001695func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1696 dirInApex := filepath.Join("etc", config.SubDir())
1697 fileToCopy := config.CompatConfig()
1698 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1699}
1700
Jiyong Park1833cef2019-12-13 13:28:36 +09001701func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001702 android.Module
1703 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001704 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001705 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001706 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001707 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001708}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001709 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001710 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001711 appDir = "priv-app"
1712 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001713 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001714 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001715 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1716 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001717 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001718
1719 if app, ok := aapp.(interface {
1720 OverriddenManifestPackageName() string
1721 }); ok {
1722 af.overriddenPackageName = app.OverriddenManifestPackageName()
1723 }
Jiyong Park618922e2020-01-08 13:35:43 +09001724 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001725}
1726
Roland Levillain935639d2019-08-13 14:55:28 +01001727// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1728type flattenedApexContext struct {
1729 android.ModuleContext
1730}
1731
1732func (c *flattenedApexContext) InstallBypassMake() bool {
1733 return true
1734}
1735
Paul Duffin133608f2020-03-30 15:54:08 +01001736// Function called while walking an APEX's payload dependencies.
1737//
1738// Return true if the `to` module should be visited, false otherwise.
1739type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1740
Jiyong Park201cedd2020-02-07 17:25:49 +09001741// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001742func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001743 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001744 am, ok := child.(android.ApexModule)
1745 if !ok || !am.CanHaveApexVariants() {
1746 return false
1747 }
1748
1749 // Check for the direct dependencies that contribute to the payload
1750 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1751 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001752 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001753 }
Paul Duffin133608f2020-03-30 15:54:08 +01001754 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001755 return false
1756 }
1757
1758 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001759 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001760 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001761 }
1762
Paul Duffin133608f2020-03-30 15:54:08 +01001763 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001764 })
1765}
1766
Jooyung Han0c4e0162020-02-26 22:45:42 +09001767func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1768 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001769 intVer, err := android.ApiStrToNum(ctx, ver)
1770 if err != nil {
1771 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001772 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001773 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001774}
1775
Paul Duffinf0207962020-03-31 11:31:36 +01001776// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1777// a dependency tag.
1778var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1779
1780func PrettyPrintTag(tag blueprint.DependencyTag) string {
1781 // Use tag's custom String() method if available.
1782 if stringer, ok := tag.(fmt.Stringer); ok {
1783 return stringer.String()
1784 }
1785
1786 // Otherwise, get a default string representation of the tag's struct.
1787 tagString := fmt.Sprintf("%#v", tag)
1788
1789 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1790 tagString = tagCleaner.ReplaceAllString(tagString, "")
1791 return tagString
1792}
1793
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001794func (a *apexBundle) Updatable() bool {
1795 return proptools.Bool(a.properties.Updatable)
1796}
1797
1798var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1799
Jiyong Park201cedd2020-02-07 17:25:49 +09001800// Ensures that the dependencies are marked as available for this APEX
1801func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1802 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1803 if ctx.Host() || a.testApex || a.vndkApex {
1804 return
1805 }
1806
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001807 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1808 // Requiring them and their transitive depencies with apex_available is not right
1809 // because they just add noise.
1810 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1811 return
1812 }
1813
Paul Duffin133608f2020-03-30 15:54:08 +01001814 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1815 if externalDep {
1816 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1817 return false
1818 }
1819
Jiyong Park201cedd2020-02-07 17:25:49 +09001820 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001821 fromName := ctx.OtherModuleName(from)
1822 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001823
1824 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1825 // do any of its dependencies.
1826 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1827 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1828 return false
1829 }
1830
Paul Duffin133608f2020-03-30 15:54:08 +01001831 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1832 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001833 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001834 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001835 tagPath := ctx.GetTagPath()
1836 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1837 walkPath := ctx.GetWalkPath()[1:]
1838 for i, m := range walkPath {
1839 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001840 }
1841 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 +01001842 // Visit this module's dependencies to check and report any issues with their availability.
1843 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001844 })
1845}
1846
Jooyung Hanced674e2020-04-27 12:10:30 +09001847func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001848 if a.Updatable() {
Jooyung Hanced674e2020-04-27 12:10:30 +09001849 if String(a.properties.Min_sdk_version) == "" {
1850 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1851 }
Artur Satayev2eedf622020-04-15 17:29:42 +01001852
1853 a.checkJavaStableSdkVersion(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001854 }
1855}
1856
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001857func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001858 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1859 switch a.properties.ApexType {
1860 case imageApex:
1861 if buildFlattenedAsDefault {
1862 a.suffix = imageApexSuffix
1863 } else {
1864 a.suffix = ""
1865 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001866
1867 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001868 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001869 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001870 }
1871 case zipApex:
1872 if proptools.String(a.properties.Payload_type) == "zip" {
1873 a.suffix = ""
1874 a.primaryApexType = true
1875 } else {
1876 a.suffix = zipApexSuffix
1877 }
1878 case flattenedApex:
1879 if buildFlattenedAsDefault {
1880 a.suffix = ""
1881 a.primaryApexType = true
1882 } else {
1883 a.suffix = flattenedSuffix
1884 }
Alex Light5098a612018-11-29 17:12:15 -08001885 }
1886
Roland Levillain630846d2019-06-26 12:48:34 +01001887 if len(a.properties.Tests) > 0 && !a.testApex {
1888 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1889 return
1890 }
1891
Jiyong Parkfa899442020-01-31 02:49:53 +09001892 a.checkApexAvailability(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001893 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001894
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001895 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1896
Jooyung Hane1633032019-08-01 17:41:43 +09001897 // native lib dependencies
1898 var provideNativeLibs []string
1899 var requireNativeLibs []string
1900
Jooyung Han5c998b92019-06-27 11:30:33 +09001901 // Check if "uses" requirements are met with dependent apexBundles
1902 var providedNativeSharedLibs []string
1903 useVendor := proptools.Bool(a.properties.Use_vendor)
1904 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1905 if ctx.OtherModuleDependencyTag(m) != usesTag {
1906 return
1907 }
1908 otherName := ctx.OtherModuleName(m)
1909 other, ok := m.(*apexBundle)
1910 if !ok {
1911 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1912 return
1913 }
1914 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1915 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1916 return
1917 }
1918 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1919 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1920 return
1921 }
1922 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1923 })
1924
Jiyong Parkf653b052019-11-18 15:39:01 +09001925 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001926 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001927 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001928 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01001929 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1930 return false
1931 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001932 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001933 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001934 switch depTag {
1935 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001936 if c, ok := child.(*cc.Module); ok {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001937 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1938 filesInfo = append(filesInfo, fi)
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001939 // bootstrap bionic libs are treated as provided by system
1940 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001941 provideNativeLibs = append(provideNativeLibs, fi.Stem())
Jooyung Hane1633032019-08-01 17:41:43 +09001942 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001943 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001944 } else {
1945 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001946 }
1947 case executableTag:
1948 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001949 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001950 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001951 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001952 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001953 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001954 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001955 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001956 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001957 } else {
Alex Light778127a2019-02-27 14:19:50 -08001958 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 +09001959 }
1960 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001961 if javaLib, ok := child.(*java.Library); ok {
Paul Duffinf299cbe2020-05-14 20:49:32 +01001962 af := apexFileForJavaLibrary(ctx, javaLib, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001963 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001964 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1965 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001966 filesInfo = append(filesInfo, af)
1967 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001968 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001969 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
Paul Duffinf299cbe2020-05-14 20:49:32 +01001970 af := apexFileForJavaLibrary(ctx, sdkLib, sdkLib)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001971 if !af.Ok() {
1972 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1973 return false
1974 }
1975 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001976 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001977 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001978 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001979 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001980 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001981 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001982 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001983 return true // track transitive dependencies
1984 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001985 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001986 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001987 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001988 } else {
1989 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1990 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001991 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001992 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001993 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001994 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1995 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001996 } else {
atrost6e126252020-01-27 17:01:16 +00001997 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001998 }
Roland Levillain630846d2019-06-26 12:48:34 +01001999 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002000 if ccTest, ok := child.(*cc.Module); ok {
2001 if ccTest.IsTestPerSrcAllTestsVariation() {
2002 // Multiple-output test module (where `test_per_src: true`).
2003 //
2004 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2005 // We do not add this variation to `filesInfo`, as it has no output;
2006 // however, we do add the other variations of this module as indirect
2007 // dependencies (see below).
2008 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002009 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002010 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002011 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002012 af.class = nativeTest
2013 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002014 }
Roland Levillain630846d2019-06-26 12:48:34 +01002015 } else {
2016 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2017 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002018 case keyTag:
2019 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002020 a.private_key_file = key.private_key_file
2021 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002022 } else {
2023 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002024 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002025 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002026 case certificateTag:
2027 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002028 a.container_certificate_file = dep.Certificate.Pem
2029 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002030 } else {
2031 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2032 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002033 case android.PrebuiltDepTag:
2034 // If the prebuilt is force disabled, remember to delete the prebuilt file
2035 // that might have been installed in the previous builds
2036 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2037 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2038 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002039 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002040 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002041 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002042 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002043 // We cannot use a switch statement on `depTag` here as the checked
2044 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002045 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002046 if cc, ok := child.(*cc.Module); ok {
2047 if android.InList(cc.Name(), providedNativeSharedLibs) {
2048 // If we're using a shared library which is provided from other APEX,
2049 // don't include it in this APEX
2050 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002051 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002052 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2053 af.transitiveDep = true
Jooyung Han671f1ce2019-12-17 12:47:13 +09002054 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002055 // If the dependency is a stubs lib, don't include it in this APEX,
2056 // but make sure that the lib is installed on the device.
2057 // In case no APEX is having the lib, the lib is installed to the system
2058 // partition.
2059 //
2060 // Always include if we are a host-apex however since those won't have any
2061 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002062 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2063 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002064 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002065 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002066 // Don't track further
2067 return false
2068 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002069 filesInfo = append(filesInfo, af)
2070 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002071 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002072 } else if cc.IsTestPerSrcDepTag(depTag) {
2073 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002074 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002075 // Handle modules created as `test_per_src` variations of a single test module:
2076 // use the name of the generated test binary (`fileToCopy`) instead of the name
2077 // of the original test module (`depName`, shared by all `test_per_src`
2078 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002079 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002080 // these are not considered transitive dep
2081 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002082 filesInfo = append(filesInfo, af)
2083 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002084 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002085 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002086 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2087 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002088 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2089 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2090 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2091 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002092 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002093 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002094 }
2095 }
2096 }
2097 return false
2098 })
2099
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002100 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2101 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2102 // via the global boot image config.
2103 if a.artApex {
2104 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2105 dirInApex := filepath.Join("javalib", arch.String())
2106 for _, f := range files {
2107 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002108 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002109 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002110 }
2111 }
2112 }
2113
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002114 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002115 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2116 return
2117 }
2118
Jiyong Park8fd61922018-11-08 02:50:25 +09002119 // remove duplicates in filesInfo
2120 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002121 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002122 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002123 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002124 if e, ok := encountered[dest]; !ok {
2125 encountered[dest] = f
2126 } else {
2127 // If a module is directly included and also transitively depended on
2128 // consider it as directly included.
2129 e.transitiveDep = e.transitiveDep && f.transitiveDep
2130 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002131 }
2132 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002133 var result []apexFile
2134 for _, v := range encountered {
2135 result = append(result, v)
2136 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002137 return result
2138 }
2139 filesInfo = removeDup(filesInfo)
2140
2141 // to have consistent build rules
2142 sort.Slice(filesInfo, func(i, j int) bool {
2143 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2144 })
2145
Jiyong Park8fd61922018-11-08 02:50:25 +09002146 a.installDir = android.PathForModuleInstall(ctx, "apex")
2147 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002148
Jooyung Han54aca7b2019-11-20 02:26:02 +09002149 if a.properties.ApexType != zipApex {
2150 if a.properties.File_contexts == nil {
2151 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2152 } else {
2153 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2154 if a.Platform() {
2155 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2156 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2157 }
2158 }
2159 }
2160 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2161 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2162 return
2163 }
2164 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002165 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2166 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2167 // the same library in the system partition, thus effectively sharing the same libraries
2168 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2169 // in the APEX.
2170 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2171 a.installable() &&
2172 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002173
Jiyong Park9d677202020-02-19 16:29:35 +09002174 // We don't need the optimization for updatable APEXes, as it might give false signal
2175 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01002176 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002177 a.linkToSystemLib = false
2178 }
2179
Jiyong Park9b964182020-02-26 18:27:19 +09002180 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2181 if ctx.Host() {
2182 a.linkToSystemLib = false
2183 }
2184
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002185 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002186 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2187
2188 a.setCertificateAndPrivateKey(ctx)
2189 if a.properties.ApexType == flattenedApex {
2190 a.buildFlattenedApex(ctx)
2191 } else {
2192 a.buildUnflattenedApex(ctx)
2193 }
2194
Jooyung Han002ab682020-01-08 01:57:58 +09002195 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002196
2197 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002198}
2199
Artur Satayev2eedf622020-04-15 17:29:42 +01002200// Enforce that Java deps of the apex are using stable SDKs to compile
2201func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2202 // Visit direct deps only. As long as we guarantee top-level deps are using
2203 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2204 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2205 tag := ctx.OtherModuleDependencyTag(module)
2206 switch tag {
2207 case javaLibTag, androidAppTag:
2208 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2209 if err := m.CheckStableSdkVersion(); err != nil {
2210 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2211 }
2212 }
2213 }
2214 })
2215}
2216
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002217func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002218 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002219 moduleName = normalizeModuleName(moduleName)
2220
2221 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2222 return true
2223 }
2224
2225 key = android.AvailableToAnyApex
2226 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2227 return true
2228 }
2229
2230 return false
2231}
2232
2233func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002234 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2235 // system. Trim the prefix for the check since they are confusing
2236 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2237 if strings.HasPrefix(moduleName, "libclang_rt.") {
2238 // This module has many arch variants that depend on the product being built.
2239 // We don't want to list them all
2240 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002241 }
Jooyung Han11c20932020-05-19 15:47:01 +09002242 if strings.HasPrefix(moduleName, "androidx.") {
2243 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2244 moduleName = "androidx"
2245 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002246 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002247}
2248
Jooyung Han344d5432019-08-23 11:17:39 +09002249func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002250 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002251 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002252 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002253 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002254 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002255 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2256 })
Alex Light5098a612018-11-29 17:12:15 -08002257 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002258 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002259 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002260 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002261 return module
2262}
Jiyong Park30ca9372019-02-07 16:27:23 +09002263
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002264func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002265 bundle := newApexBundle()
2266 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002267 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002268 return bundle
2269}
2270
Jiyong Parkfce0b422020-02-11 03:56:06 +09002271// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2272// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002273func testApexBundleFactory() android.Module {
2274 bundle := newApexBundle()
2275 bundle.testApex = true
2276 return bundle
2277}
2278
Jiyong Parkfce0b422020-02-11 03:56:06 +09002279// apex packages other modules into an APEX file which is a packaging format for system-level
2280// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002281func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002282 return newApexBundle()
2283}
2284
Jiyong Park30ca9372019-02-07 16:27:23 +09002285//
2286// Defaults
2287//
2288type Defaults struct {
2289 android.ModuleBase
2290 android.DefaultsModuleBase
2291}
2292
Jiyong Park30ca9372019-02-07 16:27:23 +09002293func defaultsFactory() android.Module {
2294 return DefaultsFactory()
2295}
2296
2297func DefaultsFactory(props ...interface{}) android.Module {
2298 module := &Defaults{}
2299
2300 module.AddProperties(props...)
2301 module.AddProperties(
2302 &apexBundleProperties{},
2303 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002304 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002305 )
2306
2307 android.InitDefaultsModule(module)
2308 return module
2309}
Jiyong Park5d790c32019-11-15 18:40:32 +09002310
2311//
2312// OverrideApex
2313//
2314type OverrideApex struct {
2315 android.ModuleBase
2316 android.OverrideModuleBase
2317}
2318
2319func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2320 // All the overrides happen in the base module.
2321}
2322
2323// override_apex is used to create an apex module based on another apex module
2324// by overriding some of its properties.
2325func overrideApexFactory() android.Module {
2326 m := &OverrideApex{}
2327 m.AddProperties(&overridableProperties{})
2328
2329 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2330 android.InitOverrideModule(m)
2331 return m
2332}