blob: 7b4f8ff8e1371d1fe576fd9653a0a3306f7b6713 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinc5192442020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090065 rroTag = dependencyTag{name: "rro", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000066 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000067
68 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069)
70
Paul Duffin7d74e7b2020-03-06 12:30:13 +000071// Transform the map of apex -> modules to module -> apexes.
72func invertApexWhiteList(m map[string][]string) map[string][]string {
73 r := make(map[string][]string)
74 for apex, modules := range m {
75 for _, module := range modules {
76 r[module] = append(r[module], apex)
77 }
78 }
79 return r
80}
81
82// Retrieve the while list of apexes to which the supplied module belongs.
83func WhitelistedApexAvailable(moduleName string) []string {
84 return inverseApexAvailWl[normalizeModuleName(moduleName)]
85}
86
Anton Hanssoneec79eb2020-01-10 15:12:39 +000087// This is a map from apex to modules, which overrides the
88// apex_available setting for that particular module to make
89// it available for the apex regardless of its setting.
90// TODO(b/147364041): remove this
91func makeApexAvailableWhitelist() map[string][]string {
92 // The "Module separator"s below are employed to minimize merge conflicts.
93 m := make(map[string][]string)
94 //
95 // Module separator
96 //
Paul Duffin50cbefd2020-03-10 13:44:19 +000097 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "art_cmdlineparser_headers",
99 "art_disassembler_headers",
100 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900101 "bionic_libc_platform_headers",
102 "core-repackaged-icu4j",
103 "cpp-define-generator-asm-support",
104 "cpp-define-generator-definitions",
105 "crtbegin_dynamic",
106 "crtbegin_dynamic1",
107 "crtbegin_so1",
108 "crtbrand",
Jiyong Park0f80c182020-01-31 02:49:53 +0900109 "dex2oat_headers",
110 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900112 "javavm_headers",
113 "jni_platform_headers",
114 "libPlatformProperties",
115 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000116 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900117 "libandroidicuinit",
118 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000119 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900120 "libdexfile_all_headers",
121 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000122 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900123 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000124 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900125 "libfdlibm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900126 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000127 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900128 "libicuuc_headers",
129 "libicuuc_stubdata",
130 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900131 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000132 "liblzma",
133 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900134 "libnativebridge-headers",
135 "libnativehelper_header_only",
136 "libnativeloader-headers",
137 "libnpt_headers",
138 "libopenjdkjvmti_headers",
139 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000140 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900141 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000142 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900143 "libv8",
144 "libv8base",
145 "libv8gen",
146 "libv8platform",
147 "libv8sampler",
148 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000149 "libvixl",
150 "libvixld",
151 "libz",
152 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900153 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000154 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000155 m["com.android.art.debug"] = artApexContents
156 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000157 //
158 // Module separator
159 //
160 m["com.android.bluetooth.updatable"] = []string{
161 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000162 "android.hardware.bluetooth.a2dp@1.0",
163 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "android.hardware.bluetooth@1.0",
165 "android.hardware.bluetooth@1.1",
166 "android.hardware.graphics.bufferqueue@1.0",
167 "android.hardware.graphics.bufferqueue@2.0",
168 "android.hardware.graphics.common@1.0",
169 "android.hardware.graphics.common@1.1",
170 "android.hardware.graphics.common@1.2",
171 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000172 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900173 "android.hidl.token@1.0",
174 "android.hidl.token@1.0-utils",
175 "avrcp-target-service",
176 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900177 "bluetooth-protos-lite",
178 "bluetooth.mapsapi",
179 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900180 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900181 "ipmemorystore-aidl-interfaces-V5-java",
182 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900183 "internal_include_headers",
184 "lib-bt-packets",
185 "lib-bt-packets-avrcp",
186 "lib-bt-packets-base",
187 "libFraunhoferAAC",
188 "libaudio-a2dp-hw-utils",
189 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900190 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000191 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900192 "libbluetooth-types",
193 "libbluetooth-types-header",
194 "libbluetooth_gd",
195 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000196 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900197 "libbt-audio-hal-interface",
198 "libbt-bta",
199 "libbt-common",
200 "libbt-hci",
201 "libbt-platform-protos-lite",
202 "libbt-protos-lite",
203 "libbt-sbc-decoder",
204 "libbt-sbc-encoder",
205 "libbt-stack",
206 "libbt-utils",
207 "libbtcore",
208 "libbtdevice",
209 "libbte",
210 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000211 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000212 "libevent",
213 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900214 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900215 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900216 "libmedia_headers",
217 "libmodpb64",
218 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900219 "libstagefright_foundation_headers",
220 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000221 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900222 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000223 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900224 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000225 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900226 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900227 "net-utils-services-common",
228 "netd_aidl_interface-unstable-java",
229 "netd_event_listener_interface-java",
230 "netlink-client",
231 "networkstack-aidl-interfaces-unstable-java",
232 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900233 "sap-api-java-static",
234 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000235 }
236 //
237 // Module separator
238 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900239 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000240 //
241 // Module separator
242 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900244 "libnativehelper_header_only",
Jiyong Park0f80c182020-01-31 02:49:53 +0900245 }
246 //
247 // Module separator
248 //
249 m["com.android.extservices"] = []string{
250 "flatbuffer_headers",
251 "liblua",
252 "libtextclassifier",
253 "libtextclassifier_hash_static",
254 "libtflite_static",
255 "libutf",
256 "libz_current",
257 "tensorflow_headers",
258 }
259 //
260 // Module separator
261 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900262 m["com.android.neuralnetworks"] = []string{
263 "android.hardware.neuralnetworks@1.0",
264 "android.hardware.neuralnetworks@1.1",
265 "android.hardware.neuralnetworks@1.2",
266 "android.hardware.neuralnetworks@1.3",
267 "android.hidl.allocator@1.0",
268 "android.hidl.memory.token@1.0",
269 "android.hidl.memory@1.0",
270 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900272 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900273 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900274 "libprocpartition",
275 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900276 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000277 //
278 // Module separator
279 //
280 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000281 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900282 "android.hardware.cas.native@1.0",
283 "android.hardware.cas@1.0",
284 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000285 "android.hardware.configstore@1.0",
286 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000287 "android.hardware.graphics.allocator@2.0",
288 "android.hardware.graphics.allocator@3.0",
289 "android.hardware.graphics.bufferqueue@1.0",
290 "android.hardware.graphics.bufferqueue@2.0",
291 "android.hardware.graphics.common@1.0",
292 "android.hardware.graphics.common@1.1",
293 "android.hardware.graphics.common@1.2",
294 "android.hardware.graphics.mapper@2.0",
295 "android.hardware.graphics.mapper@2.1",
296 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900297 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000298 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900299 "android.hidl.allocator@1.0",
300 "android.hidl.memory.token@1.0",
301 "android.hidl.memory@1.0",
302 "android.hidl.token@1.0",
303 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900304 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900305 "gl_headers",
306 "libEGL",
307 "libEGL_blobCache",
308 "libEGL_getProcAddress",
309 "libFLAC",
310 "libFLAC-config",
311 "libFLAC-headers",
312 "libGLESv2",
313 "libaacextractor",
314 "libamrextractor",
315 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900316 "libaudio_system_headers",
317 "libaudioclient",
318 "libaudioclient_headers",
319 "libaudiofoundation",
320 "libaudiofoundation_headers",
321 "libaudiomanager",
322 "libaudiopolicy",
323 "libaudioutils",
324 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900325 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900326 "libbluetooth-types-header",
327 "libbufferhub",
328 "libbufferhub_headers",
329 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900330 "libc_malloc_debug_backtrace",
331 "libcamera_client",
332 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900333 "libdexfile_external_headers",
334 "libdexfile_support",
335 "libdvr_headers",
336 "libexpat",
337 "libfifo",
338 "libflacextractor",
339 "libgrallocusage",
340 "libgraphicsenv",
341 "libgui",
342 "libgui_headers",
343 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900344 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900345 "liblzma",
346 "libmath",
347 "libmedia",
348 "libmedia_codeclist",
349 "libmedia_headers",
350 "libmedia_helper",
351 "libmedia_helper_headers",
352 "libmedia_midiiowrapper",
353 "libmedia_omx",
354 "libmediautils",
355 "libmidiextractor",
356 "libmkvextractor",
357 "libmp3extractor",
358 "libmp4extractor",
359 "libmpeg2extractor",
360 "libnativebase_headers",
361 "libnativebridge-headers",
362 "libnativebridge_lazy",
363 "libnativeloader-headers",
364 "libnativeloader_lazy",
365 "libnativewindow_headers",
366 "libnblog",
367 "liboggextractor",
368 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900369 "libpdx",
370 "libpdx_default_transport",
371 "libpdx_headers",
372 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900373 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900374 "libsonivox",
375 "libspeexresampler",
376 "libspeexresampler",
377 "libstagefright_esds",
378 "libstagefright_flacdec",
379 "libstagefright_flacdec",
380 "libstagefright_foundation",
381 "libstagefright_foundation_headers",
382 "libstagefright_foundation_without_imemory",
383 "libstagefright_headers",
384 "libstagefright_id3",
385 "libstagefright_metadatautils",
386 "libstagefright_mpeg2extractor",
387 "libstagefright_mpeg2support",
388 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900389 "libui",
390 "libui_headers",
391 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900392 "libvibrator",
393 "libvorbisidec",
394 "libwavextractor",
395 "libwebm",
396 "media_ndk_headers",
397 "media_plugin_headers",
398 "updatable-media",
399 }
400 //
401 // Module separator
402 //
403 m["com.android.media.swcodec"] = []string{
404 "android.frameworks.bufferhub@1.0",
405 "android.hardware.common-ndk_platform",
406 "android.hardware.configstore-utils",
407 "android.hardware.configstore@1.0",
408 "android.hardware.configstore@1.1",
409 "android.hardware.graphics.allocator@2.0",
410 "android.hardware.graphics.allocator@3.0",
411 "android.hardware.graphics.bufferqueue@1.0",
412 "android.hardware.graphics.bufferqueue@2.0",
413 "android.hardware.graphics.common-ndk_platform",
414 "android.hardware.graphics.common@1.0",
415 "android.hardware.graphics.common@1.1",
416 "android.hardware.graphics.common@1.2",
417 "android.hardware.graphics.mapper@2.0",
418 "android.hardware.graphics.mapper@2.1",
419 "android.hardware.graphics.mapper@3.0",
420 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000421 "android.hardware.media.bufferpool@2.0",
422 "android.hardware.media.c2@1.0",
423 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900424 "android.hardware.media@1.0",
425 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000426 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900427 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000428 "android.hidl.safe_union@1.0",
429 "android.hidl.token@1.0",
430 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900431 "libEGL",
432 "libFLAC",
433 "libFLAC-config",
434 "libFLAC-headers",
435 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900436 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900437 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900438 "libaudio_system_headers",
439 "libaudioutils",
440 "libaudioutils",
441 "libaudioutils_fixedfft",
442 "libavcdec",
443 "libavcenc",
444 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000445 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900446 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900447 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900448 "libbluetooth-types-header",
449 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900450 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000451 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900452 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000453 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900454 "libcodec2_hidl@1.1",
455 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000456 "libcodec2_soft_aacdec",
457 "libcodec2_soft_aacenc",
458 "libcodec2_soft_amrnbdec",
459 "libcodec2_soft_amrnbenc",
460 "libcodec2_soft_amrwbdec",
461 "libcodec2_soft_amrwbenc",
462 "libcodec2_soft_av1dec_gav1",
463 "libcodec2_soft_avcdec",
464 "libcodec2_soft_avcenc",
465 "libcodec2_soft_common",
466 "libcodec2_soft_flacdec",
467 "libcodec2_soft_flacenc",
468 "libcodec2_soft_g711alawdec",
469 "libcodec2_soft_g711mlawdec",
470 "libcodec2_soft_gsmdec",
471 "libcodec2_soft_h263dec",
472 "libcodec2_soft_h263enc",
473 "libcodec2_soft_hevcdec",
474 "libcodec2_soft_hevcenc",
475 "libcodec2_soft_mp3dec",
476 "libcodec2_soft_mpeg2dec",
477 "libcodec2_soft_mpeg4dec",
478 "libcodec2_soft_mpeg4enc",
479 "libcodec2_soft_opusdec",
480 "libcodec2_soft_opusenc",
481 "libcodec2_soft_rawdec",
482 "libcodec2_soft_vorbisdec",
483 "libcodec2_soft_vp8dec",
484 "libcodec2_soft_vp8enc",
485 "libcodec2_soft_vp9dec",
486 "libcodec2_soft_vp9enc",
487 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000488 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900489 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000490 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900491 "libfmq",
492 "libgav1",
493 "libgralloctypes",
494 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000495 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900496 "libgsm",
497 "libgui_bufferqueue_static",
498 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000499 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900500 "libhardware_headers",
501 "libhevcdec",
502 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000503 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900504 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000505 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900506 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000507 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900508 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900509 "libmpeg2dec",
510 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000511 "libnativebridge_lazy",
512 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900513 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900514 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000515 "libscudo_wrapper",
516 "libsfplugin_ccodec_utils",
517 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900518 "libstagefright_amrnbdec",
519 "libstagefright_amrnbenc",
520 "libstagefright_amrwbdec",
521 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000522 "libstagefright_bufferpool@2.0.1",
523 "libstagefright_bufferqueue_helper",
524 "libstagefright_enc_common",
525 "libstagefright_flacdec",
526 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900527 "libstagefright_foundation_headers",
528 "libstagefright_headers",
529 "libstagefright_m4vh263dec",
530 "libstagefright_m4vh263enc",
531 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000532 "libsync",
533 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900534 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000535 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000536 "libvorbisidec",
537 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900538 "libyuv",
539 "libyuv_static",
540 "media_ndk_headers",
541 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000542 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900543 }
544 //
545 // Module separator
546 //
547 m["com.android.mediaprovider"] = []string{
548 "MediaProvider",
549 "MediaProviderGoogle",
550 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900551 "libbase_ndk",
552 "libfuse",
553 "libfuse_jni",
554 "libnativehelper_header_only",
555 }
556 //
557 // Module separator
558 //
559 m["com.android.permission"] = []string{
560 "androidx.annotation_annotation",
561 "androidx.annotation_annotation-nodeps",
562 "androidx.lifecycle_lifecycle-common",
563 "androidx.lifecycle_lifecycle-common-java8",
564 "androidx.lifecycle_lifecycle-common-java8-nodeps",
565 "androidx.lifecycle_lifecycle-common-nodeps",
566 "kotlin-annotations",
567 "kotlin-stdlib",
568 "kotlin-stdlib-jdk7",
569 "kotlin-stdlib-jdk8",
570 "kotlinx-coroutines-android",
571 "kotlinx-coroutines-android-nodeps",
572 "kotlinx-coroutines-core",
573 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900574 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000575 }
576 //
577 // Module separator
578 //
579 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900582 "libc_aeabi",
583 "libc_bionic",
584 "libc_bionic_ndk",
585 "libc_bootstrap",
586 "libc_common",
587 "libc_common_shared",
588 "libc_common_static",
589 "libc_dns",
590 "libc_dynamic_dispatch",
591 "libc_fortify",
592 "libc_freebsd",
593 "libc_freebsd_large_stack",
594 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900595 "libc_init_dynamic",
596 "libc_init_static",
597 "libc_jemalloc_wrapper",
598 "libc_netbsd",
599 "libc_nomalloc",
600 "libc_nopthread",
601 "libc_openbsd",
602 "libc_openbsd_large_stack",
603 "libc_openbsd_ndk",
604 "libc_pthread",
605 "libc_static_dispatch",
606 "libc_syscalls",
607 "libc_tzcode",
608 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900609 "libdebuggerd",
610 "libdebuggerd_common_headers",
611 "libdebuggerd_handler_core",
612 "libdebuggerd_handler_fallback",
613 "libdexfile_external_headers",
614 "libdexfile_support",
615 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900616 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900617 "libjemalloc5",
618 "liblinker_main",
619 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900620 "liblz4",
621 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900622 "libprocinfo",
623 "libpropertyinfoparser",
624 "libscudo",
625 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900626 "libsystemproperties",
627 "libtombstoned_client_static",
628 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900629 "libz",
630 "libziparchive",
631 }
632 //
633 // Module separator
634 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900635 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900636 "libnativehelper_compat_libc++",
637 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900638 "libcgrouprc",
639 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900640 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900641 "libvndksupport",
642 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000643 }
644 //
645 // Module separator
646 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 m["com.android.wifi"] = []string{
648 "PlatformProperties",
649 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900650 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900651 "android.hardware.wifi-V1.1-java",
652 "android.hardware.wifi-V1.2-java",
653 "android.hardware.wifi-V1.3-java",
654 "android.hardware.wifi-V1.4-java",
655 "android.hardware.wifi.hostapd-V1.0-java",
656 "android.hardware.wifi.hostapd-V1.1-java",
657 "android.hardware.wifi.hostapd-V1.2-java",
658 "android.hardware.wifi.supplicant-V1.0-java",
659 "android.hardware.wifi.supplicant-V1.1-java",
660 "android.hardware.wifi.supplicant-V1.2-java",
661 "android.hardware.wifi.supplicant-V1.3-java",
662 "android.hidl.base-V1.0-java",
663 "android.hidl.manager-V1.0-java",
664 "android.hidl.manager-V1.1-java",
665 "android.hidl.manager-V1.2-java",
666 "androidx.annotation_annotation",
667 "androidx.annotation_annotation-nodeps",
668 "bouncycastle-unbundled",
669 "dnsresolver_aidl_interface-V2-java",
670 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900671 "framework-wifi-pre-jarjar",
672 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900673 "ipmemorystore-aidl-interfaces-V3-java",
674 "ipmemorystore-aidl-interfaces-java",
675 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900676 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900677 "libwifi-jni",
678 "net-utils-services-common",
679 "netd_aidl_interface-V2-java",
680 "netd_aidl_interface-unstable-java",
681 "netd_event_listener_interface-java",
682 "netlink-client",
683 "networkstack-aidl-interfaces-unstable-java",
684 "networkstack-client",
685 "services.net",
686 "wifi-lite-protos",
687 "wifi-nano-protos",
688 "wifi-service-pre-jarjar",
689 "wifi-service-resources",
690 "prebuilt_androidx.annotation_annotation-nodeps",
691 }
692 //
693 // Module separator
694 //
695 m["com.android.sdkext"] = []string{
696 "fmtlib_ndk",
697 "libbase_ndk",
698 "libprotobuf-cpp-lite-ndk",
699 }
700 //
701 // Module separator
702 //
703 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900704 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900705 }
706 //
707 // Module separator
708 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000709 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900710 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900711 "libclang_rt",
712 "libgcc_stripped",
713 "libprofile-clang-extras",
714 "libprofile-clang-extras_ndk",
715 "libprofile-extras",
716 "libprofile-extras_ndk",
717 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900718 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000719 return m
720}
721
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900722func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900723 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800724 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900725 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900726 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700727 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900728 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900729
Jooyung Han31c470b2019-10-18 16:26:59 +0900730 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900731 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900732
733 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
734 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
735 sort.Strings(*apexFileContextsInfos)
736 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
737 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900738}
739
Jooyung Han31c470b2019-10-18 16:26:59 +0900740func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
741 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
742 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
743}
744
Jiyong Parkd1063c12019-07-17 20:08:41 +0900745func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900746 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900747 ctx.BottomUp("apex", apexMutator).Parallel()
748 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
749 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900750 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900751}
752
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900753// Mark the direct and transitive dependencies of apex bundles so that they
754// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900755func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900756 if !mctx.Module().Enabled() {
757 return
758 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800759 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900760 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000761 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900762 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900763 ApexName: mctx.ModuleName(),
764 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100765 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900766 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900767 directDep = true
768 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800769 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900770 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900771 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900772
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800773 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900774 return
775 }
776
Paul Duffin923e8a52020-03-30 15:33:32 +0100777 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900778
Jiyong Parkf760cae2020-02-12 07:53:12 +0900779 mctx.VisitDirectDeps(func(child android.Module) {
780 depName := mctx.OtherModuleName(child)
781 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100782 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800783 android.UpdateApexDependency(apexBundles, depName, directDep)
784 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900785 }
786 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900787}
788
Jiyong Park89e850a2020-04-07 16:37:39 +0900789// mark if a module cannot be available to platform. A module cannot be available
790// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
791// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
792func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
793 // Host and recovery are not considered as platform
794 if mctx.Host() || mctx.Module().InstallInRecovery() {
795 return
796 }
797
798 if am, ok := mctx.Module().(android.ApexModule); ok {
799 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
800
801 // In a rare case when a lib is marked as available only to an apex
802 // but the apex doesn't exist. This can happen in a partial manifest branch
803 // like master-art. Currently, libstatssocket in the stats APEX is causing
804 // this problem.
805 // Include the lib in platform because the module SDK that ought to provide
806 // it doesn't exist, so it would otherwise be left out completely.
807 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
808 // this check for libraries provided by SDKs.
809 if !availableToPlatform && !android.InAnyApex(am.Name()) {
810 availableToPlatform = true
811 }
812
813 // If any of the dep is not available to platform, this module is also considered
814 // as being not available to platform even if it has "//apex_available:platform"
815 mctx.VisitDirectDeps(func(child android.Module) {
816 if !am.DepIsInSameApex(mctx, child) {
817 // if the dependency crosses apex boundary, don't consider it
818 return
819 }
820 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
821 availableToPlatform = false
822 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
823 }
824 })
825
826 // Exception 1: stub libraries and native bridge libraries are always available to platform
827 if cc, ok := mctx.Module().(*cc.Module); ok &&
828 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
829 availableToPlatform = true
830 }
831
832 // Exception 2: bootstrap bionic libraries are also always available to platform
833 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
834 availableToPlatform = true
835 }
836
837 if !availableToPlatform {
838 am.SetNotAvailableForPlatform()
839 }
840 }
841}
842
Paul Duffin65347702020-03-31 15:23:40 +0100843// If a module in an APEX depends on a module from an SDK then it needs an APEX
844// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
845func inAnySdk(module android.Module) bool {
846 if sa, ok := module.(android.SdkAware); ok {
847 return sa.IsInAnySdk()
848 }
849
850 return false
851}
852
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900853// Create apex variations if a module is included in APEX(s).
854func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900855 if !mctx.Module().Enabled() {
856 return
857 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900858 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900859 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000860 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900861 // apex bundle itself is mutated so that it and its modules have same
862 // apex variant.
863 apexBundleName := mctx.ModuleName()
864 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900865 } else if o, ok := mctx.Module().(*OverrideApex); ok {
866 apexBundleName := o.GetOverriddenModuleName()
867 if apexBundleName == "" {
868 mctx.ModuleErrorf("base property is not set")
869 return
870 }
871 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900872 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900873
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900874}
Sundong Ahne9b55722019-09-06 17:37:42 +0900875
Jooyung Han7a78a922019-10-08 21:59:58 +0900876var (
877 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
878 apexFileContextsInfosMutex sync.Mutex
879)
880
881func apexFileContextsInfos(config android.Config) *[]string {
882 return config.Once(apexFileContextsInfosKey, func() interface{} {
883 return &[]string{}
884 }).(*[]string)
885}
886
Jooyung Han54aca7b2019-11-20 02:26:02 +0900887func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900888 apexFileContextsInfosMutex.Lock()
889 defer apexFileContextsInfosMutex.Unlock()
890 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900891 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900892}
893
Sundong Ahne9b55722019-09-06 17:37:42 +0900894func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900895 if !mctx.Module().Enabled() {
896 return
897 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900898 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900899 var variants []string
900 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
901 case "image":
902 variants = append(variants, imageApexType, flattenedApexType)
903 case "zip":
904 variants = append(variants, zipApexType)
905 case "both":
906 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
907 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900908 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900909 return
910 }
911
912 modules := mctx.CreateLocalVariations(variants...)
913
914 for i, v := range variants {
915 switch v {
916 case imageApexType:
917 modules[i].(*apexBundle).properties.ApexType = imageApex
918 case zipApexType:
919 modules[i].(*apexBundle).properties.ApexType = zipApex
920 case flattenedApexType:
921 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900922 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900923 modules[i].(*apexBundle).MakeAsSystemExt()
924 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900925 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900926 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900927 } else if _, ok := mctx.Module().(*OverrideApex); ok {
928 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900929 }
930}
931
Jooyung Han5c998b92019-06-27 11:30:33 +0900932func apexUsesMutator(mctx android.BottomUpMutatorContext) {
933 if ab, ok := mctx.Module().(*apexBundle); ok {
934 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
935 }
936}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900937
Jooyung Handc782442019-11-01 03:14:38 +0900938var (
939 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
940)
941
942// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
943// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
944// which may cause compatibility issues. (e.g. libbinder)
945// Even though libbinder restricts its availability via 'apex_available' property and relies on
946// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
947// to avoid similar problems.
948func useVendorWhitelist(config android.Config) []string {
949 return config.Once(useVendorWhitelistKey, func() interface{} {
950 return []string{
951 // swcodec uses "vendor" variants for smaller size
952 "com.android.media.swcodec",
953 "test_com.android.media.swcodec",
954 }
955 }).([]string)
956}
957
958// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
959// called before the first call to useVendorWhitelist()
960func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
961 config.Once(useVendorWhitelistKey, func() interface{} {
962 return whitelist
963 })
964}
965
Jooyung Han01a868d2020-02-27 13:40:44 +0900966type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800967 // List of native libraries
968 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900969
Jooyung Han643adc42020-02-27 13:50:06 +0900970 // List of JNI libraries
971 Jni_libs []string
972
Alex Light9670d332019-01-29 18:07:33 -0800973 // List of native executables
974 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900975
Roland Levillain630846d2019-06-26 12:48:34 +0100976 // List of native tests
977 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800978}
Jooyung Han344d5432019-08-23 11:17:39 +0900979
Alex Light9670d332019-01-29 18:07:33 -0800980type apexMultilibProperties struct {
981 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900982 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800983
984 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900985 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800986
987 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900988 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800989
990 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900991 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800992
993 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900994 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800995}
996
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900997type apexBundleProperties struct {
998 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000999 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001000 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001001
Jiyong Park40e26a22019-02-08 02:53:06 +09001002 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1003 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001004 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001005
Roland Levillain411c5842019-09-19 16:37:20 +01001006 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1007 // device (/apex/<apex_name>).
1008 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001009 Apex_name *string
1010
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001011 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001012 // For platform APEXes, this should points to a file under /system/sepolicy
1013 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1014 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001015
Jooyung Han01a868d2020-02-27 13:40:44 +09001016 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001017
1018 // List of java libraries that are embedded inside this APEX bundle
1019 Java_libs []string
1020
1021 // List of prebuilt files that are embedded inside this APEX bundle
1022 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001023
1024 // Name of the apex_key module that provides the private key to sign APEX
1025 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001026
Alex Light5098a612018-11-29 17:12:15 -08001027 // The type of APEX to build. Controls what the APEX payload is. Either
1028 // 'image', 'zip' or 'both'. Default: 'image'.
1029 Payload_type *string
1030
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001031 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1032 // or an android_app_certificate module name in the form ":module".
1033 Certificate *string
1034
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001035 // Whether this APEX is installable to one of the partitions. Default: true.
1036 Installable *bool
1037
Jiyong Parkda6eb592018-12-19 17:12:36 +09001038 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1039 // Default is false.
1040 Use_vendor *bool
1041
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001042 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1043 Ignore_system_library_special_case *bool
1044
Alex Light9670d332019-01-29 18:07:33 -08001045 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001046
Jiyong Parkf97782b2019-02-13 20:28:58 +09001047 // List of sanitizer names that this APEX is enabled for
1048 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001049
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001050 PreventInstall bool `blueprint:"mutated"`
1051
1052 HideFromMake bool `blueprint:"mutated"`
1053
Jooyung Han5c998b92019-06-27 11:30:33 +09001054 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1055 Provide_cpp_shared_libs *bool
1056
1057 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1058 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001059
1060 // A txt file containing list of files that are whitelisted to be included in this APEX.
1061 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001062
Sundong Ahnabb64432019-10-22 13:58:29 +09001063 // package format of this apex variant; could be non-flattened, flattened, or zip.
1064 // imageApex, zipApex or flattened
1065 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001066
Jiyong Parkd1063c12019-07-17 20:08:41 +09001067 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1068 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1069 // is implied. This value affects all modules included in this APEX. In other words, they are
1070 // also built with the SDKs specified here.
1071 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001072
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001073 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1074 // Should be only used in tests#.
1075 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001076
Dario Frenica913392020-04-27 18:21:11 +01001077 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1078 // Should be only used in tests#.
1079 Test_only_unsigned_payload *bool
1080
Jiyong Park956305c2020-01-09 12:32:06 +09001081 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001082
1083 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001084 // rules for making sure that the APEX is truly updatable.
1085 // - To be updatable, min_sdk_version should be set as well
1086 // This will also disable the size optimizations like symlinking to the system libs.
1087 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001088 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001089
1090 // The minimum SDK version that this apex must be compatibile with.
1091 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001092}
1093
1094type apexTargetBundleProperties struct {
1095 Target struct {
1096 // Multilib properties only for android.
1097 Android struct {
1098 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001099 }
Jooyung Han344d5432019-08-23 11:17:39 +09001100
Alex Light9670d332019-01-29 18:07:33 -08001101 // Multilib properties only for host.
1102 Host struct {
1103 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001104 }
Jooyung Han344d5432019-08-23 11:17:39 +09001105
Alex Light9670d332019-01-29 18:07:33 -08001106 // Multilib properties only for host linux_bionic.
1107 Linux_bionic struct {
1108 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001109 }
Jooyung Han344d5432019-08-23 11:17:39 +09001110
Alex Light9670d332019-01-29 18:07:33 -08001111 // Multilib properties only for host linux_glibc.
1112 Linux_glibc struct {
1113 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001114 }
1115 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001116}
1117
Jiyong Park5d790c32019-11-15 18:40:32 +09001118type overridableProperties struct {
1119 // List of APKs to package inside APEX
1120 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001121
Jiyong Park69aeba92020-04-24 21:16:36 +09001122 // List of runtime resource overlays (RROs) inside APEX
1123 Rros []string
1124
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001125 // Names of modules to be overridden. Listed modules can only be other binaries
1126 // (in Make or Soong).
1127 // This does not completely prevent installation of the overridden binaries, but if both
1128 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1129 // from PRODUCT_PACKAGES.
1130 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001131
1132 // Logging Parent value
1133 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001134
1135 // Apex Container Package Name.
1136 // Override value for attribute package:name in AndroidManifest.xml
1137 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001138}
1139
Alex Light5098a612018-11-29 17:12:15 -08001140type apexPackaging int
1141
1142const (
1143 imageApex apexPackaging = iota
1144 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001145 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001146)
1147
Sundong Ahnabb64432019-10-22 13:58:29 +09001148// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001149func (a apexPackaging) suffix() string {
1150 switch a {
1151 case imageApex:
1152 return imageApexSuffix
1153 case zipApex:
1154 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001155 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001156 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001157 }
1158}
1159
1160func (a apexPackaging) name() string {
1161 switch a {
1162 case imageApex:
1163 return imageApexType
1164 case zipApex:
1165 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001166 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001167 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001168 }
1169}
1170
Jiyong Parkf653b052019-11-18 15:39:01 +09001171type apexFileClass int
1172
1173const (
1174 etc apexFileClass = iota
1175 nativeSharedLib
1176 nativeExecutable
1177 shBinary
1178 pyBinary
1179 goBinary
1180 javaSharedLib
1181 nativeTest
1182 app
1183)
1184
Jiyong Park8fd61922018-11-08 02:50:25 +09001185func (class apexFileClass) NameInMake() string {
1186 switch class {
1187 case etc:
1188 return "ETC"
1189 case nativeSharedLib:
1190 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001191 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001192 return "EXECUTABLES"
1193 case javaSharedLib:
1194 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001195 case nativeTest:
1196 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001197 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001198 // b/142537672 Why isn't this APP? We want to have full control over
1199 // the paths and file names of the apk file under the flattend APEX.
1200 // If this is set to APP, then the paths and file names are modified
1201 // by the Make build system. For example, it is installed to
1202 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1203 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1204 // appends module name (which is <apexname>.<Appname> to the path.
1205 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001206 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001207 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001208 }
1209}
1210
Jiyong Parkf653b052019-11-18 15:39:01 +09001211// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001212type apexFile struct {
1213 builtFile android.Path
1214 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001215 installDir string
1216 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001217 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001218 // list of symlinks that will be created in installDir that point to this apexFile
1219 symlinks []string
1220 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001221 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001222
1223 requiredModuleNames []string
1224 targetRequiredModuleNames []string
1225 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001226
Colin Cross503c1d02020-01-28 14:00:53 -08001227 jacocoReportClassesFile android.Path // only for javalibs and apps
1228 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001229 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001230
1231 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001232}
1233
Jiyong Park1833cef2019-12-13 13:28:36 +09001234func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1235 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001236 builtFile: builtFile,
1237 moduleName: moduleName,
1238 installDir: installDir,
1239 class: class,
1240 module: module,
1241 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001242 if module != nil {
1243 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001244 ret.requiredModuleNames = module.RequiredModuleNames()
1245 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1246 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001247 }
1248 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001249}
1250
1251func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001252 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001253}
1254
Jiyong Park7cd10e32020-01-14 09:22:18 +09001255// Path() returns path of this apex file relative to the APEX root
1256func (af *apexFile) Path() string {
1257 return filepath.Join(af.installDir, af.builtFile.Base())
1258}
1259
1260// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1261func (af *apexFile) SymlinkPaths() []string {
1262 var ret []string
1263 for _, symlink := range af.symlinks {
1264 ret = append(ret, filepath.Join(af.installDir, symlink))
1265 }
1266 return ret
1267}
1268
1269func (af *apexFile) AvailableToPlatform() bool {
1270 if af.module == nil {
1271 return false
1272 }
1273 if am, ok := af.module.(android.ApexModule); ok {
1274 return am.AvailableFor(android.AvailableToPlatform)
1275 }
1276 return false
1277}
1278
Jiyong Park678c8812020-02-07 17:25:49 +09001279type depInfo struct {
1280 to string
1281 from []string
1282 isExternal bool
1283}
1284
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001285type apexBundle struct {
1286 android.ModuleBase
1287 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001288 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001289 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001290
Jiyong Park5d790c32019-11-15 18:40:32 +09001291 properties apexBundleProperties
1292 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001293 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001294
Jooyung Hanf21c7972019-12-16 22:32:06 +09001295 // specific to apex_vndk modules
1296 vndkProperties apexVndkProperties
1297
Colin Crossa4925902018-11-16 11:36:28 -08001298 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001299 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001300 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001301
Jiyong Park03b68dd2019-07-26 23:20:40 +09001302 prebuiltFileToDelete string
1303
Jiyong Park42cca6c2019-04-01 11:15:50 +09001304 public_key_file android.Path
1305 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001306
1307 container_certificate_file android.Path
1308 container_private_key_file android.Path
1309
Jooyung Han54aca7b2019-11-20 02:26:02 +09001310 fileContexts android.Path
1311
Jiyong Park8fd61922018-11-08 02:50:25 +09001312 // list of files to be included in this apex
1313 filesInfo []apexFile
1314
Jiyong Park956305c2020-01-09 12:32:06 +09001315 // list of module names that should be installed along with this APEX
1316 requiredDeps []string
1317
Jiyong Park956305c2020-01-09 12:32:06 +09001318 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001319 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001320
Sundong Ahnabb64432019-10-22 13:58:29 +09001321 testApex bool
1322 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001323 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001324 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001325
Jooyung Han214bf372019-11-12 13:03:50 +09001326 manifestJsonOut android.WritablePath
1327 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001328
Jooyung Han002ab682020-01-08 01:57:58 +09001329 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001330 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001331 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001332 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1333 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001334
1335 // Suffix of module name in Android.mk
1336 // ".flattened", ".apex", ".zipapex", or ""
1337 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001338
1339 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001340
1341 // Whether to create symlink to the system file instead of having a file
1342 // inside the apex or not
1343 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001344
1345 // Struct holding the merged notice file paths in different formats
1346 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001347}
1348
Jiyong Park397e55e2018-10-24 21:09:55 +09001349func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001350 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001351 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001352 // Use *FarVariation* to be able to depend on modules having
1353 // conflicting variations with this module. This is required since
1354 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1355 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001356 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001357 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001358 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001359 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001360 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001361
Jooyung Han643adc42020-02-27 13:50:06 +09001362 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1363 {Mutator: "image", Variation: imageVariation},
1364 {Mutator: "link", Variation: "shared"},
1365 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1366 }...), jniLibTag, nativeModules.Jni_libs...)
1367
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001368 ctx.AddFarVariationDependencies(append(target.Variations(),
1369 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001370 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001371
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001372 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001373 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001374 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001375 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001376}
1377
Alex Light9670d332019-01-29 18:07:33 -08001378func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1379 if ctx.Os().Class == android.Device {
1380 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1381 } else {
1382 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1383 if ctx.Os().Bionic() {
1384 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1385 } else {
1386 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1387 }
1388 }
1389}
1390
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001391func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001392 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1393 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1394 }
1395
Jiyong Park397e55e2018-10-24 21:09:55 +09001396 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001397 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001398
1399 a.combineProperties(ctx)
1400
Jiyong Park397e55e2018-10-24 21:09:55 +09001401 has32BitTarget := false
1402 for _, target := range targets {
1403 if target.Arch.ArchType.Multilib == "lib32" {
1404 has32BitTarget = true
1405 }
1406 }
1407 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001408 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001409 // multilib.both
1410 addDependenciesForNativeModules(ctx,
1411 ApexNativeDependencies{
1412 Native_shared_libs: a.properties.Native_shared_libs,
1413 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001414 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001415 Binaries: nil,
1416 },
1417 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001418
Jiyong Park397e55e2018-10-24 21:09:55 +09001419 // Add native modules targetting both ABIs
1420 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001421 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001422 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001423 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001424
Alex Light3d673592019-01-18 14:37:31 -08001425 isPrimaryAbi := i == 0
1426 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001427 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001428 // multilib.first
1429 addDependenciesForNativeModules(ctx,
1430 ApexNativeDependencies{
1431 Native_shared_libs: nil,
1432 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001433 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001434 Binaries: a.properties.Binaries,
1435 },
1436 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001437
1438 // Add native modules targetting the first ABI
1439 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001440 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001441 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001442 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001443 }
1444
1445 switch target.Arch.ArchType.Multilib {
1446 case "lib32":
1447 // Add native modules targetting 32-bit ABI
1448 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001449 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001450 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001451 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001452
1453 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001454 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001455 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001456 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001457 case "lib64":
1458 // Add native modules targetting 64-bit ABI
1459 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001460 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001461 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001462 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001463
1464 if !has32BitTarget {
1465 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001466 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001467 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001468 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001469 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001470
1471 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1472 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1473 if sanitizer == "hwaddress" {
1474 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001475 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001476 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001477 break
1478 }
1479 }
1480 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001481 }
1482
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001483 }
1484
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001485 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1486 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1487 // b/144532908
1488 archForPrebuiltEtc := config.Arches()[0]
1489 for _, arch := range config.Arches() {
1490 // Prefer 64-bit arch if there is any
1491 if arch.ArchType.Multilib == "lib64" {
1492 archForPrebuiltEtc = arch
1493 break
1494 }
1495 }
1496 ctx.AddFarVariationDependencies([]blueprint.Variation{
1497 {Mutator: "os", Variation: ctx.Os().String()},
1498 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1499 }, prebuiltTag, a.properties.Prebuilts...)
1500
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001501 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1502 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001503
Ulya Trafimovich44561882020-01-03 13:25:54 +00001504 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1505 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1506 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1507 javaLibTag, "jacocoagent")
1508 }
1509
Jiyong Park23c52b02019-02-02 13:13:47 +09001510 if String(a.properties.Key) == "" {
1511 ctx.ModuleErrorf("key is missing")
1512 return
1513 }
1514 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001515
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001516 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001517 if cert != "" {
1518 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001519 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001520
1521 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1522 if len(a.properties.Uses_sdks) > 0 {
1523 sdkRefs := []android.SdkRef{}
1524 for _, str := range a.properties.Uses_sdks {
1525 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1526 sdkRefs = append(sdkRefs, parsed)
1527 }
1528 a.BuildWithSdks(sdkRefs)
1529 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001530}
1531
Jiyong Park5d790c32019-11-15 18:40:32 +09001532func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1533 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1534 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001535 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1536 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001537}
1538
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001539func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1540 // direct deps of an APEX bundle are all part of the APEX bundle
1541 return true
1542}
1543
Colin Cross0ea8ba82019-06-06 14:33:29 -07001544func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001545 moduleName := ctx.ModuleName()
1546 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1547 // we check with the pseudo module name to see if its certificate is overridden.
1548 if a.vndkApex {
1549 moduleName = vndkApexName
1550 }
1551 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001552 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001553 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001554 }
1555 return String(a.properties.Certificate)
1556}
1557
Colin Cross41955e82019-05-29 14:40:35 -07001558func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1559 switch tag {
1560 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001561 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001562 default:
1563 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001564 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001565}
1566
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001567func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001568 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001569}
1570
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001571func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1572 return proptools.Bool(a.properties.Test_only_no_hashtree)
1573}
1574
Dario Frenica913392020-04-27 18:21:11 +01001575func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1576 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1577}
1578
Jiyong Park7c1dc612019-01-05 11:15:24 +09001579func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001580 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001581 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001582 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001583 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001584 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001585 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001586 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001587 }
1588}
1589
Jiyong Parkf97782b2019-02-13 20:28:58 +09001590func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1591 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1592 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1593 }
1594}
1595
Jiyong Park388ef3f2019-01-28 19:47:32 +09001596func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001597 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1598 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001599 }
1600
1601 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001602 globalSanitizerNames := []string{}
1603 if a.Host() {
1604 globalSanitizerNames = ctx.Config().SanitizeHost()
1605 } else {
1606 arches := ctx.Config().SanitizeDeviceArch()
1607 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1608 globalSanitizerNames = ctx.Config().SanitizeDevice()
1609 }
1610 }
1611 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001612}
1613
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001614func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001615 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001616}
1617
1618func (a *apexBundle) PreventInstall() {
1619 a.properties.PreventInstall = true
1620}
1621
1622func (a *apexBundle) HideFromMake() {
1623 a.properties.HideFromMake = true
1624}
1625
Jiyong Park956305c2020-01-09 12:32:06 +09001626func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1627 a.properties.IsCoverageVariant = coverage
1628}
1629
Jiyong Parkf653b052019-11-18 15:39:01 +09001630// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001631func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001632 // Decide the APEX-local directory by the multilib of the library
1633 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001634 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001635 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001636 case "lib32":
1637 dirInApex = "lib"
1638 case "lib64":
1639 dirInApex = "lib64"
1640 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001641 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001642 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001643 }
Jooyung Han35155c42020-02-06 17:33:20 +09001644 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001645 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001646 // Special case for Bionic libs and other libs installed with them. This is
1647 // to prevent those libs from being included in the search path
1648 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1649 // those libs in the Runtime APEX are available via the legacy paths in
1650 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1651 // to the legacy paths and thus will be loaded into the default linker
1652 // namespace (aka "platform" namespace). If the libs are directly in
1653 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1654 // into the runtime linker namespace, which will result in double loading of
1655 // them, which isn't supported.
1656 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001657 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001658
Jiyong Parkf653b052019-11-18 15:39:01 +09001659 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001660 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001661}
1662
Jiyong Park1833cef2019-12-13 13:28:36 +09001663func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001664 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001665 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001666 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001667 }
Jooyung Han35155c42020-02-06 17:33:20 +09001668 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001669 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001670 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001671 af.symlinks = cc.Symlinks()
1672 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001673}
1674
Jiyong Park1833cef2019-12-13 13:28:36 +09001675func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001676 dirInApex := "bin"
1677 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001678 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001679}
Jiyong Park1833cef2019-12-13 13:28:36 +09001680func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001681 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001682 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1683 if err != nil {
1684 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001685 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001686 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001687 fileToCopy := android.PathForOutput(ctx, s)
1688 // NB: Since go binaries are static we don't need the module for anything here, which is
1689 // good since the go tool is a blueprint.Module not an android.Module like we would
1690 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001691 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001692}
1693
Jiyong Park1833cef2019-12-13 13:28:36 +09001694func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001695 dirInApex := filepath.Join("bin", sh.SubDir())
1696 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001697 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001698 af.symlinks = sh.Symlinks()
1699 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001700}
1701
Jooyung Han58f26ab2019-12-18 15:34:32 +09001702// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1703type javaLibrary interface {
1704 android.Module
1705 java.Dependency
1706}
1707
1708func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001709 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001710 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001711 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1712 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1713 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001714}
1715
Jiyong Park1833cef2019-12-13 13:28:36 +09001716func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001717 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1718 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001719 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001720}
1721
atrost6e126252020-01-27 17:01:16 +00001722func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1723 dirInApex := filepath.Join("etc", config.SubDir())
1724 fileToCopy := config.CompatConfig()
1725 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1726}
1727
Jiyong Park1833cef2019-12-13 13:28:36 +09001728func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001729 android.Module
1730 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001731 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001732 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001733 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001734 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001735}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001736 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001737 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001738 appDir = "priv-app"
1739 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001740 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001741 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001742 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1743 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001744 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001745
1746 if app, ok := aapp.(interface {
1747 OverriddenManifestPackageName() string
1748 }); ok {
1749 af.overriddenPackageName = app.OverriddenManifestPackageName()
1750 }
Jiyong Park618922e2020-01-08 13:35:43 +09001751 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001752}
1753
Jiyong Park69aeba92020-04-24 21:16:36 +09001754func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1755 rroDir := "overlay"
1756 dirInApex := filepath.Join(rroDir, rro.Theme())
1757 fileToCopy := rro.OutputFile()
1758 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1759 af.certificate = rro.Certificate()
1760
1761 if a, ok := rro.(interface {
1762 OverriddenManifestPackageName() string
1763 }); ok {
1764 af.overriddenPackageName = a.OverriddenManifestPackageName()
1765 }
1766 return af
1767}
1768
Roland Levillain935639d2019-08-13 14:55:28 +01001769// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1770type flattenedApexContext struct {
1771 android.ModuleContext
1772}
1773
1774func (c *flattenedApexContext) InstallBypassMake() bool {
1775 return true
1776}
1777
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001778// Function called while walking an APEX's payload dependencies.
1779//
1780// Return true if the `to` module should be visited, false otherwise.
1781type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1782
Jiyong Park201cedd2020-02-07 17:25:49 +09001783// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001784func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001785 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001786 am, ok := child.(android.ApexModule)
1787 if !ok || !am.CanHaveApexVariants() {
1788 return false
1789 }
1790
1791 // Check for the direct dependencies that contribute to the payload
1792 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1793 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001794 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001795 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001796 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001797 return false
1798 }
1799
1800 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001801 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001802 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001803 }
1804
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001805 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001806 })
1807}
1808
Jooyung Han03b51852020-02-26 22:45:42 +09001809func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1810 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001811 intVer, err := android.ApiStrToNum(ctx, ver)
1812 if err != nil {
1813 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001814 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001815 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001816}
1817
Paul Duffinc5192442020-03-31 11:31:36 +01001818// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1819// a dependency tag.
1820var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1821
1822func PrettyPrintTag(tag blueprint.DependencyTag) string {
1823 // Use tag's custom String() method if available.
1824 if stringer, ok := tag.(fmt.Stringer); ok {
1825 return stringer.String()
1826 }
1827
1828 // Otherwise, get a default string representation of the tag's struct.
1829 tagString := fmt.Sprintf("%#v", tag)
1830
1831 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1832 tagString = tagCleaner.ReplaceAllString(tagString, "")
1833 return tagString
1834}
1835
Jiyong Park201cedd2020-02-07 17:25:49 +09001836// Ensures that the dependencies are marked as available for this APEX
1837func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1838 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1839 if ctx.Host() || a.testApex || a.vndkApex {
1840 return
1841 }
1842
Jiyong Park58d10902020-03-28 14:43:19 +09001843 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1844 // Requiring them and their transitive depencies with apex_available is not right
1845 // because they just add noise.
1846 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1847 return
1848 }
1849
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001850 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1851 if externalDep {
1852 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1853 return false
1854 }
1855
Jiyong Park201cedd2020-02-07 17:25:49 +09001856 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001857 fromName := ctx.OtherModuleName(from)
1858 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001859
1860 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1861 // do any of its dependencies.
1862 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1863 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1864 return false
1865 }
1866
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001867 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1868 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001869 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001870 message := ""
Paul Duffinc5192442020-03-31 11:31:36 +01001871 tagPath := ctx.GetTagPath()
1872 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1873 walkPath := ctx.GetWalkPath()[1:]
1874 for i, m := range walkPath {
1875 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffindf915ff2020-03-30 17:58:21 +01001876 }
1877 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001878 // Visit this module's dependencies to check and report any issues with their availability.
1879 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001880 })
1881}
1882
Jooyung Han548640b2020-04-27 12:10:30 +09001883func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
1884 if proptools.Bool(a.properties.Updatable) {
1885 if String(a.properties.Min_sdk_version) == "" {
1886 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1887 }
1888 }
1889}
1890
Jiyong Park678c8812020-02-07 17:25:49 +09001891// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1892func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1893 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001894 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001895 if from.Name() == to.Name() {
1896 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001897 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1898 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001899 }
1900
1901 if info, exists := a.depInfos[to.Name()]; exists {
1902 if !android.InList(from.Name(), info.from) {
1903 info.from = append(info.from, from.Name())
1904 }
1905 info.isExternal = info.isExternal && externalDep
1906 a.depInfos[to.Name()] = info
1907 } else {
1908 a.depInfos[to.Name()] = depInfo{
1909 to: to.Name(),
1910 from: []string{from.Name()},
1911 isExternal: externalDep,
1912 }
1913 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001914
1915 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1916 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001917 })
1918}
1919
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001920func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001921 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1922 switch a.properties.ApexType {
1923 case imageApex:
1924 if buildFlattenedAsDefault {
1925 a.suffix = imageApexSuffix
1926 } else {
1927 a.suffix = ""
1928 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001929
1930 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001931 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001932 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001933 }
1934 case zipApex:
1935 if proptools.String(a.properties.Payload_type) == "zip" {
1936 a.suffix = ""
1937 a.primaryApexType = true
1938 } else {
1939 a.suffix = zipApexSuffix
1940 }
1941 case flattenedApex:
1942 if buildFlattenedAsDefault {
1943 a.suffix = ""
1944 a.primaryApexType = true
1945 } else {
1946 a.suffix = flattenedSuffix
1947 }
Alex Light5098a612018-11-29 17:12:15 -08001948 }
1949
Roland Levillain630846d2019-06-26 12:48:34 +01001950 if len(a.properties.Tests) > 0 && !a.testApex {
1951 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1952 return
1953 }
1954
Jiyong Park0f80c182020-01-31 02:49:53 +09001955 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001956 a.checkUpdatable(ctx)
Jiyong Park0f80c182020-01-31 02:49:53 +09001957
Jiyong Park678c8812020-02-07 17:25:49 +09001958 a.collectDepsInfo(ctx)
1959
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001960 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1961
Jooyung Hane1633032019-08-01 17:41:43 +09001962 // native lib dependencies
1963 var provideNativeLibs []string
1964 var requireNativeLibs []string
1965
Jooyung Han5c998b92019-06-27 11:30:33 +09001966 // Check if "uses" requirements are met with dependent apexBundles
1967 var providedNativeSharedLibs []string
1968 useVendor := proptools.Bool(a.properties.Use_vendor)
1969 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1970 if ctx.OtherModuleDependencyTag(m) != usesTag {
1971 return
1972 }
1973 otherName := ctx.OtherModuleName(m)
1974 other, ok := m.(*apexBundle)
1975 if !ok {
1976 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1977 return
1978 }
1979 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1980 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1981 return
1982 }
1983 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1984 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1985 return
1986 }
1987 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1988 })
1989
Jiyong Parkf653b052019-11-18 15:39:01 +09001990 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001991 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001992 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001993 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001994 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1995 return false
1996 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001997 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001998 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001999 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002000 case sharedLibTag, jniLibTag:
2001 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002002 if c, ok := child.(*cc.Module); ok {
2003 // bootstrap bionic libs are treated as provided by system
2004 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2005 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002006 }
Jooyung Han643adc42020-02-27 13:50:06 +09002007 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2008 fi.isJniLib = isJniLib
2009 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002010 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002011 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002012 propertyName := "native_shared_libs"
2013 if isJniLib {
2014 propertyName = "jni_libs"
2015 }
2016 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002017 }
2018 case executableTag:
2019 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002020 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002021 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002022 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002023 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002024 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002025 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002026 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002027 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002028 } else {
Alex Light778127a2019-02-27 14:19:50 -08002029 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 +09002030 }
2031 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002032 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002033 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002034 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002035 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2036 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002037 filesInfo = append(filesInfo, af)
2038 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002039 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002040 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2041 af := apexFileForJavaLibrary(ctx, sdkLib)
2042 if !af.Ok() {
2043 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2044 return false
2045 }
2046 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002047 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002048 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002049 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002050 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002051 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002052 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002053 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002054 return true // track transitive dependencies
2055 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002056 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002057 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002058 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002059 } else {
2060 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2061 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002062 case rroTag:
2063 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2064 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2065 } else {
2066 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2067 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002068 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002069 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002070 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002071 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2072 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002073 } else {
atrost6e126252020-01-27 17:01:16 +00002074 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002075 }
Roland Levillain630846d2019-06-26 12:48:34 +01002076 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002077 if ccTest, ok := child.(*cc.Module); ok {
2078 if ccTest.IsTestPerSrcAllTestsVariation() {
2079 // Multiple-output test module (where `test_per_src: true`).
2080 //
2081 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2082 // We do not add this variation to `filesInfo`, as it has no output;
2083 // however, we do add the other variations of this module as indirect
2084 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002085 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002086 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002087 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002088 af.class = nativeTest
2089 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002090 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002091 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002092 } else {
2093 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2094 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002095 case keyTag:
2096 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002097 a.private_key_file = key.private_key_file
2098 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002099 } else {
2100 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002101 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002102 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002103 case certificateTag:
2104 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002105 a.container_certificate_file = dep.Certificate.Pem
2106 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002107 } else {
2108 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2109 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002110 case android.PrebuiltDepTag:
2111 // If the prebuilt is force disabled, remember to delete the prebuilt file
2112 // that might have been installed in the previous builds
2113 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2114 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2115 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002116 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002117 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002118 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002119 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002120 // We cannot use a switch statement on `depTag` here as the checked
2121 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002122 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002123 if cc, ok := child.(*cc.Module); ok {
2124 if android.InList(cc.Name(), providedNativeSharedLibs) {
2125 // If we're using a shared library which is provided from other APEX,
2126 // don't include it in this APEX
2127 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002128 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002129 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002130 // If the dependency is a stubs lib, don't include it in this APEX,
2131 // but make sure that the lib is installed on the device.
2132 // In case no APEX is having the lib, the lib is installed to the system
2133 // partition.
2134 //
2135 // Always include if we are a host-apex however since those won't have any
2136 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002137 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2138 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002139 }
Jooyung Hane1633032019-08-01 17:41:43 +09002140 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002141 // Don't track further
2142 return false
2143 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002144 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002145 af.transitiveDep = true
2146 filesInfo = append(filesInfo, af)
2147 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002148 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002149 } else if cc.IsTestPerSrcDepTag(depTag) {
2150 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002151 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002152 // Handle modules created as `test_per_src` variations of a single test module:
2153 // use the name of the generated test binary (`fileToCopy`) instead of the name
2154 // of the original test module (`depName`, shared by all `test_per_src`
2155 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002156 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002157 // these are not considered transitive dep
2158 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002159 filesInfo = append(filesInfo, af)
2160 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002161 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002162 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002163 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2164 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002165 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2166 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2167 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2168 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002169 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffindddd5462020-04-07 15:25:44 +01002170 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002171 }
2172 }
2173 }
2174 return false
2175 })
2176
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002177 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2178 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2179 // via the global boot image config.
2180 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002181 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002182 dirInApex := filepath.Join("javalib", arch.String())
2183 for _, f := range files {
2184 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002185 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002186 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002187 }
2188 }
2189 }
2190
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002191 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002192 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2193 return
2194 }
2195
Jiyong Park8fd61922018-11-08 02:50:25 +09002196 // remove duplicates in filesInfo
2197 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002198 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002199 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002200 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002201 if e, ok := encountered[dest]; !ok {
2202 encountered[dest] = f
2203 } else {
2204 // If a module is directly included and also transitively depended on
2205 // consider it as directly included.
2206 e.transitiveDep = e.transitiveDep && f.transitiveDep
2207 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002208 }
2209 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002210 var result []apexFile
2211 for _, v := range encountered {
2212 result = append(result, v)
2213 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002214 return result
2215 }
2216 filesInfo = removeDup(filesInfo)
2217
2218 // to have consistent build rules
2219 sort.Slice(filesInfo, func(i, j int) bool {
2220 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2221 })
2222
Jiyong Park8fd61922018-11-08 02:50:25 +09002223 a.installDir = android.PathForModuleInstall(ctx, "apex")
2224 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002225
Jooyung Han54aca7b2019-11-20 02:26:02 +09002226 if a.properties.ApexType != zipApex {
2227 if a.properties.File_contexts == nil {
2228 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2229 } else {
2230 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2231 if a.Platform() {
2232 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2233 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2234 }
2235 }
2236 }
2237 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2238 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2239 return
2240 }
2241 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002242 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2243 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2244 // the same library in the system partition, thus effectively sharing the same libraries
2245 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2246 // in the APEX.
2247 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2248 a.installable() &&
2249 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002250
Jiyong Park9d677202020-02-19 16:29:35 +09002251 // We don't need the optimization for updatable APEXes, as it might give false signal
2252 // to the system health when the APEXes are still bundled (b/149805758)
2253 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2254 a.linkToSystemLib = false
2255 }
2256
Jiyong Park638d30e2020-02-26 18:27:19 +09002257 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2258 if ctx.Host() {
2259 a.linkToSystemLib = false
2260 }
2261
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002262 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002263 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2264
2265 a.setCertificateAndPrivateKey(ctx)
2266 if a.properties.ApexType == flattenedApex {
2267 a.buildFlattenedApex(ctx)
2268 } else {
2269 a.buildUnflattenedApex(ctx)
2270 }
2271
Jooyung Han002ab682020-01-08 01:57:58 +09002272 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002273
2274 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002275}
2276
Jooyung Han5e9013b2020-03-10 06:23:13 +09002277func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002278 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002279 moduleName = normalizeModuleName(moduleName)
2280
2281 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2282 return true
2283 }
2284
2285 key = android.AvailableToAnyApex
2286 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2287 return true
2288 }
2289
2290 return false
2291}
2292
2293func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002294 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2295 // system. Trim the prefix for the check since they are confusing
2296 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2297 if strings.HasPrefix(moduleName, "libclang_rt.") {
2298 // This module has many arch variants that depend on the product being built.
2299 // We don't want to list them all
2300 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002301 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002302 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002303}
2304
Jooyung Han344d5432019-08-23 11:17:39 +09002305func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002306 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002307 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002308 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002309 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002310 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002311 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2312 })
Alex Light5098a612018-11-29 17:12:15 -08002313 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002314 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002315 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002316 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002317 return module
2318}
Jiyong Park30ca9372019-02-07 16:27:23 +09002319
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002320func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002321 bundle := newApexBundle()
2322 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002323 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002324 return bundle
2325}
2326
Jiyong Parkfce0b422020-02-11 03:56:06 +09002327// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2328// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002329func testApexBundleFactory() android.Module {
2330 bundle := newApexBundle()
2331 bundle.testApex = true
2332 return bundle
2333}
2334
Jiyong Parkfce0b422020-02-11 03:56:06 +09002335// apex packages other modules into an APEX file which is a packaging format for system-level
2336// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002337func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002338 return newApexBundle()
2339}
2340
Jiyong Park30ca9372019-02-07 16:27:23 +09002341//
2342// Defaults
2343//
2344type Defaults struct {
2345 android.ModuleBase
2346 android.DefaultsModuleBase
2347}
2348
Jiyong Park30ca9372019-02-07 16:27:23 +09002349func defaultsFactory() android.Module {
2350 return DefaultsFactory()
2351}
2352
2353func DefaultsFactory(props ...interface{}) android.Module {
2354 module := &Defaults{}
2355
2356 module.AddProperties(props...)
2357 module.AddProperties(
2358 &apexBundleProperties{},
2359 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002360 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002361 )
2362
2363 android.InitDefaultsModule(module)
2364 return module
2365}
Jiyong Park5d790c32019-11-15 18:40:32 +09002366
2367//
2368// OverrideApex
2369//
2370type OverrideApex struct {
2371 android.ModuleBase
2372 android.OverrideModuleBase
2373}
2374
2375func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2376 // All the overrides happen in the base module.
2377}
2378
2379// override_apex is used to create an apex module based on another apex module
2380// by overriding some of its properties.
2381func overrideApexFactory() android.Module {
2382 m := &OverrideApex{}
2383 m.AddProperties(&overridableProperties{})
2384
2385 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2386 android.InitOverrideModule(m)
2387 return m
2388}