blob: f925066d4941a672eafec1683cb2e21bf2613ac0 [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 Park48ca7dc2018-10-10 14:01:00 +0900821}
822
Jiyong Park397e55e2018-10-24 21:09:55 +0900823func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100824 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700825 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900826 // Use *FarVariation* to be able to depend on modules having
827 // conflicting variations with this module. This is required since
828 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
829 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700830 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +0900831 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900832 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900833 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700834 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900835
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700836 ctx.AddFarVariationDependencies(append(target.Variations(),
837 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
838 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100839
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700840 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100841 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100842 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700843 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900844}
845
Alex Light9670d332019-01-29 18:07:33 -0800846func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
847 if ctx.Os().Class == android.Device {
848 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
849 } else {
850 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
851 if ctx.Os().Bionic() {
852 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
853 } else {
854 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
855 }
856 }
857}
858
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900859func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +0900860 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
861 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
862 }
863
Jiyong Park397e55e2018-10-24 21:09:55 +0900864 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900865 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800866
867 a.combineProperties(ctx)
868
Jiyong Park397e55e2018-10-24 21:09:55 +0900869 has32BitTarget := false
870 for _, target := range targets {
871 if target.Arch.ArchType.Multilib == "lib32" {
872 has32BitTarget = true
873 }
874 }
875 for i, target := range targets {
876 // When multilib.* is omitted for native_shared_libs, it implies
877 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700878 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +0900879 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900880 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700881 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900882
Roland Levillain630846d2019-06-26 12:48:34 +0100883 // When multilib.* is omitted for tests, it implies
884 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700885 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100886 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100887 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700888 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +0100889
Jiyong Park397e55e2018-10-24 21:09:55 +0900890 // Add native modules targetting both ABIs
891 addDependenciesForNativeModules(ctx,
892 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100893 a.properties.Multilib.Both.Binaries,
894 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700895 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900896 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900897
Alex Light3d673592019-01-18 14:37:31 -0800898 isPrimaryAbi := i == 0
899 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900900 // When multilib.* is omitted for binaries, it implies
901 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700902 ctx.AddFarVariationDependencies(append(target.Variations(),
903 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
904 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900905
906 // Add native modules targetting the first ABI
907 addDependenciesForNativeModules(ctx,
908 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100909 a.properties.Multilib.First.Binaries,
910 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700911 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900912 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900913 }
914
915 switch target.Arch.ArchType.Multilib {
916 case "lib32":
917 // Add native modules targetting 32-bit ABI
918 addDependenciesForNativeModules(ctx,
919 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100920 a.properties.Multilib.Lib32.Binaries,
921 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700922 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900923 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900924
925 addDependenciesForNativeModules(ctx,
926 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100927 a.properties.Multilib.Prefer32.Binaries,
928 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700929 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900930 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900931 case "lib64":
932 // Add native modules targetting 64-bit ABI
933 addDependenciesForNativeModules(ctx,
934 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100935 a.properties.Multilib.Lib64.Binaries,
936 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700937 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900938 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900939
940 if !has32BitTarget {
941 addDependenciesForNativeModules(ctx,
942 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100943 a.properties.Multilib.Prefer32.Binaries,
944 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700945 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900946 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900947 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700948
949 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
950 for _, sanitizer := range ctx.Config().SanitizeDevice() {
951 if sanitizer == "hwaddress" {
952 addDependenciesForNativeModules(ctx,
953 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700954 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700955 break
956 }
957 }
958 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900959 }
960
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900961 }
962
Jiyong Parkce6aadc2019-11-20 13:58:28 +0900963 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
964 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
965 // b/144532908
966 archForPrebuiltEtc := config.Arches()[0]
967 for _, arch := range config.Arches() {
968 // Prefer 64-bit arch if there is any
969 if arch.ArchType.Multilib == "lib64" {
970 archForPrebuiltEtc = arch
971 break
972 }
973 }
974 ctx.AddFarVariationDependencies([]blueprint.Variation{
975 {Mutator: "os", Variation: ctx.Os().String()},
976 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
977 }, prebuiltTag, a.properties.Prebuilts...)
978
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700979 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
980 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900981
Ulya Trafimovich44561882020-01-03 13:25:54 +0000982 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
983 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
984 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
985 javaLibTag, "jacocoagent")
986 }
987
Jiyong Park23c52b02019-02-02 13:13:47 +0900988 if String(a.properties.Key) == "" {
989 ctx.ModuleErrorf("key is missing")
990 return
991 }
992 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900993
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900994 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900995 if cert != "" {
996 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900997 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900998
999 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1000 if len(a.properties.Uses_sdks) > 0 {
1001 sdkRefs := []android.SdkRef{}
1002 for _, str := range a.properties.Uses_sdks {
1003 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1004 sdkRefs = append(sdkRefs, parsed)
1005 }
1006 a.BuildWithSdks(sdkRefs)
1007 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001008}
1009
Jiyong Park5d790c32019-11-15 18:40:32 +09001010func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1011 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1012 androidAppTag, a.overridableProperties.Apps...)
1013}
1014
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001015func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1016 // direct deps of an APEX bundle are all part of the APEX bundle
1017 return true
1018}
1019
Colin Cross0ea8ba82019-06-06 14:33:29 -07001020func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001021 moduleName := ctx.ModuleName()
1022 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1023 // we check with the pseudo module name to see if its certificate is overridden.
1024 if a.vndkApex {
1025 moduleName = vndkApexName
1026 }
1027 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001028 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001029 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001030 }
1031 return String(a.properties.Certificate)
1032}
1033
Colin Cross41955e82019-05-29 14:40:35 -07001034func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1035 switch tag {
1036 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001037 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001038 default:
1039 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001040 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001041}
1042
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001043func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001044 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001045}
1046
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001047func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1048 return proptools.Bool(a.properties.Test_only_no_hashtree)
1049}
1050
Jiyong Park7c1dc612019-01-05 11:15:24 +09001051func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001052 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001053 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001054 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001055 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001056 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001057 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001058 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001059 }
1060}
1061
Jiyong Parkf97782b2019-02-13 20:28:58 +09001062func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1063 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1064 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1065 }
1066}
1067
Jiyong Park388ef3f2019-01-28 19:47:32 +09001068func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001069 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1070 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001071 }
1072
1073 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001074 globalSanitizerNames := []string{}
1075 if a.Host() {
1076 globalSanitizerNames = ctx.Config().SanitizeHost()
1077 } else {
1078 arches := ctx.Config().SanitizeDeviceArch()
1079 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1080 globalSanitizerNames = ctx.Config().SanitizeDevice()
1081 }
1082 }
1083 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001084}
1085
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001086func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001087 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001088}
1089
1090func (a *apexBundle) PreventInstall() {
1091 a.properties.PreventInstall = true
1092}
1093
1094func (a *apexBundle) HideFromMake() {
1095 a.properties.HideFromMake = true
1096}
1097
Jiyong Park956305c2020-01-09 12:32:06 +09001098func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1099 a.properties.IsCoverageVariant = coverage
1100}
1101
Jiyong Parkf653b052019-11-18 15:39:01 +09001102// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001103func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001104 // Decide the APEX-local directory by the multilib of the library
1105 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001106 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001107 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001108 case "lib32":
1109 dirInApex = "lib"
1110 case "lib64":
1111 dirInApex = "lib64"
1112 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001113 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001114 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001115 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001116 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001117 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001118 // Special case for Bionic libs and other libs installed with them. This is
1119 // to prevent those libs from being included in the search path
1120 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1121 // those libs in the Runtime APEX are available via the legacy paths in
1122 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1123 // to the legacy paths and thus will be loaded into the default linker
1124 // namespace (aka "platform" namespace). If the libs are directly in
1125 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1126 // into the runtime linker namespace, which will result in double loading of
1127 // them, which isn't supported.
1128 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001129 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001130
Jiyong Parkf653b052019-11-18 15:39:01 +09001131 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001132 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001133}
1134
Jiyong Park1833cef2019-12-13 13:28:36 +09001135func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001136 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001137 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001138 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001139 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001140 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001141 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001142 af.symlinks = cc.Symlinks()
1143 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001144}
1145
Jiyong Park1833cef2019-12-13 13:28:36 +09001146func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001147 dirInApex := "bin"
1148 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001149 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001150}
Jiyong Park1833cef2019-12-13 13:28:36 +09001151func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001152 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001153 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1154 if err != nil {
1155 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001156 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001157 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001158 fileToCopy := android.PathForOutput(ctx, s)
1159 // NB: Since go binaries are static we don't need the module for anything here, which is
1160 // good since the go tool is a blueprint.Module not an android.Module like we would
1161 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001162 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001163}
1164
Jiyong Park1833cef2019-12-13 13:28:36 +09001165func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001166 dirInApex := filepath.Join("bin", sh.SubDir())
1167 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001168 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001169 af.symlinks = sh.Symlinks()
1170 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001171}
1172
Jooyung Han58f26ab2019-12-18 15:34:32 +09001173// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1174type javaLibrary interface {
1175 android.Module
1176 java.Dependency
1177}
1178
1179func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001180 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001181 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001182 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1183 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1184 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001185}
1186
Jiyong Park1833cef2019-12-13 13:28:36 +09001187func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001188 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1189 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001190 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001191}
1192
Jiyong Park1833cef2019-12-13 13:28:36 +09001193func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001194 android.Module
1195 Privileged() bool
1196 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001197 JacocoReportClassesFile() android.Path
Jiyong Parkf653b052019-11-18 15:39:01 +09001198}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001199 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001200 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001201 appDir = "priv-app"
1202 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001203 dirInApex := filepath.Join(appDir, pkgName)
1204 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001205 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1206 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
1207 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001208}
1209
Roland Levillain935639d2019-08-13 14:55:28 +01001210// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1211type flattenedApexContext struct {
1212 android.ModuleContext
1213}
1214
1215func (c *flattenedApexContext) InstallBypassMake() bool {
1216 return true
1217}
1218
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001219func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001220 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1221 switch a.properties.ApexType {
1222 case imageApex:
1223 if buildFlattenedAsDefault {
1224 a.suffix = imageApexSuffix
1225 } else {
1226 a.suffix = ""
1227 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001228
1229 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001230 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001231 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001232 }
1233 case zipApex:
1234 if proptools.String(a.properties.Payload_type) == "zip" {
1235 a.suffix = ""
1236 a.primaryApexType = true
1237 } else {
1238 a.suffix = zipApexSuffix
1239 }
1240 case flattenedApex:
1241 if buildFlattenedAsDefault {
1242 a.suffix = ""
1243 a.primaryApexType = true
1244 } else {
1245 a.suffix = flattenedSuffix
1246 }
Alex Light5098a612018-11-29 17:12:15 -08001247 }
1248
Roland Levillain630846d2019-06-26 12:48:34 +01001249 if len(a.properties.Tests) > 0 && !a.testApex {
1250 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1251 return
1252 }
1253
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001254 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1255
Jooyung Hane1633032019-08-01 17:41:43 +09001256 // native lib dependencies
1257 var provideNativeLibs []string
1258 var requireNativeLibs []string
1259
Jooyung Han5c998b92019-06-27 11:30:33 +09001260 // Check if "uses" requirements are met with dependent apexBundles
1261 var providedNativeSharedLibs []string
1262 useVendor := proptools.Bool(a.properties.Use_vendor)
1263 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1264 if ctx.OtherModuleDependencyTag(m) != usesTag {
1265 return
1266 }
1267 otherName := ctx.OtherModuleName(m)
1268 other, ok := m.(*apexBundle)
1269 if !ok {
1270 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1271 return
1272 }
1273 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1274 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1275 return
1276 }
1277 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1278 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1279 return
1280 }
1281 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1282 })
1283
Jiyong Parkf653b052019-11-18 15:39:01 +09001284 var filesInfo []apexFile
Alex Light778127a2019-02-27 14:19:50 -08001285 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001286 depTag := ctx.OtherModuleDependencyTag(child)
1287 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001288 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park956305c2020-01-09 12:32:06 +09001289 if depTag != keyTag && depTag != certificateTag {
1290 a.internalDeps = append(a.internalDeps, depName)
1291 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001292 switch depTag {
1293 case sharedLibTag:
1294 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001295 if cc.HasStubsVariants() {
1296 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1297 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001298 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, cc, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001299 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001300 } else {
1301 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001302 }
1303 case executableTag:
1304 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001305 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001306 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001307 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001308 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001309 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001310 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001311 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001312 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001313 } else {
Alex Light778127a2019-02-27 14:19:50 -08001314 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 +09001315 }
1316 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001317 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001318 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001319 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001320 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1321 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001322 filesInfo = append(filesInfo, af)
1323 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001324 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001325 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1326 af := apexFileForJavaLibrary(ctx, sdkLib)
1327 if !af.Ok() {
1328 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1329 return false
1330 }
1331 filesInfo = append(filesInfo, af)
1332
Jooyung Han624058e2019-12-24 18:38:06 +09001333 pf, _ := sdkLib.OutputFiles(".xml")
1334 if len(pf) != 1 {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001335 ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
1336 return false
1337 }
Jooyung Han624058e2019-12-24 18:38:06 +09001338 filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil))
Jooyung Han58f26ab2019-12-18 15:34:32 +09001339 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001340 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001341 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001342 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001343 case androidAppTag:
1344 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1345 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001346 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001347 return true // track transitive dependencies
1348 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001349 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00001350 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
1351 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001352 } else {
1353 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1354 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001355 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001356 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001357 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001358 } else {
1359 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1360 }
Roland Levillain630846d2019-06-26 12:48:34 +01001361 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001362 if ccTest, ok := child.(*cc.Module); ok {
1363 if ccTest.IsTestPerSrcAllTestsVariation() {
1364 // Multiple-output test module (where `test_per_src: true`).
1365 //
1366 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1367 // We do not add this variation to `filesInfo`, as it has no output;
1368 // however, we do add the other variations of this module as indirect
1369 // dependencies (see below).
1370 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001371 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001372 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001373 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001374 af.class = nativeTest
1375 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001376 }
Roland Levillain630846d2019-06-26 12:48:34 +01001377 } else {
1378 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1379 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001380 case keyTag:
1381 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001382 a.private_key_file = key.private_key_file
1383 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001384 } else {
1385 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001386 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001387 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001388 case certificateTag:
1389 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001390 a.container_certificate_file = dep.Certificate.Pem
1391 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001392 } else {
1393 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1394 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001395 case android.PrebuiltDepTag:
1396 // If the prebuilt is force disabled, remember to delete the prebuilt file
1397 // that might have been installed in the previous builds
1398 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1399 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1400 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001401 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001402 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001403 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001404 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001405 // We cannot use a switch statement on `depTag` here as the checked
1406 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001407 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001408 if cc, ok := child.(*cc.Module); ok {
1409 if android.InList(cc.Name(), providedNativeSharedLibs) {
1410 // If we're using a shared library which is provided from other APEX,
1411 // don't include it in this APEX
1412 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001413 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09001414 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001415 // If the dependency is a stubs lib, don't include it in this APEX,
1416 // but make sure that the lib is installed on the device.
1417 // In case no APEX is having the lib, the lib is installed to the system
1418 // partition.
1419 //
1420 // Always include if we are a host-apex however since those won't have any
1421 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09001422 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
1423 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01001424 }
Jiyong Park956305c2020-01-09 12:32:06 +09001425 a.externalDeps = append(a.externalDeps, depName)
Jooyung Hane1633032019-08-01 17:41:43 +09001426 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001427 // Don't track further
1428 return false
1429 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001430 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09001431 af.transitiveDep = true
1432 filesInfo = append(filesInfo, af)
Jiyong Park956305c2020-01-09 12:32:06 +09001433 a.internalDeps = append(a.internalDeps, depName)
1434 a.internalDeps = append(a.internalDeps, cc.AllStaticDeps()...)
Jiyong Parkf653b052019-11-18 15:39:01 +09001435 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001436 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001437 } else if cc.IsTestPerSrcDepTag(depTag) {
1438 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001439 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001440 // Handle modules created as `test_per_src` variations of a single test module:
1441 // use the name of the generated test binary (`fileToCopy`) instead of the name
1442 // of the original test module (`depName`, shared by all `test_per_src`
1443 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09001444 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001445 // these are not considered transitive dep
1446 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09001447 filesInfo = append(filesInfo, af)
1448 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001449 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001450 } else if java.IsJniDepTag(depTag) {
Jiyong Park956305c2020-01-09 12:32:06 +09001451 a.externalDeps = append(a.externalDeps, depName)
Jiyong Parkf653b052019-11-18 15:39:01 +09001452 return true
Jiyong Park956305c2020-01-09 12:32:06 +09001453 } else if java.IsStaticLibDepTag(depTag) {
1454 a.internalDeps = append(a.internalDeps, depName)
Jooyung Han9c80bae2019-08-20 17:30:57 +09001455 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001456 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001457 }
1458 }
1459 }
1460 return false
1461 })
1462
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001463 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
1464 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
1465 // via the global boot image config.
1466 if a.artApex {
1467 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
1468 dirInApex := filepath.Join("javalib", arch.String())
1469 for _, f := range files {
1470 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001471 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001472 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001473 }
1474 }
1475 }
1476
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001477 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001478 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1479 return
1480 }
1481
Jiyong Park8fd61922018-11-08 02:50:25 +09001482 // remove duplicates in filesInfo
1483 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001484 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09001485 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001486 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09001487 if e, ok := encountered[dest]; !ok {
1488 encountered[dest] = f
1489 } else {
1490 // If a module is directly included and also transitively depended on
1491 // consider it as directly included.
1492 e.transitiveDep = e.transitiveDep && f.transitiveDep
1493 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09001494 }
1495 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001496 var result []apexFile
1497 for _, v := range encountered {
1498 result = append(result, v)
1499 }
Jiyong Park8fd61922018-11-08 02:50:25 +09001500 return result
1501 }
1502 filesInfo = removeDup(filesInfo)
1503
1504 // to have consistent build rules
1505 sort.Slice(filesInfo, func(i, j int) bool {
1506 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1507 })
1508
Jiyong Park127b40b2019-09-30 16:04:35 +09001509 // check apex_available requirements
Jiyong Park3814f4d2019-12-02 13:08:53 +09001510 if !ctx.Host() && !a.testApex {
Jiyong Park583a2262019-10-08 20:55:38 +09001511 for _, fi := range filesInfo {
1512 if am, ok := fi.module.(android.ApexModule); ok {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001513 // vndk {enabled:true} implies visibility to the vndk apex
1514 if ccm, ok := fi.module.(*cc.Module); ok && ccm.IsVndk() && a.vndkApex {
1515 continue
1516 }
1517
1518 if !am.AvailableFor(ctx.ModuleName()) && !whitelistedApexAvailable(ctx.ModuleName(), a.vndkApex, fi.module) {
Jiyong Park583a2262019-10-08 20:55:38 +09001519 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
Jiyong Park3814f4d2019-12-02 13:08:53 +09001520 // don't stop so that we can report other violations in the same run
Jiyong Park583a2262019-10-08 20:55:38 +09001521 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001522 }
1523 }
1524 }
1525
Jiyong Park8fd61922018-11-08 02:50:25 +09001526 a.installDir = android.PathForModuleInstall(ctx, "apex")
1527 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001528
Jooyung Han54aca7b2019-11-20 02:26:02 +09001529 if a.properties.ApexType != zipApex {
1530 if a.properties.File_contexts == nil {
1531 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
1532 } else {
1533 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
1534 if a.Platform() {
1535 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
1536 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
1537 }
1538 }
1539 }
1540 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
1541 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
1542 return
1543 }
1544 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001545 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
1546 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
1547 // the same library in the system partition, thus effectively sharing the same libraries
1548 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
1549 // in the APEX.
1550 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
1551 a.installable() &&
1552 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09001553
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001554 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09001555 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1556
1557 a.setCertificateAndPrivateKey(ctx)
1558 if a.properties.ApexType == flattenedApex {
1559 a.buildFlattenedApex(ctx)
1560 } else {
1561 a.buildUnflattenedApex(ctx)
1562 }
1563
Jooyung Han002ab682020-01-08 01:57:58 +09001564 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09001565
1566 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001567}
1568
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001569func whitelistedApexAvailable(apex string, is_vndk bool, module android.Module) bool {
1570 key := apex
1571 key = strings.Replace(key, "test_", "", 1)
1572 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
1573 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
1574
1575 moduleName := module.Name()
1576 if strings.Contains(moduleName, "prebuilt_libclang_rt") {
1577 // This module has variants that depend on the product being built.
1578 moduleName = "prebuilt_libclang_rt"
1579 }
1580
1581 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
1582 return true
1583 }
1584
1585 return false
1586}
1587
Jooyung Han344d5432019-08-23 11:17:39 +09001588func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09001589 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001590 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001591 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09001592 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08001593 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001594 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1595 })
Alex Light5098a612018-11-29 17:12:15 -08001596 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001597 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001598 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001599 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001600 return module
1601}
Jiyong Park30ca9372019-02-07 16:27:23 +09001602
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001603func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001604 bundle := newApexBundle()
1605 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001606 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09001607 return bundle
1608}
1609
1610func testApexBundleFactory() android.Module {
1611 bundle := newApexBundle()
1612 bundle.testApex = true
1613 return bundle
1614}
1615
Jiyong Parkd1063c12019-07-17 20:08:41 +09001616func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001617 return newApexBundle()
1618}
1619
Jiyong Park30ca9372019-02-07 16:27:23 +09001620//
1621// Defaults
1622//
1623type Defaults struct {
1624 android.ModuleBase
1625 android.DefaultsModuleBase
1626}
1627
Jiyong Park30ca9372019-02-07 16:27:23 +09001628func defaultsFactory() android.Module {
1629 return DefaultsFactory()
1630}
1631
1632func DefaultsFactory(props ...interface{}) android.Module {
1633 module := &Defaults{}
1634
1635 module.AddProperties(props...)
1636 module.AddProperties(
1637 &apexBundleProperties{},
1638 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09001639 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09001640 )
1641
1642 android.InitDefaultsModule(module)
1643 return module
1644}
Jiyong Park5d790c32019-11-15 18:40:32 +09001645
1646//
1647// OverrideApex
1648//
1649type OverrideApex struct {
1650 android.ModuleBase
1651 android.OverrideModuleBase
1652}
1653
1654func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1655 // All the overrides happen in the base module.
1656}
1657
1658// override_apex is used to create an apex module based on another apex module
1659// by overriding some of its properties.
1660func overrideApexFactory() android.Module {
1661 m := &OverrideApex{}
1662 m.AddProperties(&overridableProperties{})
1663
1664 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1665 android.InitOverrideModule(m)
1666 return m
1667}