blob: b70815384aa10b0556aadcdb405a6c68887f66fd [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"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090019 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090020 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090022 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080025 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090026 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070027
28 "android/soong/android"
markchien2f59ec92020-09-02 16:23:38 +080029 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070030 "android/soong/cc"
31 prebuilt_etc "android/soong/etc"
32 "android/soong/java"
33 "android/soong/python"
34 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090035)
36
Jooyung Han72bd2f82019-10-23 16:46:38 +090037const (
38 imageApexSuffix = ".apex"
39 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090040 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080041
Sundong Ahnabb64432019-10-22 13:58:29 +090042 imageApexType = "image"
43 zipApexType = "zip"
44 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090045)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090046
47type dependencyTag struct {
48 blueprint.BaseDependencyTag
49 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090050
51 // determines if the dependent will be part of the APEX payload
52 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090053}
54
55var (
Jiyong Park0f80c182020-01-31 02:49:53 +090056 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090057 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090058 executableTag = dependencyTag{name: "executable", payload: true}
59 javaLibTag = dependencyTag{name: "javaLib", payload: true}
60 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
61 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090062 keyTag = dependencyTag{name: "key"}
63 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090064 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090065 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090066 rroTag = dependencyTag{name: "rro", payload: true}
markchien2f59ec92020-09-02 16:23:38 +080067 bpfTag = dependencyTag{name: "bpf", payload: true}
Paul Duffin7d74e7b2020-03-06 12:30:13 +000068
Colin Cross440e0d02020-06-11 11:32:11 -070069 apexAvailBaseline = makeApexAvailableBaseline()
70
71 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090072)
73
Paul Duffin7d74e7b2020-03-06 12:30:13 +000074// Transform the map of apex -> modules to module -> apexes.
Colin Cross440e0d02020-06-11 11:32:11 -070075func invertApexBaseline(m map[string][]string) map[string][]string {
Paul Duffin7d74e7b2020-03-06 12:30:13 +000076 r := make(map[string][]string)
77 for apex, modules := range m {
78 for _, module := range modules {
79 r[module] = append(r[module], apex)
80 }
81 }
82 return r
83}
84
Colin Cross440e0d02020-06-11 11:32:11 -070085// Retrieve the baseline of apexes to which the supplied module belongs.
86func BaselineApexAvailable(moduleName string) []string {
87 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
Paul Duffin7d74e7b2020-03-06 12:30:13 +000088}
89
Anton Hanssoneec79eb2020-01-10 15:12:39 +000090// This is a map from apex to modules, which overrides the
91// apex_available setting for that particular module to make
92// it available for the apex regardless of its setting.
93// TODO(b/147364041): remove this
Colin Cross440e0d02020-06-11 11:32:11 -070094func makeApexAvailableBaseline() map[string][]string {
Anton Hanssoneec79eb2020-01-10 15:12:39 +000095 // The "Module separator"s below are employed to minimize merge conflicts.
96 m := make(map[string][]string)
97 //
98 // Module separator
99 //
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000100 m["com.android.bluetooth.updatable"] = []string{
101 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000102 "android.hardware.bluetooth.a2dp@1.0",
103 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900104 "android.hardware.bluetooth@1.0",
105 "android.hardware.bluetooth@1.1",
106 "android.hardware.graphics.bufferqueue@1.0",
107 "android.hardware.graphics.bufferqueue@2.0",
108 "android.hardware.graphics.common@1.0",
109 "android.hardware.graphics.common@1.1",
110 "android.hardware.graphics.common@1.2",
111 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000112 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900113 "android.hidl.token@1.0",
114 "android.hidl.token@1.0-utils",
115 "avrcp-target-service",
116 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900117 "bluetooth-protos-lite",
118 "bluetooth.mapsapi",
119 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900120 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900121 "ipmemorystore-aidl-interfaces-V5-java",
122 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900123 "internal_include_headers",
124 "lib-bt-packets",
125 "lib-bt-packets-avrcp",
126 "lib-bt-packets-base",
127 "libFraunhoferAAC",
128 "libaudio-a2dp-hw-utils",
129 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000131 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900132 "libbluetooth-types",
133 "libbluetooth-types-header",
134 "libbluetooth_gd",
135 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000136 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900137 "libbt-audio-hal-interface",
138 "libbt-bta",
139 "libbt-common",
140 "libbt-hci",
141 "libbt-platform-protos-lite",
142 "libbt-protos-lite",
143 "libbt-sbc-decoder",
144 "libbt-sbc-encoder",
145 "libbt-stack",
146 "libbt-utils",
147 "libbtcore",
148 "libbtdevice",
149 "libbte",
150 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000151 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000152 "libevent",
153 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900154 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900156 "libmedia_headers",
157 "libmodpb64",
158 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900159 "libstagefright_foundation_headers",
160 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000163 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000165 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900166 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900167 "net-utils-services-common",
168 "netd_aidl_interface-unstable-java",
169 "netd_event_listener_interface-java",
170 "netlink-client",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900171 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900172 "sap-api-java-static",
173 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000174 }
175 //
176 // Module separator
177 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900178 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000179 //
180 // Module separator
181 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900182 m["com.android.neuralnetworks"] = []string{
183 "android.hardware.neuralnetworks@1.0",
184 "android.hardware.neuralnetworks@1.1",
185 "android.hardware.neuralnetworks@1.2",
186 "android.hardware.neuralnetworks@1.3",
187 "android.hidl.allocator@1.0",
188 "android.hidl.memory.token@1.0",
189 "android.hidl.memory@1.0",
190 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900191 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900192 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900193 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900194 "libprocpartition",
195 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000197 //
198 // Module separator
199 //
200 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000201 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900202 "android.hardware.cas.native@1.0",
203 "android.hardware.cas@1.0",
204 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000205 "android.hardware.configstore@1.0",
206 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000207 "android.hardware.graphics.allocator@2.0",
208 "android.hardware.graphics.allocator@3.0",
209 "android.hardware.graphics.bufferqueue@1.0",
210 "android.hardware.graphics.bufferqueue@2.0",
211 "android.hardware.graphics.common@1.0",
212 "android.hardware.graphics.common@1.1",
213 "android.hardware.graphics.common@1.2",
214 "android.hardware.graphics.mapper@2.0",
215 "android.hardware.graphics.mapper@2.1",
216 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900217 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000218 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900219 "android.hidl.allocator@1.0",
220 "android.hidl.memory.token@1.0",
221 "android.hidl.memory@1.0",
222 "android.hidl.token@1.0",
223 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900224 "bionic_libc_platform_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900225 "exoplayer2-extractor",
226 "exoplayer2-extractor-annotation-stubs",
Jiyong Park0f80c182020-01-31 02:49:53 +0900227 "gl_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900228 "jsr305",
Jiyong Park0f80c182020-01-31 02:49:53 +0900229 "libEGL",
230 "libEGL_blobCache",
231 "libEGL_getProcAddress",
232 "libFLAC",
233 "libFLAC-config",
234 "libFLAC-headers",
235 "libGLESv2",
236 "libaacextractor",
237 "libamrextractor",
238 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900239 "libaudio_system_headers",
240 "libaudioclient",
241 "libaudioclient_headers",
242 "libaudiofoundation",
243 "libaudiofoundation_headers",
244 "libaudiomanager",
245 "libaudiopolicy",
246 "libaudioutils",
247 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900248 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900249 "libbluetooth-types-header",
250 "libbufferhub",
251 "libbufferhub_headers",
252 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900253 "libc_malloc_debug_backtrace",
254 "libcamera_client",
255 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900256 "libdexfile_external_headers",
257 "libdexfile_support",
258 "libdvr_headers",
259 "libexpat",
260 "libfifo",
261 "libflacextractor",
262 "libgrallocusage",
263 "libgraphicsenv",
264 "libgui",
265 "libgui_headers",
266 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900268 "liblzma",
269 "libmath",
270 "libmedia",
271 "libmedia_codeclist",
272 "libmedia_headers",
273 "libmedia_helper",
274 "libmedia_helper_headers",
275 "libmedia_midiiowrapper",
276 "libmedia_omx",
277 "libmediautils",
278 "libmidiextractor",
279 "libmkvextractor",
280 "libmp3extractor",
281 "libmp4extractor",
282 "libmpeg2extractor",
283 "libnativebase_headers",
284 "libnativebridge-headers",
285 "libnativebridge_lazy",
286 "libnativeloader-headers",
287 "libnativeloader_lazy",
288 "libnativewindow_headers",
289 "libnblog",
290 "liboggextractor",
291 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900292 "libpdx",
293 "libpdx_default_transport",
294 "libpdx_headers",
295 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900296 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900297 "libsonivox",
298 "libspeexresampler",
299 "libspeexresampler",
300 "libstagefright_esds",
301 "libstagefright_flacdec",
302 "libstagefright_flacdec",
303 "libstagefright_foundation",
304 "libstagefright_foundation_headers",
305 "libstagefright_foundation_without_imemory",
306 "libstagefright_headers",
307 "libstagefright_id3",
308 "libstagefright_metadatautils",
309 "libstagefright_mpeg2extractor",
310 "libstagefright_mpeg2support",
311 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900312 "libui",
313 "libui_headers",
314 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900315 "libvibrator",
316 "libvorbisidec",
317 "libwavextractor",
318 "libwebm",
319 "media_ndk_headers",
320 "media_plugin_headers",
321 "updatable-media",
322 }
323 //
324 // Module separator
325 //
326 m["com.android.media.swcodec"] = []string{
327 "android.frameworks.bufferhub@1.0",
328 "android.hardware.common-ndk_platform",
329 "android.hardware.configstore-utils",
330 "android.hardware.configstore@1.0",
331 "android.hardware.configstore@1.1",
332 "android.hardware.graphics.allocator@2.0",
333 "android.hardware.graphics.allocator@3.0",
334 "android.hardware.graphics.bufferqueue@1.0",
335 "android.hardware.graphics.bufferqueue@2.0",
336 "android.hardware.graphics.common-ndk_platform",
337 "android.hardware.graphics.common@1.0",
338 "android.hardware.graphics.common@1.1",
339 "android.hardware.graphics.common@1.2",
340 "android.hardware.graphics.mapper@2.0",
341 "android.hardware.graphics.mapper@2.1",
342 "android.hardware.graphics.mapper@3.0",
343 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000344 "android.hardware.media.bufferpool@2.0",
345 "android.hardware.media.c2@1.0",
346 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900347 "android.hardware.media@1.0",
348 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000349 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900350 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000351 "android.hidl.safe_union@1.0",
352 "android.hidl.token@1.0",
353 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900354 "libEGL",
355 "libFLAC",
356 "libFLAC-config",
357 "libFLAC-headers",
358 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900359 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900360 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900361 "libaudio_system_headers",
362 "libaudioutils",
363 "libaudioutils",
364 "libaudioutils_fixedfft",
365 "libavcdec",
366 "libavcenc",
367 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000368 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900369 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900370 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900371 "libbluetooth-types-header",
372 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000373 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900374 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000375 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900376 "libcodec2_hidl@1.1",
377 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000378 "libcodec2_soft_aacdec",
379 "libcodec2_soft_aacenc",
380 "libcodec2_soft_amrnbdec",
381 "libcodec2_soft_amrnbenc",
382 "libcodec2_soft_amrwbdec",
383 "libcodec2_soft_amrwbenc",
384 "libcodec2_soft_av1dec_gav1",
385 "libcodec2_soft_avcdec",
386 "libcodec2_soft_avcenc",
387 "libcodec2_soft_common",
388 "libcodec2_soft_flacdec",
389 "libcodec2_soft_flacenc",
390 "libcodec2_soft_g711alawdec",
391 "libcodec2_soft_g711mlawdec",
392 "libcodec2_soft_gsmdec",
393 "libcodec2_soft_h263dec",
394 "libcodec2_soft_h263enc",
395 "libcodec2_soft_hevcdec",
396 "libcodec2_soft_hevcenc",
397 "libcodec2_soft_mp3dec",
398 "libcodec2_soft_mpeg2dec",
399 "libcodec2_soft_mpeg4dec",
400 "libcodec2_soft_mpeg4enc",
401 "libcodec2_soft_opusdec",
402 "libcodec2_soft_opusenc",
403 "libcodec2_soft_rawdec",
404 "libcodec2_soft_vorbisdec",
405 "libcodec2_soft_vp8dec",
406 "libcodec2_soft_vp8enc",
407 "libcodec2_soft_vp9dec",
408 "libcodec2_soft_vp9enc",
409 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000410 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900411 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000412 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900413 "libfmq",
414 "libgav1",
415 "libgralloctypes",
416 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000417 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900418 "libgsm",
419 "libgui_bufferqueue_static",
420 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000421 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900422 "libhardware_headers",
423 "libhevcdec",
424 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000425 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900426 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000427 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900428 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000429 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900430 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900431 "libmpeg2dec",
432 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000433 "libnativebridge_lazy",
434 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900435 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900436 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000437 "libscudo_wrapper",
438 "libsfplugin_ccodec_utils",
439 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900440 "libstagefright_amrnbdec",
441 "libstagefright_amrnbenc",
442 "libstagefright_amrwbdec",
443 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000444 "libstagefright_bufferpool@2.0.1",
445 "libstagefright_bufferqueue_helper",
446 "libstagefright_enc_common",
447 "libstagefright_flacdec",
448 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900449 "libstagefright_foundation_headers",
450 "libstagefright_headers",
451 "libstagefright_m4vh263dec",
452 "libstagefright_m4vh263enc",
453 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000454 "libsync",
455 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900456 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000457 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000458 "libvorbisidec",
459 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900460 "libyuv",
461 "libyuv_static",
462 "media_ndk_headers",
463 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000464 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900465 }
466 //
467 // Module separator
468 //
469 m["com.android.mediaprovider"] = []string{
470 "MediaProvider",
471 "MediaProviderGoogle",
472 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900473 "libbase_ndk",
474 "libfuse",
475 "libfuse_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900476 }
477 //
478 // Module separator
479 //
480 m["com.android.permission"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900481 "kotlin-annotations",
482 "kotlin-stdlib",
483 "kotlin-stdlib-jdk7",
484 "kotlin-stdlib-jdk8",
485 "kotlinx-coroutines-android",
486 "kotlinx-coroutines-android-nodeps",
487 "kotlinx-coroutines-core",
488 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900489 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000490 }
491 //
492 // Module separator
493 //
494 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900495 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900496 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900497 "libc_aeabi",
498 "libc_bionic",
499 "libc_bionic_ndk",
500 "libc_bootstrap",
501 "libc_common",
502 "libc_common_shared",
503 "libc_common_static",
504 "libc_dns",
505 "libc_dynamic_dispatch",
506 "libc_fortify",
507 "libc_freebsd",
508 "libc_freebsd_large_stack",
509 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900510 "libc_init_dynamic",
511 "libc_init_static",
512 "libc_jemalloc_wrapper",
513 "libc_netbsd",
514 "libc_nomalloc",
515 "libc_nopthread",
516 "libc_openbsd",
517 "libc_openbsd_large_stack",
518 "libc_openbsd_ndk",
519 "libc_pthread",
520 "libc_static_dispatch",
521 "libc_syscalls",
522 "libc_tzcode",
523 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900524 "libdebuggerd",
525 "libdebuggerd_common_headers",
526 "libdebuggerd_handler_core",
527 "libdebuggerd_handler_fallback",
528 "libdexfile_external_headers",
529 "libdexfile_support",
530 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900531 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900532 "libjemalloc5",
533 "liblinker_main",
534 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900535 "liblz4",
536 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900537 "libprocinfo",
538 "libpropertyinfoparser",
539 "libscudo",
540 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900541 "libsystemproperties",
542 "libtombstoned_client_static",
543 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900544 "libz",
545 "libziparchive",
546 }
547 //
548 // Module separator
549 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900550 m["com.android.tethering"] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900551 "android.hardware.tetheroffload.config-V1.0-java",
552 "android.hardware.tetheroffload.control-V1.0-java",
553 "android.hidl.base-V1.0-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900554 "libcgrouprc",
555 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900556 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900557 "libvndksupport",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900558 "net-utils-framework-common",
559 "netd_aidl_interface-V3-java",
560 "netlink-client",
561 "networkstack-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "tethering-aidl-interfaces-java",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900563 "TetheringApiCurrentLib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000564 }
565 //
566 // Module separator
567 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900568 m["com.android.wifi"] = []string{
569 "PlatformProperties",
570 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900571 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900572 "android.hardware.wifi-V1.1-java",
573 "android.hardware.wifi-V1.2-java",
574 "android.hardware.wifi-V1.3-java",
575 "android.hardware.wifi-V1.4-java",
576 "android.hardware.wifi.hostapd-V1.0-java",
577 "android.hardware.wifi.hostapd-V1.1-java",
578 "android.hardware.wifi.hostapd-V1.2-java",
579 "android.hardware.wifi.supplicant-V1.0-java",
580 "android.hardware.wifi.supplicant-V1.1-java",
581 "android.hardware.wifi.supplicant-V1.2-java",
582 "android.hardware.wifi.supplicant-V1.3-java",
583 "android.hidl.base-V1.0-java",
584 "android.hidl.manager-V1.0-java",
585 "android.hidl.manager-V1.1-java",
586 "android.hidl.manager-V1.2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900587 "bouncycastle-unbundled",
588 "dnsresolver_aidl_interface-V2-java",
589 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900590 "framework-wifi-pre-jarjar",
591 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900592 "ipmemorystore-aidl-interfaces-V3-java",
593 "ipmemorystore-aidl-interfaces-java",
594 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900595 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900596 "libwifi-jni",
597 "net-utils-services-common",
598 "netd_aidl_interface-V2-java",
599 "netd_aidl_interface-unstable-java",
600 "netd_event_listener_interface-java",
601 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900602 "networkstack-client",
603 "services.net",
604 "wifi-lite-protos",
605 "wifi-nano-protos",
606 "wifi-service-pre-jarjar",
607 "wifi-service-resources",
Jiyong Park0f80c182020-01-31 02:49:53 +0900608 }
609 //
610 // Module separator
611 //
612 m["com.android.sdkext"] = []string{
613 "fmtlib_ndk",
614 "libbase_ndk",
615 "libprotobuf-cpp-lite-ndk",
616 }
617 //
618 // Module separator
619 //
620 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900621 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900622 }
623 //
624 // Module separator
625 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000626 m[android.AvailableToAnyApex] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900627 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
628 "androidx",
629 "androidx-constraintlayout_constraintlayout",
630 "androidx-constraintlayout_constraintlayout-nodeps",
631 "androidx-constraintlayout_constraintlayout-solver",
632 "androidx-constraintlayout_constraintlayout-solver-nodeps",
633 "com.google.android.material_material",
634 "com.google.android.material_material-nodeps",
635
Jiyong Park0f80c182020-01-31 02:49:53 +0900636 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900637 "libclang_rt",
638 "libgcc_stripped",
639 "libprofile-clang-extras",
640 "libprofile-clang-extras_ndk",
641 "libprofile-extras",
642 "libprofile-extras_ndk",
643 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900644 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000645 return m
646}
647
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900648func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900649 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800650 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900651 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900652 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700653 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900654 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700655 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900656
Jooyung Han31c470b2019-10-18 16:26:59 +0900657 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900658 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900659
660 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
661 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
662 sort.Strings(*apexFileContextsInfos)
663 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
664 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900665}
666
Jooyung Han31c470b2019-10-18 16:26:59 +0900667func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
668 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
669 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
670}
671
Jiyong Parkd1063c12019-07-17 20:08:41 +0900672func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900673 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
Colin Crossaede88c2020-08-11 12:17:01 -0700674 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900675 ctx.BottomUp("apex", apexMutator).Parallel()
676 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
677 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900678 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900679}
680
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900681// Mark the direct and transitive dependencies of apex bundles so that they
682// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900683func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900684 if !mctx.Module().Enabled() {
685 return
686 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900687 a, ok := mctx.Module().(*apexBundle)
688 if !ok || a.vndkApex {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900689 return
690 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900691 apexInfo := android.ApexInfo{
Colin Crosse07f2312020-08-13 11:24:56 -0700692 ApexVariationName: mctx.ModuleName(),
693 MinSdkVersion: a.minSdkVersion(mctx),
Colin Crossaede88c2020-08-11 12:17:01 -0700694 RequiredSdks: a.RequiredSdks(),
Colin Crosse07f2312020-08-13 11:24:56 -0700695 Updatable: a.Updatable(),
Colin Crossaede88c2020-08-11 12:17:01 -0700696 InApexes: []string{mctx.ModuleName()},
Jooyung Han698dd9f2020-07-22 15:17:19 +0900697 }
Jooyung Handf78e212020-07-22 15:54:47 +0900698
699 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
700 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
701 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
702 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
703 return
704 }
705
Jooyung Han698dd9f2020-07-22 15:17:19 +0900706 mctx.WalkDeps(func(child, parent android.Module) bool {
707 am, ok := child.(android.ApexModule)
708 if !ok || !am.CanHaveApexVariants() {
709 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900710 }
Paul Duffina37eca22020-07-22 13:00:54 +0100711 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900712 return false
713 }
Jooyung Handf78e212020-07-22 15:54:47 +0900714 if excludeVndkLibs {
715 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
716 return false
717 }
718 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900719
720 depName := mctx.OtherModuleName(child)
721 // If the parent is apexBundle, this child is directly depended.
722 _, directDep := parent.(*apexBundle)
723 android.UpdateApexDependency(apexInfo, depName, directDep)
724 am.BuildForApex(apexInfo)
725 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900726 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900727}
728
Colin Crossaede88c2020-08-11 12:17:01 -0700729func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
730 if !mctx.Module().Enabled() {
731 return
732 }
733 if am, ok := mctx.Module().(android.ApexModule); ok {
734 // Check if any dependencies use unique apex variations. If so, use unique apex variations
735 // for this module.
736 am.UpdateUniqueApexVariationsForDeps(mctx)
737 }
738}
739
Jiyong Park89e850a2020-04-07 16:37:39 +0900740// mark if a module cannot be available to platform. A module cannot be available
741// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
742// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
743func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
744 // Host and recovery are not considered as platform
745 if mctx.Host() || mctx.Module().InstallInRecovery() {
746 return
747 }
748
749 if am, ok := mctx.Module().(android.ApexModule); ok {
750 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
751
752 // In a rare case when a lib is marked as available only to an apex
753 // but the apex doesn't exist. This can happen in a partial manifest branch
754 // like master-art. Currently, libstatssocket in the stats APEX is causing
755 // this problem.
756 // Include the lib in platform because the module SDK that ought to provide
757 // it doesn't exist, so it would otherwise be left out completely.
758 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
759 // this check for libraries provided by SDKs.
760 if !availableToPlatform && !android.InAnyApex(am.Name()) {
761 availableToPlatform = true
762 }
763
764 // If any of the dep is not available to platform, this module is also considered
765 // as being not available to platform even if it has "//apex_available:platform"
766 mctx.VisitDirectDeps(func(child android.Module) {
767 if !am.DepIsInSameApex(mctx, child) {
768 // if the dependency crosses apex boundary, don't consider it
769 return
770 }
771 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
772 availableToPlatform = false
773 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
774 }
775 })
776
777 // Exception 1: stub libraries and native bridge libraries are always available to platform
778 if cc, ok := mctx.Module().(*cc.Module); ok &&
779 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
780 availableToPlatform = true
781 }
782
783 // Exception 2: bootstrap bionic libraries are also always available to platform
784 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
785 availableToPlatform = true
786 }
787
788 if !availableToPlatform {
789 am.SetNotAvailableForPlatform()
790 }
791 }
792}
793
Paul Duffin65347702020-03-31 15:23:40 +0100794// If a module in an APEX depends on a module from an SDK then it needs an APEX
795// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
796func inAnySdk(module android.Module) bool {
797 if sa, ok := module.(android.SdkAware); ok {
798 return sa.IsInAnySdk()
799 }
800
801 return false
802}
803
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900804// Create apex variations if a module is included in APEX(s).
805func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900806 if !mctx.Module().Enabled() {
807 return
808 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900809 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900810 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000811 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900812 // apex bundle itself is mutated so that it and its modules have same
813 // apex variant.
814 apexBundleName := mctx.ModuleName()
815 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900816 } else if o, ok := mctx.Module().(*OverrideApex); ok {
817 apexBundleName := o.GetOverriddenModuleName()
818 if apexBundleName == "" {
819 mctx.ModuleErrorf("base property is not set")
820 return
821 }
822 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900823 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900824
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900825}
Sundong Ahne9b55722019-09-06 17:37:42 +0900826
Jooyung Han7a78a922019-10-08 21:59:58 +0900827var (
828 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
829 apexFileContextsInfosMutex sync.Mutex
830)
831
832func apexFileContextsInfos(config android.Config) *[]string {
833 return config.Once(apexFileContextsInfosKey, func() interface{} {
834 return &[]string{}
835 }).(*[]string)
836}
837
Jooyung Han54aca7b2019-11-20 02:26:02 +0900838func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900839 apexFileContextsInfosMutex.Lock()
840 defer apexFileContextsInfosMutex.Unlock()
841 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900842 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900843}
844
Sundong Ahne9b55722019-09-06 17:37:42 +0900845func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900846 if !mctx.Module().Enabled() {
847 return
848 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900849 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900850 var variants []string
851 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
852 case "image":
853 variants = append(variants, imageApexType, flattenedApexType)
854 case "zip":
855 variants = append(variants, zipApexType)
856 case "both":
857 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
858 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900859 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900860 return
861 }
862
863 modules := mctx.CreateLocalVariations(variants...)
864
865 for i, v := range variants {
866 switch v {
867 case imageApexType:
868 modules[i].(*apexBundle).properties.ApexType = imageApex
869 case zipApexType:
870 modules[i].(*apexBundle).properties.ApexType = zipApex
871 case flattenedApexType:
872 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900873 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900874 modules[i].(*apexBundle).MakeAsSystemExt()
875 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900876 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900877 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900878 } else if _, ok := mctx.Module().(*OverrideApex); ok {
879 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900880 }
881}
882
Jooyung Han5c998b92019-06-27 11:30:33 +0900883func apexUsesMutator(mctx android.BottomUpMutatorContext) {
884 if ab, ok := mctx.Module().(*apexBundle); ok {
885 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
886 }
887}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900888
Jooyung Handc782442019-11-01 03:14:38 +0900889var (
Colin Cross440e0d02020-06-11 11:32:11 -0700890 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +0900891)
892
Colin Cross440e0d02020-06-11 11:32:11 -0700893// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +0900894// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
895// which may cause compatibility issues. (e.g. libbinder)
896// Even though libbinder restricts its availability via 'apex_available' property and relies on
897// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
898// to avoid similar problems.
Colin Cross440e0d02020-06-11 11:32:11 -0700899func useVendorAllowList(config android.Config) []string {
900 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +0900901 return []string{
902 // swcodec uses "vendor" variants for smaller size
903 "com.android.media.swcodec",
904 "test_com.android.media.swcodec",
905 }
906 }).([]string)
907}
908
Colin Cross440e0d02020-06-11 11:32:11 -0700909// setUseVendorAllowListForTest overrides useVendorAllowList and must be
910// called before the first call to useVendorAllowList()
911func setUseVendorAllowListForTest(config android.Config, allowList []string) {
912 config.Once(useVendorAllowListKey, func() interface{} {
913 return allowList
Jooyung Handc782442019-11-01 03:14:38 +0900914 })
915}
916
Jooyung Han01a868d2020-02-27 13:40:44 +0900917type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800918 // List of native libraries
919 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900920
Jooyung Han643adc42020-02-27 13:50:06 +0900921 // List of JNI libraries
922 Jni_libs []string
923
Alex Light9670d332019-01-29 18:07:33 -0800924 // List of native executables
925 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900926
Roland Levillain630846d2019-06-26 12:48:34 +0100927 // List of native tests
928 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800929}
Jooyung Han344d5432019-08-23 11:17:39 +0900930
Alex Light9670d332019-01-29 18:07:33 -0800931type apexMultilibProperties struct {
932 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900933 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800934
935 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900936 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800937
938 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900939 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800940
941 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900942 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800943
944 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900945 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800946}
947
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900948type apexBundleProperties struct {
949 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000950 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800951 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900952
Jiyong Park40e26a22019-02-08 02:53:06 +0900953 // AndroidManifest.xml file used for the zip container of this APEX bundle.
954 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800955 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900956
Roland Levillain411c5842019-09-19 16:37:20 +0100957 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
958 // device (/apex/<apex_name>).
959 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900960 Apex_name *string
961
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900962 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900963 // For platform APEXes, this should points to a file under /system/sepolicy
964 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
965 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900966
Jooyung Han01a868d2020-02-27 13:40:44 +0900967 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900968
969 // List of java libraries that are embedded inside this APEX bundle
970 Java_libs []string
971
972 // List of prebuilt files that are embedded inside this APEX bundle
973 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900974
markchien2f59ec92020-09-02 16:23:38 +0800975 // List of BPF programs inside APEX
976 Bpfs []string
977
Jiyong Parkff1458f2018-10-12 21:49:38 +0900978 // Name of the apex_key module that provides the private key to sign APEX
979 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900980
Alex Light5098a612018-11-29 17:12:15 -0800981 // The type of APEX to build. Controls what the APEX payload is. Either
982 // 'image', 'zip' or 'both'. Default: 'image'.
983 Payload_type *string
984
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900985 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
986 // or an android_app_certificate module name in the form ":module".
987 Certificate *string
988
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900989 // Whether this APEX is installable to one of the partitions. Default: true.
990 Installable *bool
991
Jiyong Parkda6eb592018-12-19 17:12:36 +0900992 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
993 // Default is false.
994 Use_vendor *bool
995
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800996 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
997 Ignore_system_library_special_case *bool
998
Alex Light9670d332019-01-29 18:07:33 -0800999 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001000
Jiyong Parkf97782b2019-02-13 20:28:58 +09001001 // List of sanitizer names that this APEX is enabled for
1002 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001003
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001004 PreventInstall bool `blueprint:"mutated"`
1005
1006 HideFromMake bool `blueprint:"mutated"`
1007
Jooyung Han5c998b92019-06-27 11:30:33 +09001008 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1009 Provide_cpp_shared_libs *bool
1010
1011 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1012 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001013
Sundong Ahnabb64432019-10-22 13:58:29 +09001014 // package format of this apex variant; could be non-flattened, flattened, or zip.
1015 // imageApex, zipApex or flattened
1016 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001017
Jiyong Parkd1063c12019-07-17 20:08:41 +09001018 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1019 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1020 // is implied. This value affects all modules included in this APEX. In other words, they are
1021 // also built with the SDKs specified here.
1022 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001023
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001024 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1025 // Should be only used in tests#.
1026 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001027
Dario Frenica913392020-04-27 18:21:11 +01001028 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1029 // Should be only used in tests#.
1030 Test_only_unsigned_payload *bool
1031
Jiyong Park956305c2020-01-09 12:32:06 +09001032 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001033
1034 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001035 // rules for making sure that the APEX is truly updatable.
1036 // - To be updatable, min_sdk_version should be set as well
1037 // This will also disable the size optimizations like symlinking to the system libs.
1038 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001039 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001040
1041 // The minimum SDK version that this apex must be compatibile with.
1042 Min_sdk_version *string
Jooyung Handf78e212020-07-22 15:54:47 +09001043
1044 // If set true, VNDK libs are considered as stable libs and are not included in this apex.
1045 // Should be only used in non-system apexes (e.g. vendor: true).
1046 // Default is false.
1047 Use_vndk_as_stable *bool
Alex Light9670d332019-01-29 18:07:33 -08001048}
1049
1050type apexTargetBundleProperties struct {
1051 Target struct {
1052 // Multilib properties only for android.
1053 Android struct {
1054 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001055 }
Jooyung Han344d5432019-08-23 11:17:39 +09001056
Alex Light9670d332019-01-29 18:07:33 -08001057 // Multilib properties only for host.
1058 Host struct {
1059 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001060 }
Jooyung Han344d5432019-08-23 11:17:39 +09001061
Alex Light9670d332019-01-29 18:07:33 -08001062 // Multilib properties only for host linux_bionic.
1063 Linux_bionic struct {
1064 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001065 }
Jooyung Han344d5432019-08-23 11:17:39 +09001066
Alex Light9670d332019-01-29 18:07:33 -08001067 // Multilib properties only for host linux_glibc.
1068 Linux_glibc struct {
1069 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001070 }
1071 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001072}
1073
Jiyong Park5d790c32019-11-15 18:40:32 +09001074type overridableProperties struct {
1075 // List of APKs to package inside APEX
1076 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001077
Jiyong Park69aeba92020-04-24 21:16:36 +09001078 // List of runtime resource overlays (RROs) inside APEX
1079 Rros []string
1080
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001081 // Names of modules to be overridden. Listed modules can only be other binaries
1082 // (in Make or Soong).
1083 // This does not completely prevent installation of the overridden binaries, but if both
1084 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1085 // from PRODUCT_PACKAGES.
1086 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001087
1088 // Logging Parent value
1089 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001090
1091 // Apex Container Package Name.
1092 // Override value for attribute package:name in AndroidManifest.xml
1093 Package_name string
Jooyung Han938b5932020-06-20 12:47:47 +09001094
1095 // A txt file containing list of files that are allowed to be included in this APEX.
1096 Allowed_files *string `android:"path"`
Jiyong Park5d790c32019-11-15 18:40:32 +09001097}
1098
Alex Light5098a612018-11-29 17:12:15 -08001099type apexPackaging int
1100
1101const (
1102 imageApex apexPackaging = iota
1103 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001104 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001105)
1106
Sundong Ahnabb64432019-10-22 13:58:29 +09001107// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001108func (a apexPackaging) suffix() string {
1109 switch a {
1110 case imageApex:
1111 return imageApexSuffix
1112 case zipApex:
1113 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001114 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001115 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001116 }
1117}
1118
1119func (a apexPackaging) name() string {
1120 switch a {
1121 case imageApex:
1122 return imageApexType
1123 case zipApex:
1124 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001125 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001126 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001127 }
1128}
1129
Jiyong Parkf653b052019-11-18 15:39:01 +09001130type apexFileClass int
1131
1132const (
1133 etc apexFileClass = iota
1134 nativeSharedLib
1135 nativeExecutable
1136 shBinary
1137 pyBinary
1138 goBinary
1139 javaSharedLib
1140 nativeTest
1141 app
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001142 appSet
Jiyong Parkf653b052019-11-18 15:39:01 +09001143)
1144
Jiyong Park8fd61922018-11-08 02:50:25 +09001145func (class apexFileClass) NameInMake() string {
1146 switch class {
1147 case etc:
1148 return "ETC"
1149 case nativeSharedLib:
1150 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001151 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001152 return "EXECUTABLES"
1153 case javaSharedLib:
1154 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001155 case nativeTest:
1156 return "NATIVE_TESTS"
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001157 case app, appSet:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001158 // b/142537672 Why isn't this APP? We want to have full control over
1159 // the paths and file names of the apk file under the flattend APEX.
1160 // If this is set to APP, then the paths and file names are modified
1161 // by the Make build system. For example, it is installed to
1162 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1163 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1164 // appends module name (which is <apexname>.<Appname> to the path.
1165 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001166 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001167 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001168 }
1169}
1170
Jiyong Parkf653b052019-11-18 15:39:01 +09001171// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001172type apexFile struct {
Yo Chiange8128052020-07-23 20:09:18 +08001173 builtFile android.Path
1174 stem string
1175 // Module name of `module` in AndroidMk. Note the generated AndroidMk module for
1176 // apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
1177 androidMkModuleName string
1178 installDir string
1179 class apexFileClass
1180 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001181 // list of symlinks that will be created in installDir that point to this apexFile
1182 symlinks []string
Chris Parsons216e10a2020-07-09 17:12:52 -04001183 dataPaths []android.DataPath
Jiyong Parkf653b052019-11-18 15:39:01 +09001184 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001185 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001186
1187 requiredModuleNames []string
1188 targetRequiredModuleNames []string
1189 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001190
Colin Cross503c1d02020-01-28 14:00:53 -08001191 jacocoReportClassesFile android.Path // only for javalibs and apps
Colin Cross08dca382020-07-21 20:31:17 -07001192 lintDepSets java.LintDepSets // only for javalibs and apps
Colin Cross503c1d02020-01-28 14:00:53 -08001193 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001194 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001195
1196 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001197}
1198
Yo Chiange8128052020-07-23 20:09:18 +08001199func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
Jiyong Park1833cef2019-12-13 13:28:36 +09001200 ret := apexFile{
Yo Chiange8128052020-07-23 20:09:18 +08001201 builtFile: builtFile,
1202 androidMkModuleName: androidMkModuleName,
1203 installDir: installDir,
1204 class: class,
1205 module: module,
Jiyong Parkf653b052019-11-18 15:39:01 +09001206 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001207 if module != nil {
1208 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001209 ret.requiredModuleNames = module.RequiredModuleNames()
1210 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1211 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001212 }
1213 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001214}
1215
1216func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001217 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001218}
1219
Liz Kammer1c14a212020-05-12 15:26:55 -07001220func (af *apexFile) apexRelativePath(path string) string {
1221 return filepath.Join(af.installDir, path)
1222}
1223
Jiyong Park7cd10e32020-01-14 09:22:18 +09001224// Path() returns path of this apex file relative to the APEX root
1225func (af *apexFile) Path() string {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001226 return af.apexRelativePath(af.Stem())
1227}
1228
1229func (af *apexFile) Stem() string {
Jiyong Parka62aa232020-05-28 23:46:55 +09001230 if af.stem != "" {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001231 return af.stem
Jiyong Parka62aa232020-05-28 23:46:55 +09001232 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001233 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001234}
1235
1236// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1237func (af *apexFile) SymlinkPaths() []string {
1238 var ret []string
1239 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001240 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001241 }
1242 return ret
1243}
1244
1245func (af *apexFile) AvailableToPlatform() bool {
1246 if af.module == nil {
1247 return false
1248 }
1249 if am, ok := af.module.(android.ApexModule); ok {
1250 return am.AvailableFor(android.AvailableToPlatform)
1251 }
1252 return false
1253}
1254
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001255type apexBundle struct {
1256 android.ModuleBase
1257 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001258 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001259 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001260
Jiyong Park5d790c32019-11-15 18:40:32 +09001261 properties apexBundleProperties
1262 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001263 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001264
Jooyung Hanf21c7972019-12-16 22:32:06 +09001265 // specific to apex_vndk modules
1266 vndkProperties apexVndkProperties
1267
Colin Crossa4925902018-11-16 11:36:28 -08001268 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001269 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001270 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001271
Jiyong Park03b68dd2019-07-26 23:20:40 +09001272 prebuiltFileToDelete string
1273
Jiyong Park42cca6c2019-04-01 11:15:50 +09001274 public_key_file android.Path
1275 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001276
1277 container_certificate_file android.Path
1278 container_private_key_file android.Path
1279
Jooyung Han580eb4f2020-06-24 19:33:06 +09001280 fileContexts android.WritablePath
Jooyung Han54aca7b2019-11-20 02:26:02 +09001281
Jiyong Park8fd61922018-11-08 02:50:25 +09001282 // list of files to be included in this apex
1283 filesInfo []apexFile
1284
Jiyong Park956305c2020-01-09 12:32:06 +09001285 // list of module names that should be installed along with this APEX
1286 requiredDeps []string
1287
Jiyong Park956305c2020-01-09 12:32:06 +09001288 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001289 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001290
Sundong Ahnabb64432019-10-22 13:58:29 +09001291 testApex bool
1292 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001293 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001294 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001295
Jooyung Han214bf372019-11-12 13:03:50 +09001296 manifestJsonOut android.WritablePath
1297 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001298
Jooyung Han002ab682020-01-08 01:57:58 +09001299 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001300 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001301 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001302 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1303 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001304
1305 // Suffix of module name in Android.mk
1306 // ".flattened", ".apex", ".zipapex", or ""
1307 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001308
1309 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001310
1311 // Whether to create symlink to the system file instead of having a file
1312 // inside the apex or not
1313 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001314
1315 // Struct holding the merged notice file paths in different formats
1316 mergedNotices android.NoticeOutputs
Colin Cross08dca382020-07-21 20:31:17 -07001317
1318 // Optional list of lint report zip files for apexes that contain java or app modules
1319 lintReports android.Paths
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001320}
1321
Jiyong Park397e55e2018-10-24 21:09:55 +09001322func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001323 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001324 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001325 // Use *FarVariation* to be able to depend on modules having
1326 // conflicting variations with this module. This is required since
1327 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1328 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001329 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001330 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001331 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001332 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001333 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001334
Jooyung Han643adc42020-02-27 13:50:06 +09001335 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1336 {Mutator: "image", Variation: imageVariation},
1337 {Mutator: "link", Variation: "shared"},
1338 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1339 }...), jniLibTag, nativeModules.Jni_libs...)
1340
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001341 ctx.AddFarVariationDependencies(append(target.Variations(),
1342 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001343 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001344
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001345 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001346 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001347 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001348 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001349}
1350
Alex Light9670d332019-01-29 18:07:33 -08001351func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1352 if ctx.Os().Class == android.Device {
1353 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1354 } else {
1355 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1356 if ctx.Os().Bionic() {
1357 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1358 } else {
1359 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1360 }
1361 }
1362}
1363
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001364func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross440e0d02020-06-11 11:32:11 -07001365 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001366 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1367 }
1368
Jiyong Park397e55e2018-10-24 21:09:55 +09001369 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001370 config := ctx.DeviceConfig()
Jooyung Han85d61762020-06-24 23:50:26 +09001371 imageVariation := a.getImageVariation(ctx)
Alex Light9670d332019-01-29 18:07:33 -08001372
1373 a.combineProperties(ctx)
1374
Jiyong Park397e55e2018-10-24 21:09:55 +09001375 has32BitTarget := false
1376 for _, target := range targets {
1377 if target.Arch.ArchType.Multilib == "lib32" {
1378 has32BitTarget = true
1379 }
1380 }
1381 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001382 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001383 // multilib.both
1384 addDependenciesForNativeModules(ctx,
1385 ApexNativeDependencies{
1386 Native_shared_libs: a.properties.Native_shared_libs,
1387 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001388 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001389 Binaries: nil,
1390 },
Jooyung Han85d61762020-06-24 23:50:26 +09001391 target, imageVariation)
Roland Levillain630846d2019-06-26 12:48:34 +01001392
Jiyong Park397e55e2018-10-24 21:09:55 +09001393 // Add native modules targetting both ABIs
1394 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001395 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001396 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001397 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001398
Alex Light3d673592019-01-18 14:37:31 -08001399 isPrimaryAbi := i == 0
1400 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001401 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001402 // multilib.first
1403 addDependenciesForNativeModules(ctx,
1404 ApexNativeDependencies{
1405 Native_shared_libs: nil,
1406 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001407 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001408 Binaries: a.properties.Binaries,
1409 },
Jooyung Han85d61762020-06-24 23:50:26 +09001410 target, imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001411
1412 // Add native modules targetting the first ABI
1413 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001414 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001415 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001416 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001417 }
1418
1419 switch target.Arch.ArchType.Multilib {
1420 case "lib32":
1421 // Add native modules targetting 32-bit ABI
1422 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001423 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001424 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001425 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001426
1427 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001428 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001429 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001430 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001431 case "lib64":
1432 // Add native modules targetting 64-bit ABI
1433 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001434 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001435 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001436 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001437
1438 if !has32BitTarget {
1439 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001440 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001441 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001442 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001443 }
1444 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001445 }
1446
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001447 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1448 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1449 // b/144532908
1450 archForPrebuiltEtc := config.Arches()[0]
1451 for _, arch := range config.Arches() {
1452 // Prefer 64-bit arch if there is any
1453 if arch.ArchType.Multilib == "lib64" {
1454 archForPrebuiltEtc = arch
1455 break
1456 }
1457 }
1458 ctx.AddFarVariationDependencies([]blueprint.Variation{
1459 {Mutator: "os", Variation: ctx.Os().String()},
1460 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1461 }, prebuiltTag, a.properties.Prebuilts...)
1462
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001463 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1464 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001465
markchien2f59ec92020-09-02 16:23:38 +08001466 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1467 bpfTag, a.properties.Bpfs...)
1468
Ulya Trafimovich44561882020-01-03 13:25:54 +00001469 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1470 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1471 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1472 javaLibTag, "jacocoagent")
1473 }
1474
Jiyong Park23c52b02019-02-02 13:13:47 +09001475 if String(a.properties.Key) == "" {
1476 ctx.ModuleErrorf("key is missing")
1477 return
1478 }
1479 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001480
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001481 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001482 if cert != "" {
1483 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001484 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001485
1486 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1487 if len(a.properties.Uses_sdks) > 0 {
1488 sdkRefs := []android.SdkRef{}
1489 for _, str := range a.properties.Uses_sdks {
1490 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1491 sdkRefs = append(sdkRefs, parsed)
1492 }
1493 a.BuildWithSdks(sdkRefs)
1494 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001495}
1496
Jiyong Park5d790c32019-11-15 18:40:32 +09001497func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Han938b5932020-06-20 12:47:47 +09001498 if a.overridableProperties.Allowed_files != nil {
1499 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1500 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001501 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1502 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001503 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1504 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001505}
1506
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001507func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1508 // direct deps of an APEX bundle are all part of the APEX bundle
1509 return true
1510}
1511
Colin Cross0ea8ba82019-06-06 14:33:29 -07001512func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001513 moduleName := ctx.ModuleName()
1514 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1515 // we check with the pseudo module name to see if its certificate is overridden.
1516 if a.vndkApex {
1517 moduleName = vndkApexName
1518 }
1519 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001520 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001521 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001522 }
1523 return String(a.properties.Certificate)
1524}
1525
Colin Cross41955e82019-05-29 14:40:35 -07001526func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1527 switch tag {
1528 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001529 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001530 default:
1531 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001532 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001533}
1534
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001535func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001536 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001537}
1538
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001539func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1540 return proptools.Bool(a.properties.Test_only_no_hashtree)
1541}
1542
Dario Frenica913392020-04-27 18:21:11 +01001543func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1544 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1545}
1546
Jooyung Han85d61762020-06-24 23:50:26 +09001547func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
1548 deviceConfig := ctx.DeviceConfig()
Jooyung Han31c470b2019-10-18 16:26:59 +09001549 if a.vndkApex {
Jooyung Han85d61762020-06-24 23:50:26 +09001550 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jooyung Han31c470b2019-10-18 16:26:59 +09001551 }
Jooyung Han85d61762020-06-24 23:50:26 +09001552
1553 var prefix string
1554 var vndkVersion string
1555 if deviceConfig.VndkVersion() != "" {
1556 if proptools.Bool(a.properties.Use_vendor) {
1557 prefix = cc.VendorVariationPrefix
1558 vndkVersion = deviceConfig.PlatformVndkVersion()
1559 } else if a.SocSpecific() || a.DeviceSpecific() {
1560 prefix = cc.VendorVariationPrefix
1561 vndkVersion = deviceConfig.VndkVersion()
1562 } else if a.ProductSpecific() {
1563 prefix = cc.ProductVariationPrefix
1564 vndkVersion = deviceConfig.ProductVndkVersion()
1565 }
Jiyong Parkda6eb592018-12-19 17:12:36 +09001566 }
Jooyung Han85d61762020-06-24 23:50:26 +09001567 if vndkVersion == "current" {
1568 vndkVersion = deviceConfig.PlatformVndkVersion()
1569 }
1570 if vndkVersion != "" {
1571 return prefix + vndkVersion
1572 }
1573 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001574}
1575
Jiyong Parkf97782b2019-02-13 20:28:58 +09001576func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1577 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1578 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1579 }
1580}
1581
Jiyong Park388ef3f2019-01-28 19:47:32 +09001582func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001583 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1584 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001585 }
1586
1587 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001588 globalSanitizerNames := []string{}
1589 if a.Host() {
1590 globalSanitizerNames = ctx.Config().SanitizeHost()
1591 } else {
1592 arches := ctx.Config().SanitizeDeviceArch()
1593 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1594 globalSanitizerNames = ctx.Config().SanitizeDevice()
1595 }
1596 }
1597 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001598}
1599
Jooyung Han8ce8db92020-05-15 19:05:05 +09001600func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1601 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1602 for _, target := range ctx.MultiTargets() {
1603 if target.Arch.ArchType.Multilib == "lib64" {
1604 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jooyung Han85d61762020-06-24 23:50:26 +09001605 {Mutator: "image", Variation: a.getImageVariation(ctx)},
Jooyung Han8ce8db92020-05-15 19:05:05 +09001606 {Mutator: "link", Variation: "shared"},
1607 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1608 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1609 break
1610 }
1611 }
1612 }
1613}
1614
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001615var _ cc.Coverage = (*apexBundle)(nil)
1616
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001617func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001618 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001619}
1620
1621func (a *apexBundle) PreventInstall() {
1622 a.properties.PreventInstall = true
1623}
1624
1625func (a *apexBundle) HideFromMake() {
1626 a.properties.HideFromMake = true
1627}
1628
Jiyong Park956305c2020-01-09 12:32:06 +09001629func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1630 a.properties.IsCoverageVariant = coverage
1631}
1632
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001633func (a *apexBundle) EnableCoverageIfNeeded() {}
1634
Jiyong Parkf653b052019-11-18 15:39:01 +09001635// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001636func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001637 // Decide the APEX-local directory by the multilib of the library
1638 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001639 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001640 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001641 case "lib32":
1642 dirInApex = "lib"
1643 case "lib64":
1644 dirInApex = "lib64"
1645 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001646 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001647 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001648 }
Jooyung Han35155c42020-02-06 17:33:20 +09001649 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001650 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001651 // Special case for Bionic libs and other libs installed with them. This is
1652 // to prevent those libs from being included in the search path
1653 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1654 // those libs in the Runtime APEX are available via the legacy paths in
1655 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1656 // to the legacy paths and thus will be loaded into the default linker
1657 // namespace (aka "platform" namespace). If the libs are directly in
1658 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1659 // into the runtime linker namespace, which will result in double loading of
1660 // them, which isn't supported.
1661 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001662 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001663
Jiyong Parkf653b052019-11-18 15:39:01 +09001664 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001665 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1666 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001667}
1668
Jiyong Park1833cef2019-12-13 13:28:36 +09001669func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001670 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001671 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001672 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001673 }
Jooyung Han35155c42020-02-06 17:33:20 +09001674 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001675 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001676 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1677 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001678 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001679 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001681}
1682
Jiyong Park1833cef2019-12-13 13:28:36 +09001683func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001684 dirInApex := "bin"
1685 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001686 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001687}
Jiyong Park1833cef2019-12-13 13:28:36 +09001688func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001689 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001690 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1691 if err != nil {
1692 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001693 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001694 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001695 fileToCopy := android.PathForOutput(ctx, s)
1696 // NB: Since go binaries are static we don't need the module for anything here, which is
1697 // good since the go tool is a blueprint.Module not an android.Module like we would
1698 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001699 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001700}
1701
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001702func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001703 dirInApex := filepath.Join("bin", sh.SubDir())
1704 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001705 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001706 af.symlinks = sh.Symlinks()
1707 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001708}
1709
Yo Chiange8128052020-07-23 20:09:18 +08001710type javaModule interface {
1711 android.Module
1712 BaseModuleName() string
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001713 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001714 JacocoReportClassesFile() android.Path
Colin Cross08dca382020-07-21 20:31:17 -07001715 LintDepSets() java.LintDepSets
1716
Jiyong Parka62aa232020-05-28 23:46:55 +09001717 Stem() string
1718}
1719
Yo Chiange8128052020-07-23 20:09:18 +08001720var _ javaModule = (*java.Library)(nil)
1721var _ javaModule = (*java.SdkLibrary)(nil)
1722var _ javaModule = (*java.DexImport)(nil)
1723var _ javaModule = (*java.SdkLibraryImport)(nil)
Colin Cross08dca382020-07-21 20:31:17 -07001724
Yo Chiange8128052020-07-23 20:09:18 +08001725func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001726 dirInApex := "javalib"
Yo Chiange8128052020-07-23 20:09:18 +08001727 fileToCopy := module.DexJarBuildPath()
1728 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1729 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1730 af.lintDepSets = module.LintDepSets()
1731 af.stem = module.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001732 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001733}
1734
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001735func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001736 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1737 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001738 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001739}
1740
atrost6e126252020-01-27 17:01:16 +00001741func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1742 dirInApex := filepath.Join("etc", config.SubDir())
1743 fileToCopy := config.CompatConfig()
1744 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1745}
1746
Jiyong Park1833cef2019-12-13 13:28:36 +09001747func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001748 android.Module
1749 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001750 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001751 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001752 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001753 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001754 BaseModuleName() string
Jooyung Han39ee1192020-03-23 20:21:11 +09001755}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001756 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001757 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001758 appDir = "priv-app"
1759 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001760 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001761 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001762 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001763 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001764 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001765
1766 if app, ok := aapp.(interface {
1767 OverriddenManifestPackageName() string
1768 }); ok {
1769 af.overriddenPackageName = app.OverriddenManifestPackageName()
1770 }
Jiyong Park618922e2020-01-08 13:35:43 +09001771 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001772}
1773
Jiyong Park69aeba92020-04-24 21:16:36 +09001774func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1775 rroDir := "overlay"
1776 dirInApex := filepath.Join(rroDir, rro.Theme())
1777 fileToCopy := rro.OutputFile()
1778 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1779 af.certificate = rro.Certificate()
1780
1781 if a, ok := rro.(interface {
1782 OverriddenManifestPackageName() string
1783 }); ok {
1784 af.overriddenPackageName = a.OverriddenManifestPackageName()
1785 }
1786 return af
1787}
1788
markchien2f59ec92020-09-02 16:23:38 +08001789func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1790 dirInApex := filepath.Join("etc", "bpf")
1791 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1792}
1793
Roland Levillain935639d2019-08-13 14:55:28 +01001794// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1795type flattenedApexContext struct {
1796 android.ModuleContext
1797}
1798
1799func (c *flattenedApexContext) InstallBypassMake() bool {
1800 return true
1801}
1802
Jiyong Park201cedd2020-02-07 17:25:49 +09001803// Visit dependencies that contributes to the payload of this APEX
Jooyung Han749dc692020-04-15 11:03:39 +09001804func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001805 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001806 am, ok := child.(android.ApexModule)
1807 if !ok || !am.CanHaveApexVariants() {
1808 return false
1809 }
1810
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001811 dt := ctx.OtherModuleDependencyTag(child)
1812
1813 if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
1814 return false
1815 }
1816
Jiyong Park0f80c182020-01-31 02:49:53 +09001817 // Check for the direct dependencies that contribute to the payload
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001818 if adt, ok := dt.(dependencyTag); ok {
1819 if adt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001820 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001821 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001822 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001823 return false
1824 }
1825
1826 // Check for the indirect dependencies if it is considered as part of the APEX
Colin Crossaede88c2020-08-11 12:17:01 -07001827 if android.InList(ctx.ModuleName(), am.InApexes()) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001828 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001829 }
1830
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001831 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001832 })
1833}
1834
Jooyung Han03b51852020-02-26 22:45:42 +09001835func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
Jooyung Han749dc692020-04-15 11:03:39 +09001836 ver := proptools.String(a.properties.Min_sdk_version)
1837 if ver == "" {
1838 return android.FutureApiLevel
1839 }
1840 // Treat the current codenames as "current", which means future API version (10000)
1841 // Otherwise, ApiStrToNum converts codename(non-finalized) to a value from [9000...]
1842 // and would fail to build against "current".
1843 if android.InList(ver, ctx.Config().PlatformVersionActiveCodenames()) {
1844 return android.FutureApiLevel
1845 }
1846 // In "REL" branch, "current" is mapped to finalized sdk version
1847 if ctx.Config().PlatformSdkCodename() == "REL" && ver == "current" {
1848 return ctx.Config().PlatformSdkVersionInt()
1849 }
1850 // Finalized codenames are OKAY and will be converted to int
Jooyung Hanaed150d2020-04-02 01:41:41 +09001851 intVer, err := android.ApiStrToNum(ctx, ver)
1852 if err != nil {
1853 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001854 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001855 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001856}
1857
Artur Satayev849f8442020-04-28 14:57:42 +01001858func (a *apexBundle) Updatable() bool {
1859 return proptools.Bool(a.properties.Updatable)
1860}
1861
1862var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1863
Jiyong Park201cedd2020-02-07 17:25:49 +09001864// Ensures that the dependencies are marked as available for this APEX
1865func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1866 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1867 if ctx.Host() || a.testApex || a.vndkApex {
1868 return
1869 }
1870
Jooyung Han85d61762020-06-24 23:50:26 +09001871 // Because APEXes targeting other than system/system_ext partitions
1872 // can't set apex_available, we skip checks for these APEXes
Jooyung Handf78e212020-07-22 15:54:47 +09001873 if a.SocSpecific() || a.DeviceSpecific() ||
1874 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001875 return
1876 }
1877
Jiyong Park58d10902020-03-28 14:43:19 +09001878 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1879 // Requiring them and their transitive depencies with apex_available is not right
1880 // because they just add noise.
1881 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1882 return
1883 }
1884
Jooyung Han749dc692020-04-15 11:03:39 +09001885 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001886 if externalDep {
1887 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1888 return false
1889 }
1890
Jiyong Park201cedd2020-02-07 17:25:49 +09001891 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001892 fromName := ctx.OtherModuleName(from)
1893 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001894
1895 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1896 // do any of its dependencies.
1897 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1898 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1899 return false
1900 }
1901
Colin Cross440e0d02020-06-11 11:32:11 -07001902 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001903 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001904 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001905 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, ctx.GetPathString(true))
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001906 // Visit this module's dependencies to check and report any issues with their availability.
1907 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001908 })
1909}
1910
Jooyung Han548640b2020-04-27 12:10:30 +09001911func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01001912 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09001913 if String(a.properties.Min_sdk_version) == "" {
1914 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1915 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001916
1917 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001918 }
1919}
1920
Jooyung Han749dc692020-04-15 11:03:39 +09001921func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
1922 if a.testApex || a.vndkApex {
1923 return
1924 }
1925 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
1926 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
1927 return
1928 }
1929 android.CheckMinSdkVersion(a, ctx, a.minSdkVersion(ctx))
1930}
1931
Jiyong Park7d95a512020-05-10 15:16:24 +09001932// Ensures that a lib providing stub isn't statically linked
1933func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1934 // Practically, we only care about regular APEXes on the device.
1935 if ctx.Host() || a.testApex || a.vndkApex {
1936 return
1937 }
1938
Jooyung Han749dc692020-04-15 11:03:39 +09001939 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park7d95a512020-05-10 15:16:24 +09001940 if ccm, ok := to.(*cc.Module); ok {
1941 apexName := ctx.ModuleName()
1942 fromName := ctx.OtherModuleName(from)
1943 toName := ctx.OtherModuleName(to)
1944
1945 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1946 // do any of its dependencies.
1947 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1948 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1949 return false
1950 }
1951
1952 // TODO(jiyong) remove this check when R is published to AOSP. Currently, libstatssocket
1953 // is capable of providing a stub variant, but is being statically linked from the bluetooth
1954 // APEX.
1955 if toName == "libstatssocket" {
1956 return false
1957 }
1958
1959 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
1960 // It can't make the static dependencies dynamic because it can't
1961 // do the dynamic linking for itself.
1962 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1963 return false
1964 }
1965
1966 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName)
1967 if isStubLibraryFromOtherApex && !externalDep {
1968 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1969 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1970 }
1971
1972 }
1973 return true
1974 })
1975}
1976
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001977func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Martin Stjernholm56507b42020-06-24 22:31:36 +01001978 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
Sundong Ahnabb64432019-10-22 13:58:29 +09001979 switch a.properties.ApexType {
1980 case imageApex:
1981 if buildFlattenedAsDefault {
1982 a.suffix = imageApexSuffix
1983 } else {
1984 a.suffix = ""
1985 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001986
1987 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001988 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001989 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001990 }
1991 case zipApex:
1992 if proptools.String(a.properties.Payload_type) == "zip" {
1993 a.suffix = ""
1994 a.primaryApexType = true
1995 } else {
1996 a.suffix = zipApexSuffix
1997 }
1998 case flattenedApex:
1999 if buildFlattenedAsDefault {
2000 a.suffix = ""
2001 a.primaryApexType = true
2002 } else {
2003 a.suffix = flattenedSuffix
2004 }
Alex Light5098a612018-11-29 17:12:15 -08002005 }
2006
Roland Levillain630846d2019-06-26 12:48:34 +01002007 if len(a.properties.Tests) > 0 && !a.testApex {
2008 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2009 return
2010 }
2011
Jiyong Park0f80c182020-01-31 02:49:53 +09002012 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002013 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09002014 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09002015 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09002016
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002017 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2018
Jooyung Hane1633032019-08-01 17:41:43 +09002019 // native lib dependencies
2020 var provideNativeLibs []string
2021 var requireNativeLibs []string
2022
Jooyung Han5c998b92019-06-27 11:30:33 +09002023 // Check if "uses" requirements are met with dependent apexBundles
2024 var providedNativeSharedLibs []string
2025 useVendor := proptools.Bool(a.properties.Use_vendor)
2026 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2027 if ctx.OtherModuleDependencyTag(m) != usesTag {
2028 return
2029 }
2030 otherName := ctx.OtherModuleName(m)
2031 other, ok := m.(*apexBundle)
2032 if !ok {
2033 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2034 return
2035 }
2036 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2037 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2038 return
2039 }
2040 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2041 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2042 return
2043 }
2044 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2045 })
2046
Jiyong Parkf653b052019-11-18 15:39:01 +09002047 var filesInfo []apexFile
Jooyung Han749dc692020-04-15 11:03:39 +09002048 // TODO(jiyong) do this using WalkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002049 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002050 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002051 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2052 return false
2053 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002054 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002055 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002056 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002057 case sharedLibTag, jniLibTag:
2058 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002059 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09002060 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2061 fi.isJniLib = isJniLib
2062 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09002063 // Collect the list of stub-providing libs except:
2064 // - VNDK libs are only for vendors
2065 // - bootstrap bionic libs are treated as provided by system
2066 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002067 provideNativeLibs = append(provideNativeLibs, fi.Stem())
2068 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002069 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002070 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002071 propertyName := "native_shared_libs"
2072 if isJniLib {
2073 propertyName = "jni_libs"
2074 }
2075 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002076 }
2077 case executableTag:
2078 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002079 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002080 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002081 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002082 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002083 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002084 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002085 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002086 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002087 } else {
Alex Light778127a2019-02-27 14:19:50 -08002088 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 +09002089 }
2090 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09002091 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01002092 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Yo Chiange8128052020-07-23 20:09:18 +08002093 af := apexFileForJavaLibrary(ctx, child.(javaModule))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002094 if !af.Ok() {
2095 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2096 return false
2097 }
2098 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002099 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09002100 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002101 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002102 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002103 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002104 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002105 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002106 return true // track transitive dependencies
2107 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002108 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002109 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002110 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002111 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2112 appDir := "app"
2113 if ap.Privileged() {
2114 appDir = "priv-app"
2115 }
Yo Chiange8128052020-07-23 20:09:18 +08002116 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002117 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2118 af.certificate = java.PresignedCertificate
2119 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002120 } else {
2121 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2122 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002123 case rroTag:
2124 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2125 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2126 } else {
2127 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2128 }
markchien2f59ec92020-09-02 16:23:38 +08002129 case bpfTag:
2130 if bpfProgram, ok := child.(bpf.BpfModule); ok {
2131 filesToCopy, _ := bpfProgram.OutputFiles("")
2132 for _, bpfFile := range filesToCopy {
2133 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
2134 }
2135 } else {
2136 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
2137 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002138 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002139 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002140 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002141 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2142 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002143 } else {
atrost6e126252020-01-27 17:01:16 +00002144 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002145 }
Roland Levillain630846d2019-06-26 12:48:34 +01002146 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002147 if ccTest, ok := child.(*cc.Module); ok {
2148 if ccTest.IsTestPerSrcAllTestsVariation() {
2149 // Multiple-output test module (where `test_per_src: true`).
2150 //
2151 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2152 // We do not add this variation to `filesInfo`, as it has no output;
2153 // however, we do add the other variations of this module as indirect
2154 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002155 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002156 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002157 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002158 af.class = nativeTest
2159 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002160 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002161 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002162 } else {
2163 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2164 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002165 case keyTag:
2166 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002167 a.private_key_file = key.private_key_file
2168 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002169 } else {
2170 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002171 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002172 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002173 case certificateTag:
2174 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002175 a.container_certificate_file = dep.Certificate.Pem
2176 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002177 } else {
2178 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2179 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002180 case android.PrebuiltDepTag:
2181 // If the prebuilt is force disabled, remember to delete the prebuilt file
2182 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002183 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002184 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2185 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002186 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002187 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002188 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002189 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002190 // We cannot use a switch statement on `depTag` here as the checked
2191 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002192 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002193 if cc, ok := child.(*cc.Module); ok {
2194 if android.InList(cc.Name(), providedNativeSharedLibs) {
2195 // If we're using a shared library which is provided from other APEX,
2196 // don't include it in this APEX
2197 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002198 }
Jooyung Handf78e212020-07-22 15:54:47 +09002199 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002200 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002201 return false
2202 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002203 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2204 af.transitiveDep = true
Jooyung Hanefb184e2020-06-25 17:14:25 +09002205 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002206 // If the dependency is a stubs lib, don't include it in this APEX,
2207 // but make sure that the lib is installed on the device.
2208 // In case no APEX is having the lib, the lib is installed to the system
2209 // partition.
2210 //
2211 // Always include if we are a host-apex however since those won't have any
2212 // system libraries.
Jooyung Hanefb184e2020-06-25 17:14:25 +09002213 if !android.DirectlyInAnyApex(ctx, depName) {
2214 // we need a module name for Make
2215 name := cc.BaseModuleName() + cc.Properties.SubName
2216 if proptools.Bool(a.properties.Use_vendor) {
2217 // we don't use subName(.vendor) for a "use_vendor: true" apex
2218 // which is supposed to be installed in /system
2219 name = cc.BaseModuleName()
2220 }
2221 if !android.InList(name, a.requiredDeps) {
2222 a.requiredDeps = append(a.requiredDeps, name)
2223 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002224 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002225 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002226 // Don't track further
2227 return false
2228 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002229 filesInfo = append(filesInfo, af)
2230 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002231 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002232 } else if cc.IsTestPerSrcDepTag(depTag) {
2233 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002234 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002235 // Handle modules created as `test_per_src` variations of a single test module:
2236 // use the name of the generated test binary (`fileToCopy`) instead of the name
2237 // of the original test module (`depName`, shared by all `test_per_src`
2238 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002239 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002240 // these are not considered transitive dep
2241 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002242 filesInfo = append(filesInfo, af)
2243 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002244 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002245 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002246 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2247 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002248 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002249 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002250 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2251 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002252 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002253 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002254 }
2255 }
2256 }
2257 return false
2258 })
2259
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002260 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2261 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2262 // via the global boot image config.
2263 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002264 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002265 dirInApex := filepath.Join("javalib", arch.String())
2266 for _, f := range files {
2267 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002268 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002269 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002270 }
2271 }
2272 }
2273
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002274 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002275 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2276 return
2277 }
2278
Jiyong Park8fd61922018-11-08 02:50:25 +09002279 // remove duplicates in filesInfo
2280 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002281 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002282 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002283 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002284 if e, ok := encountered[dest]; !ok {
2285 encountered[dest] = f
2286 } else {
2287 // If a module is directly included and also transitively depended on
2288 // consider it as directly included.
2289 e.transitiveDep = e.transitiveDep && f.transitiveDep
2290 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002291 }
2292 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002293 var result []apexFile
2294 for _, v := range encountered {
2295 result = append(result, v)
2296 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002297 return result
2298 }
2299 filesInfo = removeDup(filesInfo)
2300
2301 // to have consistent build rules
2302 sort.Slice(filesInfo, func(i, j int) bool {
2303 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2304 })
2305
Jiyong Park8fd61922018-11-08 02:50:25 +09002306 a.installDir = android.PathForModuleInstall(ctx, "apex")
2307 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002308
Jiyong Park7cd10e32020-01-14 09:22:18 +09002309 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2310 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2311 // the same library in the system partition, thus effectively sharing the same libraries
2312 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2313 // in the APEX.
2314 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2315 a.installable() &&
2316 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002317
Jooyung Han85d61762020-06-24 23:50:26 +09002318 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2319 // So we can't link them to /system/lib libs which are core variants.
Jooyung Handf78e212020-07-22 15:54:47 +09002320 if a.SocSpecific() || a.DeviceSpecific() ||
2321 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002322 a.linkToSystemLib = false
2323 }
2324
Jiyong Park9d677202020-02-19 16:29:35 +09002325 // We don't need the optimization for updatable APEXes, as it might give false signal
2326 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002327 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002328 a.linkToSystemLib = false
2329 }
2330
Jiyong Park638d30e2020-02-26 18:27:19 +09002331 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2332 if ctx.Host() {
2333 a.linkToSystemLib = false
2334 }
2335
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002336 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002337 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2338
Jooyung Han580eb4f2020-06-24 19:33:06 +09002339 a.buildFileContexts(ctx)
2340
Jooyung Han01a3ee22019-11-02 02:52:25 +09002341 a.setCertificateAndPrivateKey(ctx)
2342 if a.properties.ApexType == flattenedApex {
2343 a.buildFlattenedApex(ctx)
2344 } else {
2345 a.buildUnflattenedApex(ctx)
2346 }
2347
Jooyung Han002ab682020-01-08 01:57:58 +09002348 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002349
2350 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002351
2352 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002353}
2354
Artur Satayev8cf899a2020-04-15 17:29:42 +01002355// Enforce that Java deps of the apex are using stable SDKs to compile
2356func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2357 // Visit direct deps only. As long as we guarantee top-level deps are using
2358 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2359 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2360 tag := ctx.OtherModuleDependencyTag(module)
2361 switch tag {
2362 case javaLibTag, androidAppTag:
2363 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2364 if err := m.CheckStableSdkVersion(); err != nil {
2365 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2366 }
2367 }
2368 }
2369 })
2370}
2371
Colin Cross440e0d02020-06-11 11:32:11 -07002372func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002373 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002374 moduleName = normalizeModuleName(moduleName)
2375
Colin Cross440e0d02020-06-11 11:32:11 -07002376 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002377 return true
2378 }
2379
2380 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002381 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002382 return true
2383 }
2384
2385 return false
2386}
2387
2388func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002389 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2390 // system. Trim the prefix for the check since they are confusing
2391 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2392 if strings.HasPrefix(moduleName, "libclang_rt.") {
2393 // This module has many arch variants that depend on the product being built.
2394 // We don't want to list them all
2395 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002396 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002397 if strings.HasPrefix(moduleName, "androidx.") {
2398 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2399 moduleName = "androidx"
2400 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002401 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002402}
2403
Jooyung Han344d5432019-08-23 11:17:39 +09002404func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002405 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002406 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002407 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002408 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002409 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002410 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002411 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002412 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002413 return module
2414}
Jiyong Park30ca9372019-02-07 16:27:23 +09002415
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002416func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002417 bundle := newApexBundle()
2418 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002419 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002420 return bundle
2421}
2422
Jiyong Parkfce0b422020-02-11 03:56:06 +09002423// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2424// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002425func testApexBundleFactory() android.Module {
2426 bundle := newApexBundle()
2427 bundle.testApex = true
2428 return bundle
2429}
2430
Jiyong Parkfce0b422020-02-11 03:56:06 +09002431// apex packages other modules into an APEX file which is a packaging format for system-level
2432// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002433func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002434 return newApexBundle()
2435}
2436
Jiyong Park30ca9372019-02-07 16:27:23 +09002437//
2438// Defaults
2439//
2440type Defaults struct {
2441 android.ModuleBase
2442 android.DefaultsModuleBase
2443}
2444
Jiyong Park30ca9372019-02-07 16:27:23 +09002445func defaultsFactory() android.Module {
2446 return DefaultsFactory()
2447}
2448
2449func DefaultsFactory(props ...interface{}) android.Module {
2450 module := &Defaults{}
2451
2452 module.AddProperties(props...)
2453 module.AddProperties(
2454 &apexBundleProperties{},
2455 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002456 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002457 )
2458
2459 android.InitDefaultsModule(module)
2460 return module
2461}
Jiyong Park5d790c32019-11-15 18:40:32 +09002462
2463//
2464// OverrideApex
2465//
2466type OverrideApex struct {
2467 android.ModuleBase
2468 android.OverrideModuleBase
2469}
2470
2471func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2472 // All the overrides happen in the base module.
2473}
2474
2475// override_apex is used to create an apex module based on another apex module
2476// by overriding some of its properties.
2477func overrideApexFactory() android.Module {
2478 m := &OverrideApex{}
2479 m.AddProperties(&overridableProperties{})
2480
2481 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2482 android.InitOverrideModule(m)
2483 return m
2484}