blob: 48cdedf3d74cba05e92110286628333b45183727 [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 Hanssoneec79eb2020-01-10 15:12:39 +000060 apexAvailWl = makeApexAvailableWhitelist()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090061)
62
Anton Hanssoneec79eb2020-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{
78 "jacocoagent",
79 "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.conscrypt"] = []string{"boringssl_self_test", "libc++", "libcrypto", "libssl"}
130 //
131 // Module separator
132 //
133 m["com.android.cronet"] = []string{"org.chromium.net.cronet", "prebuilt_libcronet.80.0.3986.0"}
134 //
135 // Module separator
136 //
137 m["com.android.media"] = []string{
138 "android.hardware.cas@1.0",
139 "android.hardware.cas.native@1.0",
140 "android.hidl.allocator@1.0",
141 "android.hidl.memory@1.0",
142 "android.hidl.memory.token@1.0",
143 "android.hidl.token@1.0",
144 "android.hidl.token@1.0-utils",
145 "libaacextractor",
146 "libamrextractor",
147 "libbase",
148 "libbinderthreadstate",
149 "libc++",
150 "libcrypto",
151 "libcutils",
152 "libflacextractor",
153 "libhidlbase",
154 "libhidlmemory",
155 "libmidiextractor",
156 "libmkvextractor",
157 "libmp3extractor",
158 "libmp4extractor",
159 "libmpeg2extractor",
160 "liboggextractor",
161 "libprocessgroup",
162 "libutils",
163 "libwavextractor",
164 "updatable-media",
165 }
166 //
167 // Module separator
168 //
169 m["com.android.media.swcodec"] = []string{
170 "android.frameworks.bufferhub@1.0",
171 "android.hardware.configstore@1.0",
172 "android.hardware.configstore@1.1",
173 "android.hardware.configstore-utils",
174 "android.hardware.graphics.allocator@2.0",
175 "android.hardware.graphics.allocator@3.0",
176 "android.hardware.graphics.bufferqueue@1.0",
177 "android.hardware.graphics.bufferqueue@2.0",
178 "android.hardware.graphics.common@1.0",
179 "android.hardware.graphics.common@1.1",
180 "android.hardware.graphics.common@1.2",
181 "android.hardware.graphics.mapper@2.0",
182 "android.hardware.graphics.mapper@2.1",
183 "android.hardware.graphics.mapper@3.0",
184 "android.hardware.media@1.0",
185 "android.hardware.media.bufferpool@2.0",
186 "android.hardware.media.c2@1.0",
187 "android.hardware.media.omx@1.0",
188 "android.hidl.memory@1.0",
189 "android.hidl.memory.token@1.0",
190 "android.hidl.safe_union@1.0",
191 "android.hidl.token@1.0",
192 "android.hidl.token@1.0-utils",
193 "libavservices_minijail",
194 "libbacktrace",
195 "libbase",
196 "libbinderthreadstate",
197 "libc++",
198 "libcap",
199 "libcodec2",
200 "libcodec2_hidl@1.0",
201 "libcodec2_soft_aacdec",
202 "libcodec2_soft_aacenc",
203 "libcodec2_soft_amrnbdec",
204 "libcodec2_soft_amrnbenc",
205 "libcodec2_soft_amrwbdec",
206 "libcodec2_soft_amrwbenc",
207 "libcodec2_soft_av1dec_gav1",
208 "libcodec2_soft_avcdec",
209 "libcodec2_soft_avcenc",
210 "libcodec2_soft_common",
211 "libcodec2_soft_flacdec",
212 "libcodec2_soft_flacenc",
213 "libcodec2_soft_g711alawdec",
214 "libcodec2_soft_g711mlawdec",
215 "libcodec2_soft_gsmdec",
216 "libcodec2_soft_h263dec",
217 "libcodec2_soft_h263enc",
218 "libcodec2_soft_hevcdec",
219 "libcodec2_soft_hevcenc",
220 "libcodec2_soft_mp3dec",
221 "libcodec2_soft_mpeg2dec",
222 "libcodec2_soft_mpeg4dec",
223 "libcodec2_soft_mpeg4enc",
224 "libcodec2_soft_opusdec",
225 "libcodec2_soft_opusenc",
226 "libcodec2_soft_rawdec",
227 "libcodec2_soft_vorbisdec",
228 "libcodec2_soft_vp8dec",
229 "libcodec2_soft_vp8enc",
230 "libcodec2_soft_vp9dec",
231 "libcodec2_soft_vp9enc",
232 "libcodec2_vndk",
233 "libc_scudo",
234 "libcutils",
235 "libdexfile_support",
236 "libEGL",
237 "libfmq",
238 "libgraphicsenv",
239 "libhardware",
240 "libhidlbase",
241 "libhidlmemory",
242 "libion",
243 "liblzma",
244 "libmedia_codecserviceregistrant",
245 "libminijail",
246 "libnativebridge_lazy",
247 "libnativeloader_lazy",
248 "libopus",
249 "libprocessgroup",
250 "libscudo_wrapper",
251 "libsfplugin_ccodec_utils",
252 "libstagefright_amrnb_common",
253 "libstagefright_bufferpool@2.0.1",
254 "libstagefright_bufferqueue_helper",
255 "libstagefright_enc_common",
256 "libstagefright_flacdec",
257 "libstagefright_foundation",
258 "libsync",
259 "libui",
260 "libunwindstack",
261 "libutils",
262 "libvorbisidec",
263 "libvpx",
264 "mediaswcodec",
265 "prebuilt_libclang_rt",
266 }
267 //
268 // Module separator
269 //
270 m["com.android.runtime"] = []string{
271 "libbase",
272 "libc++",
273 "libdexfile_support",
274 "liblzma",
275 "libunwindstack",
276 "prebuilt_libclang_rt",
277 }
278 //
279 // Module separator
280 //
281 m["com.android.resolv"] = []string{"libcrypto", "libnetd_resolv", "libssl"}
282 //
283 // Module separator
284 //
285 m["com.android.tethering"] = []string{"libbase", "libc++", "libnativehelper_compat_libc++"}
286 //
287 // Module separator
288 //
289 m["com.android.vndk"] = []string{
290 "libbacktrace",
291 "libbinderthreadstate",
292 "libblas",
293 "libcompiler_rt",
294 "libgui",
295 "libunwind",
296 }
297 //
298 // Module separator
299 //
300 return m
301}
302
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900303func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900304 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800305 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900306 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900307 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700308 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900309 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900310
Jooyung Han31c470b2019-10-18 16:26:59 +0900311 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900312 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900313
314 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
315 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
316 sort.Strings(*apexFileContextsInfos)
317 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
318 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900319}
320
Jooyung Han31c470b2019-10-18 16:26:59 +0900321func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
322 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
323 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
324}
325
Jiyong Parkd1063c12019-07-17 20:08:41 +0900326func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parka308ea12019-11-15 10:38:39 +0900327 ctx.BottomUp("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900328 ctx.BottomUp("apex", apexMutator).Parallel()
329 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
330 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900331}
332
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900333// Mark the direct and transitive dependencies of apex bundles so that they
334// can be built for the apex bundles.
Jiyong Parka308ea12019-11-15 10:38:39 +0900335func apexDepsMutator(mctx android.BottomUpMutatorContext) {
Jooyung Hana57af4a2020-01-23 05:36:59 +0000336 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Colin Crossa4925902018-11-16 11:36:28 -0800337 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900338 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900339 depName := mctx.OtherModuleName(child)
340 // If the parent is apexBundle, this child is directly depended.
341 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800342 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800343 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
344 // non-installable apex's cannot be installed and so should not prevent libraries from being
345 // installed to the system.
346 android.UpdateApexDependency(apexBundleName, depName, directDep)
347 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900348
Jiyong Park3ff16992019-12-27 14:11:47 +0900349 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
350 (directDep || am.DepIsInSameApex(mctx, child)) {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900351 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900352 return true
353 } else {
354 return false
355 }
356 })
357 }
358}
359
360// Create apex variations if a module is included in APEX(s).
361func apexMutator(mctx android.BottomUpMutatorContext) {
362 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900363 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000364 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900365 // apex bundle itself is mutated so that it and its modules have same
366 // apex variant.
367 apexBundleName := mctx.ModuleName()
368 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900369 } else if o, ok := mctx.Module().(*OverrideApex); ok {
370 apexBundleName := o.GetOverriddenModuleName()
371 if apexBundleName == "" {
372 mctx.ModuleErrorf("base property is not set")
373 return
374 }
375 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900376 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900377
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900378}
Sundong Ahne9b55722019-09-06 17:37:42 +0900379
Jooyung Han7a78a922019-10-08 21:59:58 +0900380var (
381 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
382 apexFileContextsInfosMutex sync.Mutex
383)
384
385func apexFileContextsInfos(config android.Config) *[]string {
386 return config.Once(apexFileContextsInfosKey, func() interface{} {
387 return &[]string{}
388 }).(*[]string)
389}
390
Jooyung Han54aca7b2019-11-20 02:26:02 +0900391func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900392 apexFileContextsInfosMutex.Lock()
393 defer apexFileContextsInfosMutex.Unlock()
394 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900395 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900396}
397
Sundong Ahne9b55722019-09-06 17:37:42 +0900398func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900399 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900400 var variants []string
401 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
402 case "image":
403 variants = append(variants, imageApexType, flattenedApexType)
404 case "zip":
405 variants = append(variants, zipApexType)
406 case "both":
407 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
408 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900409 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900410 return
411 }
412
413 modules := mctx.CreateLocalVariations(variants...)
414
415 for i, v := range variants {
416 switch v {
417 case imageApexType:
418 modules[i].(*apexBundle).properties.ApexType = imageApex
419 case zipApexType:
420 modules[i].(*apexBundle).properties.ApexType = zipApex
421 case flattenedApexType:
422 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900423 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900424 modules[i].(*apexBundle).MakeAsSystemExt()
425 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900426 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900427 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900428 } else if _, ok := mctx.Module().(*OverrideApex); ok {
429 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900430 }
431}
432
Jooyung Han5c998b92019-06-27 11:30:33 +0900433func apexUsesMutator(mctx android.BottomUpMutatorContext) {
434 if ab, ok := mctx.Module().(*apexBundle); ok {
435 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
436 }
437}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900438
Jooyung Handc782442019-11-01 03:14:38 +0900439var (
440 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
441)
442
443// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
444// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
445// which may cause compatibility issues. (e.g. libbinder)
446// Even though libbinder restricts its availability via 'apex_available' property and relies on
447// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
448// to avoid similar problems.
449func useVendorWhitelist(config android.Config) []string {
450 return config.Once(useVendorWhitelistKey, func() interface{} {
451 return []string{
452 // swcodec uses "vendor" variants for smaller size
453 "com.android.media.swcodec",
454 "test_com.android.media.swcodec",
455 }
456 }).([]string)
457}
458
459// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
460// called before the first call to useVendorWhitelist()
461func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
462 config.Once(useVendorWhitelistKey, func() interface{} {
463 return whitelist
464 })
465}
466
Alex Light9670d332019-01-29 18:07:33 -0800467type apexNativeDependencies struct {
468 // List of native libraries
469 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900470
Alex Light9670d332019-01-29 18:07:33 -0800471 // List of native executables
472 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900473
Roland Levillain630846d2019-06-26 12:48:34 +0100474 // List of native tests
475 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800476}
Jooyung Han344d5432019-08-23 11:17:39 +0900477
Alex Light9670d332019-01-29 18:07:33 -0800478type apexMultilibProperties struct {
479 // Native dependencies whose compile_multilib is "first"
480 First apexNativeDependencies
481
482 // Native dependencies whose compile_multilib is "both"
483 Both apexNativeDependencies
484
485 // Native dependencies whose compile_multilib is "prefer32"
486 Prefer32 apexNativeDependencies
487
488 // Native dependencies whose compile_multilib is "32"
489 Lib32 apexNativeDependencies
490
491 // Native dependencies whose compile_multilib is "64"
492 Lib64 apexNativeDependencies
493}
494
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900495type apexBundleProperties struct {
496 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000497 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800498 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900499
Jiyong Park40e26a22019-02-08 02:53:06 +0900500 // AndroidManifest.xml file used for the zip container of this APEX bundle.
501 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800502 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900503
Roland Levillain411c5842019-09-19 16:37:20 +0100504 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
505 // device (/apex/<apex_name>).
506 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900507 Apex_name *string
508
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900509 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900510 // For platform APEXes, this should points to a file under /system/sepolicy
511 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
512 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900513
514 // List of native shared libs that are embedded inside this APEX bundle
515 Native_shared_libs []string
516
Roland Levillain630846d2019-06-26 12:48:34 +0100517 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900518 Binaries []string
519
520 // List of java libraries that are embedded inside this APEX bundle
521 Java_libs []string
522
523 // List of prebuilt files that are embedded inside this APEX bundle
524 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900525
Roland Levillain630846d2019-06-26 12:48:34 +0100526 // List of tests that are embedded inside this APEX bundle
527 Tests []string
528
Jiyong Parkff1458f2018-10-12 21:49:38 +0900529 // Name of the apex_key module that provides the private key to sign APEX
530 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900531
Alex Light5098a612018-11-29 17:12:15 -0800532 // The type of APEX to build. Controls what the APEX payload is. Either
533 // 'image', 'zip' or 'both'. Default: 'image'.
534 Payload_type *string
535
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900536 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
537 // or an android_app_certificate module name in the form ":module".
538 Certificate *string
539
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900540 // Whether this APEX is installable to one of the partitions. Default: true.
541 Installable *bool
542
Jiyong Parkda6eb592018-12-19 17:12:36 +0900543 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
544 // Default is false.
545 Use_vendor *bool
546
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800547 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
548 Ignore_system_library_special_case *bool
549
Alex Light9670d332019-01-29 18:07:33 -0800550 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900551
Jiyong Parkf97782b2019-02-13 20:28:58 +0900552 // List of sanitizer names that this APEX is enabled for
553 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900554
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900555 PreventInstall bool `blueprint:"mutated"`
556
557 HideFromMake bool `blueprint:"mutated"`
558
Jooyung Han5c998b92019-06-27 11:30:33 +0900559 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
560 Provide_cpp_shared_libs *bool
561
562 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
563 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100564
565 // A txt file containing list of files that are whitelisted to be included in this APEX.
566 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900567
Sundong Ahnabb64432019-10-22 13:58:29 +0900568 // package format of this apex variant; could be non-flattened, flattened, or zip.
569 // imageApex, zipApex or flattened
570 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +0900571
Jiyong Parkd1063c12019-07-17 20:08:41 +0900572 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
573 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
574 // is implied. This value affects all modules included in this APEX. In other words, they are
575 // also built with the SDKs specified here.
576 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +0900577
Nikita Ioffec72b5dd2019-12-07 17:30:22 +0000578 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
579 // Should be only used in tests#.
580 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +0900581
582 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
583 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
584 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +0900585
586 IsCoverageVariant bool `blueprint:"mutated"`
Alex Light9670d332019-01-29 18:07:33 -0800587}
588
589type apexTargetBundleProperties struct {
590 Target struct {
591 // Multilib properties only for android.
592 Android struct {
593 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900594 }
Jooyung Han344d5432019-08-23 11:17:39 +0900595
Alex Light9670d332019-01-29 18:07:33 -0800596 // Multilib properties only for host.
597 Host struct {
598 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900599 }
Jooyung Han344d5432019-08-23 11:17:39 +0900600
Alex Light9670d332019-01-29 18:07:33 -0800601 // Multilib properties only for host linux_bionic.
602 Linux_bionic 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 linux_glibc.
607 Linux_glibc struct {
608 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900609 }
610 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900611}
612
Jiyong Park5d790c32019-11-15 18:40:32 +0900613type overridableProperties struct {
614 // List of APKs to package inside APEX
615 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -0800616
617 // Names of modules to be overridden. Listed modules can only be other binaries
618 // (in Make or Soong).
619 // This does not completely prevent installation of the overridden binaries, but if both
620 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
621 // from PRODUCT_PACKAGES.
622 Overrides []string
Jiyong Park5d790c32019-11-15 18:40:32 +0900623}
624
Alex Light5098a612018-11-29 17:12:15 -0800625type apexPackaging int
626
627const (
628 imageApex apexPackaging = iota
629 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +0900630 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -0800631)
632
Sundong Ahnabb64432019-10-22 13:58:29 +0900633// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -0800634func (a apexPackaging) suffix() string {
635 switch a {
636 case imageApex:
637 return imageApexSuffix
638 case zipApex:
639 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -0800640 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100641 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800642 }
643}
644
645func (a apexPackaging) name() string {
646 switch a {
647 case imageApex:
648 return imageApexType
649 case zipApex:
650 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -0800651 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100652 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800653 }
654}
655
Jiyong Parkf653b052019-11-18 15:39:01 +0900656type apexFileClass int
657
658const (
659 etc apexFileClass = iota
660 nativeSharedLib
661 nativeExecutable
662 shBinary
663 pyBinary
664 goBinary
665 javaSharedLib
666 nativeTest
667 app
668)
669
Jiyong Park8fd61922018-11-08 02:50:25 +0900670func (class apexFileClass) NameInMake() string {
671 switch class {
672 case etc:
673 return "ETC"
674 case nativeSharedLib:
675 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800676 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900677 return "EXECUTABLES"
678 case javaSharedLib:
679 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100680 case nativeTest:
681 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900682 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +0900683 // b/142537672 Why isn't this APP? We want to have full control over
684 // the paths and file names of the apk file under the flattend APEX.
685 // If this is set to APP, then the paths and file names are modified
686 // by the Make build system. For example, it is installed to
687 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
688 // /system/apex/<apexname>/app/<Appname> because the build system automatically
689 // appends module name (which is <apexname>.<Appname> to the path.
690 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +0900691 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100692 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900693 }
694}
695
Jiyong Parkf653b052019-11-18 15:39:01 +0900696// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +0900697type apexFile struct {
698 builtFile android.Path
699 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900700 installDir string
701 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900702 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +0900703 // list of symlinks that will be created in installDir that point to this apexFile
704 symlinks []string
705 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +0900706 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +0900707
708 requiredModuleNames []string
709 targetRequiredModuleNames []string
710 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +0900711
Colin Cross503c1d02020-01-28 14:00:53 -0800712 jacocoReportClassesFile android.Path // only for javalibs and apps
713 certificate java.Certificate // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +0900714}
715
Jiyong Park1833cef2019-12-13 13:28:36 +0900716func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
717 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +0900718 builtFile: builtFile,
719 moduleName: moduleName,
720 installDir: installDir,
721 class: class,
722 module: module,
723 }
Jiyong Park1833cef2019-12-13 13:28:36 +0900724 if module != nil {
725 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +0900726 ret.requiredModuleNames = module.RequiredModuleNames()
727 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
728 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +0900729 }
730 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +0900731}
732
733func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +0900734 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +0900735}
736
Jiyong Park7cd10e32020-01-14 09:22:18 +0900737// Path() returns path of this apex file relative to the APEX root
738func (af *apexFile) Path() string {
739 return filepath.Join(af.installDir, af.builtFile.Base())
740}
741
742// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
743func (af *apexFile) SymlinkPaths() []string {
744 var ret []string
745 for _, symlink := range af.symlinks {
746 ret = append(ret, filepath.Join(af.installDir, symlink))
747 }
748 return ret
749}
750
751func (af *apexFile) AvailableToPlatform() bool {
752 if af.module == nil {
753 return false
754 }
755 if am, ok := af.module.(android.ApexModule); ok {
756 return am.AvailableFor(android.AvailableToPlatform)
757 }
758 return false
759}
760
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900761type apexBundle struct {
762 android.ModuleBase
763 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +0900764 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900765 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900766
Jiyong Park5d790c32019-11-15 18:40:32 +0900767 properties apexBundleProperties
768 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +0900769 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900770
Jooyung Hanf21c7972019-12-16 22:32:06 +0900771 // specific to apex_vndk modules
772 vndkProperties apexVndkProperties
773
Colin Crossa4925902018-11-16 11:36:28 -0800774 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +0900775 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700776 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900777
Jiyong Park03b68dd2019-07-26 23:20:40 +0900778 prebuiltFileToDelete string
779
Jiyong Park42cca6c2019-04-01 11:15:50 +0900780 public_key_file android.Path
781 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900782
783 container_certificate_file android.Path
784 container_private_key_file android.Path
785
Jooyung Han54aca7b2019-11-20 02:26:02 +0900786 fileContexts android.Path
787
Jiyong Park8fd61922018-11-08 02:50:25 +0900788 // list of files to be included in this apex
789 filesInfo []apexFile
790
Jiyong Park956305c2020-01-09 12:32:06 +0900791 // list of module names that should be installed along with this APEX
792 requiredDeps []string
793
794 // list of module names that this APEX is depending on (to be shown via *-deps-info target)
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900795 externalDeps []string
Jiyong Park956305c2020-01-09 12:32:06 +0900796 // list of module names that this APEX is including (to be shown via *-deps-info target)
797 internalDeps []string
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900798
Sundong Ahnabb64432019-10-22 13:58:29 +0900799 testApex bool
800 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000801 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +0900802 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +0900803
Jooyung Han214bf372019-11-12 13:03:50 +0900804 manifestJsonOut android.WritablePath
805 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +0900806
Jooyung Han002ab682020-01-08 01:57:58 +0900807 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +0900808 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +0900809 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +0900810 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
811 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +0900812
813 // Suffix of module name in Android.mk
814 // ".flattened", ".apex", ".zipapex", or ""
815 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +0900816
817 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +0900818
819 // Whether to create symlink to the system file instead of having a file
820 // inside the apex or not
821 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +0900822
823 // Struct holding the merged notice file paths in different formats
824 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900825}
826
Jiyong Park397e55e2018-10-24 21:09:55 +0900827func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100828 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700829 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900830 // Use *FarVariation* to be able to depend on modules having
831 // conflicting variations with this module. This is required since
832 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
833 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700834 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +0900835 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900836 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900837 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700838 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900839
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700840 ctx.AddFarVariationDependencies(append(target.Variations(),
841 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
842 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100843
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700844 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100845 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100846 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700847 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900848}
849
Alex Light9670d332019-01-29 18:07:33 -0800850func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
851 if ctx.Os().Class == android.Device {
852 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
853 } else {
854 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
855 if ctx.Os().Bionic() {
856 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
857 } else {
858 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
859 }
860 }
861}
862
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900863func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +0900864 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
865 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
866 }
867
Jiyong Park397e55e2018-10-24 21:09:55 +0900868 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900869 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800870
871 a.combineProperties(ctx)
872
Jiyong Park397e55e2018-10-24 21:09:55 +0900873 has32BitTarget := false
874 for _, target := range targets {
875 if target.Arch.ArchType.Multilib == "lib32" {
876 has32BitTarget = true
877 }
878 }
879 for i, target := range targets {
880 // When multilib.* is omitted for native_shared_libs, it implies
881 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700882 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +0900883 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900884 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700885 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900886
Roland Levillain630846d2019-06-26 12:48:34 +0100887 // When multilib.* is omitted for tests, it implies
888 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700889 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100890 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100891 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700892 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +0100893
Jiyong Park397e55e2018-10-24 21:09:55 +0900894 // Add native modules targetting both ABIs
895 addDependenciesForNativeModules(ctx,
896 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100897 a.properties.Multilib.Both.Binaries,
898 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700899 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900900 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900901
Alex Light3d673592019-01-18 14:37:31 -0800902 isPrimaryAbi := i == 0
903 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900904 // When multilib.* is omitted for binaries, it implies
905 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700906 ctx.AddFarVariationDependencies(append(target.Variations(),
907 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
908 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900909
910 // Add native modules targetting the first ABI
911 addDependenciesForNativeModules(ctx,
912 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100913 a.properties.Multilib.First.Binaries,
914 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700915 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900916 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900917 }
918
919 switch target.Arch.ArchType.Multilib {
920 case "lib32":
921 // Add native modules targetting 32-bit ABI
922 addDependenciesForNativeModules(ctx,
923 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100924 a.properties.Multilib.Lib32.Binaries,
925 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700926 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900927 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900928
929 addDependenciesForNativeModules(ctx,
930 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100931 a.properties.Multilib.Prefer32.Binaries,
932 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700933 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900934 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900935 case "lib64":
936 // Add native modules targetting 64-bit ABI
937 addDependenciesForNativeModules(ctx,
938 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100939 a.properties.Multilib.Lib64.Binaries,
940 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700941 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900942 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900943
944 if !has32BitTarget {
945 addDependenciesForNativeModules(ctx,
946 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100947 a.properties.Multilib.Prefer32.Binaries,
948 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700949 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900950 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900951 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700952
953 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
954 for _, sanitizer := range ctx.Config().SanitizeDevice() {
955 if sanitizer == "hwaddress" {
956 addDependenciesForNativeModules(ctx,
957 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700958 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700959 break
960 }
961 }
962 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900963 }
964
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900965 }
966
Jiyong Parkce6aadc2019-11-20 13:58:28 +0900967 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
968 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
969 // b/144532908
970 archForPrebuiltEtc := config.Arches()[0]
971 for _, arch := range config.Arches() {
972 // Prefer 64-bit arch if there is any
973 if arch.ArchType.Multilib == "lib64" {
974 archForPrebuiltEtc = arch
975 break
976 }
977 }
978 ctx.AddFarVariationDependencies([]blueprint.Variation{
979 {Mutator: "os", Variation: ctx.Os().String()},
980 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
981 }, prebuiltTag, a.properties.Prebuilts...)
982
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700983 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
984 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900985
Ulya Trafimovich44561882020-01-03 13:25:54 +0000986 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
987 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
988 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
989 javaLibTag, "jacocoagent")
990 }
991
Jiyong Park23c52b02019-02-02 13:13:47 +0900992 if String(a.properties.Key) == "" {
993 ctx.ModuleErrorf("key is missing")
994 return
995 }
996 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900997
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900998 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900999 if cert != "" {
1000 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001001 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001002
1003 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1004 if len(a.properties.Uses_sdks) > 0 {
1005 sdkRefs := []android.SdkRef{}
1006 for _, str := range a.properties.Uses_sdks {
1007 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1008 sdkRefs = append(sdkRefs, parsed)
1009 }
1010 a.BuildWithSdks(sdkRefs)
1011 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001012}
1013
Jiyong Park5d790c32019-11-15 18:40:32 +09001014func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1015 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1016 androidAppTag, a.overridableProperties.Apps...)
1017}
1018
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001019func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1020 // direct deps of an APEX bundle are all part of the APEX bundle
1021 return true
1022}
1023
Colin Cross0ea8ba82019-06-06 14:33:29 -07001024func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001025 moduleName := ctx.ModuleName()
1026 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1027 // we check with the pseudo module name to see if its certificate is overridden.
1028 if a.vndkApex {
1029 moduleName = vndkApexName
1030 }
1031 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001032 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001033 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001034 }
1035 return String(a.properties.Certificate)
1036}
1037
Colin Cross41955e82019-05-29 14:40:35 -07001038func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1039 switch tag {
1040 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001041 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001042 default:
1043 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001044 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001045}
1046
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001047func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001048 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001049}
1050
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001051func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1052 return proptools.Bool(a.properties.Test_only_no_hashtree)
1053}
1054
Jiyong Park7c1dc612019-01-05 11:15:24 +09001055func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001056 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001057 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001058 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001059 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001060 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001061 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001062 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001063 }
1064}
1065
Jiyong Parkf97782b2019-02-13 20:28:58 +09001066func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1067 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1068 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1069 }
1070}
1071
Jiyong Park388ef3f2019-01-28 19:47:32 +09001072func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001073 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1074 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001075 }
1076
1077 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001078 globalSanitizerNames := []string{}
1079 if a.Host() {
1080 globalSanitizerNames = ctx.Config().SanitizeHost()
1081 } else {
1082 arches := ctx.Config().SanitizeDeviceArch()
1083 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1084 globalSanitizerNames = ctx.Config().SanitizeDevice()
1085 }
1086 }
1087 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001088}
1089
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001090func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001091 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001092}
1093
1094func (a *apexBundle) PreventInstall() {
1095 a.properties.PreventInstall = true
1096}
1097
1098func (a *apexBundle) HideFromMake() {
1099 a.properties.HideFromMake = true
1100}
1101
Jiyong Park956305c2020-01-09 12:32:06 +09001102func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1103 a.properties.IsCoverageVariant = coverage
1104}
1105
Jiyong Parkf653b052019-11-18 15:39:01 +09001106// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001107func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001108 // Decide the APEX-local directory by the multilib of the library
1109 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001110 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001111 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001112 case "lib32":
1113 dirInApex = "lib"
1114 case "lib64":
1115 dirInApex = "lib64"
1116 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001117 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001118 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001119 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001120 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001121 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001122 // Special case for Bionic libs and other libs installed with them. This is
1123 // to prevent those libs from being included in the search path
1124 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1125 // those libs in the Runtime APEX are available via the legacy paths in
1126 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1127 // to the legacy paths and thus will be loaded into the default linker
1128 // namespace (aka "platform" namespace). If the libs are directly in
1129 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1130 // into the runtime linker namespace, which will result in double loading of
1131 // them, which isn't supported.
1132 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001133 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001134
Jiyong Parkf653b052019-11-18 15:39:01 +09001135 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001136 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001137}
1138
Jiyong Park1833cef2019-12-13 13:28:36 +09001139func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001140 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001141 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001142 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001143 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001144 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001145 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001146 af.symlinks = cc.Symlinks()
1147 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001148}
1149
Jiyong Park1833cef2019-12-13 13:28:36 +09001150func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001151 dirInApex := "bin"
1152 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001153 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001154}
Jiyong Park1833cef2019-12-13 13:28:36 +09001155func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001156 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001157 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1158 if err != nil {
1159 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001160 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001161 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001162 fileToCopy := android.PathForOutput(ctx, s)
1163 // NB: Since go binaries are static we don't need the module for anything here, which is
1164 // good since the go tool is a blueprint.Module not an android.Module like we would
1165 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001166 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001167}
1168
Jiyong Park1833cef2019-12-13 13:28:36 +09001169func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001170 dirInApex := filepath.Join("bin", sh.SubDir())
1171 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001172 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001173 af.symlinks = sh.Symlinks()
1174 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001175}
1176
Jooyung Han58f26ab2019-12-18 15:34:32 +09001177// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1178type javaLibrary interface {
1179 android.Module
1180 java.Dependency
1181}
1182
1183func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001184 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001185 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001186 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1187 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1188 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001189}
1190
Jiyong Park1833cef2019-12-13 13:28:36 +09001191func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001192 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1193 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001194 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001195}
1196
Jiyong Park1833cef2019-12-13 13:28:36 +09001197func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001198 android.Module
1199 Privileged() bool
1200 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001201 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001202 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001203}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001204 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001205 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001206 appDir = "priv-app"
1207 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001208 dirInApex := filepath.Join(appDir, pkgName)
1209 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001210 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1211 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001212 af.certificate = aapp.Certificate()
Jiyong Park618922e2020-01-08 13:35:43 +09001213 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001214}
1215
Roland Levillain935639d2019-08-13 14:55:28 +01001216// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1217type flattenedApexContext struct {
1218 android.ModuleContext
1219}
1220
1221func (c *flattenedApexContext) InstallBypassMake() bool {
1222 return true
1223}
1224
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001225func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001226 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1227 switch a.properties.ApexType {
1228 case imageApex:
1229 if buildFlattenedAsDefault {
1230 a.suffix = imageApexSuffix
1231 } else {
1232 a.suffix = ""
1233 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001234
1235 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001236 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001237 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001238 }
1239 case zipApex:
1240 if proptools.String(a.properties.Payload_type) == "zip" {
1241 a.suffix = ""
1242 a.primaryApexType = true
1243 } else {
1244 a.suffix = zipApexSuffix
1245 }
1246 case flattenedApex:
1247 if buildFlattenedAsDefault {
1248 a.suffix = ""
1249 a.primaryApexType = true
1250 } else {
1251 a.suffix = flattenedSuffix
1252 }
Alex Light5098a612018-11-29 17:12:15 -08001253 }
1254
Roland Levillain630846d2019-06-26 12:48:34 +01001255 if len(a.properties.Tests) > 0 && !a.testApex {
1256 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1257 return
1258 }
1259
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001260 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1261
Jooyung Hane1633032019-08-01 17:41:43 +09001262 // native lib dependencies
1263 var provideNativeLibs []string
1264 var requireNativeLibs []string
1265
Jooyung Han5c998b92019-06-27 11:30:33 +09001266 // Check if "uses" requirements are met with dependent apexBundles
1267 var providedNativeSharedLibs []string
1268 useVendor := proptools.Bool(a.properties.Use_vendor)
1269 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1270 if ctx.OtherModuleDependencyTag(m) != usesTag {
1271 return
1272 }
1273 otherName := ctx.OtherModuleName(m)
1274 other, ok := m.(*apexBundle)
1275 if !ok {
1276 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1277 return
1278 }
1279 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1280 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1281 return
1282 }
1283 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1284 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1285 return
1286 }
1287 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1288 })
1289
Jiyong Parkf653b052019-11-18 15:39:01 +09001290 var filesInfo []apexFile
Alex Light778127a2019-02-27 14:19:50 -08001291 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001292 depTag := ctx.OtherModuleDependencyTag(child)
1293 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001294 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park956305c2020-01-09 12:32:06 +09001295 if depTag != keyTag && depTag != certificateTag {
1296 a.internalDeps = append(a.internalDeps, depName)
1297 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001298 switch depTag {
1299 case sharedLibTag:
1300 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001301 if cc.HasStubsVariants() {
1302 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1303 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001304 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, cc, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001305 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001306 } else {
1307 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001308 }
1309 case executableTag:
1310 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001311 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001312 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001313 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001314 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001315 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001316 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001317 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001318 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001319 } else {
Alex Light778127a2019-02-27 14:19:50 -08001320 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 +09001321 }
1322 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001323 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001324 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001325 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001326 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1327 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001328 filesInfo = append(filesInfo, af)
1329 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001330 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001331 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1332 af := apexFileForJavaLibrary(ctx, sdkLib)
1333 if !af.Ok() {
1334 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1335 return false
1336 }
1337 filesInfo = append(filesInfo, af)
1338
Jooyung Han624058e2019-12-24 18:38:06 +09001339 pf, _ := sdkLib.OutputFiles(".xml")
1340 if len(pf) != 1 {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001341 ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
1342 return false
1343 }
Jooyung Han624058e2019-12-24 18:38:06 +09001344 filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil))
Jooyung Han58f26ab2019-12-18 15:34:32 +09001345 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001346 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001347 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001348 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001349 case androidAppTag:
1350 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1351 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001352 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001353 return true // track transitive dependencies
1354 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001355 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00001356 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
1357 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001358 } else {
1359 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1360 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001361 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001362 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001363 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001364 } else {
1365 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1366 }
Roland Levillain630846d2019-06-26 12:48:34 +01001367 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001368 if ccTest, ok := child.(*cc.Module); ok {
1369 if ccTest.IsTestPerSrcAllTestsVariation() {
1370 // Multiple-output test module (where `test_per_src: true`).
1371 //
1372 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1373 // We do not add this variation to `filesInfo`, as it has no output;
1374 // however, we do add the other variations of this module as indirect
1375 // dependencies (see below).
1376 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001377 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001378 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001379 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001380 af.class = nativeTest
1381 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001382 }
Roland Levillain630846d2019-06-26 12:48:34 +01001383 } else {
1384 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1385 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001386 case keyTag:
1387 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001388 a.private_key_file = key.private_key_file
1389 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001390 } else {
1391 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001392 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001393 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001394 case certificateTag:
1395 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001396 a.container_certificate_file = dep.Certificate.Pem
1397 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001398 } else {
1399 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1400 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001401 case android.PrebuiltDepTag:
1402 // If the prebuilt is force disabled, remember to delete the prebuilt file
1403 // that might have been installed in the previous builds
1404 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1405 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1406 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001407 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001408 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001409 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001410 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001411 // We cannot use a switch statement on `depTag` here as the checked
1412 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001413 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001414 if cc, ok := child.(*cc.Module); ok {
1415 if android.InList(cc.Name(), providedNativeSharedLibs) {
1416 // If we're using a shared library which is provided from other APEX,
1417 // don't include it in this APEX
1418 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001419 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09001420 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001421 // If the dependency is a stubs lib, don't include it in this APEX,
1422 // but make sure that the lib is installed on the device.
1423 // In case no APEX is having the lib, the lib is installed to the system
1424 // partition.
1425 //
1426 // Always include if we are a host-apex however since those won't have any
1427 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09001428 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
1429 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01001430 }
Jiyong Park956305c2020-01-09 12:32:06 +09001431 a.externalDeps = append(a.externalDeps, depName)
Jooyung Hane1633032019-08-01 17:41:43 +09001432 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001433 // Don't track further
1434 return false
1435 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001436 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09001437 af.transitiveDep = true
1438 filesInfo = append(filesInfo, af)
Jiyong Park956305c2020-01-09 12:32:06 +09001439 a.internalDeps = append(a.internalDeps, depName)
1440 a.internalDeps = append(a.internalDeps, cc.AllStaticDeps()...)
Jiyong Parkf653b052019-11-18 15:39:01 +09001441 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001442 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001443 } else if cc.IsTestPerSrcDepTag(depTag) {
1444 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001445 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001446 // Handle modules created as `test_per_src` variations of a single test module:
1447 // use the name of the generated test binary (`fileToCopy`) instead of the name
1448 // of the original test module (`depName`, shared by all `test_per_src`
1449 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09001450 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001451 // these are not considered transitive dep
1452 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001453 filesInfo = append(filesInfo, af)
1454 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001455 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001456 } else if java.IsJniDepTag(depTag) {
Jiyong Park956305c2020-01-09 12:32:06 +09001457 a.externalDeps = append(a.externalDeps, depName)
Jiyong Parkf653b052019-11-18 15:39:01 +09001458 return true
Jiyong Park956305c2020-01-09 12:32:06 +09001459 } else if java.IsStaticLibDepTag(depTag) {
1460 a.internalDeps = append(a.internalDeps, depName)
Jooyung Han9c80bae2019-08-20 17:30:57 +09001461 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001462 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001463 }
1464 }
1465 }
1466 return false
1467 })
1468
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001469 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
1470 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
1471 // via the global boot image config.
1472 if a.artApex {
1473 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
1474 dirInApex := filepath.Join("javalib", arch.String())
1475 for _, f := range files {
1476 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001477 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001478 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001479 }
1480 }
1481 }
1482
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001483 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001484 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1485 return
1486 }
1487
Jiyong Park8fd61922018-11-08 02:50:25 +09001488 // remove duplicates in filesInfo
1489 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001490 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001491 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001492 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001493 if e, ok := encountered[dest]; !ok {
1494 encountered[dest] = f
1495 } else {
1496 // If a module is directly included and also transitively depended on
1497 // consider it as directly included.
1498 e.transitiveDep = e.transitiveDep && f.transitiveDep
1499 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001500 }
1501 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001502 var result []apexFile
1503 for _, v := range encountered {
1504 result = append(result, v)
1505 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001506 return result
1507 }
1508 filesInfo = removeDup(filesInfo)
1509
1510 // to have consistent build rules
1511 sort.Slice(filesInfo, func(i, j int) bool {
1512 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1513 })
1514
Jiyong Park127b40b2019-09-30 16:04:35 +09001515 // check apex_available requirements
Jiyong Park3814f4d2019-12-02 13:08:53 +09001516 if !ctx.Host() && !a.testApex {
Jiyong Park583a2262019-10-08 20:55:38 +09001517 for _, fi := range filesInfo {
1518 if am, ok := fi.module.(android.ApexModule); ok {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001519 // vndk {enabled:true} implies visibility to the vndk apex
1520 if ccm, ok := fi.module.(*cc.Module); ok && ccm.IsVndk() && a.vndkApex {
1521 continue
1522 }
1523
1524 if !am.AvailableFor(ctx.ModuleName()) && !whitelistedApexAvailable(ctx.ModuleName(), a.vndkApex, fi.module) {
Jiyong Park583a2262019-10-08 20:55:38 +09001525 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
Jiyong Park3814f4d2019-12-02 13:08:53 +09001526 // don't stop so that we can report other violations in the same run
Jiyong Park583a2262019-10-08 20:55:38 +09001527 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001528 }
1529 }
1530 }
1531
Jiyong Park8fd61922018-11-08 02:50:25 +09001532 a.installDir = android.PathForModuleInstall(ctx, "apex")
1533 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001534
Jooyung Han54aca7b2019-11-20 02:26:02 +09001535 if a.properties.ApexType != zipApex {
1536 if a.properties.File_contexts == nil {
1537 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
1538 } else {
1539 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
1540 if a.Platform() {
1541 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
1542 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
1543 }
1544 }
1545 }
1546 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
1547 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
1548 return
1549 }
1550 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001551 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1552 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1553 // the same library in the system partition, thus effectively sharing the same libraries
1554 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1555 // in the APEX.
1556 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
1557 a.installable() &&
1558 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001559
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001560 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09001561 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1562
1563 a.setCertificateAndPrivateKey(ctx)
1564 if a.properties.ApexType == flattenedApex {
1565 a.buildFlattenedApex(ctx)
1566 } else {
1567 a.buildUnflattenedApex(ctx)
1568 }
1569
Jooyung Han002ab682020-01-08 01:57:58 +09001570 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09001571
1572 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001573}
1574
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001575func whitelistedApexAvailable(apex string, is_vndk bool, module android.Module) bool {
1576 key := apex
1577 key = strings.Replace(key, "test_", "", 1)
1578 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
1579 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
1580
1581 moduleName := module.Name()
1582 if strings.Contains(moduleName, "prebuilt_libclang_rt") {
1583 // This module has variants that depend on the product being built.
1584 moduleName = "prebuilt_libclang_rt"
1585 }
1586
1587 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
1588 return true
1589 }
1590
1591 return false
1592}
1593
Jooyung Han344d5432019-08-23 11:17:39 +09001594func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09001595 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001596 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001597 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09001598 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08001599 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001600 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1601 })
Alex Light5098a612018-11-29 17:12:15 -08001602 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001603 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001604 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001605 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001606 return module
1607}
Jiyong Park30ca9372019-02-07 16:27:23 +09001608
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001609func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001610 bundle := newApexBundle()
1611 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001612 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09001613 return bundle
1614}
1615
1616func testApexBundleFactory() android.Module {
1617 bundle := newApexBundle()
1618 bundle.testApex = true
1619 return bundle
1620}
1621
Jiyong Parkd1063c12019-07-17 20:08:41 +09001622func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001623 return newApexBundle()
1624}
1625
Jiyong Park30ca9372019-02-07 16:27:23 +09001626//
1627// Defaults
1628//
1629type Defaults struct {
1630 android.ModuleBase
1631 android.DefaultsModuleBase
1632}
1633
Jiyong Park30ca9372019-02-07 16:27:23 +09001634func defaultsFactory() android.Module {
1635 return DefaultsFactory()
1636}
1637
1638func DefaultsFactory(props ...interface{}) android.Module {
1639 module := &Defaults{}
1640
1641 module.AddProperties(props...)
1642 module.AddProperties(
1643 &apexBundleProperties{},
1644 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09001645 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09001646 )
1647
1648 android.InitDefaultsModule(module)
1649 return module
1650}
Jiyong Park5d790c32019-11-15 18:40:32 +09001651
1652//
1653// OverrideApex
1654//
1655type OverrideApex struct {
1656 android.ModuleBase
1657 android.OverrideModuleBase
1658}
1659
1660func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1661 // All the overrides happen in the base module.
1662}
1663
1664// override_apex is used to create an apex module based on another apex module
1665// by overriding some of its properties.
1666func overrideApexFactory() android.Module {
1667 m := &OverrideApex{}
1668 m.AddProperties(&overridableProperties{})
1669
1670 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1671 android.InitOverrideModule(m)
1672 return m
1673}