blob: 1f8a7baa224434d1c8c1d00c059e3e3527929db5 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
48}
49
50var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +090051 sharedLibTag = dependencyTag{name: "sharedLib"}
52 executableTag = dependencyTag{name: "executable"}
53 javaLibTag = dependencyTag{name: "javaLib"}
54 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +010055 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090056 keyTag = dependencyTag{name: "key"}
57 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090058 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +090059 androidAppTag = dependencyTag{name: "androidApp"}
Anton Hansson5053c292020-01-10 15:12:39 +000060 apexAvailWl = makeApexAvailableWhitelist()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090061)
62
Anton Hansson5053c292020-01-10 15:12:39 +000063// This is a map from apex to modules, which overrides the
64// apex_available setting for that particular module to make
65// it available for the apex regardless of its setting.
66// TODO(b/147364041): remove this
67func makeApexAvailableWhitelist() map[string][]string {
68 // The "Module separator"s below are employed to minimize merge conflicts.
69 m := make(map[string][]string)
70 //
71 // Module separator
72 //
73 m["com.android.adbd"] = []string{"adbd", "libcrypto"}
74 //
75 // Module separator
76 //
77 m["com.android.art"] = []string{
Anton Hanssonf17f2482020-01-16 09:11:57 +000078 "jacocoagent",
Anton Hansson5053c292020-01-10 15:12:39 +000079 "libadbconnection_server",
80 "libartd-disassembler",
81 "libbacktrace",
82 "libbase",
83 "libc++",
84 "libcrypto",
85 "libdexfile_support",
86 "libexpat",
87 "libicuuc",
88 "liblzma",
89 "libmeminfo",
90 "libprocinfo",
91 "libunwindstack",
92 "libvixl",
93 "libvixld",
94 "libz",
95 "libziparchive",
96 "prebuilt_libclang_rt",
97 }
98 //
99 // Module separator
100 //
101 m["com.android.bluetooth.updatable"] = []string{
102 "android.hardware.audio.common@5.0",
103 "android.hardware.bluetooth@1.0",
104 "android.hardware.bluetooth@1.1",
105 "android.hardware.bluetooth.a2dp@1.0",
106 "android.hardware.bluetooth.audio@2.0",
107 "android.hidl.safe_union@1.0",
108 "libbase",
109 "libbinderthreadstate",
110 "libbluetooth",
111 "libbluetooth_jni",
112 "libc++",
113 "libchrome",
114 "libcrypto",
115 "libcutils",
116 "libevent",
117 "libfmq",
118 "libhidlbase",
119 "libprocessgroup",
120 "libprotobuf-cpp-lite",
121 "libstatslog",
122 "libtinyxml2",
123 "libutils",
124 "libz",
125 }
126 //
127 // Module separator
128 //
129 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
130 //
131 // Module separator
132 //
133 m["com.android.conscrypt"] = []string{"boringssl_self_test", "libc++", "libcrypto", "libssl"}
134 //
135 // Module separator
136 //
137 m["com.android.cronet"] = []string{"org.chromium.net.cronet", "prebuilt_libcronet.80.0.3986.0"}
138 //
139 // Module separator
140 //
Anton Hansson5053c292020-01-10 15:12:39 +0000141 m["com.android.media"] = []string{
142 "android.hardware.cas@1.0",
143 "android.hardware.cas.native@1.0",
144 "android.hidl.allocator@1.0",
145 "android.hidl.memory@1.0",
146 "android.hidl.memory.token@1.0",
147 "android.hidl.token@1.0",
148 "android.hidl.token@1.0-utils",
149 "libaacextractor",
150 "libamrextractor",
151 "libaudioutils",
152 "libbase",
153 "libbinderthreadstate",
154 "libc++",
155 "libcrypto",
156 "libcutils",
157 "libflacextractor",
158 "libhidlbase",
159 "libhidlmemory",
160 "libmidiextractor",
161 "libmkvextractor",
162 "libmp3extractor",
163 "libmp4extractor",
164 "libmpeg2extractor",
165 "liboggextractor",
166 "libprocessgroup",
167 "libspeexresampler",
168 "libstagefright_flacdec",
169 "libutils",
170 "libwavextractor",
171 "updatable-media",
172 }
173 //
174 // Module separator
175 //
176 m["com.android.media.swcodec"] = []string{
177 "android.frameworks.bufferhub@1.0",
178 "android.hardware.common-ndk_platform",
179 "android.hardware.graphics.allocator@2.0",
180 "android.hardware.graphics.allocator@3.0",
181 "android.hardware.graphics.allocator@4.0",
182 "android.hardware.graphics.bufferqueue@1.0",
183 "android.hardware.graphics.bufferqueue@2.0",
184 "android.hardware.graphics.common@1.0",
185 "android.hardware.graphics.common@1.1",
186 "android.hardware.graphics.common@1.2",
187 "android.hardware.graphics.common-ndk_platform",
188 "android.hardware.graphics.mapper@2.0",
189 "android.hardware.graphics.mapper@2.1",
190 "android.hardware.graphics.mapper@3.0",
191 "android.hardware.graphics.mapper@4.0",
192 "android.hardware.media@1.0",
193 "android.hardware.media.bufferpool@2.0",
194 "android.hardware.media.c2@1.0",
195 "android.hardware.media.c2@1.1",
196 "android.hardware.media.omx@1.0",
197 "android.hidl.memory@1.0",
198 "android.hidl.memory.token@1.0",
199 "android.hidl.safe_union@1.0",
200 "android.hidl.token@1.0",
201 "android.hidl.token@1.0-utils",
202 "libaudioutils",
203 "libavservices_minijail",
204 "libbase",
205 "libbinderthreadstate",
206 "libc++",
207 "libcap",
208 "libcodec2",
209 "libcodec2_hidl@1.0",
210 "libcodec2_hidl@1.1",
211 "libcodec2_soft_aacdec",
212 "libcodec2_soft_aacenc",
213 "libcodec2_soft_amrnbdec",
214 "libcodec2_soft_amrnbenc",
215 "libcodec2_soft_amrwbdec",
216 "libcodec2_soft_amrwbenc",
217 "libcodec2_soft_av1dec_gav1",
218 "libcodec2_soft_avcdec",
219 "libcodec2_soft_avcenc",
220 "libcodec2_soft_common",
221 "libcodec2_soft_flacdec",
222 "libcodec2_soft_flacenc",
223 "libcodec2_soft_g711alawdec",
224 "libcodec2_soft_g711mlawdec",
225 "libcodec2_soft_gsmdec",
226 "libcodec2_soft_h263dec",
227 "libcodec2_soft_h263enc",
228 "libcodec2_soft_hevcdec",
229 "libcodec2_soft_hevcenc",
230 "libcodec2_soft_mp3dec",
231 "libcodec2_soft_mpeg2dec",
232 "libcodec2_soft_mpeg4dec",
233 "libcodec2_soft_mpeg4enc",
234 "libcodec2_soft_opusdec",
235 "libcodec2_soft_opusenc",
236 "libcodec2_soft_rawdec",
237 "libcodec2_soft_vorbisdec",
238 "libcodec2_soft_vp8dec",
239 "libcodec2_soft_vp8enc",
240 "libcodec2_soft_vp9dec",
241 "libcodec2_soft_vp9enc",
242 "libcodec2_vndk",
243 "libc_scudo",
244 "libcutils",
245 "libfmq",
246 "libgralloctypes",
247 "libhardware",
248 "libhidlbase",
249 "libhidlmemory",
250 "libion",
251 "libmedia_codecserviceregistrant",
252 "libminijail",
253 "libopus",
254 "libprocessgroup",
255 "libscudo_wrapper",
256 "libsfplugin_ccodec_utils",
257 "libspeexresampler",
258 "libstagefright_amrnb_common",
259 "libstagefright_bufferpool@2.0.1",
260 "libstagefright_bufferqueue_helper",
261 "libstagefright_enc_common",
262 "libstagefright_flacdec",
263 "libstagefright_foundation",
264 "libsync",
265 "libui",
266 "libutils",
267 "libvorbisidec",
268 "libvpx",
269 "mediaswcodec",
270 "prebuilt_libclang_rt",
271 }
272 //
273 // Module separator
274 //
275 m["com.android.mediaprovider"] = []string{"libfuse", "MediaProvider", "MediaProviderGoogle"}
276 //
277 // Module separator
278 //
Anton Hansson5053c292020-01-10 15:12:39 +0000279 m["com.android.runtime"] = []string{
280 "libbase",
281 "libc++",
282 "libdexfile_support",
283 "liblzma",
284 "libunwindstack",
285 "prebuilt_libclang_rt",
286 }
287 //
288 // Module separator
289 //
290 m["com.android.resolv"] = []string{"libcrypto", "libnetd_resolv", "libssl"}
291 //
292 // Module separator
293 //
294 m["com.android.tethering"] = []string{"libbase", "libc++", "libnativehelper_compat_libc++"}
295 //
296 // Module separator
297 //
298 m["com.android.wifi"] = []string{
299 "libbase",
300 "libc++",
301 "libcutils",
302 "libprocessgroup",
303 "libutils",
304 "libwifi-jni",
305 "wifi-service-resources",
306 }
307 //
308 // Module separator
309 //
310 return m
311}
312
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900313func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900314 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800315 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900316 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900317 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700318 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900319 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900320
Jooyung Han31c470b2019-10-18 16:26:59 +0900321 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900322 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900323
324 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
325 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
326 sort.Strings(*apexFileContextsInfos)
327 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
328 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900329}
330
Jooyung Han31c470b2019-10-18 16:26:59 +0900331func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
332 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
333 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
334}
335
Jiyong Parkd1063c12019-07-17 20:08:41 +0900336func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parka308ea12019-11-15 10:38:39 +0900337 ctx.BottomUp("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900338 ctx.BottomUp("apex", apexMutator).Parallel()
339 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
340 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900341}
342
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900343// Mark the direct and transitive dependencies of apex bundles so that they
344// can be built for the apex bundles.
Jiyong Parka308ea12019-11-15 10:38:39 +0900345func apexDepsMutator(mctx android.BottomUpMutatorContext) {
Jooyung Hana57af4a2020-01-23 05:36:59 +0000346 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Colin Crossa4925902018-11-16 11:36:28 -0800347 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900348 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900349 depName := mctx.OtherModuleName(child)
350 // If the parent is apexBundle, this child is directly depended.
351 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800352 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800353 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
354 // non-installable apex's cannot be installed and so should not prevent libraries from being
355 // installed to the system.
356 android.UpdateApexDependency(apexBundleName, depName, directDep)
357 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900358
Jiyong Park3ff16992019-12-27 14:11:47 +0900359 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
360 (directDep || am.DepIsInSameApex(mctx, child)) {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900361 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900362 return true
363 } else {
364 return false
365 }
366 })
367 }
368}
369
370// Create apex variations if a module is included in APEX(s).
371func apexMutator(mctx android.BottomUpMutatorContext) {
372 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900373 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000374 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900375 // apex bundle itself is mutated so that it and its modules have same
376 // apex variant.
377 apexBundleName := mctx.ModuleName()
378 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900379 } else if o, ok := mctx.Module().(*OverrideApex); ok {
380 apexBundleName := o.GetOverriddenModuleName()
381 if apexBundleName == "" {
382 mctx.ModuleErrorf("base property is not set")
383 return
384 }
385 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900386 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900387
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900388}
Sundong Ahne9b55722019-09-06 17:37:42 +0900389
Jooyung Han7a78a922019-10-08 21:59:58 +0900390var (
391 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
392 apexFileContextsInfosMutex sync.Mutex
393)
394
395func apexFileContextsInfos(config android.Config) *[]string {
396 return config.Once(apexFileContextsInfosKey, func() interface{} {
397 return &[]string{}
398 }).(*[]string)
399}
400
Jooyung Han54aca7b2019-11-20 02:26:02 +0900401func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900402 apexFileContextsInfosMutex.Lock()
403 defer apexFileContextsInfosMutex.Unlock()
404 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900405 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900406}
407
Sundong Ahne9b55722019-09-06 17:37:42 +0900408func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900409 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900410 var variants []string
411 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
412 case "image":
413 variants = append(variants, imageApexType, flattenedApexType)
414 case "zip":
415 variants = append(variants, zipApexType)
416 case "both":
417 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
418 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900419 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900420 return
421 }
422
423 modules := mctx.CreateLocalVariations(variants...)
424
425 for i, v := range variants {
426 switch v {
427 case imageApexType:
428 modules[i].(*apexBundle).properties.ApexType = imageApex
429 case zipApexType:
430 modules[i].(*apexBundle).properties.ApexType = zipApex
431 case flattenedApexType:
432 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900433 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900434 modules[i].(*apexBundle).MakeAsSystemExt()
435 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900436 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900437 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900438 } else if _, ok := mctx.Module().(*OverrideApex); ok {
439 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900440 }
441}
442
Jooyung Han5c998b92019-06-27 11:30:33 +0900443func apexUsesMutator(mctx android.BottomUpMutatorContext) {
444 if ab, ok := mctx.Module().(*apexBundle); ok {
445 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
446 }
447}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900448
Jooyung Handc782442019-11-01 03:14:38 +0900449var (
450 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
451)
452
453// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
454// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
455// which may cause compatibility issues. (e.g. libbinder)
456// Even though libbinder restricts its availability via 'apex_available' property and relies on
457// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
458// to avoid similar problems.
459func useVendorWhitelist(config android.Config) []string {
460 return config.Once(useVendorWhitelistKey, func() interface{} {
461 return []string{
462 // swcodec uses "vendor" variants for smaller size
463 "com.android.media.swcodec",
464 "test_com.android.media.swcodec",
465 }
466 }).([]string)
467}
468
469// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
470// called before the first call to useVendorWhitelist()
471func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
472 config.Once(useVendorWhitelistKey, func() interface{} {
473 return whitelist
474 })
475}
476
Alex Light9670d332019-01-29 18:07:33 -0800477type apexNativeDependencies struct {
478 // List of native libraries
479 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900480
Alex Light9670d332019-01-29 18:07:33 -0800481 // List of native executables
482 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900483
Roland Levillain630846d2019-06-26 12:48:34 +0100484 // List of native tests
485 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800486}
Jooyung Han344d5432019-08-23 11:17:39 +0900487
Alex Light9670d332019-01-29 18:07:33 -0800488type apexMultilibProperties struct {
489 // Native dependencies whose compile_multilib is "first"
490 First apexNativeDependencies
491
492 // Native dependencies whose compile_multilib is "both"
493 Both apexNativeDependencies
494
495 // Native dependencies whose compile_multilib is "prefer32"
496 Prefer32 apexNativeDependencies
497
498 // Native dependencies whose compile_multilib is "32"
499 Lib32 apexNativeDependencies
500
501 // Native dependencies whose compile_multilib is "64"
502 Lib64 apexNativeDependencies
503}
504
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900505type apexBundleProperties struct {
506 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000507 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800508 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900509
Jiyong Park40e26a22019-02-08 02:53:06 +0900510 // AndroidManifest.xml file used for the zip container of this APEX bundle.
511 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800512 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900513
Roland Levillain411c5842019-09-19 16:37:20 +0100514 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
515 // device (/apex/<apex_name>).
516 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900517 Apex_name *string
518
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900519 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900520 // For platform APEXes, this should points to a file under /system/sepolicy
521 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
522 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900523
524 // List of native shared libs that are embedded inside this APEX bundle
525 Native_shared_libs []string
526
Roland Levillain630846d2019-06-26 12:48:34 +0100527 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900528 Binaries []string
529
530 // List of java libraries that are embedded inside this APEX bundle
531 Java_libs []string
532
533 // List of prebuilt files that are embedded inside this APEX bundle
534 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900535
Roland Levillain630846d2019-06-26 12:48:34 +0100536 // List of tests that are embedded inside this APEX bundle
537 Tests []string
538
Jiyong Parkff1458f2018-10-12 21:49:38 +0900539 // Name of the apex_key module that provides the private key to sign APEX
540 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900541
Alex Light5098a612018-11-29 17:12:15 -0800542 // The type of APEX to build. Controls what the APEX payload is. Either
543 // 'image', 'zip' or 'both'. Default: 'image'.
544 Payload_type *string
545
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900546 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
547 // or an android_app_certificate module name in the form ":module".
548 Certificate *string
549
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900550 // Whether this APEX is installable to one of the partitions. Default: true.
551 Installable *bool
552
Jiyong Parkda6eb592018-12-19 17:12:36 +0900553 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
554 // Default is false.
555 Use_vendor *bool
556
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800557 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
558 Ignore_system_library_special_case *bool
559
Alex Light9670d332019-01-29 18:07:33 -0800560 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900561
Jiyong Parkf97782b2019-02-13 20:28:58 +0900562 // List of sanitizer names that this APEX is enabled for
563 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900564
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900565 PreventInstall bool `blueprint:"mutated"`
566
567 HideFromMake bool `blueprint:"mutated"`
568
Jooyung Han5c998b92019-06-27 11:30:33 +0900569 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
570 Provide_cpp_shared_libs *bool
571
572 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
573 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100574
575 // A txt file containing list of files that are whitelisted to be included in this APEX.
576 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900577
Sundong Ahnabb64432019-10-22 13:58:29 +0900578 // package format of this apex variant; could be non-flattened, flattened, or zip.
579 // imageApex, zipApex or flattened
580 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +0900581
Jiyong Parkd1063c12019-07-17 20:08:41 +0900582 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
583 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
584 // is implied. This value affects all modules included in this APEX. In other words, they are
585 // also built with the SDKs specified here.
586 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +0900587
Nikita Ioffec72b5dd2019-12-07 17:30:22 +0000588 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
589 // Should be only used in tests#.
590 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +0900591
592 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
593 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
594 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +0900595
596 IsCoverageVariant bool `blueprint:"mutated"`
Alex Light9670d332019-01-29 18:07:33 -0800597}
598
599type apexTargetBundleProperties struct {
600 Target struct {
601 // Multilib properties only for android.
602 Android struct {
603 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900604 }
Jooyung Han344d5432019-08-23 11:17:39 +0900605
Alex Light9670d332019-01-29 18:07:33 -0800606 // Multilib properties only for host.
607 Host struct {
608 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900609 }
Jooyung Han344d5432019-08-23 11:17:39 +0900610
Alex Light9670d332019-01-29 18:07:33 -0800611 // Multilib properties only for host linux_bionic.
612 Linux_bionic struct {
613 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900614 }
Jooyung Han344d5432019-08-23 11:17:39 +0900615
Alex Light9670d332019-01-29 18:07:33 -0800616 // Multilib properties only for host linux_glibc.
617 Linux_glibc struct {
618 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900619 }
620 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900621}
622
Jiyong Park5d790c32019-11-15 18:40:32 +0900623type overridableProperties struct {
624 // List of APKs to package inside APEX
625 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -0800626
627 // Names of modules to be overridden. Listed modules can only be other binaries
628 // (in Make or Soong).
629 // This does not completely prevent installation of the overridden binaries, but if both
630 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
631 // from PRODUCT_PACKAGES.
632 Overrides []string
Jiyong Park5d790c32019-11-15 18:40:32 +0900633}
634
Alex Light5098a612018-11-29 17:12:15 -0800635type apexPackaging int
636
637const (
638 imageApex apexPackaging = iota
639 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +0900640 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -0800641)
642
Sundong Ahnabb64432019-10-22 13:58:29 +0900643// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -0800644func (a apexPackaging) suffix() string {
645 switch a {
646 case imageApex:
647 return imageApexSuffix
648 case zipApex:
649 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -0800650 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100651 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800652 }
653}
654
655func (a apexPackaging) name() string {
656 switch a {
657 case imageApex:
658 return imageApexType
659 case zipApex:
660 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -0800661 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100662 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800663 }
664}
665
Jiyong Parkf653b052019-11-18 15:39:01 +0900666type apexFileClass int
667
668const (
669 etc apexFileClass = iota
670 nativeSharedLib
671 nativeExecutable
672 shBinary
673 pyBinary
674 goBinary
675 javaSharedLib
676 nativeTest
677 app
678)
679
Jiyong Park8fd61922018-11-08 02:50:25 +0900680func (class apexFileClass) NameInMake() string {
681 switch class {
682 case etc:
683 return "ETC"
684 case nativeSharedLib:
685 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800686 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900687 return "EXECUTABLES"
688 case javaSharedLib:
689 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100690 case nativeTest:
691 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900692 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +0900693 // b/142537672 Why isn't this APP? We want to have full control over
694 // the paths and file names of the apk file under the flattend APEX.
695 // If this is set to APP, then the paths and file names are modified
696 // by the Make build system. For example, it is installed to
697 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
698 // /system/apex/<apexname>/app/<Appname> because the build system automatically
699 // appends module name (which is <apexname>.<Appname> to the path.
700 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +0900701 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100702 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900703 }
704}
705
Jiyong Parkf653b052019-11-18 15:39:01 +0900706// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +0900707type apexFile struct {
708 builtFile android.Path
709 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900710 installDir string
711 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900712 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +0900713 // list of symlinks that will be created in installDir that point to this apexFile
714 symlinks []string
715 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +0900716 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +0900717
718 requiredModuleNames []string
719 targetRequiredModuleNames []string
720 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +0900721
Colin Cross503c1d02020-01-28 14:00:53 -0800722 jacocoReportClassesFile android.Path // only for javalibs and apps
723 certificate java.Certificate // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +0900724}
725
Jiyong Park1833cef2019-12-13 13:28:36 +0900726func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
727 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +0900728 builtFile: builtFile,
729 moduleName: moduleName,
730 installDir: installDir,
731 class: class,
732 module: module,
733 }
Jiyong Park1833cef2019-12-13 13:28:36 +0900734 if module != nil {
735 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +0900736 ret.requiredModuleNames = module.RequiredModuleNames()
737 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
738 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +0900739 }
740 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +0900741}
742
743func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +0900744 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +0900745}
746
Jiyong Park7cd10e32020-01-14 09:22:18 +0900747// Path() returns path of this apex file relative to the APEX root
748func (af *apexFile) Path() string {
749 return filepath.Join(af.installDir, af.builtFile.Base())
750}
751
752// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
753func (af *apexFile) SymlinkPaths() []string {
754 var ret []string
755 for _, symlink := range af.symlinks {
756 ret = append(ret, filepath.Join(af.installDir, symlink))
757 }
758 return ret
759}
760
761func (af *apexFile) AvailableToPlatform() bool {
762 if af.module == nil {
763 return false
764 }
765 if am, ok := af.module.(android.ApexModule); ok {
766 return am.AvailableFor(android.AvailableToPlatform)
767 }
768 return false
769}
770
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900771type apexBundle struct {
772 android.ModuleBase
773 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +0900774 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900775 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900776
Jiyong Park5d790c32019-11-15 18:40:32 +0900777 properties apexBundleProperties
778 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +0900779 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900780
Jooyung Hanf21c7972019-12-16 22:32:06 +0900781 // specific to apex_vndk modules
782 vndkProperties apexVndkProperties
783
Colin Crossa4925902018-11-16 11:36:28 -0800784 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +0900785 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700786 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900787
Jiyong Park03b68dd2019-07-26 23:20:40 +0900788 prebuiltFileToDelete string
789
Jiyong Park42cca6c2019-04-01 11:15:50 +0900790 public_key_file android.Path
791 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900792
793 container_certificate_file android.Path
794 container_private_key_file android.Path
795
Jooyung Han54aca7b2019-11-20 02:26:02 +0900796 fileContexts android.Path
797
Jiyong Park8fd61922018-11-08 02:50:25 +0900798 // list of files to be included in this apex
799 filesInfo []apexFile
800
Jiyong Park956305c2020-01-09 12:32:06 +0900801 // list of module names that should be installed along with this APEX
802 requiredDeps []string
803
804 // list of module names that this APEX is depending on (to be shown via *-deps-info target)
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900805 externalDeps []string
Jiyong Park956305c2020-01-09 12:32:06 +0900806 // list of module names that this APEX is including (to be shown via *-deps-info target)
807 internalDeps []string
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900808
Sundong Ahnabb64432019-10-22 13:58:29 +0900809 testApex bool
810 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000811 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +0900812 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +0900813
Jooyung Han214bf372019-11-12 13:03:50 +0900814 manifestJsonOut android.WritablePath
815 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +0900816
Jooyung Han002ab682020-01-08 01:57:58 +0900817 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +0900818 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +0900819 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +0900820 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
821 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +0900822
823 // Suffix of module name in Android.mk
824 // ".flattened", ".apex", ".zipapex", or ""
825 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +0900826
827 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +0900828
829 // Whether to create symlink to the system file instead of having a file
830 // inside the apex or not
831 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +0900832
833 // Struct holding the merged notice file paths in different formats
834 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900835}
836
Jiyong Park397e55e2018-10-24 21:09:55 +0900837func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100838 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700839 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900840 // Use *FarVariation* to be able to depend on modules having
841 // conflicting variations with this module. This is required since
842 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
843 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700844 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +0900845 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900846 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900847 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700848 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900849
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700850 ctx.AddFarVariationDependencies(append(target.Variations(),
851 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
852 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100853
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700854 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100855 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100856 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700857 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900858}
859
Alex Light9670d332019-01-29 18:07:33 -0800860func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
861 if ctx.Os().Class == android.Device {
862 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
863 } else {
864 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
865 if ctx.Os().Bionic() {
866 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
867 } else {
868 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
869 }
870 }
871}
872
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900873func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +0900874 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
875 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
876 }
877
Jiyong Park397e55e2018-10-24 21:09:55 +0900878 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900879 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800880
881 a.combineProperties(ctx)
882
Jiyong Park397e55e2018-10-24 21:09:55 +0900883 has32BitTarget := false
884 for _, target := range targets {
885 if target.Arch.ArchType.Multilib == "lib32" {
886 has32BitTarget = true
887 }
888 }
889 for i, target := range targets {
890 // When multilib.* is omitted for native_shared_libs, it implies
891 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700892 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +0900893 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900894 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700895 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900896
Roland Levillain630846d2019-06-26 12:48:34 +0100897 // When multilib.* is omitted for tests, it implies
898 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700899 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100900 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100901 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700902 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +0100903
Jiyong Park397e55e2018-10-24 21:09:55 +0900904 // Add native modules targetting both ABIs
905 addDependenciesForNativeModules(ctx,
906 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100907 a.properties.Multilib.Both.Binaries,
908 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700909 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900910 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900911
Alex Light3d673592019-01-18 14:37:31 -0800912 isPrimaryAbi := i == 0
913 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900914 // When multilib.* is omitted for binaries, it implies
915 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700916 ctx.AddFarVariationDependencies(append(target.Variations(),
917 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
918 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900919
920 // Add native modules targetting the first ABI
921 addDependenciesForNativeModules(ctx,
922 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100923 a.properties.Multilib.First.Binaries,
924 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700925 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900926 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900927 }
928
929 switch target.Arch.ArchType.Multilib {
930 case "lib32":
931 // Add native modules targetting 32-bit ABI
932 addDependenciesForNativeModules(ctx,
933 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100934 a.properties.Multilib.Lib32.Binaries,
935 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700936 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900937 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900938
939 addDependenciesForNativeModules(ctx,
940 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100941 a.properties.Multilib.Prefer32.Binaries,
942 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700943 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900944 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900945 case "lib64":
946 // Add native modules targetting 64-bit ABI
947 addDependenciesForNativeModules(ctx,
948 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100949 a.properties.Multilib.Lib64.Binaries,
950 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700951 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900952 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900953
954 if !has32BitTarget {
955 addDependenciesForNativeModules(ctx,
956 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100957 a.properties.Multilib.Prefer32.Binaries,
958 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700959 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900960 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900961 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700962
963 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
964 for _, sanitizer := range ctx.Config().SanitizeDevice() {
965 if sanitizer == "hwaddress" {
966 addDependenciesForNativeModules(ctx,
967 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700968 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700969 break
970 }
971 }
972 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900973 }
974
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900975 }
976
Jiyong Parkce6aadc2019-11-20 13:58:28 +0900977 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
978 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
979 // b/144532908
980 archForPrebuiltEtc := config.Arches()[0]
981 for _, arch := range config.Arches() {
982 // Prefer 64-bit arch if there is any
983 if arch.ArchType.Multilib == "lib64" {
984 archForPrebuiltEtc = arch
985 break
986 }
987 }
988 ctx.AddFarVariationDependencies([]blueprint.Variation{
989 {Mutator: "os", Variation: ctx.Os().String()},
990 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
991 }, prebuiltTag, a.properties.Prebuilts...)
992
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700993 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
994 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900995
Ulya Trafimovich44561882020-01-03 13:25:54 +0000996 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
997 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
998 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
999 javaLibTag, "jacocoagent")
1000 }
1001
Jiyong Park23c52b02019-02-02 13:13:47 +09001002 if String(a.properties.Key) == "" {
1003 ctx.ModuleErrorf("key is missing")
1004 return
1005 }
1006 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001007
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001008 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001009 if cert != "" {
1010 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001011 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001012
1013 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1014 if len(a.properties.Uses_sdks) > 0 {
1015 sdkRefs := []android.SdkRef{}
1016 for _, str := range a.properties.Uses_sdks {
1017 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1018 sdkRefs = append(sdkRefs, parsed)
1019 }
1020 a.BuildWithSdks(sdkRefs)
1021 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001022}
1023
Jiyong Park5d790c32019-11-15 18:40:32 +09001024func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1025 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1026 androidAppTag, a.overridableProperties.Apps...)
1027}
1028
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001029func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1030 // direct deps of an APEX bundle are all part of the APEX bundle
1031 return true
1032}
1033
Colin Cross0ea8ba82019-06-06 14:33:29 -07001034func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001035 moduleName := ctx.ModuleName()
1036 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1037 // we check with the pseudo module name to see if its certificate is overridden.
1038 if a.vndkApex {
1039 moduleName = vndkApexName
1040 }
1041 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001042 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001043 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001044 }
1045 return String(a.properties.Certificate)
1046}
1047
Colin Cross41955e82019-05-29 14:40:35 -07001048func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1049 switch tag {
1050 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001051 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001052 default:
1053 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001054 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001055}
1056
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001057func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001058 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001059}
1060
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001061func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1062 return proptools.Bool(a.properties.Test_only_no_hashtree)
1063}
1064
Jiyong Park7c1dc612019-01-05 11:15:24 +09001065func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001066 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001067 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001068 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001069 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001070 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001071 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001072 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001073 }
1074}
1075
Jiyong Parkf97782b2019-02-13 20:28:58 +09001076func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1077 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1078 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1079 }
1080}
1081
Jiyong Park388ef3f2019-01-28 19:47:32 +09001082func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001083 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1084 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001085 }
1086
1087 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001088 globalSanitizerNames := []string{}
1089 if a.Host() {
1090 globalSanitizerNames = ctx.Config().SanitizeHost()
1091 } else {
1092 arches := ctx.Config().SanitizeDeviceArch()
1093 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1094 globalSanitizerNames = ctx.Config().SanitizeDevice()
1095 }
1096 }
1097 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001098}
1099
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001100func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001101 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001102}
1103
1104func (a *apexBundle) PreventInstall() {
1105 a.properties.PreventInstall = true
1106}
1107
1108func (a *apexBundle) HideFromMake() {
1109 a.properties.HideFromMake = true
1110}
1111
Jiyong Park956305c2020-01-09 12:32:06 +09001112func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1113 a.properties.IsCoverageVariant = coverage
1114}
1115
Jiyong Parkf653b052019-11-18 15:39:01 +09001116// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001117func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001118 // Decide the APEX-local directory by the multilib of the library
1119 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001120 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001121 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001122 case "lib32":
1123 dirInApex = "lib"
1124 case "lib64":
1125 dirInApex = "lib64"
1126 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001127 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001128 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001129 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001130 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001131 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001132 // Special case for Bionic libs and other libs installed with them. This is
1133 // to prevent those libs from being included in the search path
1134 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1135 // those libs in the Runtime APEX are available via the legacy paths in
1136 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1137 // to the legacy paths and thus will be loaded into the default linker
1138 // namespace (aka "platform" namespace). If the libs are directly in
1139 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1140 // into the runtime linker namespace, which will result in double loading of
1141 // them, which isn't supported.
1142 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001143 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001144
Jiyong Parkf653b052019-11-18 15:39:01 +09001145 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001146 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001147}
1148
Jiyong Park1833cef2019-12-13 13:28:36 +09001149func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001150 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001151 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001152 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001153 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001154 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001155 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001156 af.symlinks = cc.Symlinks()
1157 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001158}
1159
Jiyong Park1833cef2019-12-13 13:28:36 +09001160func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001161 dirInApex := "bin"
1162 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001163 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001164}
Jiyong Park1833cef2019-12-13 13:28:36 +09001165func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001166 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001167 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1168 if err != nil {
1169 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001170 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001171 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001172 fileToCopy := android.PathForOutput(ctx, s)
1173 // NB: Since go binaries are static we don't need the module for anything here, which is
1174 // good since the go tool is a blueprint.Module not an android.Module like we would
1175 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001176 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001177}
1178
Jiyong Park1833cef2019-12-13 13:28:36 +09001179func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001180 dirInApex := filepath.Join("bin", sh.SubDir())
1181 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001182 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001183 af.symlinks = sh.Symlinks()
1184 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001185}
1186
Jooyung Han58f26ab2019-12-18 15:34:32 +09001187// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1188type javaLibrary interface {
1189 android.Module
1190 java.Dependency
1191}
1192
1193func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001194 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001195 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001196 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1197 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1198 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001199}
1200
Jiyong Park1833cef2019-12-13 13:28:36 +09001201func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001202 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1203 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001204 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001205}
1206
atrost6e126252020-01-27 17:01:16 +00001207func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1208 dirInApex := filepath.Join("etc", config.SubDir())
1209 fileToCopy := config.CompatConfig()
1210 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1211}
1212
Jiyong Park1833cef2019-12-13 13:28:36 +09001213func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001214 android.Module
1215 Privileged() bool
1216 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001217 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001218 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001219}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001220 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001221 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001222 appDir = "priv-app"
1223 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001224 dirInApex := filepath.Join(appDir, pkgName)
1225 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001226 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1227 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001228 af.certificate = aapp.Certificate()
Jiyong Park618922e2020-01-08 13:35:43 +09001229 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001230}
1231
Roland Levillain935639d2019-08-13 14:55:28 +01001232// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1233type flattenedApexContext struct {
1234 android.ModuleContext
1235}
1236
1237func (c *flattenedApexContext) InstallBypassMake() bool {
1238 return true
1239}
1240
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001241func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001242 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1243 switch a.properties.ApexType {
1244 case imageApex:
1245 if buildFlattenedAsDefault {
1246 a.suffix = imageApexSuffix
1247 } else {
1248 a.suffix = ""
1249 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001250
1251 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001252 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001253 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001254 }
1255 case zipApex:
1256 if proptools.String(a.properties.Payload_type) == "zip" {
1257 a.suffix = ""
1258 a.primaryApexType = true
1259 } else {
1260 a.suffix = zipApexSuffix
1261 }
1262 case flattenedApex:
1263 if buildFlattenedAsDefault {
1264 a.suffix = ""
1265 a.primaryApexType = true
1266 } else {
1267 a.suffix = flattenedSuffix
1268 }
Alex Light5098a612018-11-29 17:12:15 -08001269 }
1270
Roland Levillain630846d2019-06-26 12:48:34 +01001271 if len(a.properties.Tests) > 0 && !a.testApex {
1272 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1273 return
1274 }
1275
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001276 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1277
Jooyung Hane1633032019-08-01 17:41:43 +09001278 // native lib dependencies
1279 var provideNativeLibs []string
1280 var requireNativeLibs []string
1281
Jooyung Han5c998b92019-06-27 11:30:33 +09001282 // Check if "uses" requirements are met with dependent apexBundles
1283 var providedNativeSharedLibs []string
1284 useVendor := proptools.Bool(a.properties.Use_vendor)
1285 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1286 if ctx.OtherModuleDependencyTag(m) != usesTag {
1287 return
1288 }
1289 otherName := ctx.OtherModuleName(m)
1290 other, ok := m.(*apexBundle)
1291 if !ok {
1292 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1293 return
1294 }
1295 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1296 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1297 return
1298 }
1299 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1300 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1301 return
1302 }
1303 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1304 })
1305
Jiyong Parkf653b052019-11-18 15:39:01 +09001306 var filesInfo []apexFile
Alex Light778127a2019-02-27 14:19:50 -08001307 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001308 depTag := ctx.OtherModuleDependencyTag(child)
1309 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001310 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park956305c2020-01-09 12:32:06 +09001311 if depTag != keyTag && depTag != certificateTag {
1312 a.internalDeps = append(a.internalDeps, depName)
1313 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001314 switch depTag {
1315 case sharedLibTag:
1316 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001317 if cc.HasStubsVariants() {
1318 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1319 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001320 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, cc, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001321 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001322 } else {
1323 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001324 }
1325 case executableTag:
1326 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001327 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001328 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001329 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001330 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001331 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001332 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001333 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001334 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001335 } else {
Alex Light778127a2019-02-27 14:19:50 -08001336 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 +09001337 }
1338 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001339 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001340 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001341 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001342 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1343 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001344 filesInfo = append(filesInfo, af)
1345 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001346 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001347 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1348 af := apexFileForJavaLibrary(ctx, sdkLib)
1349 if !af.Ok() {
1350 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1351 return false
1352 }
1353 filesInfo = append(filesInfo, af)
1354
Jooyung Han624058e2019-12-24 18:38:06 +09001355 pf, _ := sdkLib.OutputFiles(".xml")
1356 if len(pf) != 1 {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001357 ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
1358 return false
1359 }
Jooyung Han624058e2019-12-24 18:38:06 +09001360 filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil))
Jooyung Han58f26ab2019-12-18 15:34:32 +09001361 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001362 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001363 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001364 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001365 case androidAppTag:
1366 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1367 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001368 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001369 return true // track transitive dependencies
1370 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001371 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00001372 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
1373 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001374 } else {
1375 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1376 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001377 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001378 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001379 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001380 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1381 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001382 } else {
atrost6e126252020-01-27 17:01:16 +00001383 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001384 }
Roland Levillain630846d2019-06-26 12:48:34 +01001385 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001386 if ccTest, ok := child.(*cc.Module); ok {
1387 if ccTest.IsTestPerSrcAllTestsVariation() {
1388 // Multiple-output test module (where `test_per_src: true`).
1389 //
1390 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1391 // We do not add this variation to `filesInfo`, as it has no output;
1392 // however, we do add the other variations of this module as indirect
1393 // dependencies (see below).
1394 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001395 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001396 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001397 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001398 af.class = nativeTest
1399 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001400 }
Roland Levillain630846d2019-06-26 12:48:34 +01001401 } else {
1402 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1403 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001404 case keyTag:
1405 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001406 a.private_key_file = key.private_key_file
1407 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001408 } else {
1409 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001410 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001411 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001412 case certificateTag:
1413 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001414 a.container_certificate_file = dep.Certificate.Pem
1415 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001416 } else {
1417 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1418 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001419 case android.PrebuiltDepTag:
1420 // If the prebuilt is force disabled, remember to delete the prebuilt file
1421 // that might have been installed in the previous builds
1422 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1423 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1424 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001425 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001426 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001427 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001428 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001429 // We cannot use a switch statement on `depTag` here as the checked
1430 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001431 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001432 if cc, ok := child.(*cc.Module); ok {
1433 if android.InList(cc.Name(), providedNativeSharedLibs) {
1434 // If we're using a shared library which is provided from other APEX,
1435 // don't include it in this APEX
1436 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001437 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09001438 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001439 // If the dependency is a stubs lib, don't include it in this APEX,
1440 // but make sure that the lib is installed on the device.
1441 // In case no APEX is having the lib, the lib is installed to the system
1442 // partition.
1443 //
1444 // Always include if we are a host-apex however since those won't have any
1445 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09001446 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
1447 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01001448 }
Jiyong Park956305c2020-01-09 12:32:06 +09001449 a.externalDeps = append(a.externalDeps, depName)
Jooyung Hane1633032019-08-01 17:41:43 +09001450 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001451 // Don't track further
1452 return false
1453 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001454 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09001455 af.transitiveDep = true
1456 filesInfo = append(filesInfo, af)
Jiyong Park956305c2020-01-09 12:32:06 +09001457 a.internalDeps = append(a.internalDeps, depName)
1458 a.internalDeps = append(a.internalDeps, cc.AllStaticDeps()...)
Jiyong Parkf653b052019-11-18 15:39:01 +09001459 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001460 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001461 } else if cc.IsTestPerSrcDepTag(depTag) {
1462 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001463 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001464 // Handle modules created as `test_per_src` variations of a single test module:
1465 // use the name of the generated test binary (`fileToCopy`) instead of the name
1466 // of the original test module (`depName`, shared by all `test_per_src`
1467 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09001468 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001469 // these are not considered transitive dep
1470 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001471 filesInfo = append(filesInfo, af)
1472 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001473 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001474 } else if java.IsJniDepTag(depTag) {
Jiyong Park956305c2020-01-09 12:32:06 +09001475 a.externalDeps = append(a.externalDeps, depName)
Jiyong Parkf653b052019-11-18 15:39:01 +09001476 return true
Jiyong Park956305c2020-01-09 12:32:06 +09001477 } else if java.IsStaticLibDepTag(depTag) {
1478 a.internalDeps = append(a.internalDeps, depName)
Jooyung Han9c80bae2019-08-20 17:30:57 +09001479 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001480 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001481 }
1482 }
1483 }
1484 return false
1485 })
1486
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001487 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
1488 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
1489 // via the global boot image config.
1490 if a.artApex {
1491 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
1492 dirInApex := filepath.Join("javalib", arch.String())
1493 for _, f := range files {
1494 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001495 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001496 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001497 }
1498 }
1499 }
1500
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001501 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001502 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1503 return
1504 }
1505
Jiyong Park8fd61922018-11-08 02:50:25 +09001506 // remove duplicates in filesInfo
1507 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001508 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001509 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001510 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001511 if e, ok := encountered[dest]; !ok {
1512 encountered[dest] = f
1513 } else {
1514 // If a module is directly included and also transitively depended on
1515 // consider it as directly included.
1516 e.transitiveDep = e.transitiveDep && f.transitiveDep
1517 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001518 }
1519 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001520 var result []apexFile
1521 for _, v := range encountered {
1522 result = append(result, v)
1523 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001524 return result
1525 }
1526 filesInfo = removeDup(filesInfo)
1527
1528 // to have consistent build rules
1529 sort.Slice(filesInfo, func(i, j int) bool {
1530 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1531 })
1532
Jiyong Park127b40b2019-09-30 16:04:35 +09001533 // check apex_available requirements
Jiyong Park3814f4d2019-12-02 13:08:53 +09001534 if !ctx.Host() && !a.testApex {
Jiyong Park583a2262019-10-08 20:55:38 +09001535 for _, fi := range filesInfo {
1536 if am, ok := fi.module.(android.ApexModule); ok {
Anton Hansson5053c292020-01-10 15:12:39 +00001537 // vndk {enabled:true} implies visibility to the vndk apex
1538 if ccm, ok := fi.module.(*cc.Module); ok && ccm.IsVndk() && a.vndkApex {
1539 continue
1540 }
1541
1542 if !am.AvailableFor(ctx.ModuleName()) && !whitelistedApexAvailable(ctx.ModuleName(), a.vndkApex, fi.module) {
Jiyong Park583a2262019-10-08 20:55:38 +09001543 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
Jiyong Park3814f4d2019-12-02 13:08:53 +09001544 // don't stop so that we can report other violations in the same run
Jiyong Park583a2262019-10-08 20:55:38 +09001545 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001546 }
1547 }
1548 }
1549
Jiyong Park8fd61922018-11-08 02:50:25 +09001550 a.installDir = android.PathForModuleInstall(ctx, "apex")
1551 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001552
Jooyung Han54aca7b2019-11-20 02:26:02 +09001553 if a.properties.ApexType != zipApex {
1554 if a.properties.File_contexts == nil {
1555 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
1556 } else {
1557 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
1558 if a.Platform() {
1559 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
1560 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
1561 }
1562 }
1563 }
1564 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
1565 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
1566 return
1567 }
1568 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001569 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1570 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1571 // the same library in the system partition, thus effectively sharing the same libraries
1572 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1573 // in the APEX.
1574 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
1575 a.installable() &&
1576 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001577
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001578 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09001579 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1580
1581 a.setCertificateAndPrivateKey(ctx)
1582 if a.properties.ApexType == flattenedApex {
1583 a.buildFlattenedApex(ctx)
1584 } else {
1585 a.buildUnflattenedApex(ctx)
1586 }
1587
Jooyung Han002ab682020-01-08 01:57:58 +09001588 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09001589
1590 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001591}
1592
Anton Hansson5053c292020-01-10 15:12:39 +00001593func whitelistedApexAvailable(apex string, is_vndk bool, module android.Module) bool {
1594 key := apex
1595 key = strings.Replace(key, "test_", "", 1)
1596 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
1597 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
1598
1599 moduleName := module.Name()
1600 if strings.Contains(moduleName, "prebuilt_libclang_rt") {
1601 // This module has variants that depend on the product being built.
1602 moduleName = "prebuilt_libclang_rt"
1603 }
1604
1605 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
1606 return true
1607 }
1608
1609 return false
1610}
1611
Jooyung Han344d5432019-08-23 11:17:39 +09001612func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09001613 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001614 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001615 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09001616 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08001617 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001618 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1619 })
Alex Light5098a612018-11-29 17:12:15 -08001620 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001621 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001622 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001623 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001624 return module
1625}
Jiyong Park30ca9372019-02-07 16:27:23 +09001626
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001627func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001628 bundle := newApexBundle()
1629 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001630 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09001631 return bundle
1632}
1633
1634func testApexBundleFactory() android.Module {
1635 bundle := newApexBundle()
1636 bundle.testApex = true
1637 return bundle
1638}
1639
Jiyong Parkd1063c12019-07-17 20:08:41 +09001640func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001641 return newApexBundle()
1642}
1643
Jiyong Park30ca9372019-02-07 16:27:23 +09001644//
1645// Defaults
1646//
1647type Defaults struct {
1648 android.ModuleBase
1649 android.DefaultsModuleBase
1650}
1651
Jiyong Park30ca9372019-02-07 16:27:23 +09001652func defaultsFactory() android.Module {
1653 return DefaultsFactory()
1654}
1655
1656func DefaultsFactory(props ...interface{}) android.Module {
1657 module := &Defaults{}
1658
1659 module.AddProperties(props...)
1660 module.AddProperties(
1661 &apexBundleProperties{},
1662 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09001663 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09001664 )
1665
1666 android.InitDefaultsModule(module)
1667 return module
1668}
Jiyong Park5d790c32019-11-15 18:40:32 +09001669
1670//
1671// OverrideApex
1672//
1673type OverrideApex struct {
1674 android.ModuleBase
1675 android.OverrideModuleBase
1676}
1677
1678func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1679 // All the overrides happen in the base module.
1680}
1681
1682// override_apex is used to create an apex module based on another apex module
1683// by overriding some of its properties.
1684func overrideApexFactory() android.Module {
1685 m := &OverrideApex{}
1686 m.AddProperties(&overridableProperties{})
1687
1688 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1689 android.InitOverrideModule(m)
1690 return m
1691}