blob: 6863c8a8f701194f8f546e08bef588a267579ba8 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinc5192442020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Paul Duffin50cbefd2020-03-10 13:44:19 +000096 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090097 "art_cmdlineparser_headers",
98 "art_disassembler_headers",
99 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "bionic_libc_platform_headers",
101 "core-repackaged-icu4j",
102 "cpp-define-generator-asm-support",
103 "cpp-define-generator-definitions",
104 "crtbegin_dynamic",
105 "crtbegin_dynamic1",
106 "crtbegin_so1",
107 "crtbrand",
Jiyong Park0f80c182020-01-31 02:49:53 +0900108 "dex2oat_headers",
109 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900110 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 "javavm_headers",
112 "jni_platform_headers",
113 "libPlatformProperties",
114 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000115 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900116 "libandroidicuinit",
117 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000118 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900119 "libdexfile_all_headers",
120 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000121 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900122 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000123 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900124 "libfdlibm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900125 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000126 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900127 "libicuuc_headers",
128 "libicuuc_stubdata",
129 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000131 "liblzma",
132 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900133 "libnativebridge-headers",
134 "libnativehelper_header_only",
135 "libnativeloader-headers",
136 "libnpt_headers",
137 "libopenjdkjvmti_headers",
138 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000139 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900140 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000141 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900142 "libv8",
143 "libv8base",
144 "libv8gen",
145 "libv8platform",
146 "libv8sampler",
147 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000148 "libvixl",
149 "libvixld",
150 "libz",
151 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000153 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000154 m["com.android.art.debug"] = artApexContents
155 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000156 //
157 // Module separator
158 //
159 m["com.android.bluetooth.updatable"] = []string{
160 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "android.hardware.bluetooth.a2dp@1.0",
162 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900163 "android.hardware.bluetooth@1.0",
164 "android.hardware.bluetooth@1.1",
165 "android.hardware.graphics.bufferqueue@1.0",
166 "android.hardware.graphics.bufferqueue@2.0",
167 "android.hardware.graphics.common@1.0",
168 "android.hardware.graphics.common@1.1",
169 "android.hardware.graphics.common@1.2",
170 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000171 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900172 "android.hidl.token@1.0",
173 "android.hidl.token@1.0-utils",
174 "avrcp-target-service",
175 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 "bluetooth-protos-lite",
177 "bluetooth.mapsapi",
178 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900179 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900180 "ipmemorystore-aidl-interfaces-V5-java",
181 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900182 "internal_include_headers",
183 "lib-bt-packets",
184 "lib-bt-packets-avrcp",
185 "lib-bt-packets-base",
186 "libFraunhoferAAC",
187 "libaudio-a2dp-hw-utils",
188 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900189 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000190 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900191 "libbluetooth-types",
192 "libbluetooth-types-header",
193 "libbluetooth_gd",
194 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000195 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "libbt-audio-hal-interface",
197 "libbt-bta",
198 "libbt-common",
199 "libbt-hci",
200 "libbt-platform-protos-lite",
201 "libbt-protos-lite",
202 "libbt-sbc-decoder",
203 "libbt-sbc-encoder",
204 "libbt-stack",
205 "libbt-utils",
206 "libbtcore",
207 "libbtdevice",
208 "libbte",
209 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000210 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000211 "libevent",
212 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900213 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900214 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900215 "libmedia_headers",
216 "libmodpb64",
217 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900218 "libstagefright_foundation_headers",
219 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000220 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900221 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000222 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900223 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000224 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900225 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900226 "net-utils-services-common",
227 "netd_aidl_interface-unstable-java",
228 "netd_event_listener_interface-java",
229 "netlink-client",
230 "networkstack-aidl-interfaces-unstable-java",
231 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900232 "sap-api-java-static",
233 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000234 }
235 //
236 // Module separator
237 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900238 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000239 //
240 // Module separator
241 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 "libnativehelper_header_only",
Jiyong Park0f80c182020-01-31 02:49:53 +0900244 }
245 //
246 // Module separator
247 //
248 m["com.android.extservices"] = []string{
249 "flatbuffer_headers",
250 "liblua",
251 "libtextclassifier",
252 "libtextclassifier_hash_static",
253 "libtflite_static",
254 "libutf",
255 "libz_current",
256 "tensorflow_headers",
257 }
258 //
259 // Module separator
260 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900261 m["com.android.neuralnetworks"] = []string{
262 "android.hardware.neuralnetworks@1.0",
263 "android.hardware.neuralnetworks@1.1",
264 "android.hardware.neuralnetworks@1.2",
265 "android.hardware.neuralnetworks@1.3",
266 "android.hidl.allocator@1.0",
267 "android.hidl.memory.token@1.0",
268 "android.hidl.memory@1.0",
269 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900270 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900272 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900273 "libprocpartition",
274 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900275 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000276 //
277 // Module separator
278 //
279 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000280 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900281 "android.hardware.cas.native@1.0",
282 "android.hardware.cas@1.0",
283 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000284 "android.hardware.configstore@1.0",
285 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000286 "android.hardware.graphics.allocator@2.0",
287 "android.hardware.graphics.allocator@3.0",
288 "android.hardware.graphics.bufferqueue@1.0",
289 "android.hardware.graphics.bufferqueue@2.0",
290 "android.hardware.graphics.common@1.0",
291 "android.hardware.graphics.common@1.1",
292 "android.hardware.graphics.common@1.2",
293 "android.hardware.graphics.mapper@2.0",
294 "android.hardware.graphics.mapper@2.1",
295 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900296 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000297 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900298 "android.hidl.allocator@1.0",
299 "android.hidl.memory.token@1.0",
300 "android.hidl.memory@1.0",
301 "android.hidl.token@1.0",
302 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900303 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900304 "gl_headers",
305 "libEGL",
306 "libEGL_blobCache",
307 "libEGL_getProcAddress",
308 "libFLAC",
309 "libFLAC-config",
310 "libFLAC-headers",
311 "libGLESv2",
312 "libaacextractor",
313 "libamrextractor",
314 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900315 "libaudio_system_headers",
316 "libaudioclient",
317 "libaudioclient_headers",
318 "libaudiofoundation",
319 "libaudiofoundation_headers",
320 "libaudiomanager",
321 "libaudiopolicy",
322 "libaudioutils",
323 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900324 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900325 "libbluetooth-types-header",
326 "libbufferhub",
327 "libbufferhub_headers",
328 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900329 "libc_malloc_debug_backtrace",
330 "libcamera_client",
331 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900332 "libdexfile_external_headers",
333 "libdexfile_support",
334 "libdvr_headers",
335 "libexpat",
336 "libfifo",
337 "libflacextractor",
338 "libgrallocusage",
339 "libgraphicsenv",
340 "libgui",
341 "libgui_headers",
342 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900343 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900344 "liblzma",
345 "libmath",
346 "libmedia",
347 "libmedia_codeclist",
348 "libmedia_headers",
349 "libmedia_helper",
350 "libmedia_helper_headers",
351 "libmedia_midiiowrapper",
352 "libmedia_omx",
353 "libmediautils",
354 "libmidiextractor",
355 "libmkvextractor",
356 "libmp3extractor",
357 "libmp4extractor",
358 "libmpeg2extractor",
359 "libnativebase_headers",
360 "libnativebridge-headers",
361 "libnativebridge_lazy",
362 "libnativeloader-headers",
363 "libnativeloader_lazy",
364 "libnativewindow_headers",
365 "libnblog",
366 "liboggextractor",
367 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900368 "libpdx",
369 "libpdx_default_transport",
370 "libpdx_headers",
371 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900372 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900373 "libsonivox",
374 "libspeexresampler",
375 "libspeexresampler",
376 "libstagefright_esds",
377 "libstagefright_flacdec",
378 "libstagefright_flacdec",
379 "libstagefright_foundation",
380 "libstagefright_foundation_headers",
381 "libstagefright_foundation_without_imemory",
382 "libstagefright_headers",
383 "libstagefright_id3",
384 "libstagefright_metadatautils",
385 "libstagefright_mpeg2extractor",
386 "libstagefright_mpeg2support",
387 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900388 "libui",
389 "libui_headers",
390 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900391 "libvibrator",
392 "libvorbisidec",
393 "libwavextractor",
394 "libwebm",
395 "media_ndk_headers",
396 "media_plugin_headers",
397 "updatable-media",
398 }
399 //
400 // Module separator
401 //
402 m["com.android.media.swcodec"] = []string{
403 "android.frameworks.bufferhub@1.0",
404 "android.hardware.common-ndk_platform",
405 "android.hardware.configstore-utils",
406 "android.hardware.configstore@1.0",
407 "android.hardware.configstore@1.1",
408 "android.hardware.graphics.allocator@2.0",
409 "android.hardware.graphics.allocator@3.0",
410 "android.hardware.graphics.bufferqueue@1.0",
411 "android.hardware.graphics.bufferqueue@2.0",
412 "android.hardware.graphics.common-ndk_platform",
413 "android.hardware.graphics.common@1.0",
414 "android.hardware.graphics.common@1.1",
415 "android.hardware.graphics.common@1.2",
416 "android.hardware.graphics.mapper@2.0",
417 "android.hardware.graphics.mapper@2.1",
418 "android.hardware.graphics.mapper@3.0",
419 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000420 "android.hardware.media.bufferpool@2.0",
421 "android.hardware.media.c2@1.0",
422 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900423 "android.hardware.media@1.0",
424 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000425 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900426 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000427 "android.hidl.safe_union@1.0",
428 "android.hidl.token@1.0",
429 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900430 "libEGL",
431 "libFLAC",
432 "libFLAC-config",
433 "libFLAC-headers",
434 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900435 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900436 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900437 "libaudio_system_headers",
438 "libaudioutils",
439 "libaudioutils",
440 "libaudioutils_fixedfft",
441 "libavcdec",
442 "libavcenc",
443 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000444 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900445 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900446 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900447 "libbluetooth-types-header",
448 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900449 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000450 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900451 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000452 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900453 "libcodec2_hidl@1.1",
454 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000455 "libcodec2_soft_aacdec",
456 "libcodec2_soft_aacenc",
457 "libcodec2_soft_amrnbdec",
458 "libcodec2_soft_amrnbenc",
459 "libcodec2_soft_amrwbdec",
460 "libcodec2_soft_amrwbenc",
461 "libcodec2_soft_av1dec_gav1",
462 "libcodec2_soft_avcdec",
463 "libcodec2_soft_avcenc",
464 "libcodec2_soft_common",
465 "libcodec2_soft_flacdec",
466 "libcodec2_soft_flacenc",
467 "libcodec2_soft_g711alawdec",
468 "libcodec2_soft_g711mlawdec",
469 "libcodec2_soft_gsmdec",
470 "libcodec2_soft_h263dec",
471 "libcodec2_soft_h263enc",
472 "libcodec2_soft_hevcdec",
473 "libcodec2_soft_hevcenc",
474 "libcodec2_soft_mp3dec",
475 "libcodec2_soft_mpeg2dec",
476 "libcodec2_soft_mpeg4dec",
477 "libcodec2_soft_mpeg4enc",
478 "libcodec2_soft_opusdec",
479 "libcodec2_soft_opusenc",
480 "libcodec2_soft_rawdec",
481 "libcodec2_soft_vorbisdec",
482 "libcodec2_soft_vp8dec",
483 "libcodec2_soft_vp8enc",
484 "libcodec2_soft_vp9dec",
485 "libcodec2_soft_vp9enc",
486 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000487 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900488 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000489 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900490 "libfmq",
491 "libgav1",
492 "libgralloctypes",
493 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000494 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900495 "libgsm",
496 "libgui_bufferqueue_static",
497 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000498 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900499 "libhardware_headers",
500 "libhevcdec",
501 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000502 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900503 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000504 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900505 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000506 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900507 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900508 "libmpeg2dec",
509 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000510 "libnativebridge_lazy",
511 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900512 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900513 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000514 "libscudo_wrapper",
515 "libsfplugin_ccodec_utils",
516 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900517 "libstagefright_amrnbdec",
518 "libstagefright_amrnbenc",
519 "libstagefright_amrwbdec",
520 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000521 "libstagefright_bufferpool@2.0.1",
522 "libstagefright_bufferqueue_helper",
523 "libstagefright_enc_common",
524 "libstagefright_flacdec",
525 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900526 "libstagefright_foundation_headers",
527 "libstagefright_headers",
528 "libstagefright_m4vh263dec",
529 "libstagefright_m4vh263enc",
530 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000531 "libsync",
532 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900533 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000534 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000535 "libvorbisidec",
536 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900537 "libyuv",
538 "libyuv_static",
539 "media_ndk_headers",
540 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000541 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900542 }
543 //
544 // Module separator
545 //
546 m["com.android.mediaprovider"] = []string{
547 "MediaProvider",
548 "MediaProviderGoogle",
549 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900550 "libbase_ndk",
551 "libfuse",
552 "libfuse_jni",
553 "libnativehelper_header_only",
554 }
555 //
556 // Module separator
557 //
558 m["com.android.permission"] = []string{
559 "androidx.annotation_annotation",
560 "androidx.annotation_annotation-nodeps",
561 "androidx.lifecycle_lifecycle-common",
562 "androidx.lifecycle_lifecycle-common-java8",
563 "androidx.lifecycle_lifecycle-common-java8-nodeps",
564 "androidx.lifecycle_lifecycle-common-nodeps",
565 "kotlin-annotations",
566 "kotlin-stdlib",
567 "kotlin-stdlib-jdk7",
568 "kotlin-stdlib-jdk8",
569 "kotlinx-coroutines-android",
570 "kotlinx-coroutines-android-nodeps",
571 "kotlinx-coroutines-core",
572 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900573 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000574 }
575 //
576 // Module separator
577 //
578 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900579 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "libc_aeabi",
582 "libc_bionic",
583 "libc_bionic_ndk",
584 "libc_bootstrap",
585 "libc_common",
586 "libc_common_shared",
587 "libc_common_static",
588 "libc_dns",
589 "libc_dynamic_dispatch",
590 "libc_fortify",
591 "libc_freebsd",
592 "libc_freebsd_large_stack",
593 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libc_init_dynamic",
595 "libc_init_static",
596 "libc_jemalloc_wrapper",
597 "libc_netbsd",
598 "libc_nomalloc",
599 "libc_nopthread",
600 "libc_openbsd",
601 "libc_openbsd_large_stack",
602 "libc_openbsd_ndk",
603 "libc_pthread",
604 "libc_static_dispatch",
605 "libc_syscalls",
606 "libc_tzcode",
607 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900608 "libdebuggerd",
609 "libdebuggerd_common_headers",
610 "libdebuggerd_handler_core",
611 "libdebuggerd_handler_fallback",
612 "libdexfile_external_headers",
613 "libdexfile_support",
614 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900615 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900616 "libjemalloc5",
617 "liblinker_main",
618 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900619 "liblz4",
620 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900621 "libprocinfo",
622 "libpropertyinfoparser",
623 "libscudo",
624 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900625 "libsystemproperties",
626 "libtombstoned_client_static",
627 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900628 "libz",
629 "libziparchive",
630 }
631 //
632 // Module separator
633 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900634 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900635 "libnativehelper_compat_libc++",
636 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900637 "libcgrouprc",
638 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900639 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900640 "libvndksupport",
641 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000642 }
643 //
644 // Module separator
645 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900646 m["com.android.wifi"] = []string{
647 "PlatformProperties",
648 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900649 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900650 "android.hardware.wifi-V1.1-java",
651 "android.hardware.wifi-V1.2-java",
652 "android.hardware.wifi-V1.3-java",
653 "android.hardware.wifi-V1.4-java",
654 "android.hardware.wifi.hostapd-V1.0-java",
655 "android.hardware.wifi.hostapd-V1.1-java",
656 "android.hardware.wifi.hostapd-V1.2-java",
657 "android.hardware.wifi.supplicant-V1.0-java",
658 "android.hardware.wifi.supplicant-V1.1-java",
659 "android.hardware.wifi.supplicant-V1.2-java",
660 "android.hardware.wifi.supplicant-V1.3-java",
661 "android.hidl.base-V1.0-java",
662 "android.hidl.manager-V1.0-java",
663 "android.hidl.manager-V1.1-java",
664 "android.hidl.manager-V1.2-java",
665 "androidx.annotation_annotation",
666 "androidx.annotation_annotation-nodeps",
667 "bouncycastle-unbundled",
668 "dnsresolver_aidl_interface-V2-java",
669 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900670 "framework-wifi-pre-jarjar",
671 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900672 "ipmemorystore-aidl-interfaces-V3-java",
673 "ipmemorystore-aidl-interfaces-java",
674 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900675 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900676 "libwifi-jni",
677 "net-utils-services-common",
678 "netd_aidl_interface-V2-java",
679 "netd_aidl_interface-unstable-java",
680 "netd_event_listener_interface-java",
681 "netlink-client",
682 "networkstack-aidl-interfaces-unstable-java",
683 "networkstack-client",
684 "services.net",
685 "wifi-lite-protos",
686 "wifi-nano-protos",
687 "wifi-service-pre-jarjar",
688 "wifi-service-resources",
689 "prebuilt_androidx.annotation_annotation-nodeps",
690 }
691 //
692 // Module separator
693 //
694 m["com.android.sdkext"] = []string{
695 "fmtlib_ndk",
696 "libbase_ndk",
697 "libprotobuf-cpp-lite-ndk",
698 }
699 //
700 // Module separator
701 //
702 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900703 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900704 }
705 //
706 // Module separator
707 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000708 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900709 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900710 "libclang_rt",
711 "libgcc_stripped",
712 "libprofile-clang-extras",
713 "libprofile-clang-extras_ndk",
714 "libprofile-extras",
715 "libprofile-extras_ndk",
716 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900717 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000718 return m
719}
720
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900721func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900722 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800723 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900724 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900725 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700726 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900727 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900728
Jooyung Han31c470b2019-10-18 16:26:59 +0900729 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900730 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900731
732 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
733 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
734 sort.Strings(*apexFileContextsInfos)
735 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
736 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900737}
738
Jooyung Han31c470b2019-10-18 16:26:59 +0900739func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
740 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
741 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
742}
743
Jiyong Parkd1063c12019-07-17 20:08:41 +0900744func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900745 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900746 ctx.BottomUp("apex", apexMutator).Parallel()
747 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
748 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900749}
750
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900751// Mark the direct and transitive dependencies of apex bundles so that they
752// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900753func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900754 if !mctx.Module().Enabled() {
755 return
756 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800757 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900758 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000759 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900760 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900761 ApexName: mctx.ModuleName(),
762 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100763 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900764 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900765 directDep = true
766 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800767 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900768 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900769 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900770
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800771 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900772 return
773 }
774
Paul Duffin923e8a52020-03-30 15:33:32 +0100775 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900776
Jiyong Parkf760cae2020-02-12 07:53:12 +0900777 mctx.VisitDirectDeps(func(child android.Module) {
778 depName := mctx.OtherModuleName(child)
779 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100780 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800781 android.UpdateApexDependency(apexBundles, depName, directDep)
782 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900783 }
784 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900785}
786
Paul Duffin65347702020-03-31 15:23:40 +0100787// If a module in an APEX depends on a module from an SDK then it needs an APEX
788// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
789func inAnySdk(module android.Module) bool {
790 if sa, ok := module.(android.SdkAware); ok {
791 return sa.IsInAnySdk()
792 }
793
794 return false
795}
796
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900797// Create apex variations if a module is included in APEX(s).
798func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900799 if !mctx.Module().Enabled() {
800 return
801 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900802 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900803 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000804 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900805 // apex bundle itself is mutated so that it and its modules have same
806 // apex variant.
807 apexBundleName := mctx.ModuleName()
808 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900809 } else if o, ok := mctx.Module().(*OverrideApex); ok {
810 apexBundleName := o.GetOverriddenModuleName()
811 if apexBundleName == "" {
812 mctx.ModuleErrorf("base property is not set")
813 return
814 }
815 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900816 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900817
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900818}
Sundong Ahne9b55722019-09-06 17:37:42 +0900819
Jooyung Han7a78a922019-10-08 21:59:58 +0900820var (
821 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
822 apexFileContextsInfosMutex sync.Mutex
823)
824
825func apexFileContextsInfos(config android.Config) *[]string {
826 return config.Once(apexFileContextsInfosKey, func() interface{} {
827 return &[]string{}
828 }).(*[]string)
829}
830
Jooyung Han54aca7b2019-11-20 02:26:02 +0900831func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900832 apexFileContextsInfosMutex.Lock()
833 defer apexFileContextsInfosMutex.Unlock()
834 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900835 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900836}
837
Sundong Ahne9b55722019-09-06 17:37:42 +0900838func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900839 if !mctx.Module().Enabled() {
840 return
841 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900842 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900843 var variants []string
844 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
845 case "image":
846 variants = append(variants, imageApexType, flattenedApexType)
847 case "zip":
848 variants = append(variants, zipApexType)
849 case "both":
850 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
851 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900852 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900853 return
854 }
855
856 modules := mctx.CreateLocalVariations(variants...)
857
858 for i, v := range variants {
859 switch v {
860 case imageApexType:
861 modules[i].(*apexBundle).properties.ApexType = imageApex
862 case zipApexType:
863 modules[i].(*apexBundle).properties.ApexType = zipApex
864 case flattenedApexType:
865 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900866 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900867 modules[i].(*apexBundle).MakeAsSystemExt()
868 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900869 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900870 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900871 } else if _, ok := mctx.Module().(*OverrideApex); ok {
872 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900873 }
874}
875
Jooyung Han5c998b92019-06-27 11:30:33 +0900876func apexUsesMutator(mctx android.BottomUpMutatorContext) {
877 if ab, ok := mctx.Module().(*apexBundle); ok {
878 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
879 }
880}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900881
Jooyung Handc782442019-11-01 03:14:38 +0900882var (
883 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
884)
885
886// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
887// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
888// which may cause compatibility issues. (e.g. libbinder)
889// Even though libbinder restricts its availability via 'apex_available' property and relies on
890// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
891// to avoid similar problems.
892func useVendorWhitelist(config android.Config) []string {
893 return config.Once(useVendorWhitelistKey, func() interface{} {
894 return []string{
895 // swcodec uses "vendor" variants for smaller size
896 "com.android.media.swcodec",
897 "test_com.android.media.swcodec",
898 }
899 }).([]string)
900}
901
902// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
903// called before the first call to useVendorWhitelist()
904func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
905 config.Once(useVendorWhitelistKey, func() interface{} {
906 return whitelist
907 })
908}
909
Jooyung Han01a868d2020-02-27 13:40:44 +0900910type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800911 // List of native libraries
912 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900913
Jooyung Han643adc42020-02-27 13:50:06 +0900914 // List of JNI libraries
915 Jni_libs []string
916
Alex Light9670d332019-01-29 18:07:33 -0800917 // List of native executables
918 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900919
Roland Levillain630846d2019-06-26 12:48:34 +0100920 // List of native tests
921 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800922}
Jooyung Han344d5432019-08-23 11:17:39 +0900923
Alex Light9670d332019-01-29 18:07:33 -0800924type apexMultilibProperties struct {
925 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900926 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800927
928 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900929 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800930
931 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900932 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800933
934 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900935 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800936
937 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900938 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800939}
940
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900941type apexBundleProperties struct {
942 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000943 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800944 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900945
Jiyong Park40e26a22019-02-08 02:53:06 +0900946 // AndroidManifest.xml file used for the zip container of this APEX bundle.
947 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800948 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900949
Roland Levillain411c5842019-09-19 16:37:20 +0100950 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
951 // device (/apex/<apex_name>).
952 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900953 Apex_name *string
954
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900955 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900956 // For platform APEXes, this should points to a file under /system/sepolicy
957 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
958 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900959
Jooyung Han01a868d2020-02-27 13:40:44 +0900960 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900961
962 // List of java libraries that are embedded inside this APEX bundle
963 Java_libs []string
964
965 // List of prebuilt files that are embedded inside this APEX bundle
966 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900967
968 // Name of the apex_key module that provides the private key to sign APEX
969 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900970
Alex Light5098a612018-11-29 17:12:15 -0800971 // The type of APEX to build. Controls what the APEX payload is. Either
972 // 'image', 'zip' or 'both'. Default: 'image'.
973 Payload_type *string
974
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900975 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
976 // or an android_app_certificate module name in the form ":module".
977 Certificate *string
978
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900979 // Whether this APEX is installable to one of the partitions. Default: true.
980 Installable *bool
981
Jiyong Parkda6eb592018-12-19 17:12:36 +0900982 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
983 // Default is false.
984 Use_vendor *bool
985
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800986 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
987 Ignore_system_library_special_case *bool
988
Alex Light9670d332019-01-29 18:07:33 -0800989 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900990
Jiyong Parkf97782b2019-02-13 20:28:58 +0900991 // List of sanitizer names that this APEX is enabled for
992 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900993
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900994 PreventInstall bool `blueprint:"mutated"`
995
996 HideFromMake bool `blueprint:"mutated"`
997
Jooyung Han5c998b92019-06-27 11:30:33 +0900998 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
999 Provide_cpp_shared_libs *bool
1000
1001 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1002 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001003
1004 // A txt file containing list of files that are whitelisted to be included in this APEX.
1005 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001006
Sundong Ahnabb64432019-10-22 13:58:29 +09001007 // package format of this apex variant; could be non-flattened, flattened, or zip.
1008 // imageApex, zipApex or flattened
1009 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001010
Jiyong Parkd1063c12019-07-17 20:08:41 +09001011 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1012 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1013 // is implied. This value affects all modules included in this APEX. In other words, they are
1014 // also built with the SDKs specified here.
1015 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001016
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001017 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1018 // Should be only used in tests#.
1019 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001020
Jiyong Park956305c2020-01-09 12:32:06 +09001021 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001022
1023 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1024 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1025 // like symlinking to the system libs. Default is false.
1026 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001027
1028 // The minimum SDK version that this apex must be compatibile with.
1029 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001030}
1031
1032type apexTargetBundleProperties struct {
1033 Target struct {
1034 // Multilib properties only for android.
1035 Android struct {
1036 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001037 }
Jooyung Han344d5432019-08-23 11:17:39 +09001038
Alex Light9670d332019-01-29 18:07:33 -08001039 // Multilib properties only for host.
1040 Host struct {
1041 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001042 }
Jooyung Han344d5432019-08-23 11:17:39 +09001043
Alex Light9670d332019-01-29 18:07:33 -08001044 // Multilib properties only for host linux_bionic.
1045 Linux_bionic struct {
1046 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001047 }
Jooyung Han344d5432019-08-23 11:17:39 +09001048
Alex Light9670d332019-01-29 18:07:33 -08001049 // Multilib properties only for host linux_glibc.
1050 Linux_glibc struct {
1051 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001052 }
1053 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054}
1055
Jiyong Park5d790c32019-11-15 18:40:32 +09001056type overridableProperties struct {
1057 // List of APKs to package inside APEX
1058 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001059
1060 // Names of modules to be overridden. Listed modules can only be other binaries
1061 // (in Make or Soong).
1062 // This does not completely prevent installation of the overridden binaries, but if both
1063 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1064 // from PRODUCT_PACKAGES.
1065 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001066
1067 // Logging Parent value
1068 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001069
1070 // Apex Container Package Name.
1071 // Override value for attribute package:name in AndroidManifest.xml
1072 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001073}
1074
Alex Light5098a612018-11-29 17:12:15 -08001075type apexPackaging int
1076
1077const (
1078 imageApex apexPackaging = iota
1079 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001080 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001081)
1082
Sundong Ahnabb64432019-10-22 13:58:29 +09001083// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001084func (a apexPackaging) suffix() string {
1085 switch a {
1086 case imageApex:
1087 return imageApexSuffix
1088 case zipApex:
1089 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001090 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001091 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001092 }
1093}
1094
1095func (a apexPackaging) name() string {
1096 switch a {
1097 case imageApex:
1098 return imageApexType
1099 case zipApex:
1100 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001101 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001102 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001103 }
1104}
1105
Jiyong Parkf653b052019-11-18 15:39:01 +09001106type apexFileClass int
1107
1108const (
1109 etc apexFileClass = iota
1110 nativeSharedLib
1111 nativeExecutable
1112 shBinary
1113 pyBinary
1114 goBinary
1115 javaSharedLib
1116 nativeTest
1117 app
1118)
1119
Jiyong Park8fd61922018-11-08 02:50:25 +09001120func (class apexFileClass) NameInMake() string {
1121 switch class {
1122 case etc:
1123 return "ETC"
1124 case nativeSharedLib:
1125 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001126 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001127 return "EXECUTABLES"
1128 case javaSharedLib:
1129 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001130 case nativeTest:
1131 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001132 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001133 // b/142537672 Why isn't this APP? We want to have full control over
1134 // the paths and file names of the apk file under the flattend APEX.
1135 // If this is set to APP, then the paths and file names are modified
1136 // by the Make build system. For example, it is installed to
1137 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1138 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1139 // appends module name (which is <apexname>.<Appname> to the path.
1140 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001141 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001142 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001143 }
1144}
1145
Jiyong Parkf653b052019-11-18 15:39:01 +09001146// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001147type apexFile struct {
1148 builtFile android.Path
1149 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001150 installDir string
1151 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001152 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001153 // list of symlinks that will be created in installDir that point to this apexFile
1154 symlinks []string
1155 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001156 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001157
1158 requiredModuleNames []string
1159 targetRequiredModuleNames []string
1160 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001161
Colin Cross503c1d02020-01-28 14:00:53 -08001162 jacocoReportClassesFile android.Path // only for javalibs and apps
1163 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001164 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001165
1166 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001167}
1168
Jiyong Park1833cef2019-12-13 13:28:36 +09001169func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1170 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001171 builtFile: builtFile,
1172 moduleName: moduleName,
1173 installDir: installDir,
1174 class: class,
1175 module: module,
1176 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001177 if module != nil {
1178 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001179 ret.requiredModuleNames = module.RequiredModuleNames()
1180 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1181 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001182 }
1183 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001184}
1185
1186func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001187 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001188}
1189
Jiyong Park7cd10e32020-01-14 09:22:18 +09001190// Path() returns path of this apex file relative to the APEX root
1191func (af *apexFile) Path() string {
1192 return filepath.Join(af.installDir, af.builtFile.Base())
1193}
1194
1195// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1196func (af *apexFile) SymlinkPaths() []string {
1197 var ret []string
1198 for _, symlink := range af.symlinks {
1199 ret = append(ret, filepath.Join(af.installDir, symlink))
1200 }
1201 return ret
1202}
1203
1204func (af *apexFile) AvailableToPlatform() bool {
1205 if af.module == nil {
1206 return false
1207 }
1208 if am, ok := af.module.(android.ApexModule); ok {
1209 return am.AvailableFor(android.AvailableToPlatform)
1210 }
1211 return false
1212}
1213
Jiyong Park678c8812020-02-07 17:25:49 +09001214type depInfo struct {
1215 to string
1216 from []string
1217 isExternal bool
1218}
1219
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001220type apexBundle struct {
1221 android.ModuleBase
1222 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001223 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001224 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001225
Jiyong Park5d790c32019-11-15 18:40:32 +09001226 properties apexBundleProperties
1227 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001228 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001229
Jooyung Hanf21c7972019-12-16 22:32:06 +09001230 // specific to apex_vndk modules
1231 vndkProperties apexVndkProperties
1232
Colin Crossa4925902018-11-16 11:36:28 -08001233 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001234 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001235 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001236
Jiyong Park03b68dd2019-07-26 23:20:40 +09001237 prebuiltFileToDelete string
1238
Jiyong Park42cca6c2019-04-01 11:15:50 +09001239 public_key_file android.Path
1240 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001241
1242 container_certificate_file android.Path
1243 container_private_key_file android.Path
1244
Jooyung Han54aca7b2019-11-20 02:26:02 +09001245 fileContexts android.Path
1246
Jiyong Park8fd61922018-11-08 02:50:25 +09001247 // list of files to be included in this apex
1248 filesInfo []apexFile
1249
Jiyong Park956305c2020-01-09 12:32:06 +09001250 // list of module names that should be installed along with this APEX
1251 requiredDeps []string
1252
Jiyong Park956305c2020-01-09 12:32:06 +09001253 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001254 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001255
Sundong Ahnabb64432019-10-22 13:58:29 +09001256 testApex bool
1257 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001258 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001259 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001260
Jooyung Han214bf372019-11-12 13:03:50 +09001261 manifestJsonOut android.WritablePath
1262 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001263
Jooyung Han002ab682020-01-08 01:57:58 +09001264 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001265 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001266 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001267 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1268 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001269
1270 // Suffix of module name in Android.mk
1271 // ".flattened", ".apex", ".zipapex", or ""
1272 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001273
1274 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001275
1276 // Whether to create symlink to the system file instead of having a file
1277 // inside the apex or not
1278 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001279
1280 // Struct holding the merged notice file paths in different formats
1281 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001282}
1283
Jiyong Park397e55e2018-10-24 21:09:55 +09001284func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001285 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001286 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001287 // Use *FarVariation* to be able to depend on modules having
1288 // conflicting variations with this module. This is required since
1289 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1290 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001291 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001292 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001293 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001294 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001295 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001296
Jooyung Han643adc42020-02-27 13:50:06 +09001297 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1298 {Mutator: "image", Variation: imageVariation},
1299 {Mutator: "link", Variation: "shared"},
1300 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1301 }...), jniLibTag, nativeModules.Jni_libs...)
1302
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001303 ctx.AddFarVariationDependencies(append(target.Variations(),
1304 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001305 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001306
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001307 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001308 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001309 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001310 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001311}
1312
Alex Light9670d332019-01-29 18:07:33 -08001313func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1314 if ctx.Os().Class == android.Device {
1315 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1316 } else {
1317 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1318 if ctx.Os().Bionic() {
1319 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1320 } else {
1321 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1322 }
1323 }
1324}
1325
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001326func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001327 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1328 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1329 }
1330
Jiyong Park397e55e2018-10-24 21:09:55 +09001331 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001332 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001333
1334 a.combineProperties(ctx)
1335
Jiyong Park397e55e2018-10-24 21:09:55 +09001336 has32BitTarget := false
1337 for _, target := range targets {
1338 if target.Arch.ArchType.Multilib == "lib32" {
1339 has32BitTarget = true
1340 }
1341 }
1342 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001343 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001344 // multilib.both
1345 addDependenciesForNativeModules(ctx,
1346 ApexNativeDependencies{
1347 Native_shared_libs: a.properties.Native_shared_libs,
1348 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001349 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001350 Binaries: nil,
1351 },
1352 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001353
Jiyong Park397e55e2018-10-24 21:09:55 +09001354 // Add native modules targetting both ABIs
1355 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001356 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001357 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001358 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001359
Alex Light3d673592019-01-18 14:37:31 -08001360 isPrimaryAbi := i == 0
1361 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001362 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001363 // multilib.first
1364 addDependenciesForNativeModules(ctx,
1365 ApexNativeDependencies{
1366 Native_shared_libs: nil,
1367 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001368 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001369 Binaries: a.properties.Binaries,
1370 },
1371 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001372
1373 // Add native modules targetting the first ABI
1374 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001375 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001376 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001377 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001378 }
1379
1380 switch target.Arch.ArchType.Multilib {
1381 case "lib32":
1382 // Add native modules targetting 32-bit ABI
1383 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001384 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001385 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001386 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001387
1388 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001389 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001390 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001391 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001392 case "lib64":
1393 // Add native modules targetting 64-bit ABI
1394 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001395 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001396 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001397 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001398
1399 if !has32BitTarget {
1400 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001401 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001402 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001403 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001404 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001405
1406 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1407 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1408 if sanitizer == "hwaddress" {
1409 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001410 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001411 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001412 break
1413 }
1414 }
1415 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001416 }
1417
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001418 }
1419
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001420 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1421 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1422 // b/144532908
1423 archForPrebuiltEtc := config.Arches()[0]
1424 for _, arch := range config.Arches() {
1425 // Prefer 64-bit arch if there is any
1426 if arch.ArchType.Multilib == "lib64" {
1427 archForPrebuiltEtc = arch
1428 break
1429 }
1430 }
1431 ctx.AddFarVariationDependencies([]blueprint.Variation{
1432 {Mutator: "os", Variation: ctx.Os().String()},
1433 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1434 }, prebuiltTag, a.properties.Prebuilts...)
1435
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001436 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1437 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001438
Ulya Trafimovich44561882020-01-03 13:25:54 +00001439 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1440 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1441 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1442 javaLibTag, "jacocoagent")
1443 }
1444
Jiyong Park23c52b02019-02-02 13:13:47 +09001445 if String(a.properties.Key) == "" {
1446 ctx.ModuleErrorf("key is missing")
1447 return
1448 }
1449 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001450
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001451 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001452 if cert != "" {
1453 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001454 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001455
1456 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1457 if len(a.properties.Uses_sdks) > 0 {
1458 sdkRefs := []android.SdkRef{}
1459 for _, str := range a.properties.Uses_sdks {
1460 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1461 sdkRefs = append(sdkRefs, parsed)
1462 }
1463 a.BuildWithSdks(sdkRefs)
1464 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001465}
1466
Jiyong Park5d790c32019-11-15 18:40:32 +09001467func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1468 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1469 androidAppTag, a.overridableProperties.Apps...)
1470}
1471
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001472func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1473 // direct deps of an APEX bundle are all part of the APEX bundle
1474 return true
1475}
1476
Colin Cross0ea8ba82019-06-06 14:33:29 -07001477func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001478 moduleName := ctx.ModuleName()
1479 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1480 // we check with the pseudo module name to see if its certificate is overridden.
1481 if a.vndkApex {
1482 moduleName = vndkApexName
1483 }
1484 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001485 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001486 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001487 }
1488 return String(a.properties.Certificate)
1489}
1490
Colin Cross41955e82019-05-29 14:40:35 -07001491func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1492 switch tag {
1493 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001494 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001495 default:
1496 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001497 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001498}
1499
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001500func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001501 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001502}
1503
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001504func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1505 return proptools.Bool(a.properties.Test_only_no_hashtree)
1506}
1507
Jiyong Park7c1dc612019-01-05 11:15:24 +09001508func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001509 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001510 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001511 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001512 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001513 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001514 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001515 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001516 }
1517}
1518
Jiyong Parkf97782b2019-02-13 20:28:58 +09001519func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1520 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1521 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1522 }
1523}
1524
Jiyong Park388ef3f2019-01-28 19:47:32 +09001525func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001526 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1527 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001528 }
1529
1530 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001531 globalSanitizerNames := []string{}
1532 if a.Host() {
1533 globalSanitizerNames = ctx.Config().SanitizeHost()
1534 } else {
1535 arches := ctx.Config().SanitizeDeviceArch()
1536 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1537 globalSanitizerNames = ctx.Config().SanitizeDevice()
1538 }
1539 }
1540 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001541}
1542
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001543func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001544 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001545}
1546
1547func (a *apexBundle) PreventInstall() {
1548 a.properties.PreventInstall = true
1549}
1550
1551func (a *apexBundle) HideFromMake() {
1552 a.properties.HideFromMake = true
1553}
1554
Jiyong Park956305c2020-01-09 12:32:06 +09001555func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1556 a.properties.IsCoverageVariant = coverage
1557}
1558
Jiyong Parkf653b052019-11-18 15:39:01 +09001559// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001560func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001561 // Decide the APEX-local directory by the multilib of the library
1562 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001563 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001564 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001565 case "lib32":
1566 dirInApex = "lib"
1567 case "lib64":
1568 dirInApex = "lib64"
1569 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001570 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001571 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001572 }
Jooyung Han35155c42020-02-06 17:33:20 +09001573 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001574 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001575 // Special case for Bionic libs and other libs installed with them. This is
1576 // to prevent those libs from being included in the search path
1577 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1578 // those libs in the Runtime APEX are available via the legacy paths in
1579 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1580 // to the legacy paths and thus will be loaded into the default linker
1581 // namespace (aka "platform" namespace). If the libs are directly in
1582 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1583 // into the runtime linker namespace, which will result in double loading of
1584 // them, which isn't supported.
1585 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001586 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001587
Jiyong Parkf653b052019-11-18 15:39:01 +09001588 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001589 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001590}
1591
Jiyong Park1833cef2019-12-13 13:28:36 +09001592func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001593 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001594 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001595 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001596 }
Jooyung Han35155c42020-02-06 17:33:20 +09001597 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001598 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001599 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001600 af.symlinks = cc.Symlinks()
1601 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001602}
1603
Jiyong Park1833cef2019-12-13 13:28:36 +09001604func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001605 dirInApex := "bin"
1606 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001607 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001608}
Jiyong Park1833cef2019-12-13 13:28:36 +09001609func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001610 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001611 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1612 if err != nil {
1613 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001614 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001615 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001616 fileToCopy := android.PathForOutput(ctx, s)
1617 // NB: Since go binaries are static we don't need the module for anything here, which is
1618 // good since the go tool is a blueprint.Module not an android.Module like we would
1619 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001620 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001621}
1622
Jiyong Park1833cef2019-12-13 13:28:36 +09001623func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001624 dirInApex := filepath.Join("bin", sh.SubDir())
1625 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001626 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001627 af.symlinks = sh.Symlinks()
1628 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001629}
1630
Jooyung Han58f26ab2019-12-18 15:34:32 +09001631// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1632type javaLibrary interface {
1633 android.Module
1634 java.Dependency
1635}
1636
1637func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001638 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001639 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001640 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1641 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1642 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001643}
1644
Jiyong Park1833cef2019-12-13 13:28:36 +09001645func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001646 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1647 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001648 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001649}
1650
atrost6e126252020-01-27 17:01:16 +00001651func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1652 dirInApex := filepath.Join("etc", config.SubDir())
1653 fileToCopy := config.CompatConfig()
1654 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1655}
1656
Jiyong Park1833cef2019-12-13 13:28:36 +09001657func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001658 android.Module
1659 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001660 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001661 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001662 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001663 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001664}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001665 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001666 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001667 appDir = "priv-app"
1668 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001669 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001670 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001671 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1672 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001673 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001674
1675 if app, ok := aapp.(interface {
1676 OverriddenManifestPackageName() string
1677 }); ok {
1678 af.overriddenPackageName = app.OverriddenManifestPackageName()
1679 }
Jiyong Park618922e2020-01-08 13:35:43 +09001680 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001681}
1682
Roland Levillain935639d2019-08-13 14:55:28 +01001683// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1684type flattenedApexContext struct {
1685 android.ModuleContext
1686}
1687
1688func (c *flattenedApexContext) InstallBypassMake() bool {
1689 return true
1690}
1691
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001692// Function called while walking an APEX's payload dependencies.
1693//
1694// Return true if the `to` module should be visited, false otherwise.
1695type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1696
Jiyong Park201cedd2020-02-07 17:25:49 +09001697// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001698func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001699 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001700 am, ok := child.(android.ApexModule)
1701 if !ok || !am.CanHaveApexVariants() {
1702 return false
1703 }
1704
1705 // Check for the direct dependencies that contribute to the payload
1706 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1707 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001708 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001709 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001710 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001711 return false
1712 }
1713
1714 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001715 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001716 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001717 }
1718
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001719 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001720 })
1721}
1722
Jooyung Han03b51852020-02-26 22:45:42 +09001723func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1724 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001725 intVer, err := android.ApiStrToNum(ctx, ver)
1726 if err != nil {
1727 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001728 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001729 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001730}
1731
Paul Duffinc5192442020-03-31 11:31:36 +01001732// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1733// a dependency tag.
1734var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1735
1736func PrettyPrintTag(tag blueprint.DependencyTag) string {
1737 // Use tag's custom String() method if available.
1738 if stringer, ok := tag.(fmt.Stringer); ok {
1739 return stringer.String()
1740 }
1741
1742 // Otherwise, get a default string representation of the tag's struct.
1743 tagString := fmt.Sprintf("%#v", tag)
1744
1745 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1746 tagString = tagCleaner.ReplaceAllString(tagString, "")
1747 return tagString
1748}
1749
Jiyong Park201cedd2020-02-07 17:25:49 +09001750// Ensures that the dependencies are marked as available for this APEX
1751func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1752 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1753 if ctx.Host() || a.testApex || a.vndkApex {
1754 return
1755 }
1756
Jiyong Park58d10902020-03-28 14:43:19 +09001757 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1758 // Requiring them and their transitive depencies with apex_available is not right
1759 // because they just add noise.
1760 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1761 return
1762 }
1763
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001764 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1765 if externalDep {
1766 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1767 return false
1768 }
1769
Jiyong Park201cedd2020-02-07 17:25:49 +09001770 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001771 fromName := ctx.OtherModuleName(from)
1772 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001773
1774 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1775 // do any of its dependencies.
1776 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1777 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1778 return false
1779 }
1780
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001781 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1782 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001783 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001784 message := ""
Paul Duffinc5192442020-03-31 11:31:36 +01001785 tagPath := ctx.GetTagPath()
1786 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1787 walkPath := ctx.GetWalkPath()[1:]
1788 for i, m := range walkPath {
1789 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffindf915ff2020-03-30 17:58:21 +01001790 }
1791 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001792 // Visit this module's dependencies to check and report any issues with their availability.
1793 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001794 })
1795}
1796
Jiyong Park678c8812020-02-07 17:25:49 +09001797// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1798func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1799 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001800 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001801 if from.Name() == to.Name() {
1802 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001803 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1804 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001805 }
1806
1807 if info, exists := a.depInfos[to.Name()]; exists {
1808 if !android.InList(from.Name(), info.from) {
1809 info.from = append(info.from, from.Name())
1810 }
1811 info.isExternal = info.isExternal && externalDep
1812 a.depInfos[to.Name()] = info
1813 } else {
1814 a.depInfos[to.Name()] = depInfo{
1815 to: to.Name(),
1816 from: []string{from.Name()},
1817 isExternal: externalDep,
1818 }
1819 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001820
1821 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1822 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001823 })
1824}
1825
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001826func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001827 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1828 switch a.properties.ApexType {
1829 case imageApex:
1830 if buildFlattenedAsDefault {
1831 a.suffix = imageApexSuffix
1832 } else {
1833 a.suffix = ""
1834 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001835
1836 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001837 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001838 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001839 }
1840 case zipApex:
1841 if proptools.String(a.properties.Payload_type) == "zip" {
1842 a.suffix = ""
1843 a.primaryApexType = true
1844 } else {
1845 a.suffix = zipApexSuffix
1846 }
1847 case flattenedApex:
1848 if buildFlattenedAsDefault {
1849 a.suffix = ""
1850 a.primaryApexType = true
1851 } else {
1852 a.suffix = flattenedSuffix
1853 }
Alex Light5098a612018-11-29 17:12:15 -08001854 }
1855
Roland Levillain630846d2019-06-26 12:48:34 +01001856 if len(a.properties.Tests) > 0 && !a.testApex {
1857 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1858 return
1859 }
1860
Jiyong Park0f80c182020-01-31 02:49:53 +09001861 a.checkApexAvailability(ctx)
1862
Jiyong Park678c8812020-02-07 17:25:49 +09001863 a.collectDepsInfo(ctx)
1864
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001865 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1866
Jooyung Hane1633032019-08-01 17:41:43 +09001867 // native lib dependencies
1868 var provideNativeLibs []string
1869 var requireNativeLibs []string
1870
Jooyung Han5c998b92019-06-27 11:30:33 +09001871 // Check if "uses" requirements are met with dependent apexBundles
1872 var providedNativeSharedLibs []string
1873 useVendor := proptools.Bool(a.properties.Use_vendor)
1874 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1875 if ctx.OtherModuleDependencyTag(m) != usesTag {
1876 return
1877 }
1878 otherName := ctx.OtherModuleName(m)
1879 other, ok := m.(*apexBundle)
1880 if !ok {
1881 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1882 return
1883 }
1884 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1885 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1886 return
1887 }
1888 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1889 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1890 return
1891 }
1892 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1893 })
1894
Jiyong Parkf653b052019-11-18 15:39:01 +09001895 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001896 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001897 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001898 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001899 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1900 return false
1901 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001902 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001903 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001904 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001905 case sharedLibTag, jniLibTag:
1906 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001907 if c, ok := child.(*cc.Module); ok {
1908 // bootstrap bionic libs are treated as provided by system
1909 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1910 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001911 }
Jooyung Han643adc42020-02-27 13:50:06 +09001912 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1913 fi.isJniLib = isJniLib
1914 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001915 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001916 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001917 propertyName := "native_shared_libs"
1918 if isJniLib {
1919 propertyName = "jni_libs"
1920 }
1921 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001922 }
1923 case executableTag:
1924 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001925 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001926 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001927 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001928 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001929 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001930 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001931 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001932 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001933 } else {
Alex Light778127a2019-02-27 14:19:50 -08001934 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 +09001935 }
1936 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001937 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001938 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001939 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001940 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1941 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001942 filesInfo = append(filesInfo, af)
1943 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001944 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001945 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1946 af := apexFileForJavaLibrary(ctx, sdkLib)
1947 if !af.Ok() {
1948 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1949 return false
1950 }
1951 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001952 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001953 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001954 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001955 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001956 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001957 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001958 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001959 return true // track transitive dependencies
1960 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001961 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001962 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001963 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001964 } else {
1965 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1966 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001967 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001968 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001969 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001970 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1971 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001972 } else {
atrost6e126252020-01-27 17:01:16 +00001973 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001974 }
Roland Levillain630846d2019-06-26 12:48:34 +01001975 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001976 if ccTest, ok := child.(*cc.Module); ok {
1977 if ccTest.IsTestPerSrcAllTestsVariation() {
1978 // Multiple-output test module (where `test_per_src: true`).
1979 //
1980 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1981 // We do not add this variation to `filesInfo`, as it has no output;
1982 // however, we do add the other variations of this module as indirect
1983 // dependencies (see below).
1984 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001985 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001986 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001987 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001988 af.class = nativeTest
1989 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001990 }
Roland Levillain630846d2019-06-26 12:48:34 +01001991 } else {
1992 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1993 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001994 case keyTag:
1995 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001996 a.private_key_file = key.private_key_file
1997 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001998 } else {
1999 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002000 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002001 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002002 case certificateTag:
2003 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002004 a.container_certificate_file = dep.Certificate.Pem
2005 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002006 } else {
2007 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2008 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002009 case android.PrebuiltDepTag:
2010 // If the prebuilt is force disabled, remember to delete the prebuilt file
2011 // that might have been installed in the previous builds
2012 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2013 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2014 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002015 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002016 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002017 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002018 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002019 // We cannot use a switch statement on `depTag` here as the checked
2020 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002021 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002022 if cc, ok := child.(*cc.Module); ok {
2023 if android.InList(cc.Name(), providedNativeSharedLibs) {
2024 // If we're using a shared library which is provided from other APEX,
2025 // don't include it in this APEX
2026 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002027 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002028 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002029 // If the dependency is a stubs lib, don't include it in this APEX,
2030 // but make sure that the lib is installed on the device.
2031 // In case no APEX is having the lib, the lib is installed to the system
2032 // partition.
2033 //
2034 // Always include if we are a host-apex however since those won't have any
2035 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002036 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2037 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002038 }
Jooyung Hane1633032019-08-01 17:41:43 +09002039 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002040 // Don't track further
2041 return false
2042 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002043 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002044 af.transitiveDep = true
2045 filesInfo = append(filesInfo, af)
2046 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002047 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002048 } else if cc.IsTestPerSrcDepTag(depTag) {
2049 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002050 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002051 // Handle modules created as `test_per_src` variations of a single test module:
2052 // use the name of the generated test binary (`fileToCopy`) instead of the name
2053 // of the original test module (`depName`, shared by all `test_per_src`
2054 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002055 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002056 // these are not considered transitive dep
2057 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002058 filesInfo = append(filesInfo, af)
2059 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002060 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002061 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002062 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2063 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002064 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2065 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2066 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2067 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002068 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffindddd5462020-04-07 15:25:44 +01002069 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002070 }
2071 }
2072 }
2073 return false
2074 })
2075
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002076 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2077 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2078 // via the global boot image config.
2079 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002080 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002081 dirInApex := filepath.Join("javalib", arch.String())
2082 for _, f := range files {
2083 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002084 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002085 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002086 }
2087 }
2088 }
2089
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002090 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002091 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2092 return
2093 }
2094
Jiyong Park8fd61922018-11-08 02:50:25 +09002095 // remove duplicates in filesInfo
2096 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002097 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002098 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002099 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002100 if e, ok := encountered[dest]; !ok {
2101 encountered[dest] = f
2102 } else {
2103 // If a module is directly included and also transitively depended on
2104 // consider it as directly included.
2105 e.transitiveDep = e.transitiveDep && f.transitiveDep
2106 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002107 }
2108 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002109 var result []apexFile
2110 for _, v := range encountered {
2111 result = append(result, v)
2112 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002113 return result
2114 }
2115 filesInfo = removeDup(filesInfo)
2116
2117 // to have consistent build rules
2118 sort.Slice(filesInfo, func(i, j int) bool {
2119 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2120 })
2121
Jiyong Park8fd61922018-11-08 02:50:25 +09002122 a.installDir = android.PathForModuleInstall(ctx, "apex")
2123 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002124
Jooyung Han54aca7b2019-11-20 02:26:02 +09002125 if a.properties.ApexType != zipApex {
2126 if a.properties.File_contexts == nil {
2127 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2128 } else {
2129 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2130 if a.Platform() {
2131 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2132 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2133 }
2134 }
2135 }
2136 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2137 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2138 return
2139 }
2140 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002141 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2142 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2143 // the same library in the system partition, thus effectively sharing the same libraries
2144 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2145 // in the APEX.
2146 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2147 a.installable() &&
2148 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002149
Jiyong Park9d677202020-02-19 16:29:35 +09002150 // We don't need the optimization for updatable APEXes, as it might give false signal
2151 // to the system health when the APEXes are still bundled (b/149805758)
2152 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2153 a.linkToSystemLib = false
2154 }
2155
Jiyong Park638d30e2020-02-26 18:27:19 +09002156 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2157 if ctx.Host() {
2158 a.linkToSystemLib = false
2159 }
2160
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002161 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002162 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2163
2164 a.setCertificateAndPrivateKey(ctx)
2165 if a.properties.ApexType == flattenedApex {
2166 a.buildFlattenedApex(ctx)
2167 } else {
2168 a.buildUnflattenedApex(ctx)
2169 }
2170
Jooyung Han002ab682020-01-08 01:57:58 +09002171 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002172
2173 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002174}
2175
Jooyung Han5e9013b2020-03-10 06:23:13 +09002176func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002177 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002178 moduleName = normalizeModuleName(moduleName)
2179
2180 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2181 return true
2182 }
2183
2184 key = android.AvailableToAnyApex
2185 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2186 return true
2187 }
2188
2189 return false
2190}
2191
2192func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002193 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2194 // system. Trim the prefix for the check since they are confusing
2195 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2196 if strings.HasPrefix(moduleName, "libclang_rt.") {
2197 // This module has many arch variants that depend on the product being built.
2198 // We don't want to list them all
2199 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002200 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002201 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002202}
2203
Jooyung Han344d5432019-08-23 11:17:39 +09002204func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002205 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002206 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002207 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002208 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002209 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002210 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2211 })
Alex Light5098a612018-11-29 17:12:15 -08002212 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002213 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002214 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002215 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002216 return module
2217}
Jiyong Park30ca9372019-02-07 16:27:23 +09002218
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002219func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002220 bundle := newApexBundle()
2221 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002222 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002223 return bundle
2224}
2225
Jiyong Parkfce0b422020-02-11 03:56:06 +09002226// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2227// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002228func testApexBundleFactory() android.Module {
2229 bundle := newApexBundle()
2230 bundle.testApex = true
2231 return bundle
2232}
2233
Jiyong Parkfce0b422020-02-11 03:56:06 +09002234// apex packages other modules into an APEX file which is a packaging format for system-level
2235// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002236func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002237 return newApexBundle()
2238}
2239
Jiyong Park30ca9372019-02-07 16:27:23 +09002240//
2241// Defaults
2242//
2243type Defaults struct {
2244 android.ModuleBase
2245 android.DefaultsModuleBase
2246}
2247
Jiyong Park30ca9372019-02-07 16:27:23 +09002248func defaultsFactory() android.Module {
2249 return DefaultsFactory()
2250}
2251
2252func DefaultsFactory(props ...interface{}) android.Module {
2253 module := &Defaults{}
2254
2255 module.AddProperties(props...)
2256 module.AddProperties(
2257 &apexBundleProperties{},
2258 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002259 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002260 )
2261
2262 android.InitDefaultsModule(module)
2263 return module
2264}
Jiyong Park5d790c32019-11-15 18:40:32 +09002265
2266//
2267// OverrideApex
2268//
2269type OverrideApex struct {
2270 android.ModuleBase
2271 android.OverrideModuleBase
2272}
2273
2274func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2275 // All the overrides happen in the base module.
2276}
2277
2278// override_apex is used to create an apex module based on another apex module
2279// by overriding some of its properties.
2280func overrideApexFactory() android.Module {
2281 m := &OverrideApex{}
2282 m.AddProperties(&overridableProperties{})
2283
2284 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2285 android.InitOverrideModule(m)
2286 return m
2287}