blob: ae93790938cb9698d28ce1455aa0334676914c54 [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
712 jacocoReportClassesFile android.Path // only for javalibs and apps
Jiyong Parkf653b052019-11-18 15:39:01 +0900713}
714
Jiyong Park1833cef2019-12-13 13:28:36 +0900715func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
716 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +0900717 builtFile: builtFile,
718 moduleName: moduleName,
719 installDir: installDir,
720 class: class,
721 module: module,
722 }
Jiyong Park1833cef2019-12-13 13:28:36 +0900723 if module != nil {
724 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +0900725 ret.requiredModuleNames = module.RequiredModuleNames()
726 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
727 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +0900728 }
729 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +0900730}
731
732func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +0900733 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +0900734}
735
Jiyong Park7cd10e32020-01-14 09:22:18 +0900736// Path() returns path of this apex file relative to the APEX root
737func (af *apexFile) Path() string {
738 return filepath.Join(af.installDir, af.builtFile.Base())
739}
740
741// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
742func (af *apexFile) SymlinkPaths() []string {
743 var ret []string
744 for _, symlink := range af.symlinks {
745 ret = append(ret, filepath.Join(af.installDir, symlink))
746 }
747 return ret
748}
749
750func (af *apexFile) AvailableToPlatform() bool {
751 if af.module == nil {
752 return false
753 }
754 if am, ok := af.module.(android.ApexModule); ok {
755 return am.AvailableFor(android.AvailableToPlatform)
756 }
757 return false
758}
759
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900760type apexBundle struct {
761 android.ModuleBase
762 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +0900763 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900764 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900765
Jiyong Park5d790c32019-11-15 18:40:32 +0900766 properties apexBundleProperties
767 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +0900768 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900769
Jooyung Hanf21c7972019-12-16 22:32:06 +0900770 // specific to apex_vndk modules
771 vndkProperties apexVndkProperties
772
Colin Crossa4925902018-11-16 11:36:28 -0800773 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +0900774 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700775 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900776
Jiyong Park03b68dd2019-07-26 23:20:40 +0900777 prebuiltFileToDelete string
778
Jiyong Park42cca6c2019-04-01 11:15:50 +0900779 public_key_file android.Path
780 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900781
782 container_certificate_file android.Path
783 container_private_key_file android.Path
784
Jooyung Han54aca7b2019-11-20 02:26:02 +0900785 fileContexts android.Path
786
Jiyong Park8fd61922018-11-08 02:50:25 +0900787 // list of files to be included in this apex
788 filesInfo []apexFile
789
Jiyong Park956305c2020-01-09 12:32:06 +0900790 // list of module names that should be installed along with this APEX
791 requiredDeps []string
792
793 // list of module names that this APEX is depending on (to be shown via *-deps-info target)
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900794 externalDeps []string
Jiyong Park956305c2020-01-09 12:32:06 +0900795 // list of module names that this APEX is including (to be shown via *-deps-info target)
796 internalDeps []string
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900797
Sundong Ahnabb64432019-10-22 13:58:29 +0900798 testApex bool
799 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000800 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +0900801 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +0900802
Jooyung Han214bf372019-11-12 13:03:50 +0900803 manifestJsonOut android.WritablePath
804 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +0900805
Jooyung Han002ab682020-01-08 01:57:58 +0900806 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +0900807 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +0900808 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +0900809 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
810 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +0900811
812 // Suffix of module name in Android.mk
813 // ".flattened", ".apex", ".zipapex", or ""
814 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +0900815
816 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +0900817
818 // Whether to create symlink to the system file instead of having a file
819 // inside the apex or not
820 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +0900821
822 // Struct holding the merged notice file paths in different formats
823 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900824}
825
Jiyong Park397e55e2018-10-24 21:09:55 +0900826func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100827 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700828 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900829 // Use *FarVariation* to be able to depend on modules having
830 // conflicting variations with this module. This is required since
831 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
832 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700833 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +0900834 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900835 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900836 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700837 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900838
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700839 ctx.AddFarVariationDependencies(append(target.Variations(),
840 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
841 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100842
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700843 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100844 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100845 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700846 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900847}
848
Alex Light9670d332019-01-29 18:07:33 -0800849func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
850 if ctx.Os().Class == android.Device {
851 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
852 } else {
853 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
854 if ctx.Os().Bionic() {
855 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
856 } else {
857 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
858 }
859 }
860}
861
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +0900863 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
864 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
865 }
866
Jiyong Park397e55e2018-10-24 21:09:55 +0900867 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900868 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800869
870 a.combineProperties(ctx)
871
Jiyong Park397e55e2018-10-24 21:09:55 +0900872 has32BitTarget := false
873 for _, target := range targets {
874 if target.Arch.ArchType.Multilib == "lib32" {
875 has32BitTarget = true
876 }
877 }
878 for i, target := range targets {
879 // When multilib.* is omitted for native_shared_libs, it implies
880 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700881 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +0900882 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900883 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700884 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900885
Roland Levillain630846d2019-06-26 12:48:34 +0100886 // When multilib.* is omitted for tests, it implies
887 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700888 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100889 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100890 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700891 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +0100892
Jiyong Park397e55e2018-10-24 21:09:55 +0900893 // Add native modules targetting both ABIs
894 addDependenciesForNativeModules(ctx,
895 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100896 a.properties.Multilib.Both.Binaries,
897 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700898 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900899 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900900
Alex Light3d673592019-01-18 14:37:31 -0800901 isPrimaryAbi := i == 0
902 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900903 // When multilib.* is omitted for binaries, it implies
904 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700905 ctx.AddFarVariationDependencies(append(target.Variations(),
906 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
907 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900908
909 // Add native modules targetting the first ABI
910 addDependenciesForNativeModules(ctx,
911 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100912 a.properties.Multilib.First.Binaries,
913 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700914 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900915 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900916 }
917
918 switch target.Arch.ArchType.Multilib {
919 case "lib32":
920 // Add native modules targetting 32-bit ABI
921 addDependenciesForNativeModules(ctx,
922 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100923 a.properties.Multilib.Lib32.Binaries,
924 a.properties.Multilib.Lib32.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 addDependenciesForNativeModules(ctx,
929 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100930 a.properties.Multilib.Prefer32.Binaries,
931 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700932 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900933 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900934 case "lib64":
935 // Add native modules targetting 64-bit ABI
936 addDependenciesForNativeModules(ctx,
937 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100938 a.properties.Multilib.Lib64.Binaries,
939 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700940 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900941 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900942
943 if !has32BitTarget {
944 addDependenciesForNativeModules(ctx,
945 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100946 a.properties.Multilib.Prefer32.Binaries,
947 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700948 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900949 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900950 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700951
952 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
953 for _, sanitizer := range ctx.Config().SanitizeDevice() {
954 if sanitizer == "hwaddress" {
955 addDependenciesForNativeModules(ctx,
956 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700957 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700958 break
959 }
960 }
961 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900962 }
963
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900964 }
965
Jiyong Parkce6aadc2019-11-20 13:58:28 +0900966 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
967 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
968 // b/144532908
969 archForPrebuiltEtc := config.Arches()[0]
970 for _, arch := range config.Arches() {
971 // Prefer 64-bit arch if there is any
972 if arch.ArchType.Multilib == "lib64" {
973 archForPrebuiltEtc = arch
974 break
975 }
976 }
977 ctx.AddFarVariationDependencies([]blueprint.Variation{
978 {Mutator: "os", Variation: ctx.Os().String()},
979 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
980 }, prebuiltTag, a.properties.Prebuilts...)
981
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700982 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
983 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900984
Ulya Trafimovich44561882020-01-03 13:25:54 +0000985 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
986 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
987 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
988 javaLibTag, "jacocoagent")
989 }
990
Jiyong Park23c52b02019-02-02 13:13:47 +0900991 if String(a.properties.Key) == "" {
992 ctx.ModuleErrorf("key is missing")
993 return
994 }
995 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900996
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900997 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900998 if cert != "" {
999 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001000 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001001
1002 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1003 if len(a.properties.Uses_sdks) > 0 {
1004 sdkRefs := []android.SdkRef{}
1005 for _, str := range a.properties.Uses_sdks {
1006 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1007 sdkRefs = append(sdkRefs, parsed)
1008 }
1009 a.BuildWithSdks(sdkRefs)
1010 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001011}
1012
Jiyong Park5d790c32019-11-15 18:40:32 +09001013func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1014 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1015 androidAppTag, a.overridableProperties.Apps...)
1016}
1017
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001018func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1019 // direct deps of an APEX bundle are all part of the APEX bundle
1020 return true
1021}
1022
Colin Cross0ea8ba82019-06-06 14:33:29 -07001023func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001024 moduleName := ctx.ModuleName()
1025 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1026 // we check with the pseudo module name to see if its certificate is overridden.
1027 if a.vndkApex {
1028 moduleName = vndkApexName
1029 }
1030 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001031 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001032 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001033 }
1034 return String(a.properties.Certificate)
1035}
1036
Colin Cross41955e82019-05-29 14:40:35 -07001037func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1038 switch tag {
1039 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001040 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001041 default:
1042 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001043 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001044}
1045
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001046func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001047 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001048}
1049
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001050func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1051 return proptools.Bool(a.properties.Test_only_no_hashtree)
1052}
1053
Jiyong Park7c1dc612019-01-05 11:15:24 +09001054func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001055 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001056 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001057 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001058 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001059 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001060 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001061 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001062 }
1063}
1064
Jiyong Parkf97782b2019-02-13 20:28:58 +09001065func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1066 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1067 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1068 }
1069}
1070
Jiyong Park388ef3f2019-01-28 19:47:32 +09001071func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001072 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1073 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001074 }
1075
1076 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001077 globalSanitizerNames := []string{}
1078 if a.Host() {
1079 globalSanitizerNames = ctx.Config().SanitizeHost()
1080 } else {
1081 arches := ctx.Config().SanitizeDeviceArch()
1082 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1083 globalSanitizerNames = ctx.Config().SanitizeDevice()
1084 }
1085 }
1086 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001087}
1088
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001089func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001090 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001091}
1092
1093func (a *apexBundle) PreventInstall() {
1094 a.properties.PreventInstall = true
1095}
1096
1097func (a *apexBundle) HideFromMake() {
1098 a.properties.HideFromMake = true
1099}
1100
Jiyong Park956305c2020-01-09 12:32:06 +09001101func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1102 a.properties.IsCoverageVariant = coverage
1103}
1104
Jiyong Parkf653b052019-11-18 15:39:01 +09001105// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001106func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001107 // Decide the APEX-local directory by the multilib of the library
1108 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001109 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001110 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001111 case "lib32":
1112 dirInApex = "lib"
1113 case "lib64":
1114 dirInApex = "lib64"
1115 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001116 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001117 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001118 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001119 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001120 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001121 // Special case for Bionic libs and other libs installed with them. This is
1122 // to prevent those libs from being included in the search path
1123 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1124 // those libs in the Runtime APEX are available via the legacy paths in
1125 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1126 // to the legacy paths and thus will be loaded into the default linker
1127 // namespace (aka "platform" namespace). If the libs are directly in
1128 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1129 // into the runtime linker namespace, which will result in double loading of
1130 // them, which isn't supported.
1131 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001132 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001133
Jiyong Parkf653b052019-11-18 15:39:01 +09001134 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001135 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001136}
1137
Jiyong Park1833cef2019-12-13 13:28:36 +09001138func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001139 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001140 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001141 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001142 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001143 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001144 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001145 af.symlinks = cc.Symlinks()
1146 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001147}
1148
Jiyong Park1833cef2019-12-13 13:28:36 +09001149func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001150 dirInApex := "bin"
1151 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001152 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001153}
Jiyong Park1833cef2019-12-13 13:28:36 +09001154func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001155 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001156 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1157 if err != nil {
1158 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001159 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001160 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001161 fileToCopy := android.PathForOutput(ctx, s)
1162 // NB: Since go binaries are static we don't need the module for anything here, which is
1163 // good since the go tool is a blueprint.Module not an android.Module like we would
1164 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001165 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001166}
1167
Jiyong Park1833cef2019-12-13 13:28:36 +09001168func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001169 dirInApex := filepath.Join("bin", sh.SubDir())
1170 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001171 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001172 af.symlinks = sh.Symlinks()
1173 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001174}
1175
Jooyung Han58f26ab2019-12-18 15:34:32 +09001176// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1177type javaLibrary interface {
1178 android.Module
1179 java.Dependency
1180}
1181
1182func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001183 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001184 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001185 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1186 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1187 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001188}
1189
Jiyong Park1833cef2019-12-13 13:28:36 +09001190func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001191 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1192 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001193 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001194}
1195
Jiyong Park1833cef2019-12-13 13:28:36 +09001196func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001197 android.Module
1198 Privileged() bool
1199 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001200 JacocoReportClassesFile() android.Path
Jiyong Parkf653b052019-11-18 15:39:01 +09001201}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001202 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001203 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001204 appDir = "priv-app"
1205 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001206 dirInApex := filepath.Join(appDir, pkgName)
1207 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001208 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1209 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
1210 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001211}
1212
Roland Levillain935639d2019-08-13 14:55:28 +01001213// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1214type flattenedApexContext struct {
1215 android.ModuleContext
1216}
1217
1218func (c *flattenedApexContext) InstallBypassMake() bool {
1219 return true
1220}
1221
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001222func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001223 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1224 switch a.properties.ApexType {
1225 case imageApex:
1226 if buildFlattenedAsDefault {
1227 a.suffix = imageApexSuffix
1228 } else {
1229 a.suffix = ""
1230 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001231
1232 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001233 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001234 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001235 }
1236 case zipApex:
1237 if proptools.String(a.properties.Payload_type) == "zip" {
1238 a.suffix = ""
1239 a.primaryApexType = true
1240 } else {
1241 a.suffix = zipApexSuffix
1242 }
1243 case flattenedApex:
1244 if buildFlattenedAsDefault {
1245 a.suffix = ""
1246 a.primaryApexType = true
1247 } else {
1248 a.suffix = flattenedSuffix
1249 }
Alex Light5098a612018-11-29 17:12:15 -08001250 }
1251
Roland Levillain630846d2019-06-26 12:48:34 +01001252 if len(a.properties.Tests) > 0 && !a.testApex {
1253 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1254 return
1255 }
1256
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001257 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1258
Jooyung Hane1633032019-08-01 17:41:43 +09001259 // native lib dependencies
1260 var provideNativeLibs []string
1261 var requireNativeLibs []string
1262
Jooyung Han5c998b92019-06-27 11:30:33 +09001263 // Check if "uses" requirements are met with dependent apexBundles
1264 var providedNativeSharedLibs []string
1265 useVendor := proptools.Bool(a.properties.Use_vendor)
1266 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1267 if ctx.OtherModuleDependencyTag(m) != usesTag {
1268 return
1269 }
1270 otherName := ctx.OtherModuleName(m)
1271 other, ok := m.(*apexBundle)
1272 if !ok {
1273 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1274 return
1275 }
1276 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1277 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1278 return
1279 }
1280 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1281 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1282 return
1283 }
1284 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1285 })
1286
Jiyong Parkf653b052019-11-18 15:39:01 +09001287 var filesInfo []apexFile
Alex Light778127a2019-02-27 14:19:50 -08001288 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001289 depTag := ctx.OtherModuleDependencyTag(child)
1290 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001291 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park956305c2020-01-09 12:32:06 +09001292 if depTag != keyTag && depTag != certificateTag {
1293 a.internalDeps = append(a.internalDeps, depName)
1294 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001295 switch depTag {
1296 case sharedLibTag:
1297 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001298 if cc.HasStubsVariants() {
1299 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1300 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001301 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, cc, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001302 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001303 } else {
1304 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001305 }
1306 case executableTag:
1307 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001308 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001309 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001310 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001311 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001312 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001313 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001314 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001315 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001316 } else {
Alex Light778127a2019-02-27 14:19:50 -08001317 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 +09001318 }
1319 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001320 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001321 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001322 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001323 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1324 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001325 filesInfo = append(filesInfo, af)
1326 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001327 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001328 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1329 af := apexFileForJavaLibrary(ctx, sdkLib)
1330 if !af.Ok() {
1331 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1332 return false
1333 }
1334 filesInfo = append(filesInfo, af)
1335
Jooyung Han624058e2019-12-24 18:38:06 +09001336 pf, _ := sdkLib.OutputFiles(".xml")
1337 if len(pf) != 1 {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001338 ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
1339 return false
1340 }
Jooyung Han624058e2019-12-24 18:38:06 +09001341 filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil))
Jooyung Han58f26ab2019-12-18 15:34:32 +09001342 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001343 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001344 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001345 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001346 case androidAppTag:
1347 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1348 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001349 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001350 return true // track transitive dependencies
1351 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001352 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00001353 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
1354 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001355 } else {
1356 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1357 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001358 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001359 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001360 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001361 } else {
1362 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1363 }
Roland Levillain630846d2019-06-26 12:48:34 +01001364 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001365 if ccTest, ok := child.(*cc.Module); ok {
1366 if ccTest.IsTestPerSrcAllTestsVariation() {
1367 // Multiple-output test module (where `test_per_src: true`).
1368 //
1369 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1370 // We do not add this variation to `filesInfo`, as it has no output;
1371 // however, we do add the other variations of this module as indirect
1372 // dependencies (see below).
1373 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001374 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001375 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001376 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001377 af.class = nativeTest
1378 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001379 }
Roland Levillain630846d2019-06-26 12:48:34 +01001380 } else {
1381 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1382 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001383 case keyTag:
1384 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001385 a.private_key_file = key.private_key_file
1386 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001387 } else {
1388 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001389 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001390 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001391 case certificateTag:
1392 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001393 a.container_certificate_file = dep.Certificate.Pem
1394 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001395 } else {
1396 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1397 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001398 case android.PrebuiltDepTag:
1399 // If the prebuilt is force disabled, remember to delete the prebuilt file
1400 // that might have been installed in the previous builds
1401 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1402 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1403 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001404 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001405 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001406 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001407 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001408 // We cannot use a switch statement on `depTag` here as the checked
1409 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001410 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001411 if cc, ok := child.(*cc.Module); ok {
1412 if android.InList(cc.Name(), providedNativeSharedLibs) {
1413 // If we're using a shared library which is provided from other APEX,
1414 // don't include it in this APEX
1415 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001416 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09001417 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001418 // If the dependency is a stubs lib, don't include it in this APEX,
1419 // but make sure that the lib is installed on the device.
1420 // In case no APEX is having the lib, the lib is installed to the system
1421 // partition.
1422 //
1423 // Always include if we are a host-apex however since those won't have any
1424 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09001425 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
1426 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01001427 }
Jiyong Park956305c2020-01-09 12:32:06 +09001428 a.externalDeps = append(a.externalDeps, depName)
Jooyung Hane1633032019-08-01 17:41:43 +09001429 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001430 // Don't track further
1431 return false
1432 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001433 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09001434 af.transitiveDep = true
1435 filesInfo = append(filesInfo, af)
Jiyong Park956305c2020-01-09 12:32:06 +09001436 a.internalDeps = append(a.internalDeps, depName)
1437 a.internalDeps = append(a.internalDeps, cc.AllStaticDeps()...)
Jiyong Parkf653b052019-11-18 15:39:01 +09001438 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001439 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001440 } else if cc.IsTestPerSrcDepTag(depTag) {
1441 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001442 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001443 // Handle modules created as `test_per_src` variations of a single test module:
1444 // use the name of the generated test binary (`fileToCopy`) instead of the name
1445 // of the original test module (`depName`, shared by all `test_per_src`
1446 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09001447 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001448 // these are not considered transitive dep
1449 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001450 filesInfo = append(filesInfo, af)
1451 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001452 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001453 } else if java.IsJniDepTag(depTag) {
Jiyong Park956305c2020-01-09 12:32:06 +09001454 a.externalDeps = append(a.externalDeps, depName)
Jiyong Parkf653b052019-11-18 15:39:01 +09001455 return true
Jiyong Park956305c2020-01-09 12:32:06 +09001456 } else if java.IsStaticLibDepTag(depTag) {
1457 a.internalDeps = append(a.internalDeps, depName)
Jooyung Han9c80bae2019-08-20 17:30:57 +09001458 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001459 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001460 }
1461 }
1462 }
1463 return false
1464 })
1465
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001466 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
1467 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
1468 // via the global boot image config.
1469 if a.artApex {
1470 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
1471 dirInApex := filepath.Join("javalib", arch.String())
1472 for _, f := range files {
1473 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001474 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001475 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001476 }
1477 }
1478 }
1479
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001480 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001481 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1482 return
1483 }
1484
Jiyong Park8fd61922018-11-08 02:50:25 +09001485 // remove duplicates in filesInfo
1486 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001487 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001488 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001489 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001490 if e, ok := encountered[dest]; !ok {
1491 encountered[dest] = f
1492 } else {
1493 // If a module is directly included and also transitively depended on
1494 // consider it as directly included.
1495 e.transitiveDep = e.transitiveDep && f.transitiveDep
1496 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001497 }
1498 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001499 var result []apexFile
1500 for _, v := range encountered {
1501 result = append(result, v)
1502 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001503 return result
1504 }
1505 filesInfo = removeDup(filesInfo)
1506
1507 // to have consistent build rules
1508 sort.Slice(filesInfo, func(i, j int) bool {
1509 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1510 })
1511
Jiyong Park127b40b2019-09-30 16:04:35 +09001512 // check apex_available requirements
Jiyong Park3814f4d2019-12-02 13:08:53 +09001513 if !ctx.Host() && !a.testApex {
Jiyong Park583a2262019-10-08 20:55:38 +09001514 for _, fi := range filesInfo {
1515 if am, ok := fi.module.(android.ApexModule); ok {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001516 // vndk {enabled:true} implies visibility to the vndk apex
1517 if ccm, ok := fi.module.(*cc.Module); ok && ccm.IsVndk() && a.vndkApex {
1518 continue
1519 }
1520
1521 if !am.AvailableFor(ctx.ModuleName()) && !whitelistedApexAvailable(ctx.ModuleName(), a.vndkApex, fi.module) {
Jiyong Park583a2262019-10-08 20:55:38 +09001522 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
Jiyong Park3814f4d2019-12-02 13:08:53 +09001523 // don't stop so that we can report other violations in the same run
Jiyong Park583a2262019-10-08 20:55:38 +09001524 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001525 }
1526 }
1527 }
1528
Jiyong Park8fd61922018-11-08 02:50:25 +09001529 a.installDir = android.PathForModuleInstall(ctx, "apex")
1530 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001531
Jooyung Han54aca7b2019-11-20 02:26:02 +09001532 if a.properties.ApexType != zipApex {
1533 if a.properties.File_contexts == nil {
1534 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
1535 } else {
1536 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
1537 if a.Platform() {
1538 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
1539 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
1540 }
1541 }
1542 }
1543 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
1544 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
1545 return
1546 }
1547 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001548 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1549 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1550 // the same library in the system partition, thus effectively sharing the same libraries
1551 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1552 // in the APEX.
1553 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
1554 a.installable() &&
1555 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001556
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001557 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09001558 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1559
1560 a.setCertificateAndPrivateKey(ctx)
1561 if a.properties.ApexType == flattenedApex {
1562 a.buildFlattenedApex(ctx)
1563 } else {
1564 a.buildUnflattenedApex(ctx)
1565 }
1566
Jooyung Han002ab682020-01-08 01:57:58 +09001567 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09001568
1569 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001570}
1571
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001572func whitelistedApexAvailable(apex string, is_vndk bool, module android.Module) bool {
1573 key := apex
1574 key = strings.Replace(key, "test_", "", 1)
1575 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
1576 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
1577
1578 moduleName := module.Name()
1579 if strings.Contains(moduleName, "prebuilt_libclang_rt") {
1580 // This module has variants that depend on the product being built.
1581 moduleName = "prebuilt_libclang_rt"
1582 }
1583
1584 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
1585 return true
1586 }
1587
1588 return false
1589}
1590
Jooyung Han344d5432019-08-23 11:17:39 +09001591func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09001592 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001593 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001594 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09001595 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08001596 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001597 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1598 })
Alex Light5098a612018-11-29 17:12:15 -08001599 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001600 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001601 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001602 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001603 return module
1604}
Jiyong Park30ca9372019-02-07 16:27:23 +09001605
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001606func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001607 bundle := newApexBundle()
1608 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001609 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09001610 return bundle
1611}
1612
1613func testApexBundleFactory() android.Module {
1614 bundle := newApexBundle()
1615 bundle.testApex = true
1616 return bundle
1617}
1618
Jiyong Parkd1063c12019-07-17 20:08:41 +09001619func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001620 return newApexBundle()
1621}
1622
Jiyong Park30ca9372019-02-07 16:27:23 +09001623//
1624// Defaults
1625//
1626type Defaults struct {
1627 android.ModuleBase
1628 android.DefaultsModuleBase
1629}
1630
Jiyong Park30ca9372019-02-07 16:27:23 +09001631func defaultsFactory() android.Module {
1632 return DefaultsFactory()
1633}
1634
1635func DefaultsFactory(props ...interface{}) android.Module {
1636 module := &Defaults{}
1637
1638 module.AddProperties(props...)
1639 module.AddProperties(
1640 &apexBundleProperties{},
1641 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09001642 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09001643 )
1644
1645 android.InitDefaultsModule(module)
1646 return module
1647}
Jiyong Park5d790c32019-11-15 18:40:32 +09001648
1649//
1650// OverrideApex
1651//
1652type OverrideApex struct {
1653 android.ModuleBase
1654 android.OverrideModuleBase
1655}
1656
1657func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1658 // All the overrides happen in the base module.
1659}
1660
1661// override_apex is used to create an apex module based on another apex module
1662// by overriding some of its properties.
1663func overrideApexFactory() android.Module {
1664 m := &OverrideApex{}
1665 m.AddProperties(&overridableProperties{})
1666
1667 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1668 android.InitOverrideModule(m)
1669 return m
1670}