blob: 359e246e90b9e746cdd323c14ac159eb5d8bf25a [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"
29 "android/soong/cc"
30 prebuilt_etc "android/soong/etc"
31 "android/soong/java"
32 "android/soong/python"
33 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090034)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090065 rroTag = dependencyTag{name: "rro", payload: true}
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
Colin Cross440e0d02020-06-11 11:32:11 -070067 apexAvailBaseline = makeApexAvailableBaseline()
68
69 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090070)
71
Paul Duffin7d74e7b2020-03-06 12:30:13 +000072// Transform the map of apex -> modules to module -> apexes.
Colin Cross440e0d02020-06-11 11:32:11 -070073func invertApexBaseline(m map[string][]string) map[string][]string {
Paul Duffin7d74e7b2020-03-06 12:30:13 +000074 r := make(map[string][]string)
75 for apex, modules := range m {
76 for _, module := range modules {
77 r[module] = append(r[module], apex)
78 }
79 }
80 return r
81}
82
Colin Cross440e0d02020-06-11 11:32:11 -070083// Retrieve the baseline of apexes to which the supplied module belongs.
84func BaselineApexAvailable(moduleName string) []string {
85 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
Paul Duffin7d74e7b2020-03-06 12:30:13 +000086}
87
Anton Hanssoneec79eb2020-01-10 15:12:39 +000088// This is a map from apex to modules, which overrides the
89// apex_available setting for that particular module to make
90// it available for the apex regardless of its setting.
91// TODO(b/147364041): remove this
Colin Cross440e0d02020-06-11 11:32:11 -070092func makeApexAvailableBaseline() map[string][]string {
Anton Hanssoneec79eb2020-01-10 15:12:39 +000093 // The "Module separator"s below are employed to minimize merge conflicts.
94 m := make(map[string][]string)
95 //
96 // Module separator
97 //
Anton Hanssoneec79eb2020-01-10 15:12:39 +000098 m["com.android.bluetooth.updatable"] = []string{
99 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000100 "android.hardware.bluetooth.a2dp@1.0",
101 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900102 "android.hardware.bluetooth@1.0",
103 "android.hardware.bluetooth@1.1",
104 "android.hardware.graphics.bufferqueue@1.0",
105 "android.hardware.graphics.bufferqueue@2.0",
106 "android.hardware.graphics.common@1.0",
107 "android.hardware.graphics.common@1.1",
108 "android.hardware.graphics.common@1.2",
109 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000110 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 "android.hidl.token@1.0",
112 "android.hidl.token@1.0-utils",
113 "avrcp-target-service",
114 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900115 "bluetooth-protos-lite",
116 "bluetooth.mapsapi",
117 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900118 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900119 "ipmemorystore-aidl-interfaces-V5-java",
120 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900121 "internal_include_headers",
122 "lib-bt-packets",
123 "lib-bt-packets-avrcp",
124 "lib-bt-packets-base",
125 "libFraunhoferAAC",
126 "libaudio-a2dp-hw-utils",
127 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900128 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000129 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "libbluetooth-types",
131 "libbluetooth-types-header",
132 "libbluetooth_gd",
133 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000134 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900135 "libbt-audio-hal-interface",
136 "libbt-bta",
137 "libbt-common",
138 "libbt-hci",
139 "libbt-platform-protos-lite",
140 "libbt-protos-lite",
141 "libbt-sbc-decoder",
142 "libbt-sbc-encoder",
143 "libbt-stack",
144 "libbt-utils",
145 "libbtcore",
146 "libbtdevice",
147 "libbte",
148 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000149 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000150 "libevent",
151 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900153 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900154 "libmedia_headers",
155 "libmodpb64",
156 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900157 "libstagefright_foundation_headers",
158 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000159 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900160 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000163 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900165 "net-utils-services-common",
166 "netd_aidl_interface-unstable-java",
167 "netd_event_listener_interface-java",
168 "netlink-client",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900169 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900170 "sap-api-java-static",
171 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000172 }
173 //
174 // Module separator
175 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 //
178 // Module separator
179 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900180 m["com.android.neuralnetworks"] = []string{
181 "android.hardware.neuralnetworks@1.0",
182 "android.hardware.neuralnetworks@1.1",
183 "android.hardware.neuralnetworks@1.2",
184 "android.hardware.neuralnetworks@1.3",
185 "android.hidl.allocator@1.0",
186 "android.hidl.memory.token@1.0",
187 "android.hidl.memory@1.0",
188 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900189 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900190 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900191 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900192 "libprocpartition",
193 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900194 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000195 //
196 // Module separator
197 //
198 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000199 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900200 "android.hardware.cas.native@1.0",
201 "android.hardware.cas@1.0",
202 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000203 "android.hardware.configstore@1.0",
204 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000205 "android.hardware.graphics.allocator@2.0",
206 "android.hardware.graphics.allocator@3.0",
207 "android.hardware.graphics.bufferqueue@1.0",
208 "android.hardware.graphics.bufferqueue@2.0",
209 "android.hardware.graphics.common@1.0",
210 "android.hardware.graphics.common@1.1",
211 "android.hardware.graphics.common@1.2",
212 "android.hardware.graphics.mapper@2.0",
213 "android.hardware.graphics.mapper@2.1",
214 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900215 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000216 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900217 "android.hidl.allocator@1.0",
218 "android.hidl.memory.token@1.0",
219 "android.hidl.memory@1.0",
220 "android.hidl.token@1.0",
221 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900222 "bionic_libc_platform_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900223 "exoplayer2-extractor",
224 "exoplayer2-extractor-annotation-stubs",
Jiyong Park0f80c182020-01-31 02:49:53 +0900225 "gl_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900226 "jsr305",
Jiyong Park0f80c182020-01-31 02:49:53 +0900227 "libEGL",
228 "libEGL_blobCache",
229 "libEGL_getProcAddress",
230 "libFLAC",
231 "libFLAC-config",
232 "libFLAC-headers",
233 "libGLESv2",
234 "libaacextractor",
235 "libamrextractor",
236 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900237 "libaudio_system_headers",
238 "libaudioclient",
239 "libaudioclient_headers",
240 "libaudiofoundation",
241 "libaudiofoundation_headers",
242 "libaudiomanager",
243 "libaudiopolicy",
244 "libaudioutils",
245 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900246 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900247 "libbluetooth-types-header",
248 "libbufferhub",
249 "libbufferhub_headers",
250 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900251 "libc_malloc_debug_backtrace",
252 "libcamera_client",
253 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900254 "libdexfile_external_headers",
255 "libdexfile_support",
256 "libdvr_headers",
257 "libexpat",
258 "libfifo",
259 "libflacextractor",
260 "libgrallocusage",
261 "libgraphicsenv",
262 "libgui",
263 "libgui_headers",
264 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900265 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900266 "liblzma",
267 "libmath",
268 "libmedia",
269 "libmedia_codeclist",
270 "libmedia_headers",
271 "libmedia_helper",
272 "libmedia_helper_headers",
273 "libmedia_midiiowrapper",
274 "libmedia_omx",
275 "libmediautils",
276 "libmidiextractor",
277 "libmkvextractor",
278 "libmp3extractor",
279 "libmp4extractor",
280 "libmpeg2extractor",
281 "libnativebase_headers",
282 "libnativebridge-headers",
283 "libnativebridge_lazy",
284 "libnativeloader-headers",
285 "libnativeloader_lazy",
286 "libnativewindow_headers",
287 "libnblog",
288 "liboggextractor",
289 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900290 "libpdx",
291 "libpdx_default_transport",
292 "libpdx_headers",
293 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900294 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 "libsonivox",
296 "libspeexresampler",
297 "libspeexresampler",
298 "libstagefright_esds",
299 "libstagefright_flacdec",
300 "libstagefright_flacdec",
301 "libstagefright_foundation",
302 "libstagefright_foundation_headers",
303 "libstagefright_foundation_without_imemory",
304 "libstagefright_headers",
305 "libstagefright_id3",
306 "libstagefright_metadatautils",
307 "libstagefright_mpeg2extractor",
308 "libstagefright_mpeg2support",
309 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900310 "libui",
311 "libui_headers",
312 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900313 "libvibrator",
314 "libvorbisidec",
315 "libwavextractor",
316 "libwebm",
317 "media_ndk_headers",
318 "media_plugin_headers",
319 "updatable-media",
320 }
321 //
322 // Module separator
323 //
324 m["com.android.media.swcodec"] = []string{
325 "android.frameworks.bufferhub@1.0",
326 "android.hardware.common-ndk_platform",
327 "android.hardware.configstore-utils",
328 "android.hardware.configstore@1.0",
329 "android.hardware.configstore@1.1",
330 "android.hardware.graphics.allocator@2.0",
331 "android.hardware.graphics.allocator@3.0",
332 "android.hardware.graphics.bufferqueue@1.0",
333 "android.hardware.graphics.bufferqueue@2.0",
334 "android.hardware.graphics.common-ndk_platform",
335 "android.hardware.graphics.common@1.0",
336 "android.hardware.graphics.common@1.1",
337 "android.hardware.graphics.common@1.2",
338 "android.hardware.graphics.mapper@2.0",
339 "android.hardware.graphics.mapper@2.1",
340 "android.hardware.graphics.mapper@3.0",
341 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000342 "android.hardware.media.bufferpool@2.0",
343 "android.hardware.media.c2@1.0",
344 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900345 "android.hardware.media@1.0",
346 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000347 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900348 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000349 "android.hidl.safe_union@1.0",
350 "android.hidl.token@1.0",
351 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900352 "libEGL",
353 "libFLAC",
354 "libFLAC-config",
355 "libFLAC-headers",
356 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900357 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900358 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900359 "libaudio_system_headers",
360 "libaudioutils",
361 "libaudioutils",
362 "libaudioutils_fixedfft",
363 "libavcdec",
364 "libavcenc",
365 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000366 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900367 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900368 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900369 "libbluetooth-types-header",
370 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000371 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900372 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000373 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900374 "libcodec2_hidl@1.1",
375 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000376 "libcodec2_soft_aacdec",
377 "libcodec2_soft_aacenc",
378 "libcodec2_soft_amrnbdec",
379 "libcodec2_soft_amrnbenc",
380 "libcodec2_soft_amrwbdec",
381 "libcodec2_soft_amrwbenc",
382 "libcodec2_soft_av1dec_gav1",
383 "libcodec2_soft_avcdec",
384 "libcodec2_soft_avcenc",
385 "libcodec2_soft_common",
386 "libcodec2_soft_flacdec",
387 "libcodec2_soft_flacenc",
388 "libcodec2_soft_g711alawdec",
389 "libcodec2_soft_g711mlawdec",
390 "libcodec2_soft_gsmdec",
391 "libcodec2_soft_h263dec",
392 "libcodec2_soft_h263enc",
393 "libcodec2_soft_hevcdec",
394 "libcodec2_soft_hevcenc",
395 "libcodec2_soft_mp3dec",
396 "libcodec2_soft_mpeg2dec",
397 "libcodec2_soft_mpeg4dec",
398 "libcodec2_soft_mpeg4enc",
399 "libcodec2_soft_opusdec",
400 "libcodec2_soft_opusenc",
401 "libcodec2_soft_rawdec",
402 "libcodec2_soft_vorbisdec",
403 "libcodec2_soft_vp8dec",
404 "libcodec2_soft_vp8enc",
405 "libcodec2_soft_vp9dec",
406 "libcodec2_soft_vp9enc",
407 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000408 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900409 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000410 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900411 "libfmq",
412 "libgav1",
413 "libgralloctypes",
414 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000415 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900416 "libgsm",
417 "libgui_bufferqueue_static",
418 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000419 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900420 "libhardware_headers",
421 "libhevcdec",
422 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000423 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900424 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000425 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900426 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000427 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900428 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900429 "libmpeg2dec",
430 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000431 "libnativebridge_lazy",
432 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900433 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900434 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000435 "libscudo_wrapper",
436 "libsfplugin_ccodec_utils",
437 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900438 "libstagefright_amrnbdec",
439 "libstagefright_amrnbenc",
440 "libstagefright_amrwbdec",
441 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000442 "libstagefright_bufferpool@2.0.1",
443 "libstagefright_bufferqueue_helper",
444 "libstagefright_enc_common",
445 "libstagefright_flacdec",
446 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900447 "libstagefright_foundation_headers",
448 "libstagefright_headers",
449 "libstagefright_m4vh263dec",
450 "libstagefright_m4vh263enc",
451 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000452 "libsync",
453 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900454 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000455 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000456 "libvorbisidec",
457 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900458 "libyuv",
459 "libyuv_static",
460 "media_ndk_headers",
461 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000462 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900463 }
464 //
465 // Module separator
466 //
467 m["com.android.mediaprovider"] = []string{
468 "MediaProvider",
469 "MediaProviderGoogle",
470 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900471 "libbase_ndk",
472 "libfuse",
473 "libfuse_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900474 }
475 //
476 // Module separator
477 //
478 m["com.android.permission"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900479 "kotlin-annotations",
480 "kotlin-stdlib",
481 "kotlin-stdlib-jdk7",
482 "kotlin-stdlib-jdk8",
483 "kotlinx-coroutines-android",
484 "kotlinx-coroutines-android-nodeps",
485 "kotlinx-coroutines-core",
486 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900487 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000488 }
489 //
490 // Module separator
491 //
492 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900493 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900494 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900495 "libc_aeabi",
496 "libc_bionic",
497 "libc_bionic_ndk",
498 "libc_bootstrap",
499 "libc_common",
500 "libc_common_shared",
501 "libc_common_static",
502 "libc_dns",
503 "libc_dynamic_dispatch",
504 "libc_fortify",
505 "libc_freebsd",
506 "libc_freebsd_large_stack",
507 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900508 "libc_init_dynamic",
509 "libc_init_static",
510 "libc_jemalloc_wrapper",
511 "libc_netbsd",
512 "libc_nomalloc",
513 "libc_nopthread",
514 "libc_openbsd",
515 "libc_openbsd_large_stack",
516 "libc_openbsd_ndk",
517 "libc_pthread",
518 "libc_static_dispatch",
519 "libc_syscalls",
520 "libc_tzcode",
521 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900522 "libdebuggerd",
523 "libdebuggerd_common_headers",
524 "libdebuggerd_handler_core",
525 "libdebuggerd_handler_fallback",
526 "libdexfile_external_headers",
527 "libdexfile_support",
528 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900529 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900530 "libjemalloc5",
531 "liblinker_main",
532 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900533 "liblz4",
534 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900535 "libprocinfo",
536 "libpropertyinfoparser",
537 "libscudo",
538 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900539 "libsystemproperties",
540 "libtombstoned_client_static",
541 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900542 "libz",
543 "libziparchive",
544 }
545 //
546 // Module separator
547 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900548 m["com.android.tethering"] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900549 "android.hardware.tetheroffload.config-V1.0-java",
550 "android.hardware.tetheroffload.control-V1.0-java",
551 "android.hidl.base-V1.0-java",
552 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900553 "libcgrouprc",
554 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900555 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900556 "libvndksupport",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900557 "net-utils-framework-common",
558 "netd_aidl_interface-V3-java",
559 "netlink-client",
560 "networkstack-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900561 "tethering-aidl-interfaces-java",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900562 "TetheringApiCurrentLib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000563 }
564 //
565 // Module separator
566 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900567 m["com.android.wifi"] = []string{
568 "PlatformProperties",
569 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900570 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900571 "android.hardware.wifi-V1.1-java",
572 "android.hardware.wifi-V1.2-java",
573 "android.hardware.wifi-V1.3-java",
574 "android.hardware.wifi-V1.4-java",
575 "android.hardware.wifi.hostapd-V1.0-java",
576 "android.hardware.wifi.hostapd-V1.1-java",
577 "android.hardware.wifi.hostapd-V1.2-java",
578 "android.hardware.wifi.supplicant-V1.0-java",
579 "android.hardware.wifi.supplicant-V1.1-java",
580 "android.hardware.wifi.supplicant-V1.2-java",
581 "android.hardware.wifi.supplicant-V1.3-java",
582 "android.hidl.base-V1.0-java",
583 "android.hidl.manager-V1.0-java",
584 "android.hidl.manager-V1.1-java",
585 "android.hidl.manager-V1.2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900586 "bouncycastle-unbundled",
587 "dnsresolver_aidl_interface-V2-java",
588 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900589 "framework-wifi-pre-jarjar",
590 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900591 "ipmemorystore-aidl-interfaces-V3-java",
592 "ipmemorystore-aidl-interfaces-java",
593 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900595 "libwifi-jni",
596 "net-utils-services-common",
597 "netd_aidl_interface-V2-java",
598 "netd_aidl_interface-unstable-java",
599 "netd_event_listener_interface-java",
600 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900601 "networkstack-client",
602 "services.net",
603 "wifi-lite-protos",
604 "wifi-nano-protos",
605 "wifi-service-pre-jarjar",
606 "wifi-service-resources",
Jiyong Park0f80c182020-01-31 02:49:53 +0900607 }
608 //
609 // Module separator
610 //
611 m["com.android.sdkext"] = []string{
612 "fmtlib_ndk",
613 "libbase_ndk",
614 "libprotobuf-cpp-lite-ndk",
615 }
616 //
617 // Module separator
618 //
619 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900620 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900621 }
622 //
623 // Module separator
624 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000625 m[android.AvailableToAnyApex] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900626 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
627 "androidx",
628 "androidx-constraintlayout_constraintlayout",
629 "androidx-constraintlayout_constraintlayout-nodeps",
630 "androidx-constraintlayout_constraintlayout-solver",
631 "androidx-constraintlayout_constraintlayout-solver-nodeps",
632 "com.google.android.material_material",
633 "com.google.android.material_material-nodeps",
634
Jiyong Park0f80c182020-01-31 02:49:53 +0900635 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900636 "libclang_rt",
637 "libgcc_stripped",
638 "libprofile-clang-extras",
639 "libprofile-clang-extras_ndk",
640 "libprofile-extras",
641 "libprofile-extras_ndk",
642 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900643 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000644 return m
645}
646
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900647func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900648 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800649 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900650 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900651 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700652 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900653 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700654 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900655
Jooyung Han31c470b2019-10-18 16:26:59 +0900656 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900657 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900658
659 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
660 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
661 sort.Strings(*apexFileContextsInfos)
662 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
663 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900664}
665
Jooyung Han31c470b2019-10-18 16:26:59 +0900666func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
667 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
668 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
669}
670
Jiyong Parkd1063c12019-07-17 20:08:41 +0900671func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900672 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
Colin Crossaede88c2020-08-11 12:17:01 -0700673 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900674 ctx.BottomUp("apex", apexMutator).Parallel()
675 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
676 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900677 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900678}
679
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900680// Mark the direct and transitive dependencies of apex bundles so that they
681// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900682func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900683 if !mctx.Module().Enabled() {
684 return
685 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900686 a, ok := mctx.Module().(*apexBundle)
687 if !ok || a.vndkApex {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900688 return
689 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900690 apexInfo := android.ApexInfo{
Colin Crosse07f2312020-08-13 11:24:56 -0700691 ApexVariationName: mctx.ModuleName(),
692 MinSdkVersion: a.minSdkVersion(mctx),
Colin Crossaede88c2020-08-11 12:17:01 -0700693 RequiredSdks: a.RequiredSdks(),
Colin Crosse07f2312020-08-13 11:24:56 -0700694 Updatable: a.Updatable(),
Colin Crossaede88c2020-08-11 12:17:01 -0700695 InApexes: []string{mctx.ModuleName()},
Jooyung Han698dd9f2020-07-22 15:17:19 +0900696 }
Jooyung Handf78e212020-07-22 15:54:47 +0900697
698 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
699 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
700 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
701 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
702 return
703 }
704
Jooyung Han698dd9f2020-07-22 15:17:19 +0900705 mctx.WalkDeps(func(child, parent android.Module) bool {
706 am, ok := child.(android.ApexModule)
707 if !ok || !am.CanHaveApexVariants() {
708 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900709 }
Paul Duffina37eca22020-07-22 13:00:54 +0100710 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900711 return false
712 }
Jooyung Handf78e212020-07-22 15:54:47 +0900713 if excludeVndkLibs {
714 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
715 return false
716 }
717 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900718
719 depName := mctx.OtherModuleName(child)
720 // If the parent is apexBundle, this child is directly depended.
721 _, directDep := parent.(*apexBundle)
722 android.UpdateApexDependency(apexInfo, depName, directDep)
723 am.BuildForApex(apexInfo)
724 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900725 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900726}
727
Colin Crossaede88c2020-08-11 12:17:01 -0700728func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
729 if !mctx.Module().Enabled() {
730 return
731 }
732 if am, ok := mctx.Module().(android.ApexModule); ok {
733 // Check if any dependencies use unique apex variations. If so, use unique apex variations
734 // for this module.
735 am.UpdateUniqueApexVariationsForDeps(mctx)
736 }
737}
738
Jiyong Park89e850a2020-04-07 16:37:39 +0900739// mark if a module cannot be available to platform. A module cannot be available
740// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
741// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
742func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
743 // Host and recovery are not considered as platform
744 if mctx.Host() || mctx.Module().InstallInRecovery() {
745 return
746 }
747
748 if am, ok := mctx.Module().(android.ApexModule); ok {
749 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
750
751 // In a rare case when a lib is marked as available only to an apex
752 // but the apex doesn't exist. This can happen in a partial manifest branch
753 // like master-art. Currently, libstatssocket in the stats APEX is causing
754 // this problem.
755 // Include the lib in platform because the module SDK that ought to provide
756 // it doesn't exist, so it would otherwise be left out completely.
757 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
758 // this check for libraries provided by SDKs.
759 if !availableToPlatform && !android.InAnyApex(am.Name()) {
760 availableToPlatform = true
761 }
762
763 // If any of the dep is not available to platform, this module is also considered
764 // as being not available to platform even if it has "//apex_available:platform"
765 mctx.VisitDirectDeps(func(child android.Module) {
766 if !am.DepIsInSameApex(mctx, child) {
767 // if the dependency crosses apex boundary, don't consider it
768 return
769 }
770 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
771 availableToPlatform = false
772 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
773 }
774 })
775
776 // Exception 1: stub libraries and native bridge libraries are always available to platform
777 if cc, ok := mctx.Module().(*cc.Module); ok &&
778 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
779 availableToPlatform = true
780 }
781
782 // Exception 2: bootstrap bionic libraries are also always available to platform
783 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
784 availableToPlatform = true
785 }
786
787 if !availableToPlatform {
788 am.SetNotAvailableForPlatform()
789 }
790 }
791}
792
Paul Duffin65347702020-03-31 15:23:40 +0100793// If a module in an APEX depends on a module from an SDK then it needs an APEX
794// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
795func inAnySdk(module android.Module) bool {
796 if sa, ok := module.(android.SdkAware); ok {
797 return sa.IsInAnySdk()
798 }
799
800 return false
801}
802
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900803// Create apex variations if a module is included in APEX(s).
804func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900805 if !mctx.Module().Enabled() {
806 return
807 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900808 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900809 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000810 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900811 // apex bundle itself is mutated so that it and its modules have same
812 // apex variant.
813 apexBundleName := mctx.ModuleName()
814 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900815 } else if o, ok := mctx.Module().(*OverrideApex); ok {
816 apexBundleName := o.GetOverriddenModuleName()
817 if apexBundleName == "" {
818 mctx.ModuleErrorf("base property is not set")
819 return
820 }
821 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900822 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900823
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900824}
Sundong Ahne9b55722019-09-06 17:37:42 +0900825
Jooyung Han7a78a922019-10-08 21:59:58 +0900826var (
827 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
828 apexFileContextsInfosMutex sync.Mutex
829)
830
831func apexFileContextsInfos(config android.Config) *[]string {
832 return config.Once(apexFileContextsInfosKey, func() interface{} {
833 return &[]string{}
834 }).(*[]string)
835}
836
Jooyung Han54aca7b2019-11-20 02:26:02 +0900837func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900838 apexFileContextsInfosMutex.Lock()
839 defer apexFileContextsInfosMutex.Unlock()
840 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900841 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900842}
843
Sundong Ahne9b55722019-09-06 17:37:42 +0900844func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900845 if !mctx.Module().Enabled() {
846 return
847 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900848 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900849 var variants []string
850 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
851 case "image":
852 variants = append(variants, imageApexType, flattenedApexType)
853 case "zip":
854 variants = append(variants, zipApexType)
855 case "both":
856 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
857 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900858 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900859 return
860 }
861
862 modules := mctx.CreateLocalVariations(variants...)
863
864 for i, v := range variants {
865 switch v {
866 case imageApexType:
867 modules[i].(*apexBundle).properties.ApexType = imageApex
868 case zipApexType:
869 modules[i].(*apexBundle).properties.ApexType = zipApex
870 case flattenedApexType:
871 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900872 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900873 modules[i].(*apexBundle).MakeAsSystemExt()
874 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900875 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900876 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900877 } else if _, ok := mctx.Module().(*OverrideApex); ok {
878 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900879 }
880}
881
Jooyung Han5c998b92019-06-27 11:30:33 +0900882func apexUsesMutator(mctx android.BottomUpMutatorContext) {
883 if ab, ok := mctx.Module().(*apexBundle); ok {
884 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
885 }
886}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900887
Jooyung Handc782442019-11-01 03:14:38 +0900888var (
Colin Cross440e0d02020-06-11 11:32:11 -0700889 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +0900890)
891
Colin Cross440e0d02020-06-11 11:32:11 -0700892// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +0900893// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
894// which may cause compatibility issues. (e.g. libbinder)
895// Even though libbinder restricts its availability via 'apex_available' property and relies on
896// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
897// to avoid similar problems.
Colin Cross440e0d02020-06-11 11:32:11 -0700898func useVendorAllowList(config android.Config) []string {
899 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +0900900 return []string{
901 // swcodec uses "vendor" variants for smaller size
902 "com.android.media.swcodec",
903 "test_com.android.media.swcodec",
904 }
905 }).([]string)
906}
907
Colin Cross440e0d02020-06-11 11:32:11 -0700908// setUseVendorAllowListForTest overrides useVendorAllowList and must be
909// called before the first call to useVendorAllowList()
910func setUseVendorAllowListForTest(config android.Config, allowList []string) {
911 config.Once(useVendorAllowListKey, func() interface{} {
912 return allowList
Jooyung Handc782442019-11-01 03:14:38 +0900913 })
914}
915
Jooyung Han01a868d2020-02-27 13:40:44 +0900916type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800917 // List of native libraries
918 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900919
Jooyung Han643adc42020-02-27 13:50:06 +0900920 // List of JNI libraries
921 Jni_libs []string
922
Alex Light9670d332019-01-29 18:07:33 -0800923 // List of native executables
924 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900925
Roland Levillain630846d2019-06-26 12:48:34 +0100926 // List of native tests
927 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800928}
Jooyung Han344d5432019-08-23 11:17:39 +0900929
Alex Light9670d332019-01-29 18:07:33 -0800930type apexMultilibProperties struct {
931 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900932 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800933
934 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900935 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800936
937 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900938 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800939
940 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900941 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800942
943 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900944 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800945}
946
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900947type apexBundleProperties struct {
948 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000949 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800950 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900951
Jiyong Park40e26a22019-02-08 02:53:06 +0900952 // AndroidManifest.xml file used for the zip container of this APEX bundle.
953 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800954 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900955
Roland Levillain411c5842019-09-19 16:37:20 +0100956 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
957 // device (/apex/<apex_name>).
958 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900959 Apex_name *string
960
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900961 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900962 // For platform APEXes, this should points to a file under /system/sepolicy
963 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
964 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900965
Jooyung Han01a868d2020-02-27 13:40:44 +0900966 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900967
968 // List of java libraries that are embedded inside this APEX bundle
969 Java_libs []string
970
971 // List of prebuilt files that are embedded inside this APEX bundle
972 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900973
974 // Name of the apex_key module that provides the private key to sign APEX
975 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900976
Alex Light5098a612018-11-29 17:12:15 -0800977 // The type of APEX to build. Controls what the APEX payload is. Either
978 // 'image', 'zip' or 'both'. Default: 'image'.
979 Payload_type *string
980
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900981 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
982 // or an android_app_certificate module name in the form ":module".
983 Certificate *string
984
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900985 // Whether this APEX is installable to one of the partitions. Default: true.
986 Installable *bool
987
Jiyong Parkda6eb592018-12-19 17:12:36 +0900988 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
989 // Default is false.
990 Use_vendor *bool
991
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800992 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
993 Ignore_system_library_special_case *bool
994
Alex Light9670d332019-01-29 18:07:33 -0800995 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900996
Jiyong Parkf97782b2019-02-13 20:28:58 +0900997 // List of sanitizer names that this APEX is enabled for
998 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900999
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001000 PreventInstall bool `blueprint:"mutated"`
1001
1002 HideFromMake bool `blueprint:"mutated"`
1003
Jooyung Han5c998b92019-06-27 11:30:33 +09001004 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1005 Provide_cpp_shared_libs *bool
1006
1007 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1008 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001009
Sundong Ahnabb64432019-10-22 13:58:29 +09001010 // package format of this apex variant; could be non-flattened, flattened, or zip.
1011 // imageApex, zipApex or flattened
1012 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001013
Jiyong Parkd1063c12019-07-17 20:08:41 +09001014 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1015 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1016 // is implied. This value affects all modules included in this APEX. In other words, they are
1017 // also built with the SDKs specified here.
1018 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001019
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001020 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1021 // Should be only used in tests#.
1022 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001023
Dario Frenica913392020-04-27 18:21:11 +01001024 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1025 // Should be only used in tests#.
1026 Test_only_unsigned_payload *bool
1027
Jiyong Park956305c2020-01-09 12:32:06 +09001028 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001029
1030 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001031 // rules for making sure that the APEX is truly updatable.
1032 // - To be updatable, min_sdk_version should be set as well
1033 // This will also disable the size optimizations like symlinking to the system libs.
1034 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001035 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001036
1037 // The minimum SDK version that this apex must be compatibile with.
1038 Min_sdk_version *string
Jooyung Handf78e212020-07-22 15:54:47 +09001039
1040 // If set true, VNDK libs are considered as stable libs and are not included in this apex.
1041 // Should be only used in non-system apexes (e.g. vendor: true).
1042 // Default is false.
1043 Use_vndk_as_stable *bool
Alex Light9670d332019-01-29 18:07:33 -08001044}
1045
1046type apexTargetBundleProperties struct {
1047 Target struct {
1048 // Multilib properties only for android.
1049 Android struct {
1050 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001051 }
Jooyung Han344d5432019-08-23 11:17:39 +09001052
Alex Light9670d332019-01-29 18:07:33 -08001053 // Multilib properties only for host.
1054 Host struct {
1055 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001056 }
Jooyung Han344d5432019-08-23 11:17:39 +09001057
Alex Light9670d332019-01-29 18:07:33 -08001058 // Multilib properties only for host linux_bionic.
1059 Linux_bionic struct {
1060 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001061 }
Jooyung Han344d5432019-08-23 11:17:39 +09001062
Alex Light9670d332019-01-29 18:07:33 -08001063 // Multilib properties only for host linux_glibc.
1064 Linux_glibc struct {
1065 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001066 }
1067 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001068}
1069
Jiyong Park5d790c32019-11-15 18:40:32 +09001070type overridableProperties struct {
1071 // List of APKs to package inside APEX
1072 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001073
Jiyong Park69aeba92020-04-24 21:16:36 +09001074 // List of runtime resource overlays (RROs) inside APEX
1075 Rros []string
1076
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001077 // Names of modules to be overridden. Listed modules can only be other binaries
1078 // (in Make or Soong).
1079 // This does not completely prevent installation of the overridden binaries, but if both
1080 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1081 // from PRODUCT_PACKAGES.
1082 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001083
1084 // Logging Parent value
1085 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001086
1087 // Apex Container Package Name.
1088 // Override value for attribute package:name in AndroidManifest.xml
1089 Package_name string
Jooyung Han938b5932020-06-20 12:47:47 +09001090
1091 // A txt file containing list of files that are allowed to be included in this APEX.
1092 Allowed_files *string `android:"path"`
Jiyong Park5d790c32019-11-15 18:40:32 +09001093}
1094
Alex Light5098a612018-11-29 17:12:15 -08001095type apexPackaging int
1096
1097const (
1098 imageApex apexPackaging = iota
1099 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001100 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001101)
1102
Sundong Ahnabb64432019-10-22 13:58:29 +09001103// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001104func (a apexPackaging) suffix() string {
1105 switch a {
1106 case imageApex:
1107 return imageApexSuffix
1108 case zipApex:
1109 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001110 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001111 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001112 }
1113}
1114
1115func (a apexPackaging) name() string {
1116 switch a {
1117 case imageApex:
1118 return imageApexType
1119 case zipApex:
1120 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001121 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001122 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001123 }
1124}
1125
Jiyong Parkf653b052019-11-18 15:39:01 +09001126type apexFileClass int
1127
1128const (
1129 etc apexFileClass = iota
1130 nativeSharedLib
1131 nativeExecutable
1132 shBinary
1133 pyBinary
1134 goBinary
1135 javaSharedLib
1136 nativeTest
1137 app
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001138 appSet
Jiyong Parkf653b052019-11-18 15:39:01 +09001139)
1140
Jiyong Park8fd61922018-11-08 02:50:25 +09001141func (class apexFileClass) NameInMake() string {
1142 switch class {
1143 case etc:
1144 return "ETC"
1145 case nativeSharedLib:
1146 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001147 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001148 return "EXECUTABLES"
1149 case javaSharedLib:
1150 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001151 case nativeTest:
1152 return "NATIVE_TESTS"
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001153 case app, appSet:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001154 // b/142537672 Why isn't this APP? We want to have full control over
1155 // the paths and file names of the apk file under the flattend APEX.
1156 // If this is set to APP, then the paths and file names are modified
1157 // by the Make build system. For example, it is installed to
1158 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1159 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1160 // appends module name (which is <apexname>.<Appname> to the path.
1161 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001162 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001163 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001164 }
1165}
1166
Jiyong Parkf653b052019-11-18 15:39:01 +09001167// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001168type apexFile struct {
Yo Chiange8128052020-07-23 20:09:18 +08001169 builtFile android.Path
1170 stem string
1171 // Module name of `module` in AndroidMk. Note the generated AndroidMk module for
1172 // apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
1173 androidMkModuleName string
1174 installDir string
1175 class apexFileClass
1176 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001177 // list of symlinks that will be created in installDir that point to this apexFile
1178 symlinks []string
Chris Parsons216e10a2020-07-09 17:12:52 -04001179 dataPaths []android.DataPath
Jiyong Parkf653b052019-11-18 15:39:01 +09001180 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001181 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001182
1183 requiredModuleNames []string
1184 targetRequiredModuleNames []string
1185 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001186
Colin Cross503c1d02020-01-28 14:00:53 -08001187 jacocoReportClassesFile android.Path // only for javalibs and apps
Colin Cross08dca382020-07-21 20:31:17 -07001188 lintDepSets java.LintDepSets // only for javalibs and apps
Colin Cross503c1d02020-01-28 14:00:53 -08001189 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001190 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001191
1192 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001193}
1194
Yo Chiange8128052020-07-23 20:09:18 +08001195func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
Jiyong Park1833cef2019-12-13 13:28:36 +09001196 ret := apexFile{
Yo Chiange8128052020-07-23 20:09:18 +08001197 builtFile: builtFile,
1198 androidMkModuleName: androidMkModuleName,
1199 installDir: installDir,
1200 class: class,
1201 module: module,
Jiyong Parkf653b052019-11-18 15:39:01 +09001202 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001203 if module != nil {
1204 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001205 ret.requiredModuleNames = module.RequiredModuleNames()
1206 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1207 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001208 }
1209 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001210}
1211
1212func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001213 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001214}
1215
Liz Kammer1c14a212020-05-12 15:26:55 -07001216func (af *apexFile) apexRelativePath(path string) string {
1217 return filepath.Join(af.installDir, path)
1218}
1219
Jiyong Park7cd10e32020-01-14 09:22:18 +09001220// Path() returns path of this apex file relative to the APEX root
1221func (af *apexFile) Path() string {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001222 return af.apexRelativePath(af.Stem())
1223}
1224
1225func (af *apexFile) Stem() string {
Jiyong Parka62aa232020-05-28 23:46:55 +09001226 if af.stem != "" {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001227 return af.stem
Jiyong Parka62aa232020-05-28 23:46:55 +09001228 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001229 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001230}
1231
1232// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1233func (af *apexFile) SymlinkPaths() []string {
1234 var ret []string
1235 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001236 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001237 }
1238 return ret
1239}
1240
1241func (af *apexFile) AvailableToPlatform() bool {
1242 if af.module == nil {
1243 return false
1244 }
1245 if am, ok := af.module.(android.ApexModule); ok {
1246 return am.AvailableFor(android.AvailableToPlatform)
1247 }
1248 return false
1249}
1250
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001251type apexBundle struct {
1252 android.ModuleBase
1253 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001254 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001255 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001256
Jiyong Park5d790c32019-11-15 18:40:32 +09001257 properties apexBundleProperties
1258 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001259 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001260
Jooyung Hanf21c7972019-12-16 22:32:06 +09001261 // specific to apex_vndk modules
1262 vndkProperties apexVndkProperties
1263
Colin Crossa4925902018-11-16 11:36:28 -08001264 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001265 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001266 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001267
Jiyong Park03b68dd2019-07-26 23:20:40 +09001268 prebuiltFileToDelete string
1269
Jiyong Park42cca6c2019-04-01 11:15:50 +09001270 public_key_file android.Path
1271 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001272
1273 container_certificate_file android.Path
1274 container_private_key_file android.Path
1275
Jooyung Han580eb4f2020-06-24 19:33:06 +09001276 fileContexts android.WritablePath
Jooyung Han54aca7b2019-11-20 02:26:02 +09001277
Jiyong Park8fd61922018-11-08 02:50:25 +09001278 // list of files to be included in this apex
1279 filesInfo []apexFile
1280
Jiyong Park956305c2020-01-09 12:32:06 +09001281 // list of module names that should be installed along with this APEX
1282 requiredDeps []string
1283
Jiyong Park956305c2020-01-09 12:32:06 +09001284 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001285 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001286
Sundong Ahnabb64432019-10-22 13:58:29 +09001287 testApex bool
1288 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001289 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001290 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001291
Jooyung Han214bf372019-11-12 13:03:50 +09001292 manifestJsonOut android.WritablePath
1293 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001294
Jooyung Han002ab682020-01-08 01:57:58 +09001295 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001296 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001297 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001298 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1299 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001300
1301 // Suffix of module name in Android.mk
1302 // ".flattened", ".apex", ".zipapex", or ""
1303 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001304
1305 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001306
1307 // Whether to create symlink to the system file instead of having a file
1308 // inside the apex or not
1309 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001310
1311 // Struct holding the merged notice file paths in different formats
1312 mergedNotices android.NoticeOutputs
Colin Cross08dca382020-07-21 20:31:17 -07001313
1314 // Optional list of lint report zip files for apexes that contain java or app modules
1315 lintReports android.Paths
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001316}
1317
Jiyong Park397e55e2018-10-24 21:09:55 +09001318func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001319 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001320 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001321 // Use *FarVariation* to be able to depend on modules having
1322 // conflicting variations with this module. This is required since
1323 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1324 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001325 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001326 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001327 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001328 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001329 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001330
Jooyung Han643adc42020-02-27 13:50:06 +09001331 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1332 {Mutator: "image", Variation: imageVariation},
1333 {Mutator: "link", Variation: "shared"},
1334 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1335 }...), jniLibTag, nativeModules.Jni_libs...)
1336
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001337 ctx.AddFarVariationDependencies(append(target.Variations(),
1338 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001339 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001340
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001341 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001342 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001343 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001344 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001345}
1346
Alex Light9670d332019-01-29 18:07:33 -08001347func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1348 if ctx.Os().Class == android.Device {
1349 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1350 } else {
1351 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1352 if ctx.Os().Bionic() {
1353 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1354 } else {
1355 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1356 }
1357 }
1358}
1359
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001360func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross440e0d02020-06-11 11:32:11 -07001361 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001362 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1363 }
1364
Jiyong Park397e55e2018-10-24 21:09:55 +09001365 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001366 config := ctx.DeviceConfig()
Jooyung Han85d61762020-06-24 23:50:26 +09001367 imageVariation := a.getImageVariation(ctx)
Alex Light9670d332019-01-29 18:07:33 -08001368
1369 a.combineProperties(ctx)
1370
Jiyong Park397e55e2018-10-24 21:09:55 +09001371 has32BitTarget := false
1372 for _, target := range targets {
1373 if target.Arch.ArchType.Multilib == "lib32" {
1374 has32BitTarget = true
1375 }
1376 }
1377 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001378 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001379 // multilib.both
1380 addDependenciesForNativeModules(ctx,
1381 ApexNativeDependencies{
1382 Native_shared_libs: a.properties.Native_shared_libs,
1383 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001384 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001385 Binaries: nil,
1386 },
Jooyung Han85d61762020-06-24 23:50:26 +09001387 target, imageVariation)
Roland Levillain630846d2019-06-26 12:48:34 +01001388
Jiyong Park397e55e2018-10-24 21:09:55 +09001389 // Add native modules targetting both ABIs
1390 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001391 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001392 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001393 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001394
Alex Light3d673592019-01-18 14:37:31 -08001395 isPrimaryAbi := i == 0
1396 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001397 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001398 // multilib.first
1399 addDependenciesForNativeModules(ctx,
1400 ApexNativeDependencies{
1401 Native_shared_libs: nil,
1402 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001403 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001404 Binaries: a.properties.Binaries,
1405 },
Jooyung Han85d61762020-06-24 23:50:26 +09001406 target, imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001407
1408 // Add native modules targetting the first ABI
1409 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001410 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001411 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001412 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001413 }
1414
1415 switch target.Arch.ArchType.Multilib {
1416 case "lib32":
1417 // Add native modules targetting 32-bit ABI
1418 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001419 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001420 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001421 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001422
1423 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001424 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001425 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001426 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001427 case "lib64":
1428 // Add native modules targetting 64-bit ABI
1429 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001430 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001431 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001432 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001433
1434 if !has32BitTarget {
1435 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001436 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001437 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001438 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001439 }
1440 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001441 }
1442
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001443 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1444 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1445 // b/144532908
1446 archForPrebuiltEtc := config.Arches()[0]
1447 for _, arch := range config.Arches() {
1448 // Prefer 64-bit arch if there is any
1449 if arch.ArchType.Multilib == "lib64" {
1450 archForPrebuiltEtc = arch
1451 break
1452 }
1453 }
1454 ctx.AddFarVariationDependencies([]blueprint.Variation{
1455 {Mutator: "os", Variation: ctx.Os().String()},
1456 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1457 }, prebuiltTag, a.properties.Prebuilts...)
1458
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001459 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1460 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001461
Ulya Trafimovich44561882020-01-03 13:25:54 +00001462 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1463 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1464 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1465 javaLibTag, "jacocoagent")
1466 }
1467
Jiyong Park23c52b02019-02-02 13:13:47 +09001468 if String(a.properties.Key) == "" {
1469 ctx.ModuleErrorf("key is missing")
1470 return
1471 }
1472 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001473
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001474 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001475 if cert != "" {
1476 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001477 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001478
1479 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1480 if len(a.properties.Uses_sdks) > 0 {
1481 sdkRefs := []android.SdkRef{}
1482 for _, str := range a.properties.Uses_sdks {
1483 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1484 sdkRefs = append(sdkRefs, parsed)
1485 }
1486 a.BuildWithSdks(sdkRefs)
1487 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001488}
1489
Jiyong Park5d790c32019-11-15 18:40:32 +09001490func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Han938b5932020-06-20 12:47:47 +09001491 if a.overridableProperties.Allowed_files != nil {
1492 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1493 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001494 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1495 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001496 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1497 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001498}
1499
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001500func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1501 // direct deps of an APEX bundle are all part of the APEX bundle
1502 return true
1503}
1504
Colin Cross0ea8ba82019-06-06 14:33:29 -07001505func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001506 moduleName := ctx.ModuleName()
1507 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1508 // we check with the pseudo module name to see if its certificate is overridden.
1509 if a.vndkApex {
1510 moduleName = vndkApexName
1511 }
1512 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001513 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001514 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001515 }
1516 return String(a.properties.Certificate)
1517}
1518
Colin Cross41955e82019-05-29 14:40:35 -07001519func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1520 switch tag {
1521 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001522 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001523 default:
1524 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001525 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001526}
1527
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001528func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001529 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001530}
1531
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001532func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1533 return proptools.Bool(a.properties.Test_only_no_hashtree)
1534}
1535
Dario Frenica913392020-04-27 18:21:11 +01001536func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1537 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1538}
1539
Jooyung Han85d61762020-06-24 23:50:26 +09001540func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
1541 deviceConfig := ctx.DeviceConfig()
Jooyung Han31c470b2019-10-18 16:26:59 +09001542 if a.vndkApex {
Jooyung Han85d61762020-06-24 23:50:26 +09001543 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jooyung Han31c470b2019-10-18 16:26:59 +09001544 }
Jooyung Han85d61762020-06-24 23:50:26 +09001545
1546 var prefix string
1547 var vndkVersion string
1548 if deviceConfig.VndkVersion() != "" {
1549 if proptools.Bool(a.properties.Use_vendor) {
1550 prefix = cc.VendorVariationPrefix
1551 vndkVersion = deviceConfig.PlatformVndkVersion()
1552 } else if a.SocSpecific() || a.DeviceSpecific() {
1553 prefix = cc.VendorVariationPrefix
1554 vndkVersion = deviceConfig.VndkVersion()
1555 } else if a.ProductSpecific() {
1556 prefix = cc.ProductVariationPrefix
1557 vndkVersion = deviceConfig.ProductVndkVersion()
1558 }
Jiyong Parkda6eb592018-12-19 17:12:36 +09001559 }
Jooyung Han85d61762020-06-24 23:50:26 +09001560 if vndkVersion == "current" {
1561 vndkVersion = deviceConfig.PlatformVndkVersion()
1562 }
1563 if vndkVersion != "" {
1564 return prefix + vndkVersion
1565 }
1566 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001567}
1568
Jiyong Parkf97782b2019-02-13 20:28:58 +09001569func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1570 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1571 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1572 }
1573}
1574
Jiyong Park388ef3f2019-01-28 19:47:32 +09001575func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001576 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1577 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001578 }
1579
1580 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001581 globalSanitizerNames := []string{}
1582 if a.Host() {
1583 globalSanitizerNames = ctx.Config().SanitizeHost()
1584 } else {
1585 arches := ctx.Config().SanitizeDeviceArch()
1586 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1587 globalSanitizerNames = ctx.Config().SanitizeDevice()
1588 }
1589 }
1590 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001591}
1592
Jooyung Han8ce8db92020-05-15 19:05:05 +09001593func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1594 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1595 for _, target := range ctx.MultiTargets() {
1596 if target.Arch.ArchType.Multilib == "lib64" {
1597 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jooyung Han85d61762020-06-24 23:50:26 +09001598 {Mutator: "image", Variation: a.getImageVariation(ctx)},
Jooyung Han8ce8db92020-05-15 19:05:05 +09001599 {Mutator: "link", Variation: "shared"},
1600 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1601 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1602 break
1603 }
1604 }
1605 }
1606}
1607
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001608var _ cc.Coverage = (*apexBundle)(nil)
1609
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001610func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001611 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001612}
1613
1614func (a *apexBundle) PreventInstall() {
1615 a.properties.PreventInstall = true
1616}
1617
1618func (a *apexBundle) HideFromMake() {
1619 a.properties.HideFromMake = true
1620}
1621
Jiyong Park956305c2020-01-09 12:32:06 +09001622func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1623 a.properties.IsCoverageVariant = coverage
1624}
1625
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001626func (a *apexBundle) EnableCoverageIfNeeded() {}
1627
Jiyong Parkf653b052019-11-18 15:39:01 +09001628// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001629func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001630 // Decide the APEX-local directory by the multilib of the library
1631 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001632 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001633 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001634 case "lib32":
1635 dirInApex = "lib"
1636 case "lib64":
1637 dirInApex = "lib64"
1638 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001639 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001640 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001641 }
Jooyung Han35155c42020-02-06 17:33:20 +09001642 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001643 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001644 // Special case for Bionic libs and other libs installed with them. This is
1645 // to prevent those libs from being included in the search path
1646 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1647 // those libs in the Runtime APEX are available via the legacy paths in
1648 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1649 // to the legacy paths and thus will be loaded into the default linker
1650 // namespace (aka "platform" namespace). If the libs are directly in
1651 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1652 // into the runtime linker namespace, which will result in double loading of
1653 // them, which isn't supported.
1654 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001655 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001656
Jiyong Parkf653b052019-11-18 15:39:01 +09001657 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001658 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1659 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001660}
1661
Jiyong Park1833cef2019-12-13 13:28:36 +09001662func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001663 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001664 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001665 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001666 }
Jooyung Han35155c42020-02-06 17:33:20 +09001667 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001668 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001669 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1670 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001671 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001672 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001673 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001674}
1675
Jiyong Park1833cef2019-12-13 13:28:36 +09001676func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001677 dirInApex := "bin"
1678 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001679 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001680}
Jiyong Park1833cef2019-12-13 13:28:36 +09001681func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001682 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001683 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1684 if err != nil {
1685 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001687 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 fileToCopy := android.PathForOutput(ctx, s)
1689 // NB: Since go binaries are static we don't need the module for anything here, which is
1690 // good since the go tool is a blueprint.Module not an android.Module like we would
1691 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001692 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001693}
1694
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001695func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001696 dirInApex := filepath.Join("bin", sh.SubDir())
1697 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001698 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001699 af.symlinks = sh.Symlinks()
1700 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001701}
1702
Yo Chiange8128052020-07-23 20:09:18 +08001703type javaModule interface {
1704 android.Module
1705 BaseModuleName() string
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001706 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001707 JacocoReportClassesFile() android.Path
Colin Cross08dca382020-07-21 20:31:17 -07001708 LintDepSets() java.LintDepSets
1709
Jiyong Parka62aa232020-05-28 23:46:55 +09001710 Stem() string
1711}
1712
Yo Chiange8128052020-07-23 20:09:18 +08001713var _ javaModule = (*java.Library)(nil)
1714var _ javaModule = (*java.SdkLibrary)(nil)
1715var _ javaModule = (*java.DexImport)(nil)
1716var _ javaModule = (*java.SdkLibraryImport)(nil)
Colin Cross08dca382020-07-21 20:31:17 -07001717
Yo Chiange8128052020-07-23 20:09:18 +08001718func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001719 dirInApex := "javalib"
Yo Chiange8128052020-07-23 20:09:18 +08001720 fileToCopy := module.DexJarBuildPath()
1721 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1722 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1723 af.lintDepSets = module.LintDepSets()
1724 af.stem = module.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001725 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001726}
1727
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001728func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001729 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1730 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001731 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001732}
1733
atrost6e126252020-01-27 17:01:16 +00001734func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1735 dirInApex := filepath.Join("etc", config.SubDir())
1736 fileToCopy := config.CompatConfig()
1737 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1738}
1739
Jiyong Park1833cef2019-12-13 13:28:36 +09001740func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001741 android.Module
1742 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001743 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001744 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001745 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001746 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001747 BaseModuleName() string
Jooyung Han39ee1192020-03-23 20:21:11 +09001748}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001749 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001750 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001751 appDir = "priv-app"
1752 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001753 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001754 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001755 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001756 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001757 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001758
1759 if app, ok := aapp.(interface {
1760 OverriddenManifestPackageName() string
1761 }); ok {
1762 af.overriddenPackageName = app.OverriddenManifestPackageName()
1763 }
Jiyong Park618922e2020-01-08 13:35:43 +09001764 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001765}
1766
Jiyong Park69aeba92020-04-24 21:16:36 +09001767func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1768 rroDir := "overlay"
1769 dirInApex := filepath.Join(rroDir, rro.Theme())
1770 fileToCopy := rro.OutputFile()
1771 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1772 af.certificate = rro.Certificate()
1773
1774 if a, ok := rro.(interface {
1775 OverriddenManifestPackageName() string
1776 }); ok {
1777 af.overriddenPackageName = a.OverriddenManifestPackageName()
1778 }
1779 return af
1780}
1781
Roland Levillain935639d2019-08-13 14:55:28 +01001782// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1783type flattenedApexContext struct {
1784 android.ModuleContext
1785}
1786
1787func (c *flattenedApexContext) InstallBypassMake() bool {
1788 return true
1789}
1790
Jiyong Park201cedd2020-02-07 17:25:49 +09001791// Visit dependencies that contributes to the payload of this APEX
Jooyung Han749dc692020-04-15 11:03:39 +09001792func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001793 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001794 am, ok := child.(android.ApexModule)
1795 if !ok || !am.CanHaveApexVariants() {
1796 return false
1797 }
1798
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001799 dt := ctx.OtherModuleDependencyTag(child)
1800
1801 if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
1802 return false
1803 }
1804
Jiyong Park0f80c182020-01-31 02:49:53 +09001805 // Check for the direct dependencies that contribute to the payload
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001806 if adt, ok := dt.(dependencyTag); ok {
1807 if adt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001808 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001809 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001810 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001811 return false
1812 }
1813
1814 // Check for the indirect dependencies if it is considered as part of the APEX
Colin Crossaede88c2020-08-11 12:17:01 -07001815 if android.InList(ctx.ModuleName(), am.InApexes()) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001816 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001817 }
1818
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001819 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001820 })
1821}
1822
Jooyung Han03b51852020-02-26 22:45:42 +09001823func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
Jooyung Han749dc692020-04-15 11:03:39 +09001824 ver := proptools.String(a.properties.Min_sdk_version)
1825 if ver == "" {
1826 return android.FutureApiLevel
1827 }
1828 // Treat the current codenames as "current", which means future API version (10000)
1829 // Otherwise, ApiStrToNum converts codename(non-finalized) to a value from [9000...]
1830 // and would fail to build against "current".
1831 if android.InList(ver, ctx.Config().PlatformVersionActiveCodenames()) {
1832 return android.FutureApiLevel
1833 }
1834 // In "REL" branch, "current" is mapped to finalized sdk version
1835 if ctx.Config().PlatformSdkCodename() == "REL" && ver == "current" {
1836 return ctx.Config().PlatformSdkVersionInt()
1837 }
1838 // Finalized codenames are OKAY and will be converted to int
Jooyung Hanaed150d2020-04-02 01:41:41 +09001839 intVer, err := android.ApiStrToNum(ctx, ver)
1840 if err != nil {
1841 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001842 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001843 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001844}
1845
Artur Satayev849f8442020-04-28 14:57:42 +01001846func (a *apexBundle) Updatable() bool {
1847 return proptools.Bool(a.properties.Updatable)
1848}
1849
1850var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1851
Jiyong Park201cedd2020-02-07 17:25:49 +09001852// Ensures that the dependencies are marked as available for this APEX
1853func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1854 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1855 if ctx.Host() || a.testApex || a.vndkApex {
1856 return
1857 }
1858
Jooyung Han85d61762020-06-24 23:50:26 +09001859 // Because APEXes targeting other than system/system_ext partitions
1860 // can't set apex_available, we skip checks for these APEXes
Jooyung Handf78e212020-07-22 15:54:47 +09001861 if a.SocSpecific() || a.DeviceSpecific() ||
1862 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001863 return
1864 }
1865
Jiyong Park58d10902020-03-28 14:43:19 +09001866 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1867 // Requiring them and their transitive depencies with apex_available is not right
1868 // because they just add noise.
1869 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1870 return
1871 }
1872
Jooyung Han749dc692020-04-15 11:03:39 +09001873 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001874 if externalDep {
1875 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1876 return false
1877 }
1878
Jiyong Park201cedd2020-02-07 17:25:49 +09001879 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001880 fromName := ctx.OtherModuleName(from)
1881 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001882
1883 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1884 // do any of its dependencies.
1885 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1886 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1887 return false
1888 }
1889
Colin Cross440e0d02020-06-11 11:32:11 -07001890 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001891 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001892 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001893 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 +01001894 // Visit this module's dependencies to check and report any issues with their availability.
1895 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001896 })
1897}
1898
Jooyung Han548640b2020-04-27 12:10:30 +09001899func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01001900 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09001901 if String(a.properties.Min_sdk_version) == "" {
1902 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1903 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001904
1905 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001906 }
1907}
1908
Jooyung Han749dc692020-04-15 11:03:39 +09001909func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
1910 if a.testApex || a.vndkApex {
1911 return
1912 }
1913 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
1914 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
1915 return
1916 }
1917 android.CheckMinSdkVersion(a, ctx, a.minSdkVersion(ctx))
1918}
1919
Jiyong Park7d95a512020-05-10 15:16:24 +09001920// Ensures that a lib providing stub isn't statically linked
1921func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1922 // Practically, we only care about regular APEXes on the device.
1923 if ctx.Host() || a.testApex || a.vndkApex {
1924 return
1925 }
1926
Jooyung Han749dc692020-04-15 11:03:39 +09001927 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park7d95a512020-05-10 15:16:24 +09001928 if ccm, ok := to.(*cc.Module); ok {
1929 apexName := ctx.ModuleName()
1930 fromName := ctx.OtherModuleName(from)
1931 toName := ctx.OtherModuleName(to)
1932
1933 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1934 // do any of its dependencies.
1935 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1936 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1937 return false
1938 }
1939
1940 // TODO(jiyong) remove this check when R is published to AOSP. Currently, libstatssocket
1941 // is capable of providing a stub variant, but is being statically linked from the bluetooth
1942 // APEX.
1943 if toName == "libstatssocket" {
1944 return false
1945 }
1946
1947 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
1948 // It can't make the static dependencies dynamic because it can't
1949 // do the dynamic linking for itself.
1950 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1951 return false
1952 }
1953
1954 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName)
1955 if isStubLibraryFromOtherApex && !externalDep {
1956 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1957 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1958 }
1959
1960 }
1961 return true
1962 })
1963}
1964
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001965func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Martin Stjernholm56507b42020-06-24 22:31:36 +01001966 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
Sundong Ahnabb64432019-10-22 13:58:29 +09001967 switch a.properties.ApexType {
1968 case imageApex:
1969 if buildFlattenedAsDefault {
1970 a.suffix = imageApexSuffix
1971 } else {
1972 a.suffix = ""
1973 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001974
1975 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001976 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001977 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001978 }
1979 case zipApex:
1980 if proptools.String(a.properties.Payload_type) == "zip" {
1981 a.suffix = ""
1982 a.primaryApexType = true
1983 } else {
1984 a.suffix = zipApexSuffix
1985 }
1986 case flattenedApex:
1987 if buildFlattenedAsDefault {
1988 a.suffix = ""
1989 a.primaryApexType = true
1990 } else {
1991 a.suffix = flattenedSuffix
1992 }
Alex Light5098a612018-11-29 17:12:15 -08001993 }
1994
Roland Levillain630846d2019-06-26 12:48:34 +01001995 if len(a.properties.Tests) > 0 && !a.testApex {
1996 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1997 return
1998 }
1999
Jiyong Park0f80c182020-01-31 02:49:53 +09002000 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002001 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09002002 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09002003 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09002004
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002005 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2006
Jooyung Hane1633032019-08-01 17:41:43 +09002007 // native lib dependencies
2008 var provideNativeLibs []string
2009 var requireNativeLibs []string
2010
Jooyung Han5c998b92019-06-27 11:30:33 +09002011 // Check if "uses" requirements are met with dependent apexBundles
2012 var providedNativeSharedLibs []string
2013 useVendor := proptools.Bool(a.properties.Use_vendor)
2014 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2015 if ctx.OtherModuleDependencyTag(m) != usesTag {
2016 return
2017 }
2018 otherName := ctx.OtherModuleName(m)
2019 other, ok := m.(*apexBundle)
2020 if !ok {
2021 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2022 return
2023 }
2024 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2025 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2026 return
2027 }
2028 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2029 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2030 return
2031 }
2032 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2033 })
2034
Jiyong Parkf653b052019-11-18 15:39:01 +09002035 var filesInfo []apexFile
Jooyung Han749dc692020-04-15 11:03:39 +09002036 // TODO(jiyong) do this using WalkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002037 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002038 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002039 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2040 return false
2041 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002042 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002043 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002044 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002045 case sharedLibTag, jniLibTag:
2046 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002047 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09002048 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2049 fi.isJniLib = isJniLib
2050 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09002051 // Collect the list of stub-providing libs except:
2052 // - VNDK libs are only for vendors
2053 // - bootstrap bionic libs are treated as provided by system
2054 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002055 provideNativeLibs = append(provideNativeLibs, fi.Stem())
2056 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002057 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002058 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002059 propertyName := "native_shared_libs"
2060 if isJniLib {
2061 propertyName = "jni_libs"
2062 }
2063 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002064 }
2065 case executableTag:
2066 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002067 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002068 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002069 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002070 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002071 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002072 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002073 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002074 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002075 } else {
Alex Light778127a2019-02-27 14:19:50 -08002076 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 +09002077 }
2078 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09002079 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01002080 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Yo Chiange8128052020-07-23 20:09:18 +08002081 af := apexFileForJavaLibrary(ctx, child.(javaModule))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002082 if !af.Ok() {
2083 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2084 return false
2085 }
2086 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002087 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09002088 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002089 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002090 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002091 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002092 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002093 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002094 return true // track transitive dependencies
2095 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002096 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002097 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002098 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002099 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2100 appDir := "app"
2101 if ap.Privileged() {
2102 appDir = "priv-app"
2103 }
Yo Chiange8128052020-07-23 20:09:18 +08002104 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002105 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2106 af.certificate = java.PresignedCertificate
2107 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002108 } else {
2109 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2110 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002111 case rroTag:
2112 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2113 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2114 } else {
2115 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2116 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002117 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002118 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002119 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002120 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2121 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002122 } else {
atrost6e126252020-01-27 17:01:16 +00002123 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002124 }
Roland Levillain630846d2019-06-26 12:48:34 +01002125 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002126 if ccTest, ok := child.(*cc.Module); ok {
2127 if ccTest.IsTestPerSrcAllTestsVariation() {
2128 // Multiple-output test module (where `test_per_src: true`).
2129 //
2130 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2131 // We do not add this variation to `filesInfo`, as it has no output;
2132 // however, we do add the other variations of this module as indirect
2133 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002134 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002135 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002136 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002137 af.class = nativeTest
2138 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002139 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002140 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002141 } else {
2142 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2143 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002144 case keyTag:
2145 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002146 a.private_key_file = key.private_key_file
2147 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002148 } else {
2149 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002150 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002151 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002152 case certificateTag:
2153 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002154 a.container_certificate_file = dep.Certificate.Pem
2155 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002156 } else {
2157 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2158 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002159 case android.PrebuiltDepTag:
2160 // If the prebuilt is force disabled, remember to delete the prebuilt file
2161 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002162 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002163 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2164 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002165 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002166 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002167 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002168 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002169 // We cannot use a switch statement on `depTag` here as the checked
2170 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002171 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002172 if cc, ok := child.(*cc.Module); ok {
2173 if android.InList(cc.Name(), providedNativeSharedLibs) {
2174 // If we're using a shared library which is provided from other APEX,
2175 // don't include it in this APEX
2176 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002177 }
Jooyung Handf78e212020-07-22 15:54:47 +09002178 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002179 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002180 return false
2181 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002182 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2183 af.transitiveDep = true
Jooyung Hanefb184e2020-06-25 17:14:25 +09002184 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002185 // If the dependency is a stubs lib, don't include it in this APEX,
2186 // but make sure that the lib is installed on the device.
2187 // In case no APEX is having the lib, the lib is installed to the system
2188 // partition.
2189 //
2190 // Always include if we are a host-apex however since those won't have any
2191 // system libraries.
Jooyung Hanefb184e2020-06-25 17:14:25 +09002192 if !android.DirectlyInAnyApex(ctx, depName) {
2193 // we need a module name for Make
2194 name := cc.BaseModuleName() + cc.Properties.SubName
2195 if proptools.Bool(a.properties.Use_vendor) {
2196 // we don't use subName(.vendor) for a "use_vendor: true" apex
2197 // which is supposed to be installed in /system
2198 name = cc.BaseModuleName()
2199 }
2200 if !android.InList(name, a.requiredDeps) {
2201 a.requiredDeps = append(a.requiredDeps, name)
2202 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002203 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002204 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002205 // Don't track further
2206 return false
2207 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002208 filesInfo = append(filesInfo, af)
2209 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002210 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002211 } else if cc.IsTestPerSrcDepTag(depTag) {
2212 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002213 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002214 // Handle modules created as `test_per_src` variations of a single test module:
2215 // use the name of the generated test binary (`fileToCopy`) instead of the name
2216 // of the original test module (`depName`, shared by all `test_per_src`
2217 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002218 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002219 // these are not considered transitive dep
2220 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002221 filesInfo = append(filesInfo, af)
2222 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002223 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002224 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002225 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2226 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002227 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002228 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002229 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2230 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002231 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002232 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002233 }
2234 }
2235 }
2236 return false
2237 })
2238
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002239 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2240 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2241 // via the global boot image config.
2242 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002243 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002244 dirInApex := filepath.Join("javalib", arch.String())
2245 for _, f := range files {
2246 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002247 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002248 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002249 }
2250 }
2251 }
2252
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002253 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002254 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2255 return
2256 }
2257
Jiyong Park8fd61922018-11-08 02:50:25 +09002258 // remove duplicates in filesInfo
2259 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002260 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002261 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002262 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002263 if e, ok := encountered[dest]; !ok {
2264 encountered[dest] = f
2265 } else {
2266 // If a module is directly included and also transitively depended on
2267 // consider it as directly included.
2268 e.transitiveDep = e.transitiveDep && f.transitiveDep
2269 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002270 }
2271 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002272 var result []apexFile
2273 for _, v := range encountered {
2274 result = append(result, v)
2275 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002276 return result
2277 }
2278 filesInfo = removeDup(filesInfo)
2279
2280 // to have consistent build rules
2281 sort.Slice(filesInfo, func(i, j int) bool {
2282 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2283 })
2284
Jiyong Park8fd61922018-11-08 02:50:25 +09002285 a.installDir = android.PathForModuleInstall(ctx, "apex")
2286 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002287
Jiyong Park7cd10e32020-01-14 09:22:18 +09002288 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2289 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2290 // the same library in the system partition, thus effectively sharing the same libraries
2291 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2292 // in the APEX.
2293 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2294 a.installable() &&
2295 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002296
Jooyung Han85d61762020-06-24 23:50:26 +09002297 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2298 // So we can't link them to /system/lib libs which are core variants.
Jooyung Handf78e212020-07-22 15:54:47 +09002299 if a.SocSpecific() || a.DeviceSpecific() ||
2300 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002301 a.linkToSystemLib = false
2302 }
2303
Jiyong Park9d677202020-02-19 16:29:35 +09002304 // We don't need the optimization for updatable APEXes, as it might give false signal
2305 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002306 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002307 a.linkToSystemLib = false
2308 }
2309
Jiyong Park638d30e2020-02-26 18:27:19 +09002310 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2311 if ctx.Host() {
2312 a.linkToSystemLib = false
2313 }
2314
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002315 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002316 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2317
Jooyung Han580eb4f2020-06-24 19:33:06 +09002318 a.buildFileContexts(ctx)
2319
Jooyung Han01a3ee22019-11-02 02:52:25 +09002320 a.setCertificateAndPrivateKey(ctx)
2321 if a.properties.ApexType == flattenedApex {
2322 a.buildFlattenedApex(ctx)
2323 } else {
2324 a.buildUnflattenedApex(ctx)
2325 }
2326
Jooyung Han002ab682020-01-08 01:57:58 +09002327 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002328
2329 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002330
2331 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002332}
2333
Artur Satayev8cf899a2020-04-15 17:29:42 +01002334// Enforce that Java deps of the apex are using stable SDKs to compile
2335func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2336 // Visit direct deps only. As long as we guarantee top-level deps are using
2337 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2338 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2339 tag := ctx.OtherModuleDependencyTag(module)
2340 switch tag {
2341 case javaLibTag, androidAppTag:
2342 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2343 if err := m.CheckStableSdkVersion(); err != nil {
2344 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2345 }
2346 }
2347 }
2348 })
2349}
2350
Colin Cross440e0d02020-06-11 11:32:11 -07002351func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002352 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002353 moduleName = normalizeModuleName(moduleName)
2354
Colin Cross440e0d02020-06-11 11:32:11 -07002355 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002356 return true
2357 }
2358
2359 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002360 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002361 return true
2362 }
2363
2364 return false
2365}
2366
2367func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002368 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2369 // system. Trim the prefix for the check since they are confusing
2370 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2371 if strings.HasPrefix(moduleName, "libclang_rt.") {
2372 // This module has many arch variants that depend on the product being built.
2373 // We don't want to list them all
2374 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002375 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002376 if strings.HasPrefix(moduleName, "androidx.") {
2377 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2378 moduleName = "androidx"
2379 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002380 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002381}
2382
Jooyung Han344d5432019-08-23 11:17:39 +09002383func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002384 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002385 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002386 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002387 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002388 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002389 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002390 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002391 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002392 return module
2393}
Jiyong Park30ca9372019-02-07 16:27:23 +09002394
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002395func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002396 bundle := newApexBundle()
2397 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002398 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002399 return bundle
2400}
2401
Jiyong Parkfce0b422020-02-11 03:56:06 +09002402// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2403// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002404func testApexBundleFactory() android.Module {
2405 bundle := newApexBundle()
2406 bundle.testApex = true
2407 return bundle
2408}
2409
Jiyong Parkfce0b422020-02-11 03:56:06 +09002410// apex packages other modules into an APEX file which is a packaging format for system-level
2411// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002412func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002413 return newApexBundle()
2414}
2415
Jiyong Park30ca9372019-02-07 16:27:23 +09002416//
2417// Defaults
2418//
2419type Defaults struct {
2420 android.ModuleBase
2421 android.DefaultsModuleBase
2422}
2423
Jiyong Park30ca9372019-02-07 16:27:23 +09002424func defaultsFactory() android.Module {
2425 return DefaultsFactory()
2426}
2427
2428func DefaultsFactory(props ...interface{}) android.Module {
2429 module := &Defaults{}
2430
2431 module.AddProperties(props...)
2432 module.AddProperties(
2433 &apexBundleProperties{},
2434 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002435 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002436 )
2437
2438 android.InitDefaultsModule(module)
2439 return module
2440}
Jiyong Park5d790c32019-11-15 18:40:32 +09002441
2442//
2443// OverrideApex
2444//
2445type OverrideApex struct {
2446 android.ModuleBase
2447 android.OverrideModuleBase
2448}
2449
2450func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2451 // All the overrides happen in the base module.
2452}
2453
2454// override_apex is used to create an apex module based on another apex module
2455// by overriding some of its properties.
2456func overrideApexFactory() android.Module {
2457 m := &OverrideApex{}
2458 m.AddProperties(&overridableProperties{})
2459
2460 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2461 android.InitOverrideModule(m)
2462 return m
2463}