blob: b521ff3f8e3989bf9bac994f9e54c7c275db0e97 [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"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090048
49 // determines if the dependent will be part of the APEX payload
50 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090051}
52
53var (
Jiyong Park0f80c182020-01-31 02:49:53 +090054 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090055 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090056 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090064 rroTag = dependencyTag{name: "rro", 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",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900230 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900231 "sap-api-java-static",
232 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000233 }
234 //
235 // Module separator
236 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900237 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000238 //
239 // Module separator
240 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libnativehelper_header_only",
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 }
244 //
245 // Module separator
246 //
247 m["com.android.extservices"] = []string{
248 "flatbuffer_headers",
249 "liblua",
250 "libtextclassifier",
251 "libtextclassifier_hash_static",
252 "libtflite_static",
253 "libutf",
Jiyong Park0f80c182020-01-31 02:49:53 +0900254 "tensorflow_headers",
255 }
256 //
257 // Module separator
258 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900259 m["com.android.neuralnetworks"] = []string{
260 "android.hardware.neuralnetworks@1.0",
261 "android.hardware.neuralnetworks@1.1",
262 "android.hardware.neuralnetworks@1.2",
263 "android.hardware.neuralnetworks@1.3",
264 "android.hidl.allocator@1.0",
265 "android.hidl.memory.token@1.0",
266 "android.hidl.memory@1.0",
267 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900268 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900269 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900270 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "libprocpartition",
272 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900273 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000274 //
275 // Module separator
276 //
277 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000278 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900279 "android.hardware.cas.native@1.0",
280 "android.hardware.cas@1.0",
281 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000282 "android.hardware.configstore@1.0",
283 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000284 "android.hardware.graphics.allocator@2.0",
285 "android.hardware.graphics.allocator@3.0",
286 "android.hardware.graphics.bufferqueue@1.0",
287 "android.hardware.graphics.bufferqueue@2.0",
288 "android.hardware.graphics.common@1.0",
289 "android.hardware.graphics.common@1.1",
290 "android.hardware.graphics.common@1.2",
291 "android.hardware.graphics.mapper@2.0",
292 "android.hardware.graphics.mapper@2.1",
293 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900294 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000295 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900296 "android.hidl.allocator@1.0",
297 "android.hidl.memory.token@1.0",
298 "android.hidl.memory@1.0",
299 "android.hidl.token@1.0",
300 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900301 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900302 "gl_headers",
303 "libEGL",
304 "libEGL_blobCache",
305 "libEGL_getProcAddress",
306 "libFLAC",
307 "libFLAC-config",
308 "libFLAC-headers",
309 "libGLESv2",
310 "libaacextractor",
311 "libamrextractor",
312 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900313 "libaudio_system_headers",
314 "libaudioclient",
315 "libaudioclient_headers",
316 "libaudiofoundation",
317 "libaudiofoundation_headers",
318 "libaudiomanager",
319 "libaudiopolicy",
320 "libaudioutils",
321 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900322 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900323 "libbluetooth-types-header",
324 "libbufferhub",
325 "libbufferhub_headers",
326 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900327 "libc_malloc_debug_backtrace",
328 "libcamera_client",
329 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900330 "libdexfile_external_headers",
331 "libdexfile_support",
332 "libdvr_headers",
333 "libexpat",
334 "libfifo",
335 "libflacextractor",
336 "libgrallocusage",
337 "libgraphicsenv",
338 "libgui",
339 "libgui_headers",
340 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900341 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900342 "liblzma",
343 "libmath",
344 "libmedia",
345 "libmedia_codeclist",
346 "libmedia_headers",
347 "libmedia_helper",
348 "libmedia_helper_headers",
349 "libmedia_midiiowrapper",
350 "libmedia_omx",
351 "libmediautils",
352 "libmidiextractor",
353 "libmkvextractor",
354 "libmp3extractor",
355 "libmp4extractor",
356 "libmpeg2extractor",
357 "libnativebase_headers",
358 "libnativebridge-headers",
359 "libnativebridge_lazy",
360 "libnativeloader-headers",
361 "libnativeloader_lazy",
362 "libnativewindow_headers",
363 "libnblog",
364 "liboggextractor",
365 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900366 "libpdx",
367 "libpdx_default_transport",
368 "libpdx_headers",
369 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900370 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900371 "libsonivox",
372 "libspeexresampler",
373 "libspeexresampler",
374 "libstagefright_esds",
375 "libstagefright_flacdec",
376 "libstagefright_flacdec",
377 "libstagefright_foundation",
378 "libstagefright_foundation_headers",
379 "libstagefright_foundation_without_imemory",
380 "libstagefright_headers",
381 "libstagefright_id3",
382 "libstagefright_metadatautils",
383 "libstagefright_mpeg2extractor",
384 "libstagefright_mpeg2support",
385 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900386 "libui",
387 "libui_headers",
388 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900389 "libvibrator",
390 "libvorbisidec",
391 "libwavextractor",
392 "libwebm",
393 "media_ndk_headers",
394 "media_plugin_headers",
395 "updatable-media",
396 }
397 //
398 // Module separator
399 //
400 m["com.android.media.swcodec"] = []string{
401 "android.frameworks.bufferhub@1.0",
402 "android.hardware.common-ndk_platform",
403 "android.hardware.configstore-utils",
404 "android.hardware.configstore@1.0",
405 "android.hardware.configstore@1.1",
406 "android.hardware.graphics.allocator@2.0",
407 "android.hardware.graphics.allocator@3.0",
408 "android.hardware.graphics.bufferqueue@1.0",
409 "android.hardware.graphics.bufferqueue@2.0",
410 "android.hardware.graphics.common-ndk_platform",
411 "android.hardware.graphics.common@1.0",
412 "android.hardware.graphics.common@1.1",
413 "android.hardware.graphics.common@1.2",
414 "android.hardware.graphics.mapper@2.0",
415 "android.hardware.graphics.mapper@2.1",
416 "android.hardware.graphics.mapper@3.0",
417 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000418 "android.hardware.media.bufferpool@2.0",
419 "android.hardware.media.c2@1.0",
420 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900421 "android.hardware.media@1.0",
422 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000423 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900424 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000425 "android.hidl.safe_union@1.0",
426 "android.hidl.token@1.0",
427 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900428 "libEGL",
429 "libFLAC",
430 "libFLAC-config",
431 "libFLAC-headers",
432 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900433 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900434 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900435 "libaudio_system_headers",
436 "libaudioutils",
437 "libaudioutils",
438 "libaudioutils_fixedfft",
439 "libavcdec",
440 "libavcenc",
441 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000442 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900443 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900444 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900445 "libbluetooth-types-header",
446 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900447 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000448 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900449 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000450 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900451 "libcodec2_hidl@1.1",
452 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000453 "libcodec2_soft_aacdec",
454 "libcodec2_soft_aacenc",
455 "libcodec2_soft_amrnbdec",
456 "libcodec2_soft_amrnbenc",
457 "libcodec2_soft_amrwbdec",
458 "libcodec2_soft_amrwbenc",
459 "libcodec2_soft_av1dec_gav1",
460 "libcodec2_soft_avcdec",
461 "libcodec2_soft_avcenc",
462 "libcodec2_soft_common",
463 "libcodec2_soft_flacdec",
464 "libcodec2_soft_flacenc",
465 "libcodec2_soft_g711alawdec",
466 "libcodec2_soft_g711mlawdec",
467 "libcodec2_soft_gsmdec",
468 "libcodec2_soft_h263dec",
469 "libcodec2_soft_h263enc",
470 "libcodec2_soft_hevcdec",
471 "libcodec2_soft_hevcenc",
472 "libcodec2_soft_mp3dec",
473 "libcodec2_soft_mpeg2dec",
474 "libcodec2_soft_mpeg4dec",
475 "libcodec2_soft_mpeg4enc",
476 "libcodec2_soft_opusdec",
477 "libcodec2_soft_opusenc",
478 "libcodec2_soft_rawdec",
479 "libcodec2_soft_vorbisdec",
480 "libcodec2_soft_vp8dec",
481 "libcodec2_soft_vp8enc",
482 "libcodec2_soft_vp9dec",
483 "libcodec2_soft_vp9enc",
484 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000485 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900486 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000487 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900488 "libfmq",
489 "libgav1",
490 "libgralloctypes",
491 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000492 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900493 "libgsm",
494 "libgui_bufferqueue_static",
495 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000496 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900497 "libhardware_headers",
498 "libhevcdec",
499 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000500 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900501 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000502 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900503 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000504 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900505 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900506 "libmpeg2dec",
507 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000508 "libnativebridge_lazy",
509 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900510 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900511 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000512 "libscudo_wrapper",
513 "libsfplugin_ccodec_utils",
514 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900515 "libstagefright_amrnbdec",
516 "libstagefright_amrnbenc",
517 "libstagefright_amrwbdec",
518 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000519 "libstagefright_bufferpool@2.0.1",
520 "libstagefright_bufferqueue_helper",
521 "libstagefright_enc_common",
522 "libstagefright_flacdec",
523 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900524 "libstagefright_foundation_headers",
525 "libstagefright_headers",
526 "libstagefright_m4vh263dec",
527 "libstagefright_m4vh263enc",
528 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000529 "libsync",
530 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900531 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000532 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000533 "libvorbisidec",
534 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900535 "libyuv",
536 "libyuv_static",
537 "media_ndk_headers",
538 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000539 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900540 }
541 //
542 // Module separator
543 //
544 m["com.android.mediaprovider"] = []string{
545 "MediaProvider",
546 "MediaProviderGoogle",
547 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900548 "libbase_ndk",
549 "libfuse",
550 "libfuse_jni",
551 "libnativehelper_header_only",
552 }
553 //
554 // Module separator
555 //
556 m["com.android.permission"] = []string{
557 "androidx.annotation_annotation",
558 "androidx.annotation_annotation-nodeps",
559 "androidx.lifecycle_lifecycle-common",
560 "androidx.lifecycle_lifecycle-common-java8",
561 "androidx.lifecycle_lifecycle-common-java8-nodeps",
562 "androidx.lifecycle_lifecycle-common-nodeps",
563 "kotlin-annotations",
564 "kotlin-stdlib",
565 "kotlin-stdlib-jdk7",
566 "kotlin-stdlib-jdk8",
567 "kotlinx-coroutines-android",
568 "kotlinx-coroutines-android-nodeps",
569 "kotlinx-coroutines-core",
570 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900571 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000572 }
573 //
574 // Module separator
575 //
576 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900577 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900578 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900579 "libc_aeabi",
580 "libc_bionic",
581 "libc_bionic_ndk",
582 "libc_bootstrap",
583 "libc_common",
584 "libc_common_shared",
585 "libc_common_static",
586 "libc_dns",
587 "libc_dynamic_dispatch",
588 "libc_fortify",
589 "libc_freebsd",
590 "libc_freebsd_large_stack",
591 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900592 "libc_init_dynamic",
593 "libc_init_static",
594 "libc_jemalloc_wrapper",
595 "libc_netbsd",
596 "libc_nomalloc",
597 "libc_nopthread",
598 "libc_openbsd",
599 "libc_openbsd_large_stack",
600 "libc_openbsd_ndk",
601 "libc_pthread",
602 "libc_static_dispatch",
603 "libc_syscalls",
604 "libc_tzcode",
605 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900606 "libdebuggerd",
607 "libdebuggerd_common_headers",
608 "libdebuggerd_handler_core",
609 "libdebuggerd_handler_fallback",
610 "libdexfile_external_headers",
611 "libdexfile_support",
612 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900613 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900614 "libjemalloc5",
615 "liblinker_main",
616 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900617 "liblz4",
618 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900619 "libprocinfo",
620 "libpropertyinfoparser",
621 "libscudo",
622 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900623 "libsystemproperties",
624 "libtombstoned_client_static",
625 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900626 "libz",
627 "libziparchive",
628 }
629 //
630 // Module separator
631 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900632 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900633 "libnativehelper_compat_libc++",
634 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900635 "libcgrouprc",
636 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900637 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900638 "libvndksupport",
639 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000640 }
641 //
642 // Module separator
643 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900644 m["com.android.wifi"] = []string{
645 "PlatformProperties",
646 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900647 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900648 "android.hardware.wifi-V1.1-java",
649 "android.hardware.wifi-V1.2-java",
650 "android.hardware.wifi-V1.3-java",
651 "android.hardware.wifi-V1.4-java",
652 "android.hardware.wifi.hostapd-V1.0-java",
653 "android.hardware.wifi.hostapd-V1.1-java",
654 "android.hardware.wifi.hostapd-V1.2-java",
655 "android.hardware.wifi.supplicant-V1.0-java",
656 "android.hardware.wifi.supplicant-V1.1-java",
657 "android.hardware.wifi.supplicant-V1.2-java",
658 "android.hardware.wifi.supplicant-V1.3-java",
659 "android.hidl.base-V1.0-java",
660 "android.hidl.manager-V1.0-java",
661 "android.hidl.manager-V1.1-java",
662 "android.hidl.manager-V1.2-java",
663 "androidx.annotation_annotation",
664 "androidx.annotation_annotation-nodeps",
665 "bouncycastle-unbundled",
666 "dnsresolver_aidl_interface-V2-java",
667 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900668 "framework-wifi-pre-jarjar",
669 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900670 "ipmemorystore-aidl-interfaces-V3-java",
671 "ipmemorystore-aidl-interfaces-java",
672 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900673 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900674 "libwifi-jni",
675 "net-utils-services-common",
676 "netd_aidl_interface-V2-java",
677 "netd_aidl_interface-unstable-java",
678 "netd_event_listener_interface-java",
679 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900680 "networkstack-client",
681 "services.net",
682 "wifi-lite-protos",
683 "wifi-nano-protos",
684 "wifi-service-pre-jarjar",
685 "wifi-service-resources",
686 "prebuilt_androidx.annotation_annotation-nodeps",
687 }
688 //
689 // Module separator
690 //
691 m["com.android.sdkext"] = []string{
692 "fmtlib_ndk",
693 "libbase_ndk",
694 "libprotobuf-cpp-lite-ndk",
695 }
696 //
697 // Module separator
698 //
699 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900700 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900701 }
702 //
703 // Module separator
704 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000705 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900706 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 "libclang_rt",
708 "libgcc_stripped",
709 "libprofile-clang-extras",
710 "libprofile-clang-extras_ndk",
711 "libprofile-extras",
712 "libprofile-extras_ndk",
713 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900714 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000715 return m
716}
717
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900718func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900719 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800720 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900721 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900722 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700723 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900724 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900725
Jooyung Han31c470b2019-10-18 16:26:59 +0900726 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900727 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900728
729 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
730 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
731 sort.Strings(*apexFileContextsInfos)
732 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
733 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900734}
735
Jooyung Han31c470b2019-10-18 16:26:59 +0900736func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
737 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
738 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
739}
740
Jiyong Parkd1063c12019-07-17 20:08:41 +0900741func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900742 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900743 ctx.BottomUp("apex", apexMutator).Parallel()
744 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
745 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900746 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900747}
748
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900749// Mark the direct and transitive dependencies of apex bundles so that they
750// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900751func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900752 if !mctx.Module().Enabled() {
753 return
754 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800755 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900756 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000757 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900758 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900759 ApexName: mctx.ModuleName(),
760 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100761 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900762 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900763 directDep = true
764 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800765 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900766 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900767 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900768
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800769 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900770 return
771 }
772
Paul Duffin923e8a52020-03-30 15:33:32 +0100773 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900774
Jiyong Parkf760cae2020-02-12 07:53:12 +0900775 mctx.VisitDirectDeps(func(child android.Module) {
776 depName := mctx.OtherModuleName(child)
777 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100778 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800779 android.UpdateApexDependency(apexBundles, depName, directDep)
780 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900781 }
782 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900783}
784
Jiyong Park89e850a2020-04-07 16:37:39 +0900785// mark if a module cannot be available to platform. A module cannot be available
786// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
787// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
788func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
789 // Host and recovery are not considered as platform
790 if mctx.Host() || mctx.Module().InstallInRecovery() {
791 return
792 }
793
794 if am, ok := mctx.Module().(android.ApexModule); ok {
795 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
796
797 // In a rare case when a lib is marked as available only to an apex
798 // but the apex doesn't exist. This can happen in a partial manifest branch
799 // like master-art. Currently, libstatssocket in the stats APEX is causing
800 // this problem.
801 // Include the lib in platform because the module SDK that ought to provide
802 // it doesn't exist, so it would otherwise be left out completely.
803 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
804 // this check for libraries provided by SDKs.
805 if !availableToPlatform && !android.InAnyApex(am.Name()) {
806 availableToPlatform = true
807 }
808
809 // If any of the dep is not available to platform, this module is also considered
810 // as being not available to platform even if it has "//apex_available:platform"
811 mctx.VisitDirectDeps(func(child android.Module) {
812 if !am.DepIsInSameApex(mctx, child) {
813 // if the dependency crosses apex boundary, don't consider it
814 return
815 }
816 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
817 availableToPlatform = false
818 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
819 }
820 })
821
822 // Exception 1: stub libraries and native bridge libraries are always available to platform
823 if cc, ok := mctx.Module().(*cc.Module); ok &&
824 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
825 availableToPlatform = true
826 }
827
828 // Exception 2: bootstrap bionic libraries are also always available to platform
829 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
830 availableToPlatform = true
831 }
832
833 if !availableToPlatform {
834 am.SetNotAvailableForPlatform()
835 }
836 }
837}
838
Paul Duffin65347702020-03-31 15:23:40 +0100839// If a module in an APEX depends on a module from an SDK then it needs an APEX
840// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
841func inAnySdk(module android.Module) bool {
842 if sa, ok := module.(android.SdkAware); ok {
843 return sa.IsInAnySdk()
844 }
845
846 return false
847}
848
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900849// Create apex variations if a module is included in APEX(s).
850func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900851 if !mctx.Module().Enabled() {
852 return
853 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900854 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900855 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000856 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900857 // apex bundle itself is mutated so that it and its modules have same
858 // apex variant.
859 apexBundleName := mctx.ModuleName()
860 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900861 } else if o, ok := mctx.Module().(*OverrideApex); ok {
862 apexBundleName := o.GetOverriddenModuleName()
863 if apexBundleName == "" {
864 mctx.ModuleErrorf("base property is not set")
865 return
866 }
867 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900868 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900869
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900870}
Sundong Ahne9b55722019-09-06 17:37:42 +0900871
Jooyung Han7a78a922019-10-08 21:59:58 +0900872var (
873 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
874 apexFileContextsInfosMutex sync.Mutex
875)
876
877func apexFileContextsInfos(config android.Config) *[]string {
878 return config.Once(apexFileContextsInfosKey, func() interface{} {
879 return &[]string{}
880 }).(*[]string)
881}
882
Jooyung Han54aca7b2019-11-20 02:26:02 +0900883func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900884 apexFileContextsInfosMutex.Lock()
885 defer apexFileContextsInfosMutex.Unlock()
886 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900887 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900888}
889
Sundong Ahne9b55722019-09-06 17:37:42 +0900890func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900891 if !mctx.Module().Enabled() {
892 return
893 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900894 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900895 var variants []string
896 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
897 case "image":
898 variants = append(variants, imageApexType, flattenedApexType)
899 case "zip":
900 variants = append(variants, zipApexType)
901 case "both":
902 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
903 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900904 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900905 return
906 }
907
908 modules := mctx.CreateLocalVariations(variants...)
909
910 for i, v := range variants {
911 switch v {
912 case imageApexType:
913 modules[i].(*apexBundle).properties.ApexType = imageApex
914 case zipApexType:
915 modules[i].(*apexBundle).properties.ApexType = zipApex
916 case flattenedApexType:
917 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900918 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900919 modules[i].(*apexBundle).MakeAsSystemExt()
920 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900921 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900922 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900923 } else if _, ok := mctx.Module().(*OverrideApex); ok {
924 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900925 }
926}
927
Jooyung Han5c998b92019-06-27 11:30:33 +0900928func apexUsesMutator(mctx android.BottomUpMutatorContext) {
929 if ab, ok := mctx.Module().(*apexBundle); ok {
930 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
931 }
932}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900933
Jooyung Handc782442019-11-01 03:14:38 +0900934var (
935 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
936)
937
938// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
939// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
940// which may cause compatibility issues. (e.g. libbinder)
941// Even though libbinder restricts its availability via 'apex_available' property and relies on
942// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
943// to avoid similar problems.
944func useVendorWhitelist(config android.Config) []string {
945 return config.Once(useVendorWhitelistKey, func() interface{} {
946 return []string{
947 // swcodec uses "vendor" variants for smaller size
948 "com.android.media.swcodec",
949 "test_com.android.media.swcodec",
950 }
951 }).([]string)
952}
953
954// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
955// called before the first call to useVendorWhitelist()
956func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
957 config.Once(useVendorWhitelistKey, func() interface{} {
958 return whitelist
959 })
960}
961
Jooyung Han01a868d2020-02-27 13:40:44 +0900962type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800963 // List of native libraries
964 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900965
Jooyung Han643adc42020-02-27 13:50:06 +0900966 // List of JNI libraries
967 Jni_libs []string
968
Alex Light9670d332019-01-29 18:07:33 -0800969 // List of native executables
970 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900971
Roland Levillain630846d2019-06-26 12:48:34 +0100972 // List of native tests
973 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800974}
Jooyung Han344d5432019-08-23 11:17:39 +0900975
Alex Light9670d332019-01-29 18:07:33 -0800976type apexMultilibProperties struct {
977 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900978 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800979
980 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900981 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800982
983 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900984 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800985
986 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900987 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800988
989 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900990 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800991}
992
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900993type apexBundleProperties struct {
994 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000995 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800996 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900997
Jiyong Park40e26a22019-02-08 02:53:06 +0900998 // AndroidManifest.xml file used for the zip container of this APEX bundle.
999 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001000 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001001
Roland Levillain411c5842019-09-19 16:37:20 +01001002 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1003 // device (/apex/<apex_name>).
1004 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001005 Apex_name *string
1006
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001007 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001008 // For platform APEXes, this should points to a file under /system/sepolicy
1009 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1010 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001011
Jooyung Han01a868d2020-02-27 13:40:44 +09001012 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001013
1014 // List of java libraries that are embedded inside this APEX bundle
1015 Java_libs []string
1016
1017 // List of prebuilt files that are embedded inside this APEX bundle
1018 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001019
1020 // Name of the apex_key module that provides the private key to sign APEX
1021 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001022
Alex Light5098a612018-11-29 17:12:15 -08001023 // The type of APEX to build. Controls what the APEX payload is. Either
1024 // 'image', 'zip' or 'both'. Default: 'image'.
1025 Payload_type *string
1026
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001027 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1028 // or an android_app_certificate module name in the form ":module".
1029 Certificate *string
1030
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001031 // Whether this APEX is installable to one of the partitions. Default: true.
1032 Installable *bool
1033
Jiyong Parkda6eb592018-12-19 17:12:36 +09001034 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1035 // Default is false.
1036 Use_vendor *bool
1037
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001038 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1039 Ignore_system_library_special_case *bool
1040
Alex Light9670d332019-01-29 18:07:33 -08001041 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001042
Jiyong Parkf97782b2019-02-13 20:28:58 +09001043 // List of sanitizer names that this APEX is enabled for
1044 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001045
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001046 PreventInstall bool `blueprint:"mutated"`
1047
1048 HideFromMake bool `blueprint:"mutated"`
1049
Jooyung Han5c998b92019-06-27 11:30:33 +09001050 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1051 Provide_cpp_shared_libs *bool
1052
1053 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1054 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001055
1056 // A txt file containing list of files that are whitelisted to be included in this APEX.
1057 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001058
Sundong Ahnabb64432019-10-22 13:58:29 +09001059 // package format of this apex variant; could be non-flattened, flattened, or zip.
1060 // imageApex, zipApex or flattened
1061 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001062
Jiyong Parkd1063c12019-07-17 20:08:41 +09001063 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1064 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1065 // is implied. This value affects all modules included in this APEX. In other words, they are
1066 // also built with the SDKs specified here.
1067 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001068
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001069 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1070 // Should be only used in tests#.
1071 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001072
Dario Frenica913392020-04-27 18:21:11 +01001073 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1074 // Should be only used in tests#.
1075 Test_only_unsigned_payload *bool
1076
Jiyong Park956305c2020-01-09 12:32:06 +09001077 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001078
1079 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001080 // rules for making sure that the APEX is truly updatable.
1081 // - To be updatable, min_sdk_version should be set as well
1082 // This will also disable the size optimizations like symlinking to the system libs.
1083 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001084 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001085
1086 // The minimum SDK version that this apex must be compatibile with.
1087 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001088}
1089
1090type apexTargetBundleProperties struct {
1091 Target struct {
1092 // Multilib properties only for android.
1093 Android struct {
1094 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001095 }
Jooyung Han344d5432019-08-23 11:17:39 +09001096
Alex Light9670d332019-01-29 18:07:33 -08001097 // Multilib properties only for host.
1098 Host struct {
1099 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001100 }
Jooyung Han344d5432019-08-23 11:17:39 +09001101
Alex Light9670d332019-01-29 18:07:33 -08001102 // Multilib properties only for host linux_bionic.
1103 Linux_bionic struct {
1104 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001105 }
Jooyung Han344d5432019-08-23 11:17:39 +09001106
Alex Light9670d332019-01-29 18:07:33 -08001107 // Multilib properties only for host linux_glibc.
1108 Linux_glibc struct {
1109 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001110 }
1111 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001112}
1113
Jiyong Park5d790c32019-11-15 18:40:32 +09001114type overridableProperties struct {
1115 // List of APKs to package inside APEX
1116 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001117
Jiyong Park69aeba92020-04-24 21:16:36 +09001118 // List of runtime resource overlays (RROs) inside APEX
1119 Rros []string
1120
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001121 // Names of modules to be overridden. Listed modules can only be other binaries
1122 // (in Make or Soong).
1123 // This does not completely prevent installation of the overridden binaries, but if both
1124 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1125 // from PRODUCT_PACKAGES.
1126 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001127
1128 // Logging Parent value
1129 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001130
1131 // Apex Container Package Name.
1132 // Override value for attribute package:name in AndroidManifest.xml
1133 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001134}
1135
Alex Light5098a612018-11-29 17:12:15 -08001136type apexPackaging int
1137
1138const (
1139 imageApex apexPackaging = iota
1140 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001141 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001142)
1143
Sundong Ahnabb64432019-10-22 13:58:29 +09001144// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001145func (a apexPackaging) suffix() string {
1146 switch a {
1147 case imageApex:
1148 return imageApexSuffix
1149 case zipApex:
1150 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001151 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001152 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001153 }
1154}
1155
1156func (a apexPackaging) name() string {
1157 switch a {
1158 case imageApex:
1159 return imageApexType
1160 case zipApex:
1161 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001162 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001163 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001164 }
1165}
1166
Jiyong Parkf653b052019-11-18 15:39:01 +09001167type apexFileClass int
1168
1169const (
1170 etc apexFileClass = iota
1171 nativeSharedLib
1172 nativeExecutable
1173 shBinary
1174 pyBinary
1175 goBinary
1176 javaSharedLib
1177 nativeTest
1178 app
1179)
1180
Jiyong Park8fd61922018-11-08 02:50:25 +09001181func (class apexFileClass) NameInMake() string {
1182 switch class {
1183 case etc:
1184 return "ETC"
1185 case nativeSharedLib:
1186 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001187 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001188 return "EXECUTABLES"
1189 case javaSharedLib:
1190 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001191 case nativeTest:
1192 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001193 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001194 // b/142537672 Why isn't this APP? We want to have full control over
1195 // the paths and file names of the apk file under the flattend APEX.
1196 // If this is set to APP, then the paths and file names are modified
1197 // by the Make build system. For example, it is installed to
1198 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1199 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1200 // appends module name (which is <apexname>.<Appname> to the path.
1201 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001202 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001203 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001204 }
1205}
1206
Jiyong Parkf653b052019-11-18 15:39:01 +09001207// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001208type apexFile struct {
1209 builtFile android.Path
1210 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001211 installDir string
1212 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001213 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001214 // list of symlinks that will be created in installDir that point to this apexFile
1215 symlinks []string
1216 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001217 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001218
1219 requiredModuleNames []string
1220 targetRequiredModuleNames []string
1221 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001222
Colin Cross503c1d02020-01-28 14:00:53 -08001223 jacocoReportClassesFile android.Path // only for javalibs and apps
1224 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001225 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001226
1227 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001228}
1229
Jiyong Park1833cef2019-12-13 13:28:36 +09001230func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1231 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001232 builtFile: builtFile,
1233 moduleName: moduleName,
1234 installDir: installDir,
1235 class: class,
1236 module: module,
1237 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001238 if module != nil {
1239 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001240 ret.requiredModuleNames = module.RequiredModuleNames()
1241 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1242 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001243 }
1244 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001245}
1246
1247func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001248 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001249}
1250
Jiyong Park7cd10e32020-01-14 09:22:18 +09001251// Path() returns path of this apex file relative to the APEX root
1252func (af *apexFile) Path() string {
1253 return filepath.Join(af.installDir, af.builtFile.Base())
1254}
1255
1256// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1257func (af *apexFile) SymlinkPaths() []string {
1258 var ret []string
1259 for _, symlink := range af.symlinks {
1260 ret = append(ret, filepath.Join(af.installDir, symlink))
1261 }
1262 return ret
1263}
1264
1265func (af *apexFile) AvailableToPlatform() bool {
1266 if af.module == nil {
1267 return false
1268 }
1269 if am, ok := af.module.(android.ApexModule); ok {
1270 return am.AvailableFor(android.AvailableToPlatform)
1271 }
1272 return false
1273}
1274
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001275type apexBundle struct {
1276 android.ModuleBase
1277 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001278 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001279 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001280
Jiyong Park5d790c32019-11-15 18:40:32 +09001281 properties apexBundleProperties
1282 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001283 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001284
Jooyung Hanf21c7972019-12-16 22:32:06 +09001285 // specific to apex_vndk modules
1286 vndkProperties apexVndkProperties
1287
Colin Crossa4925902018-11-16 11:36:28 -08001288 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001289 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001290 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001291
Jiyong Park03b68dd2019-07-26 23:20:40 +09001292 prebuiltFileToDelete string
1293
Jiyong Park42cca6c2019-04-01 11:15:50 +09001294 public_key_file android.Path
1295 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001296
1297 container_certificate_file android.Path
1298 container_private_key_file android.Path
1299
Jooyung Han54aca7b2019-11-20 02:26:02 +09001300 fileContexts android.Path
1301
Jiyong Park8fd61922018-11-08 02:50:25 +09001302 // list of files to be included in this apex
1303 filesInfo []apexFile
1304
Jiyong Park956305c2020-01-09 12:32:06 +09001305 // list of module names that should be installed along with this APEX
1306 requiredDeps []string
1307
Jiyong Park956305c2020-01-09 12:32:06 +09001308 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001309 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001310
Sundong Ahnabb64432019-10-22 13:58:29 +09001311 testApex bool
1312 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001313 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001314 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001315
Jooyung Han214bf372019-11-12 13:03:50 +09001316 manifestJsonOut android.WritablePath
1317 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001318
Jooyung Han002ab682020-01-08 01:57:58 +09001319 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001320 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001321 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001322 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1323 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001324
1325 // Suffix of module name in Android.mk
1326 // ".flattened", ".apex", ".zipapex", or ""
1327 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001328
1329 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001330
1331 // Whether to create symlink to the system file instead of having a file
1332 // inside the apex or not
1333 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001334
1335 // Struct holding the merged notice file paths in different formats
1336 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001337}
1338
Jiyong Park397e55e2018-10-24 21:09:55 +09001339func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001340 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001341 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001342 // Use *FarVariation* to be able to depend on modules having
1343 // conflicting variations with this module. This is required since
1344 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1345 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001346 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001347 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001348 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001349 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001350 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001351
Jooyung Han643adc42020-02-27 13:50:06 +09001352 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1353 {Mutator: "image", Variation: imageVariation},
1354 {Mutator: "link", Variation: "shared"},
1355 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1356 }...), jniLibTag, nativeModules.Jni_libs...)
1357
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001358 ctx.AddFarVariationDependencies(append(target.Variations(),
1359 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001360 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001361
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001362 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001363 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001364 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001365 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001366}
1367
Alex Light9670d332019-01-29 18:07:33 -08001368func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1369 if ctx.Os().Class == android.Device {
1370 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1371 } else {
1372 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1373 if ctx.Os().Bionic() {
1374 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1375 } else {
1376 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1377 }
1378 }
1379}
1380
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001381func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001382 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1383 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1384 }
1385
Jiyong Park397e55e2018-10-24 21:09:55 +09001386 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001387 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001388
1389 a.combineProperties(ctx)
1390
Jiyong Park397e55e2018-10-24 21:09:55 +09001391 has32BitTarget := false
1392 for _, target := range targets {
1393 if target.Arch.ArchType.Multilib == "lib32" {
1394 has32BitTarget = true
1395 }
1396 }
1397 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001398 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001399 // multilib.both
1400 addDependenciesForNativeModules(ctx,
1401 ApexNativeDependencies{
1402 Native_shared_libs: a.properties.Native_shared_libs,
1403 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001404 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001405 Binaries: nil,
1406 },
1407 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001408
Jiyong Park397e55e2018-10-24 21:09:55 +09001409 // Add native modules targetting both ABIs
1410 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001411 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001412 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001413 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001414
Alex Light3d673592019-01-18 14:37:31 -08001415 isPrimaryAbi := i == 0
1416 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001417 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001418 // multilib.first
1419 addDependenciesForNativeModules(ctx,
1420 ApexNativeDependencies{
1421 Native_shared_libs: nil,
1422 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001423 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001424 Binaries: a.properties.Binaries,
1425 },
1426 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001427
1428 // Add native modules targetting the first ABI
1429 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001430 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001431 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001432 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001433 }
1434
1435 switch target.Arch.ArchType.Multilib {
1436 case "lib32":
1437 // Add native modules targetting 32-bit ABI
1438 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001439 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001440 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001441 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001442
1443 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001444 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001445 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001446 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001447 case "lib64":
1448 // Add native modules targetting 64-bit ABI
1449 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001450 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001451 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001452 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001453
1454 if !has32BitTarget {
1455 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001456 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001457 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001458 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001459 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001460
1461 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1462 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1463 if sanitizer == "hwaddress" {
1464 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001465 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001466 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001467 break
1468 }
1469 }
1470 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001471 }
1472
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001473 }
1474
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001475 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1476 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1477 // b/144532908
1478 archForPrebuiltEtc := config.Arches()[0]
1479 for _, arch := range config.Arches() {
1480 // Prefer 64-bit arch if there is any
1481 if arch.ArchType.Multilib == "lib64" {
1482 archForPrebuiltEtc = arch
1483 break
1484 }
1485 }
1486 ctx.AddFarVariationDependencies([]blueprint.Variation{
1487 {Mutator: "os", Variation: ctx.Os().String()},
1488 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1489 }, prebuiltTag, a.properties.Prebuilts...)
1490
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001491 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1492 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001493
Ulya Trafimovich44561882020-01-03 13:25:54 +00001494 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1495 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1496 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1497 javaLibTag, "jacocoagent")
1498 }
1499
Jiyong Park23c52b02019-02-02 13:13:47 +09001500 if String(a.properties.Key) == "" {
1501 ctx.ModuleErrorf("key is missing")
1502 return
1503 }
1504 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001505
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001506 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001507 if cert != "" {
1508 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001509 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001510
1511 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1512 if len(a.properties.Uses_sdks) > 0 {
1513 sdkRefs := []android.SdkRef{}
1514 for _, str := range a.properties.Uses_sdks {
1515 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1516 sdkRefs = append(sdkRefs, parsed)
1517 }
1518 a.BuildWithSdks(sdkRefs)
1519 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001520}
1521
Jiyong Park5d790c32019-11-15 18:40:32 +09001522func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1523 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1524 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001525 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1526 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001527}
1528
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001529func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1530 // direct deps of an APEX bundle are all part of the APEX bundle
1531 return true
1532}
1533
Colin Cross0ea8ba82019-06-06 14:33:29 -07001534func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001535 moduleName := ctx.ModuleName()
1536 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1537 // we check with the pseudo module name to see if its certificate is overridden.
1538 if a.vndkApex {
1539 moduleName = vndkApexName
1540 }
1541 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001542 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001543 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001544 }
1545 return String(a.properties.Certificate)
1546}
1547
Colin Cross41955e82019-05-29 14:40:35 -07001548func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1549 switch tag {
1550 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001551 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001552 default:
1553 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001554 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001555}
1556
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001557func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001558 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001559}
1560
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001561func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1562 return proptools.Bool(a.properties.Test_only_no_hashtree)
1563}
1564
Dario Frenica913392020-04-27 18:21:11 +01001565func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1566 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1567}
1568
Jiyong Park7c1dc612019-01-05 11:15:24 +09001569func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001570 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001571 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001572 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001573 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001574 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001575 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001576 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001577 }
1578}
1579
Jiyong Parkf97782b2019-02-13 20:28:58 +09001580func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1581 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1582 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1583 }
1584}
1585
Jiyong Park388ef3f2019-01-28 19:47:32 +09001586func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001587 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1588 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001589 }
1590
1591 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001592 globalSanitizerNames := []string{}
1593 if a.Host() {
1594 globalSanitizerNames = ctx.Config().SanitizeHost()
1595 } else {
1596 arches := ctx.Config().SanitizeDeviceArch()
1597 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1598 globalSanitizerNames = ctx.Config().SanitizeDevice()
1599 }
1600 }
1601 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001602}
1603
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001604var _ cc.Coverage = (*apexBundle)(nil)
1605
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001606func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001607 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001608}
1609
1610func (a *apexBundle) PreventInstall() {
1611 a.properties.PreventInstall = true
1612}
1613
1614func (a *apexBundle) HideFromMake() {
1615 a.properties.HideFromMake = true
1616}
1617
Jiyong Park956305c2020-01-09 12:32:06 +09001618func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1619 a.properties.IsCoverageVariant = coverage
1620}
1621
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001622func (a *apexBundle) EnableCoverageIfNeeded() {}
1623
Jiyong Parkf653b052019-11-18 15:39:01 +09001624// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001625func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001626 // Decide the APEX-local directory by the multilib of the library
1627 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001628 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001629 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001630 case "lib32":
1631 dirInApex = "lib"
1632 case "lib64":
1633 dirInApex = "lib64"
1634 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001635 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001636 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001637 }
Jooyung Han35155c42020-02-06 17:33:20 +09001638 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001639 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001640 // Special case for Bionic libs and other libs installed with them. This is
1641 // to prevent those libs from being included in the search path
1642 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1643 // those libs in the Runtime APEX are available via the legacy paths in
1644 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1645 // to the legacy paths and thus will be loaded into the default linker
1646 // namespace (aka "platform" namespace). If the libs are directly in
1647 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1648 // into the runtime linker namespace, which will result in double loading of
1649 // them, which isn't supported.
1650 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001651 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001652
Jiyong Parkf653b052019-11-18 15:39:01 +09001653 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001654 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001655}
1656
Jiyong Park1833cef2019-12-13 13:28:36 +09001657func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001658 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001659 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001660 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001661 }
Jooyung Han35155c42020-02-06 17:33:20 +09001662 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001663 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001664 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001665 af.symlinks = cc.Symlinks()
1666 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001667}
1668
Jiyong Park1833cef2019-12-13 13:28:36 +09001669func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001670 dirInApex := "bin"
1671 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001672 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001673}
Jiyong Park1833cef2019-12-13 13:28:36 +09001674func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001675 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001676 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1677 if err != nil {
1678 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001679 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001680 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001681 fileToCopy := android.PathForOutput(ctx, s)
1682 // NB: Since go binaries are static we don't need the module for anything here, which is
1683 // good since the go tool is a blueprint.Module not an android.Module like we would
1684 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001685 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001686}
1687
Jiyong Park1833cef2019-12-13 13:28:36 +09001688func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001689 dirInApex := filepath.Join("bin", sh.SubDir())
1690 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001691 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001692 af.symlinks = sh.Symlinks()
1693 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001694}
1695
Paul Duffin581bbbe2020-05-14 20:49:32 +01001696func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib java.Dependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001697 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001698 fileToCopy := lib.DexJar()
Paul Duffin581bbbe2020-05-14 20:49:32 +01001699 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001700 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1701 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001702}
1703
Jiyong Park1833cef2019-12-13 13:28:36 +09001704func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001705 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1706 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001707 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001708}
1709
atrost6e126252020-01-27 17:01:16 +00001710func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1711 dirInApex := filepath.Join("etc", config.SubDir())
1712 fileToCopy := config.CompatConfig()
1713 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1714}
1715
Jiyong Park1833cef2019-12-13 13:28:36 +09001716func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001717 android.Module
1718 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001719 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001720 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001721 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001722 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001723}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001724 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001725 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001726 appDir = "priv-app"
1727 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001728 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001729 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001730 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1731 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001732 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001733
1734 if app, ok := aapp.(interface {
1735 OverriddenManifestPackageName() string
1736 }); ok {
1737 af.overriddenPackageName = app.OverriddenManifestPackageName()
1738 }
Jiyong Park618922e2020-01-08 13:35:43 +09001739 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001740}
1741
Jiyong Park69aeba92020-04-24 21:16:36 +09001742func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1743 rroDir := "overlay"
1744 dirInApex := filepath.Join(rroDir, rro.Theme())
1745 fileToCopy := rro.OutputFile()
1746 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1747 af.certificate = rro.Certificate()
1748
1749 if a, ok := rro.(interface {
1750 OverriddenManifestPackageName() string
1751 }); ok {
1752 af.overriddenPackageName = a.OverriddenManifestPackageName()
1753 }
1754 return af
1755}
1756
Roland Levillain935639d2019-08-13 14:55:28 +01001757// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1758type flattenedApexContext struct {
1759 android.ModuleContext
1760}
1761
1762func (c *flattenedApexContext) InstallBypassMake() bool {
1763 return true
1764}
1765
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001766// Function called while walking an APEX's payload dependencies.
1767//
1768// Return true if the `to` module should be visited, false otherwise.
1769type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1770
Jiyong Park201cedd2020-02-07 17:25:49 +09001771// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001772func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001773 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001774 am, ok := child.(android.ApexModule)
1775 if !ok || !am.CanHaveApexVariants() {
1776 return false
1777 }
1778
1779 // Check for the direct dependencies that contribute to the payload
1780 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1781 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001782 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001783 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001784 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001785 return false
1786 }
1787
1788 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001789 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001790 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001791 }
1792
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001793 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001794 })
1795}
1796
Jooyung Han03b51852020-02-26 22:45:42 +09001797func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1798 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001799 intVer, err := android.ApiStrToNum(ctx, ver)
1800 if err != nil {
1801 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001802 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001803 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001804}
1805
Jiyong Park201cedd2020-02-07 17:25:49 +09001806// Ensures that the dependencies are marked as available for this APEX
1807func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1808 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1809 if ctx.Host() || a.testApex || a.vndkApex {
1810 return
1811 }
1812
Jiyong Park58d10902020-03-28 14:43:19 +09001813 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1814 // Requiring them and their transitive depencies with apex_available is not right
1815 // because they just add noise.
1816 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1817 return
1818 }
1819
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001820 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1821 if externalDep {
1822 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1823 return false
1824 }
1825
Jiyong Park201cedd2020-02-07 17:25:49 +09001826 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001827 fromName := ctx.OtherModuleName(from)
1828 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001829
1830 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1831 // do any of its dependencies.
1832 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1833 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1834 return false
1835 }
1836
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001837 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1838 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001839 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001840 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, ctx.GetPathString(true))
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001841 // Visit this module's dependencies to check and report any issues with their availability.
1842 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001843 })
1844}
1845
Jooyung Han548640b2020-04-27 12:10:30 +09001846func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1847 if proptools.Bool(a.properties.Updatable) {
1848 if String(a.properties.Min_sdk_version) == "" {
1849 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1850 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001851
1852 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001853 }
1854}
1855
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001856func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001857 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1858 switch a.properties.ApexType {
1859 case imageApex:
1860 if buildFlattenedAsDefault {
1861 a.suffix = imageApexSuffix
1862 } else {
1863 a.suffix = ""
1864 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001865
1866 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001867 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001868 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001869 }
1870 case zipApex:
1871 if proptools.String(a.properties.Payload_type) == "zip" {
1872 a.suffix = ""
1873 a.primaryApexType = true
1874 } else {
1875 a.suffix = zipApexSuffix
1876 }
1877 case flattenedApex:
1878 if buildFlattenedAsDefault {
1879 a.suffix = ""
1880 a.primaryApexType = true
1881 } else {
1882 a.suffix = flattenedSuffix
1883 }
Alex Light5098a612018-11-29 17:12:15 -08001884 }
1885
Roland Levillain630846d2019-06-26 12:48:34 +01001886 if len(a.properties.Tests) > 0 && !a.testApex {
1887 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1888 return
1889 }
1890
Jiyong Park0f80c182020-01-31 02:49:53 +09001891 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001892 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001893
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001894 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1895
Jooyung Hane1633032019-08-01 17:41:43 +09001896 // native lib dependencies
1897 var provideNativeLibs []string
1898 var requireNativeLibs []string
1899
Jooyung Han5c998b92019-06-27 11:30:33 +09001900 // Check if "uses" requirements are met with dependent apexBundles
1901 var providedNativeSharedLibs []string
1902 useVendor := proptools.Bool(a.properties.Use_vendor)
1903 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1904 if ctx.OtherModuleDependencyTag(m) != usesTag {
1905 return
1906 }
1907 otherName := ctx.OtherModuleName(m)
1908 other, ok := m.(*apexBundle)
1909 if !ok {
1910 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1911 return
1912 }
1913 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1914 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1915 return
1916 }
1917 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1918 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1919 return
1920 }
1921 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1922 })
1923
Jiyong Parkf653b052019-11-18 15:39:01 +09001924 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001925 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001926 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001927 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001928 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1929 return false
1930 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001931 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001932 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001933 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001934 case sharedLibTag, jniLibTag:
1935 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001936 if c, ok := child.(*cc.Module); ok {
1937 // bootstrap bionic libs are treated as provided by system
1938 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1939 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001940 }
Jooyung Han643adc42020-02-27 13:50:06 +09001941 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1942 fi.isJniLib = isJniLib
1943 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09001944 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001945 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001946 propertyName := "native_shared_libs"
1947 if isJniLib {
1948 propertyName = "jni_libs"
1949 }
1950 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001951 }
1952 case executableTag:
1953 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001954 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001955 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001956 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001957 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001958 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001959 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001960 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001961 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001962 } else {
Alex Light778127a2019-02-27 14:19:50 -08001963 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 +09001964 }
1965 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001966 if javaLib, ok := child.(*java.Library); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01001967 af := apexFileForJavaLibrary(ctx, javaLib, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001968 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001969 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1970 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001971 filesInfo = append(filesInfo, af)
1972 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001973 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001974 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01001975 af := apexFileForJavaLibrary(ctx, sdkLib, sdkLib)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001976 if !af.Ok() {
1977 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1978 return false
1979 }
1980 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001981 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001982 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001983 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001984 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001985 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001986 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001987 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001988 return true // track transitive dependencies
1989 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001990 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001991 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001992 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001993 } else {
1994 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1995 }
Jiyong Park69aeba92020-04-24 21:16:36 +09001996 case rroTag:
1997 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
1998 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
1999 } else {
2000 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2001 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002002 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002003 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002004 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002005 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2006 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002007 } else {
atrost6e126252020-01-27 17:01:16 +00002008 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002009 }
Roland Levillain630846d2019-06-26 12:48:34 +01002010 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002011 if ccTest, ok := child.(*cc.Module); ok {
2012 if ccTest.IsTestPerSrcAllTestsVariation() {
2013 // Multiple-output test module (where `test_per_src: true`).
2014 //
2015 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2016 // We do not add this variation to `filesInfo`, as it has no output;
2017 // however, we do add the other variations of this module as indirect
2018 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002019 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002020 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002021 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002022 af.class = nativeTest
2023 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002024 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002025 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002026 } else {
2027 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2028 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002029 case keyTag:
2030 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002031 a.private_key_file = key.private_key_file
2032 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002033 } else {
2034 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002035 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002036 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002037 case certificateTag:
2038 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002039 a.container_certificate_file = dep.Certificate.Pem
2040 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002041 } else {
2042 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2043 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002044 case android.PrebuiltDepTag:
2045 // If the prebuilt is force disabled, remember to delete the prebuilt file
2046 // that might have been installed in the previous builds
2047 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2048 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2049 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002050 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002051 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002052 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002053 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002054 // We cannot use a switch statement on `depTag` here as the checked
2055 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002056 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002057 if cc, ok := child.(*cc.Module); ok {
2058 if android.InList(cc.Name(), providedNativeSharedLibs) {
2059 // If we're using a shared library which is provided from other APEX,
2060 // don't include it in this APEX
2061 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002062 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002063 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002064 // If the dependency is a stubs lib, don't include it in this APEX,
2065 // but make sure that the lib is installed on the device.
2066 // In case no APEX is having the lib, the lib is installed to the system
2067 // partition.
2068 //
2069 // Always include if we are a host-apex however since those won't have any
2070 // system libraries.
Yo Chiang29555d52020-05-06 15:59:59 +08002071 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.BaseModuleName(), a.requiredDeps) {
2072 a.requiredDeps = append(a.requiredDeps, cc.BaseModuleName())
Roland Levillainf89cd092019-07-29 16:22:59 +01002073 }
Jooyung Hane1633032019-08-01 17:41:43 +09002074 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002075 // Don't track further
2076 return false
2077 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002078 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002079 af.transitiveDep = true
2080 filesInfo = append(filesInfo, af)
2081 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002082 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002083 } else if cc.IsTestPerSrcDepTag(depTag) {
2084 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002085 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002086 // Handle modules created as `test_per_src` variations of a single test module:
2087 // use the name of the generated test binary (`fileToCopy`) instead of the name
2088 // of the original test module (`depName`, shared by all `test_per_src`
2089 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002090 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002091 // these are not considered transitive dep
2092 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002093 filesInfo = append(filesInfo, af)
2094 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002095 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002096 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002097 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2098 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002099 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2100 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2101 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2102 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002103 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002104 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002105 }
2106 }
2107 }
2108 return false
2109 })
2110
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002111 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2112 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2113 // via the global boot image config.
2114 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002115 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002116 dirInApex := filepath.Join("javalib", arch.String())
2117 for _, f := range files {
2118 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002119 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002120 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002121 }
2122 }
2123 }
2124
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002125 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002126 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2127 return
2128 }
2129
Jiyong Park8fd61922018-11-08 02:50:25 +09002130 // remove duplicates in filesInfo
2131 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002132 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002133 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002134 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002135 if e, ok := encountered[dest]; !ok {
2136 encountered[dest] = f
2137 } else {
2138 // If a module is directly included and also transitively depended on
2139 // consider it as directly included.
2140 e.transitiveDep = e.transitiveDep && f.transitiveDep
2141 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002142 }
2143 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002144 var result []apexFile
2145 for _, v := range encountered {
2146 result = append(result, v)
2147 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002148 return result
2149 }
2150 filesInfo = removeDup(filesInfo)
2151
2152 // to have consistent build rules
2153 sort.Slice(filesInfo, func(i, j int) bool {
2154 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2155 })
2156
Jiyong Park8fd61922018-11-08 02:50:25 +09002157 a.installDir = android.PathForModuleInstall(ctx, "apex")
2158 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002159
Jooyung Han54aca7b2019-11-20 02:26:02 +09002160 if a.properties.ApexType != zipApex {
2161 if a.properties.File_contexts == nil {
2162 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2163 } else {
2164 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2165 if a.Platform() {
2166 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2167 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2168 }
2169 }
2170 }
2171 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2172 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2173 return
2174 }
2175 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002176 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2177 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2178 // the same library in the system partition, thus effectively sharing the same libraries
2179 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2180 // in the APEX.
2181 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2182 a.installable() &&
2183 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002184
Jiyong Park9d677202020-02-19 16:29:35 +09002185 // We don't need the optimization for updatable APEXes, as it might give false signal
2186 // to the system health when the APEXes are still bundled (b/149805758)
2187 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2188 a.linkToSystemLib = false
2189 }
2190
Jiyong Park638d30e2020-02-26 18:27:19 +09002191 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2192 if ctx.Host() {
2193 a.linkToSystemLib = false
2194 }
2195
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002196 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002197 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2198
2199 a.setCertificateAndPrivateKey(ctx)
2200 if a.properties.ApexType == flattenedApex {
2201 a.buildFlattenedApex(ctx)
2202 } else {
2203 a.buildUnflattenedApex(ctx)
2204 }
2205
Jooyung Han002ab682020-01-08 01:57:58 +09002206 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002207
2208 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002209}
2210
Artur Satayev8cf899a2020-04-15 17:29:42 +01002211// Enforce that Java deps of the apex are using stable SDKs to compile
2212func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2213 // Visit direct deps only. As long as we guarantee top-level deps are using
2214 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2215 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2216 tag := ctx.OtherModuleDependencyTag(module)
2217 switch tag {
2218 case javaLibTag, androidAppTag:
2219 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2220 if err := m.CheckStableSdkVersion(); err != nil {
2221 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2222 }
2223 }
2224 }
2225 })
2226}
2227
Jooyung Han5e9013b2020-03-10 06:23:13 +09002228func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002229 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002230 moduleName = normalizeModuleName(moduleName)
2231
2232 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2233 return true
2234 }
2235
2236 key = android.AvailableToAnyApex
2237 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2238 return true
2239 }
2240
2241 return false
2242}
2243
2244func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002245 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2246 // system. Trim the prefix for the check since they are confusing
2247 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2248 if strings.HasPrefix(moduleName, "libclang_rt.") {
2249 // This module has many arch variants that depend on the product being built.
2250 // We don't want to list them all
2251 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002252 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002253 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002254}
2255
Jooyung Han344d5432019-08-23 11:17:39 +09002256func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002257 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002258 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002259 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002260 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002261 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002262 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2263 })
Alex Light5098a612018-11-29 17:12:15 -08002264 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002265 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002266 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002267 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002268 return module
2269}
Jiyong Park30ca9372019-02-07 16:27:23 +09002270
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002271func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002272 bundle := newApexBundle()
2273 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002274 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002275 return bundle
2276}
2277
Jiyong Parkfce0b422020-02-11 03:56:06 +09002278// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2279// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002280func testApexBundleFactory() android.Module {
2281 bundle := newApexBundle()
2282 bundle.testApex = true
2283 return bundle
2284}
2285
Jiyong Parkfce0b422020-02-11 03:56:06 +09002286// apex packages other modules into an APEX file which is a packaging format for system-level
2287// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002288func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002289 return newApexBundle()
2290}
2291
Jiyong Park30ca9372019-02-07 16:27:23 +09002292//
2293// Defaults
2294//
2295type Defaults struct {
2296 android.ModuleBase
2297 android.DefaultsModuleBase
2298}
2299
Jiyong Park30ca9372019-02-07 16:27:23 +09002300func defaultsFactory() android.Module {
2301 return DefaultsFactory()
2302}
2303
2304func DefaultsFactory(props ...interface{}) android.Module {
2305 module := &Defaults{}
2306
2307 module.AddProperties(props...)
2308 module.AddProperties(
2309 &apexBundleProperties{},
2310 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002311 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002312 )
2313
2314 android.InitDefaultsModule(module)
2315 return module
2316}
Jiyong Park5d790c32019-11-15 18:40:32 +09002317
2318//
2319// OverrideApex
2320//
2321type OverrideApex struct {
2322 android.ModuleBase
2323 android.OverrideModuleBase
2324}
2325
2326func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2327 // All the overrides happen in the base module.
2328}
2329
2330// override_apex is used to create an apex module based on another apex module
2331// by overriding some of its properties.
2332func overrideApexFactory() android.Module {
2333 m := &OverrideApex{}
2334 m.AddProperties(&overridableProperties{})
2335
2336 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2337 android.InitOverrideModule(m)
2338 return m
2339}