blob: 03714f7fe949b1d825bf74829bfe1d14273801b3 [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"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090019 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090020 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090022 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023
24 "android/soong/android"
25 "android/soong/cc"
26 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080027 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090028
29 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080030 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090031 "github.com/google/blueprint/proptools"
32)
33
Jooyung Han72bd2f82019-10-23 16:46:38 +090034const (
35 imageApexSuffix = ".apex"
36 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090037 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080038
Sundong Ahnabb64432019-10-22 13:58:29 +090039 imageApexType = "image"
40 zipApexType = "zip"
41 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090042)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090043
44type dependencyTag struct {
45 blueprint.BaseDependencyTag
46 name string
47}
48
49var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +090050 sharedLibTag = dependencyTag{name: "sharedLib"}
51 executableTag = dependencyTag{name: "executable"}
52 javaLibTag = dependencyTag{name: "javaLib"}
53 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +010054 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090055 keyTag = dependencyTag{name: "key"}
56 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090057 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +090058 androidAppTag = dependencyTag{name: "androidApp"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +090059)
60
61func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +090062 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -080063 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +090064 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +090065 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -070066 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067
Jooyung Han31c470b2019-10-18 16:26:59 +090068 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +090069 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +090070
71 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
72 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
73 sort.Strings(*apexFileContextsInfos)
74 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
75 })
Jiyong Parkd1063c12019-07-17 20:08:41 +090076}
77
Jooyung Han31c470b2019-10-18 16:26:59 +090078func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
79 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
80 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
81}
82
Jiyong Parkd1063c12019-07-17 20:08:41 +090083func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parka308ea12019-11-15 10:38:39 +090084 ctx.BottomUp("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +090085 ctx.BottomUp("apex", apexMutator).Parallel()
86 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
87 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090088}
89
Jiyong Park48ca7dc2018-10-10 14:01:00 +090090// Mark the direct and transitive dependencies of apex bundles so that they
91// can be built for the apex bundles.
Jiyong Parka308ea12019-11-15 10:38:39 +090092func apexDepsMutator(mctx android.BottomUpMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -080093 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -080094 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090095 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +090096 depName := mctx.OtherModuleName(child)
97 // If the parent is apexBundle, this child is directly depended.
98 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -080099 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800100 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
101 // non-installable apex's cannot be installed and so should not prevent libraries from being
102 // installed to the system.
103 android.UpdateApexDependency(apexBundleName, depName, directDep)
104 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900105
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900106 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900107 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900108 return true
109 } else {
110 return false
111 }
112 })
113 }
114}
115
116// Create apex variations if a module is included in APEX(s).
117func apexMutator(mctx android.BottomUpMutatorContext) {
118 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900119 am.CreateApexVariations(mctx)
Jooyung Han7a78a922019-10-08 21:59:58 +0900120 } else if a, ok := mctx.Module().(*apexBundle); ok {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900121 // apex bundle itself is mutated so that it and its modules have same
122 // apex variant.
123 apexBundleName := mctx.ModuleName()
124 mctx.CreateVariations(apexBundleName)
Jooyung Han7a78a922019-10-08 21:59:58 +0900125
126 // collects APEX list
127 if mctx.Device() && a.installable() {
128 addApexFileContextsInfos(mctx, a)
129 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900130 }
131}
Sundong Ahne9b55722019-09-06 17:37:42 +0900132
Jooyung Han7a78a922019-10-08 21:59:58 +0900133var (
134 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
135 apexFileContextsInfosMutex sync.Mutex
136)
137
138func apexFileContextsInfos(config android.Config) *[]string {
139 return config.Once(apexFileContextsInfosKey, func() interface{} {
140 return &[]string{}
141 }).(*[]string)
142}
143
144func addApexFileContextsInfos(ctx android.BaseModuleContext, a *apexBundle) {
145 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
146 fileContextsName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
147
148 apexFileContextsInfosMutex.Lock()
149 defer apexFileContextsInfosMutex.Unlock()
150 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
151 *apexFileContextsInfos = append(*apexFileContextsInfos, apexName+":"+fileContextsName)
152}
153
Sundong Ahne9b55722019-09-06 17:37:42 +0900154func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900155 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900156 var variants []string
157 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
158 case "image":
159 variants = append(variants, imageApexType, flattenedApexType)
160 case "zip":
161 variants = append(variants, zipApexType)
162 case "both":
163 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
164 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900165 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900166 return
167 }
168
169 modules := mctx.CreateLocalVariations(variants...)
170
171 for i, v := range variants {
172 switch v {
173 case imageApexType:
174 modules[i].(*apexBundle).properties.ApexType = imageApex
175 case zipApexType:
176 modules[i].(*apexBundle).properties.ApexType = zipApex
177 case flattenedApexType:
178 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900179 if !mctx.Config().FlattenApex() {
180 modules[i].(*apexBundle).MakeAsSystemExt()
181 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900182 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900183 }
184 }
185}
186
Jooyung Han5c998b92019-06-27 11:30:33 +0900187func apexUsesMutator(mctx android.BottomUpMutatorContext) {
188 if ab, ok := mctx.Module().(*apexBundle); ok {
189 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
190 }
191}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900192
Jooyung Handc782442019-11-01 03:14:38 +0900193var (
194 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
195)
196
197// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
198// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
199// which may cause compatibility issues. (e.g. libbinder)
200// Even though libbinder restricts its availability via 'apex_available' property and relies on
201// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
202// to avoid similar problems.
203func useVendorWhitelist(config android.Config) []string {
204 return config.Once(useVendorWhitelistKey, func() interface{} {
205 return []string{
206 // swcodec uses "vendor" variants for smaller size
207 "com.android.media.swcodec",
208 "test_com.android.media.swcodec",
209 }
210 }).([]string)
211}
212
213// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
214// called before the first call to useVendorWhitelist()
215func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
216 config.Once(useVendorWhitelistKey, func() interface{} {
217 return whitelist
218 })
219}
220
Alex Light9670d332019-01-29 18:07:33 -0800221type apexNativeDependencies struct {
222 // List of native libraries
223 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900224
Alex Light9670d332019-01-29 18:07:33 -0800225 // List of native executables
226 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900227
Roland Levillain630846d2019-06-26 12:48:34 +0100228 // List of native tests
229 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800230}
Jooyung Han344d5432019-08-23 11:17:39 +0900231
Alex Light9670d332019-01-29 18:07:33 -0800232type apexMultilibProperties struct {
233 // Native dependencies whose compile_multilib is "first"
234 First apexNativeDependencies
235
236 // Native dependencies whose compile_multilib is "both"
237 Both apexNativeDependencies
238
239 // Native dependencies whose compile_multilib is "prefer32"
240 Prefer32 apexNativeDependencies
241
242 // Native dependencies whose compile_multilib is "32"
243 Lib32 apexNativeDependencies
244
245 // Native dependencies whose compile_multilib is "64"
246 Lib64 apexNativeDependencies
247}
248
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900249type apexBundleProperties struct {
250 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000251 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800252 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900253
Jiyong Park40e26a22019-02-08 02:53:06 +0900254 // AndroidManifest.xml file used for the zip container of this APEX bundle.
255 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800256 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900257
Roland Levillain411c5842019-09-19 16:37:20 +0100258 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
259 // device (/apex/<apex_name>).
260 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900261 Apex_name *string
262
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900263 // Determines the file contexts file for setting security context to each file in this APEX bundle.
264 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
265 // used.
266 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900267 File_contexts *string
268
269 // List of native shared libs that are embedded inside this APEX bundle
270 Native_shared_libs []string
271
Roland Levillain630846d2019-06-26 12:48:34 +0100272 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900273 Binaries []string
274
275 // List of java libraries that are embedded inside this APEX bundle
276 Java_libs []string
277
278 // List of prebuilt files that are embedded inside this APEX bundle
279 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900280
Roland Levillain630846d2019-06-26 12:48:34 +0100281 // List of tests that are embedded inside this APEX bundle
282 Tests []string
283
Jiyong Parkff1458f2018-10-12 21:49:38 +0900284 // Name of the apex_key module that provides the private key to sign APEX
285 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900286
Alex Light5098a612018-11-29 17:12:15 -0800287 // The type of APEX to build. Controls what the APEX payload is. Either
288 // 'image', 'zip' or 'both'. Default: 'image'.
289 Payload_type *string
290
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900291 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
292 // or an android_app_certificate module name in the form ":module".
293 Certificate *string
294
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900295 // Whether this APEX is installable to one of the partitions. Default: true.
296 Installable *bool
297
Jiyong Parkda6eb592018-12-19 17:12:36 +0900298 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
299 // Default is false.
300 Use_vendor *bool
301
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800302 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
303 Ignore_system_library_special_case *bool
304
Alex Light9670d332019-01-29 18:07:33 -0800305 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900306
Jiyong Parkf97782b2019-02-13 20:28:58 +0900307 // List of sanitizer names that this APEX is enabled for
308 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900309
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900310 PreventInstall bool `blueprint:"mutated"`
311
312 HideFromMake bool `blueprint:"mutated"`
313
Jooyung Han5c998b92019-06-27 11:30:33 +0900314 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
315 Provide_cpp_shared_libs *bool
316
317 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
318 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100319
320 // A txt file containing list of files that are whitelisted to be included in this APEX.
321 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900322
323 // List of APKs to package inside APEX
324 Apps []string
Sundong Ahne9b55722019-09-06 17:37:42 +0900325
Sundong Ahnabb64432019-10-22 13:58:29 +0900326 // package format of this apex variant; could be non-flattened, flattened, or zip.
327 // imageApex, zipApex or flattened
328 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +0900329
Jiyong Parkd1063c12019-07-17 20:08:41 +0900330 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
331 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
332 // is implied. This value affects all modules included in this APEX. In other words, they are
333 // also built with the SDKs specified here.
334 Uses_sdks []string
Alex Light9670d332019-01-29 18:07:33 -0800335}
336
337type apexTargetBundleProperties struct {
338 Target struct {
339 // Multilib properties only for android.
340 Android struct {
341 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900342 }
Jooyung Han344d5432019-08-23 11:17:39 +0900343
Alex Light9670d332019-01-29 18:07:33 -0800344 // Multilib properties only for host.
345 Host struct {
346 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900347 }
Jooyung Han344d5432019-08-23 11:17:39 +0900348
Alex Light9670d332019-01-29 18:07:33 -0800349 // Multilib properties only for host linux_bionic.
350 Linux_bionic struct {
351 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900352 }
Jooyung Han344d5432019-08-23 11:17:39 +0900353
Alex Light9670d332019-01-29 18:07:33 -0800354 // Multilib properties only for host linux_glibc.
355 Linux_glibc struct {
356 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900357 }
358 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900359}
360
Jiyong Park8fd61922018-11-08 02:50:25 +0900361type apexFileClass int
362
363const (
364 etc apexFileClass = iota
365 nativeSharedLib
366 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900367 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800368 pyBinary
369 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900370 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100371 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900372 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900373)
374
Alex Light5098a612018-11-29 17:12:15 -0800375type apexPackaging int
376
377const (
378 imageApex apexPackaging = iota
379 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +0900380 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -0800381)
382
Sundong Ahnabb64432019-10-22 13:58:29 +0900383// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -0800384func (a apexPackaging) suffix() string {
385 switch a {
386 case imageApex:
387 return imageApexSuffix
388 case zipApex:
389 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -0800390 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100391 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800392 }
393}
394
395func (a apexPackaging) name() string {
396 switch a {
397 case imageApex:
398 return imageApexType
399 case zipApex:
400 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -0800401 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100402 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800403 }
404}
405
Jiyong Park8fd61922018-11-08 02:50:25 +0900406func (class apexFileClass) NameInMake() string {
407 switch class {
408 case etc:
409 return "ETC"
410 case nativeSharedLib:
411 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800412 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900413 return "EXECUTABLES"
414 case javaSharedLib:
415 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100416 case nativeTest:
417 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900418 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +0900419 // b/142537672 Why isn't this APP? We want to have full control over
420 // the paths and file names of the apk file under the flattend APEX.
421 // If this is set to APP, then the paths and file names are modified
422 // by the Make build system. For example, it is installed to
423 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
424 // /system/apex/<apexname>/app/<Appname> because the build system automatically
425 // appends module name (which is <apexname>.<Appname> to the path.
426 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +0900427 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100428 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900429 }
430}
431
432type apexFile struct {
433 builtFile android.Path
434 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900435 installDir string
436 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900437 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800438 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900439}
440
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900441type apexBundle struct {
442 android.ModuleBase
443 android.DefaultableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900444 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900445
Alex Light9670d332019-01-29 18:07:33 -0800446 properties apexBundleProperties
447 targetProperties apexTargetBundleProperties
Jooyung Han344d5432019-08-23 11:17:39 +0900448 vndkProperties apexVndkProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900449
Colin Crossa4925902018-11-16 11:36:28 -0800450 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +0900451 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700452 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900453
Jiyong Park03b68dd2019-07-26 23:20:40 +0900454 prebuiltFileToDelete string
455
Jiyong Park42cca6c2019-04-01 11:15:50 +0900456 public_key_file android.Path
457 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900458
459 container_certificate_file android.Path
460 container_private_key_file android.Path
461
Jiyong Park8fd61922018-11-08 02:50:25 +0900462 // list of files to be included in this apex
463 filesInfo []apexFile
464
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900465 // list of module names that this APEX is depending on
466 externalDeps []string
467
Sundong Ahnabb64432019-10-22 13:58:29 +0900468 testApex bool
469 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000470 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +0900471 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +0900472
473 // intermediate path for apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +0900474 manifestJsonOut android.WritablePath
475 manifestJsonFullOut android.WritablePath
476 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +0900477
478 // list of commands to create symlinks for backward compatibility
479 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
480 // apex package itself(for unflattened build) or apex_manifest.json(for flattened build)
481 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
482 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +0900483
484 // Suffix of module name in Android.mk
485 // ".flattened", ".apex", ".zipapex", or ""
486 suffix string
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900487}
488
Jiyong Park397e55e2018-10-24 21:09:55 +0900489func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100490 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700491 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900492 // Use *FarVariation* to be able to depend on modules having
493 // conflicting variations with this module. This is required since
494 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
495 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700496 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +0900497 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900498 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900499 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700500 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900501
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700502 ctx.AddFarVariationDependencies(append(target.Variations(),
503 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
504 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100505
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700506 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100507 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100508 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700509 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900510}
511
Alex Light9670d332019-01-29 18:07:33 -0800512func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
513 if ctx.Os().Class == android.Device {
514 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
515 } else {
516 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
517 if ctx.Os().Bionic() {
518 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
519 } else {
520 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
521 }
522 }
523}
524
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900525func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +0900526 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
527 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
528 }
529
Jiyong Park397e55e2018-10-24 21:09:55 +0900530 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900531 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800532
533 a.combineProperties(ctx)
534
Jiyong Park397e55e2018-10-24 21:09:55 +0900535 has32BitTarget := false
536 for _, target := range targets {
537 if target.Arch.ArchType.Multilib == "lib32" {
538 has32BitTarget = true
539 }
540 }
541 for i, target := range targets {
542 // When multilib.* is omitted for native_shared_libs, it implies
543 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700544 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +0900545 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900546 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700547 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900548
Roland Levillain630846d2019-06-26 12:48:34 +0100549 // When multilib.* is omitted for tests, it implies
550 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700551 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100552 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100553 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700554 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +0100555
Jiyong Park397e55e2018-10-24 21:09:55 +0900556 // Add native modules targetting both ABIs
557 addDependenciesForNativeModules(ctx,
558 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100559 a.properties.Multilib.Both.Binaries,
560 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700561 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900562 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900563
Alex Light3d673592019-01-18 14:37:31 -0800564 isPrimaryAbi := i == 0
565 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900566 // When multilib.* is omitted for binaries, it implies
567 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700568 ctx.AddFarVariationDependencies(append(target.Variations(),
569 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
570 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900571
572 // Add native modules targetting the first ABI
573 addDependenciesForNativeModules(ctx,
574 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100575 a.properties.Multilib.First.Binaries,
576 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700577 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900578 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900579 }
580
581 switch target.Arch.ArchType.Multilib {
582 case "lib32":
583 // Add native modules targetting 32-bit ABI
584 addDependenciesForNativeModules(ctx,
585 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100586 a.properties.Multilib.Lib32.Binaries,
587 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700588 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900589 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900590
591 addDependenciesForNativeModules(ctx,
592 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100593 a.properties.Multilib.Prefer32.Binaries,
594 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700595 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900596 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900597 case "lib64":
598 // Add native modules targetting 64-bit ABI
599 addDependenciesForNativeModules(ctx,
600 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100601 a.properties.Multilib.Lib64.Binaries,
602 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700603 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900604 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900605
606 if !has32BitTarget {
607 addDependenciesForNativeModules(ctx,
608 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100609 a.properties.Multilib.Prefer32.Binaries,
610 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700611 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900612 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900613 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700614
615 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
616 for _, sanitizer := range ctx.Config().SanitizeDevice() {
617 if sanitizer == "hwaddress" {
618 addDependenciesForNativeModules(ctx,
619 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700620 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700621 break
622 }
623 }
624 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900625 }
626
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900627 }
628
Jiyong Parkce6aadc2019-11-20 13:58:28 +0900629 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
630 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
631 // b/144532908
632 archForPrebuiltEtc := config.Arches()[0]
633 for _, arch := range config.Arches() {
634 // Prefer 64-bit arch if there is any
635 if arch.ArchType.Multilib == "lib64" {
636 archForPrebuiltEtc = arch
637 break
638 }
639 }
640 ctx.AddFarVariationDependencies([]blueprint.Variation{
641 {Mutator: "os", Variation: ctx.Os().String()},
642 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
643 }, prebuiltTag, a.properties.Prebuilts...)
644
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700645 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
646 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900647
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700648 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
649 androidAppTag, a.properties.Apps...)
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900650
Jiyong Park23c52b02019-02-02 13:13:47 +0900651 if String(a.properties.Key) == "" {
652 ctx.ModuleErrorf("key is missing")
653 return
654 }
655 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900656
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900657 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900658 if cert != "" {
659 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900660 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900661
662 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
663 if len(a.properties.Uses_sdks) > 0 {
664 sdkRefs := []android.SdkRef{}
665 for _, str := range a.properties.Uses_sdks {
666 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
667 sdkRefs = append(sdkRefs, parsed)
668 }
669 a.BuildWithSdks(sdkRefs)
670 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900671}
672
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900673func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
674 // direct deps of an APEX bundle are all part of the APEX bundle
675 return true
676}
677
Colin Cross0ea8ba82019-06-06 14:33:29 -0700678func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900679 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
680 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000681 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900682 }
683 return String(a.properties.Certificate)
684}
685
Colin Cross41955e82019-05-29 14:40:35 -0700686func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
687 switch tag {
688 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +0900689 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700690 default:
691 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900692 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900693}
694
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900695func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900696 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900697}
698
Jiyong Park7c1dc612019-01-05 11:15:24 +0900699func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +0900700 if a.vndkApex {
701 return "vendor." + a.vndkVersion(config)
702 }
Jiyong Park7c1dc612019-01-05 11:15:24 +0900703 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900704 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900705 } else {
706 return "core"
707 }
708}
709
Jiyong Parkf97782b2019-02-13 20:28:58 +0900710func (a *apexBundle) EnableSanitizer(sanitizerName string) {
711 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
712 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
713 }
714}
715
Jiyong Park388ef3f2019-01-28 19:47:32 +0900716func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900717 if android.InList(sanitizerName, a.properties.SanitizerNames) {
718 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900719 }
720
721 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900722 globalSanitizerNames := []string{}
723 if a.Host() {
724 globalSanitizerNames = ctx.Config().SanitizeHost()
725 } else {
726 arches := ctx.Config().SanitizeDeviceArch()
727 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
728 globalSanitizerNames = ctx.Config().SanitizeDevice()
729 }
730 }
731 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900732}
733
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900734func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
735 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
736}
737
738func (a *apexBundle) PreventInstall() {
739 a.properties.PreventInstall = true
740}
741
742func (a *apexBundle) HideFromMake() {
743 a.properties.HideFromMake = true
744}
745
Martin Stjernholm279de572019-09-10 23:18:20 +0100746func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900747 // Decide the APEX-local directory by the multilib of the library
748 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100749 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900750 case "lib32":
751 dirInApex = "lib"
752 case "lib64":
753 dirInApex = "lib64"
754 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100755 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700756 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +0100757 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900758 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100759 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
760 // Special case for Bionic libs and other libs installed with them. This is
761 // to prevent those libs from being included in the search path
762 // /apex/com.android.runtime/${LIB}. This exclusion is required because
763 // those libs in the Runtime APEX are available via the legacy paths in
764 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
765 // to the legacy paths and thus will be loaded into the default linker
766 // namespace (aka "platform" namespace). If the libs are directly in
767 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
768 // into the runtime linker namespace, which will result in double loading of
769 // them, which isn't supported.
770 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900771 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900772
Martin Stjernholm279de572019-09-10 23:18:20 +0100773 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900774 return
775}
776
777func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900778 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700779 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +0200780 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900781 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900782 fileToCopy = cc.OutputFile().Path()
783 return
784}
785
Alex Light778127a2019-02-27 14:19:50 -0800786func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
787 dirInApex = "bin"
788 fileToCopy = py.HostToolPath().Path()
789 return
790}
791func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
792 dirInApex = "bin"
793 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
794 if err != nil {
795 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
796 return
797 }
798 fileToCopy = android.PathForOutput(ctx, s)
799 return
800}
801
Jiyong Park04480cf2019-02-06 00:16:29 +0900802func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
803 dirInApex = filepath.Join("bin", sh.SubDir())
804 fileToCopy = sh.OutputFile()
805 return
806}
807
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900808func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
809 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900810 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900811 return
812}
813
Jiyong Park9e6c2422019-08-09 20:39:45 +0900814func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
815 dirInApex = "javalib"
816 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
817 implJars := java.ImplementationJars()
818 if len(implJars) != 1 {
819 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
820 strings.Join(implJars.Strings(), ", ")))
821 }
822 fileToCopy = implJars[0]
823 return
824}
825
Jooyung Han39edb6c2019-11-06 16:53:07 +0900826func getCopyManifestForPrebuiltEtc(prebuilt android.PrebuiltEtcModule) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900827 dirInApex = filepath.Join("etc", prebuilt.SubDir())
828 fileToCopy = prebuilt.OutputFile()
829 return
830}
831
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900832func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkf7487312019-10-17 12:54:30 +0900833 appDir := "app"
834 if app.Privileged() {
835 appDir = "priv-app"
836 }
837 dirInApex = filepath.Join(appDir, pkgName)
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900838 fileToCopy = app.OutputFile()
839 return
840}
841
Dario Frenicde2a032019-10-27 00:29:22 +0100842func getCopyManifestForAndroidAppImport(app *java.AndroidAppImport, pkgName string) (fileToCopy android.Path, dirInApex string) {
843 appDir := "app"
844 if app.Privileged() {
845 appDir = "priv-app"
846 }
847 dirInApex = filepath.Join(appDir, pkgName)
848 fileToCopy = app.OutputFile()
849 return
850}
851
Roland Levillain935639d2019-08-13 14:55:28 +0100852// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
853type flattenedApexContext struct {
854 android.ModuleContext
855}
856
857func (c *flattenedApexContext) InstallBypassMake() bool {
858 return true
859}
860
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900861func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900862 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900863
Sundong Ahnabb64432019-10-22 13:58:29 +0900864 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
865 switch a.properties.ApexType {
866 case imageApex:
867 if buildFlattenedAsDefault {
868 a.suffix = imageApexSuffix
869 } else {
870 a.suffix = ""
871 a.primaryApexType = true
872 }
873 case zipApex:
874 if proptools.String(a.properties.Payload_type) == "zip" {
875 a.suffix = ""
876 a.primaryApexType = true
877 } else {
878 a.suffix = zipApexSuffix
879 }
880 case flattenedApex:
881 if buildFlattenedAsDefault {
882 a.suffix = ""
883 a.primaryApexType = true
884 } else {
885 a.suffix = flattenedSuffix
886 }
Alex Light5098a612018-11-29 17:12:15 -0800887 }
888
Roland Levillain630846d2019-06-26 12:48:34 +0100889 if len(a.properties.Tests) > 0 && !a.testApex {
890 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
891 return
892 }
893
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800894 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
895
Jooyung Hane1633032019-08-01 17:41:43 +0900896 // native lib dependencies
897 var provideNativeLibs []string
898 var requireNativeLibs []string
899
Jooyung Han5c998b92019-06-27 11:30:33 +0900900 // Check if "uses" requirements are met with dependent apexBundles
901 var providedNativeSharedLibs []string
902 useVendor := proptools.Bool(a.properties.Use_vendor)
903 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
904 if ctx.OtherModuleDependencyTag(m) != usesTag {
905 return
906 }
907 otherName := ctx.OtherModuleName(m)
908 other, ok := m.(*apexBundle)
909 if !ok {
910 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
911 return
912 }
913 if proptools.Bool(other.properties.Use_vendor) != useVendor {
914 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
915 return
916 }
917 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
918 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
919 return
920 }
921 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
922 })
923
Alex Light778127a2019-02-27 14:19:50 -0800924 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +0100925 depTag := ctx.OtherModuleDependencyTag(child)
926 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900927 if _, ok := parent.(*apexBundle); ok {
928 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900929 switch depTag {
930 case sharedLibTag:
931 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +0900932 if cc.HasStubsVariants() {
933 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
934 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100935 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900936 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900937 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900938 } else {
939 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900940 }
941 case executableTag:
942 if cc, ok := child.(*cc.Module); ok {
943 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +0900944 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900945 return true
Jiyong Park04480cf2019-02-06 00:16:29 +0900946 } else if sh, ok := child.(*android.ShBinary); ok {
947 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700948 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()})
Alex Light778127a2019-02-27 14:19:50 -0800949 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
950 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
951 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
952 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
953 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
954 // NB: Since go binaries are static we don't need the module for anything here, which is
955 // good since the go tool is a blueprint.Module not an android.Module like we would
956 // normally use.
957 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +0900958 } else {
Alex Light778127a2019-02-27 14:19:50 -0800959 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 +0900960 }
961 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +0900962 if javaLib, ok := child.(*java.Library); ok {
963 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +0900964 if fileToCopy == nil {
965 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
966 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +0900967 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
968 }
969 return true
970 } else if javaLib, ok := child.(*java.Import); ok {
971 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
972 if fileToCopy == nil {
973 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
974 } else {
975 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +0900976 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900977 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900978 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +0900979 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900980 }
981 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +0900982 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900983 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +0900984 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900985 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900986 } else {
987 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
988 }
Roland Levillain630846d2019-06-26 12:48:34 +0100989 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +0100990 if ccTest, ok := child.(*cc.Module); ok {
991 if ccTest.IsTestPerSrcAllTestsVariation() {
992 // Multiple-output test module (where `test_per_src: true`).
993 //
994 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
995 // We do not add this variation to `filesInfo`, as it has no output;
996 // however, we do add the other variations of this module as indirect
997 // dependencies (see below).
998 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +0100999 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001000 // Single-output test module (where `test_per_src: false`).
1001 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1002 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001003 }
Roland Levillain630846d2019-06-26 12:48:34 +01001004 return true
1005 } else {
1006 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1007 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001008 case keyTag:
1009 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001010 a.private_key_file = key.private_key_file
1011 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001012 return false
1013 } else {
1014 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001015 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001016 case certificateTag:
1017 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001018 a.container_certificate_file = dep.Certificate.Pem
1019 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001020 return false
1021 } else {
1022 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1023 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001024 case android.PrebuiltDepTag:
1025 // If the prebuilt is force disabled, remember to delete the prebuilt file
1026 // that might have been installed in the previous builds
1027 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1028 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1029 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001030 case androidAppTag:
1031 if ap, ok := child.(*java.AndroidApp); ok {
1032 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1033 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1034 return true
Dario Frenicde2a032019-10-27 00:29:22 +01001035 } else if ap, ok := child.(*java.AndroidAppImport); ok {
1036 fileToCopy, dirInApex := getCopyManifestForAndroidAppImport(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1037 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001038 } else {
1039 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1040 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001041 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001042 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001043 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001044 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001045 // We cannot use a switch statement on `depTag` here as the checked
1046 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001047 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001048 if cc, ok := child.(*cc.Module); ok {
1049 if android.InList(cc.Name(), providedNativeSharedLibs) {
1050 // If we're using a shared library which is provided from other APEX,
1051 // don't include it in this APEX
1052 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001053 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001054 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1055 // If the dependency is a stubs lib, don't include it in this APEX,
1056 // but make sure that the lib is installed on the device.
1057 // In case no APEX is having the lib, the lib is installed to the system
1058 // partition.
1059 //
1060 // Always include if we are a host-apex however since those won't have any
1061 // system libraries.
1062 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1063 a.externalDeps = append(a.externalDeps, cc.Name())
1064 }
Jooyung Hane1633032019-08-01 17:41:43 +09001065 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001066 // Don't track further
1067 return false
1068 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001069 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001070 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1071 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001072 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001073 } else if cc.IsTestPerSrcDepTag(depTag) {
1074 if cc, ok := child.(*cc.Module); ok {
1075 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1076 // Handle modules created as `test_per_src` variations of a single test module:
1077 // use the name of the generated test binary (`fileToCopy`) instead of the name
1078 // of the original test module (`depName`, shared by all `test_per_src`
1079 // variations of that module).
1080 moduleName := filepath.Base(fileToCopy.String())
1081 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1082 return true
1083 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001084 } else if java.IsJniDepTag(depTag) {
1085 // Do nothing for JNI dep. JNI libraries are always embedded in APK-in-APEX.
Jooyung Han9c80bae2019-08-20 17:30:57 +09001086 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001087 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001088 }
1089 }
1090 }
1091 return false
1092 })
1093
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001094 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
1095 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
1096 // via the global boot image config.
1097 if a.artApex {
1098 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
1099 dirInApex := filepath.Join("javalib", arch.String())
1100 for _, f := range files {
1101 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
1102 filesInfo = append(filesInfo, apexFile{f, localModule, dirInApex, etc, nil, nil})
1103 }
1104 }
1105 }
1106
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001107 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001108 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1109 return
1110 }
1111
Jiyong Park8fd61922018-11-08 02:50:25 +09001112 // remove duplicates in filesInfo
1113 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001114 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001115 result := []apexFile{}
1116 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001117 dest := filepath.Join(f.installDir, f.builtFile.Base())
1118 if !encountered[dest] {
1119 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001120 result = append(result, f)
1121 }
1122 }
1123 return result
1124 }
1125 filesInfo = removeDup(filesInfo)
1126
1127 // to have consistent build rules
1128 sort.Slice(filesInfo, func(i, j int) bool {
1129 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1130 })
1131
Jiyong Park127b40b2019-09-30 16:04:35 +09001132 // check apex_available requirements
Jiyong Park583a2262019-10-08 20:55:38 +09001133 if !ctx.Host() {
1134 for _, fi := range filesInfo {
1135 if am, ok := fi.module.(android.ApexModule); ok {
1136 if !am.AvailableFor(ctx.ModuleName()) {
1137 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
1138 return
1139 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001140 }
1141 }
1142 }
1143
Jiyong Park8fd61922018-11-08 02:50:25 +09001144 // prepend the name of this APEX to the module names. These names will be the names of
1145 // modules that will be defined if the APEX is flattened.
1146 for i := range filesInfo {
Sundong Ahnabb64432019-10-22 13:58:29 +09001147 filesInfo[i].moduleName = filesInfo[i].moduleName + "." + ctx.ModuleName() + a.suffix
Jiyong Park8fd61922018-11-08 02:50:25 +09001148 }
1149
Jiyong Park8fd61922018-11-08 02:50:25 +09001150 a.installDir = android.PathForModuleInstall(ctx, "apex")
1151 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001152
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001153 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09001154 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1155
1156 a.setCertificateAndPrivateKey(ctx)
1157 if a.properties.ApexType == flattenedApex {
1158 a.buildFlattenedApex(ctx)
1159 } else {
1160 a.buildUnflattenedApex(ctx)
1161 }
1162
1163 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
1164 a.compatSymlinks = makeCompatSymlinks(apexName, ctx)
1165}
1166
Jooyung Han344d5432019-08-23 11:17:39 +09001167func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09001168 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001169 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001170 module.AddProperties(&module.targetProperties)
Alex Light5098a612018-11-29 17:12:15 -08001171 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001172 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1173 })
Alex Light5098a612018-11-29 17:12:15 -08001174 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001175 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001176 android.InitSdkAwareModule(module)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001177 return module
1178}
Jiyong Park30ca9372019-02-07 16:27:23 +09001179
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001180func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001181 bundle := newApexBundle()
1182 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001183 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09001184 return bundle
1185}
1186
1187func testApexBundleFactory() android.Module {
1188 bundle := newApexBundle()
1189 bundle.testApex = true
1190 return bundle
1191}
1192
Jiyong Parkd1063c12019-07-17 20:08:41 +09001193func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001194 return newApexBundle()
1195}
1196
Jiyong Park30ca9372019-02-07 16:27:23 +09001197//
1198// Defaults
1199//
1200type Defaults struct {
1201 android.ModuleBase
1202 android.DefaultsModuleBase
1203}
1204
Jiyong Park30ca9372019-02-07 16:27:23 +09001205func defaultsFactory() android.Module {
1206 return DefaultsFactory()
1207}
1208
1209func DefaultsFactory(props ...interface{}) android.Module {
1210 module := &Defaults{}
1211
1212 module.AddProperties(props...)
1213 module.AddProperties(
1214 &apexBundleProperties{},
1215 &apexTargetBundleProperties{},
1216 )
1217
1218 android.InitDefaultsModule(module)
1219 return module
1220}