blob: b831333e68b9265e1ef71ad7d6393773e2cbb0dd [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 Park5d790c32019-11-15 18:40:32 +090067 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068
Jooyung Han31c470b2019-10-18 16:26:59 +090069 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +090070 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +090071
72 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
73 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
74 sort.Strings(*apexFileContextsInfos)
75 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
76 })
Jiyong Parkd1063c12019-07-17 20:08:41 +090077}
78
Jooyung Han31c470b2019-10-18 16:26:59 +090079func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
80 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
81 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
82}
83
Jiyong Parkd1063c12019-07-17 20:08:41 +090084func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parka308ea12019-11-15 10:38:39 +090085 ctx.BottomUp("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +090086 ctx.BottomUp("apex", apexMutator).Parallel()
87 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
88 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090089}
90
Jiyong Park48ca7dc2018-10-10 14:01:00 +090091// Mark the direct and transitive dependencies of apex bundles so that they
92// can be built for the apex bundles.
Jiyong Parka308ea12019-11-15 10:38:39 +090093func apexDepsMutator(mctx android.BottomUpMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -080094 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -080095 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090096 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +090097 depName := mctx.OtherModuleName(child)
98 // If the parent is apexBundle, this child is directly depended.
99 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800100 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800101 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
102 // non-installable apex's cannot be installed and so should not prevent libraries from being
103 // installed to the system.
104 android.UpdateApexDependency(apexBundleName, depName, directDep)
105 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900106
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900107 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900108 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900109 return true
110 } else {
111 return false
112 }
113 })
114 }
115}
116
117// Create apex variations if a module is included in APEX(s).
118func apexMutator(mctx android.BottomUpMutatorContext) {
119 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900120 am.CreateApexVariations(mctx)
Jooyung Han7a78a922019-10-08 21:59:58 +0900121 } else if a, ok := mctx.Module().(*apexBundle); ok {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900122 // apex bundle itself is mutated so that it and its modules have same
123 // apex variant.
124 apexBundleName := mctx.ModuleName()
125 mctx.CreateVariations(apexBundleName)
Jooyung Han7a78a922019-10-08 21:59:58 +0900126
127 // collects APEX list
128 if mctx.Device() && a.installable() {
129 addApexFileContextsInfos(mctx, a)
130 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900131 } else if o, ok := mctx.Module().(*OverrideApex); ok {
132 apexBundleName := o.GetOverriddenModuleName()
133 if apexBundleName == "" {
134 mctx.ModuleErrorf("base property is not set")
135 return
136 }
137 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900138 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900139
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900140}
Sundong Ahne9b55722019-09-06 17:37:42 +0900141
Jooyung Han7a78a922019-10-08 21:59:58 +0900142var (
143 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
144 apexFileContextsInfosMutex sync.Mutex
145)
146
147func apexFileContextsInfos(config android.Config) *[]string {
148 return config.Once(apexFileContextsInfosKey, func() interface{} {
149 return &[]string{}
150 }).(*[]string)
151}
152
153func addApexFileContextsInfos(ctx android.BaseModuleContext, a *apexBundle) {
154 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
155 fileContextsName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName())
156
157 apexFileContextsInfosMutex.Lock()
158 defer apexFileContextsInfosMutex.Unlock()
159 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
160 *apexFileContextsInfos = append(*apexFileContextsInfos, apexName+":"+fileContextsName)
161}
162
Sundong Ahne9b55722019-09-06 17:37:42 +0900163func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900164 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900165 var variants []string
166 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
167 case "image":
168 variants = append(variants, imageApexType, flattenedApexType)
169 case "zip":
170 variants = append(variants, zipApexType)
171 case "both":
172 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
173 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900174 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900175 return
176 }
177
178 modules := mctx.CreateLocalVariations(variants...)
179
180 for i, v := range variants {
181 switch v {
182 case imageApexType:
183 modules[i].(*apexBundle).properties.ApexType = imageApex
184 case zipApexType:
185 modules[i].(*apexBundle).properties.ApexType = zipApex
186 case flattenedApexType:
187 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900188 if !mctx.Config().FlattenApex() {
189 modules[i].(*apexBundle).MakeAsSystemExt()
190 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900191 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900192 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900193 } else if _, ok := mctx.Module().(*OverrideApex); ok {
194 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900195 }
196}
197
Jooyung Han5c998b92019-06-27 11:30:33 +0900198func apexUsesMutator(mctx android.BottomUpMutatorContext) {
199 if ab, ok := mctx.Module().(*apexBundle); ok {
200 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
201 }
202}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900203
Jooyung Handc782442019-11-01 03:14:38 +0900204var (
205 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
206)
207
208// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
209// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
210// which may cause compatibility issues. (e.g. libbinder)
211// Even though libbinder restricts its availability via 'apex_available' property and relies on
212// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
213// to avoid similar problems.
214func useVendorWhitelist(config android.Config) []string {
215 return config.Once(useVendorWhitelistKey, func() interface{} {
216 return []string{
217 // swcodec uses "vendor" variants for smaller size
218 "com.android.media.swcodec",
219 "test_com.android.media.swcodec",
220 }
221 }).([]string)
222}
223
224// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
225// called before the first call to useVendorWhitelist()
226func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
227 config.Once(useVendorWhitelistKey, func() interface{} {
228 return whitelist
229 })
230}
231
Alex Light9670d332019-01-29 18:07:33 -0800232type apexNativeDependencies struct {
233 // List of native libraries
234 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900235
Alex Light9670d332019-01-29 18:07:33 -0800236 // List of native executables
237 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900238
Roland Levillain630846d2019-06-26 12:48:34 +0100239 // List of native tests
240 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800241}
Jooyung Han344d5432019-08-23 11:17:39 +0900242
Alex Light9670d332019-01-29 18:07:33 -0800243type apexMultilibProperties struct {
244 // Native dependencies whose compile_multilib is "first"
245 First apexNativeDependencies
246
247 // Native dependencies whose compile_multilib is "both"
248 Both apexNativeDependencies
249
250 // Native dependencies whose compile_multilib is "prefer32"
251 Prefer32 apexNativeDependencies
252
253 // Native dependencies whose compile_multilib is "32"
254 Lib32 apexNativeDependencies
255
256 // Native dependencies whose compile_multilib is "64"
257 Lib64 apexNativeDependencies
258}
259
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900260type apexBundleProperties struct {
261 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000262 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800263 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900264
Jiyong Park40e26a22019-02-08 02:53:06 +0900265 // AndroidManifest.xml file used for the zip container of this APEX bundle.
266 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800267 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900268
Roland Levillain411c5842019-09-19 16:37:20 +0100269 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
270 // device (/apex/<apex_name>).
271 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900272 Apex_name *string
273
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900274 // Determines the file contexts file for setting security context to each file in this APEX bundle.
275 // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is
276 // used.
277 // Default: <name_of_this_module>
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900278 File_contexts *string
279
280 // List of native shared libs that are embedded inside this APEX bundle
281 Native_shared_libs []string
282
Roland Levillain630846d2019-06-26 12:48:34 +0100283 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900284 Binaries []string
285
286 // List of java libraries that are embedded inside this APEX bundle
287 Java_libs []string
288
289 // List of prebuilt files that are embedded inside this APEX bundle
290 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900291
Roland Levillain630846d2019-06-26 12:48:34 +0100292 // List of tests that are embedded inside this APEX bundle
293 Tests []string
294
Jiyong Parkff1458f2018-10-12 21:49:38 +0900295 // Name of the apex_key module that provides the private key to sign APEX
296 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900297
Alex Light5098a612018-11-29 17:12:15 -0800298 // The type of APEX to build. Controls what the APEX payload is. Either
299 // 'image', 'zip' or 'both'. Default: 'image'.
300 Payload_type *string
301
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900302 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
303 // or an android_app_certificate module name in the form ":module".
304 Certificate *string
305
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900306 // Whether this APEX is installable to one of the partitions. Default: true.
307 Installable *bool
308
Jiyong Parkda6eb592018-12-19 17:12:36 +0900309 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
310 // Default is false.
311 Use_vendor *bool
312
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800313 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
314 Ignore_system_library_special_case *bool
315
Alex Light9670d332019-01-29 18:07:33 -0800316 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900317
Jiyong Parkf97782b2019-02-13 20:28:58 +0900318 // List of sanitizer names that this APEX is enabled for
319 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900320
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900321 PreventInstall bool `blueprint:"mutated"`
322
323 HideFromMake bool `blueprint:"mutated"`
324
Jooyung Han5c998b92019-06-27 11:30:33 +0900325 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
326 Provide_cpp_shared_libs *bool
327
328 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
329 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100330
331 // A txt file containing list of files that are whitelisted to be included in this APEX.
332 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900333
Sundong Ahnabb64432019-10-22 13:58:29 +0900334 // package format of this apex variant; could be non-flattened, flattened, or zip.
335 // imageApex, zipApex or flattened
336 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +0900337
Jiyong Parkd1063c12019-07-17 20:08:41 +0900338 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
339 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
340 // is implied. This value affects all modules included in this APEX. In other words, they are
341 // also built with the SDKs specified here.
342 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +0900343
344 // Names of modules to be overridden. Listed modules can only be other binaries
345 // (in Make or Soong).
346 // This does not completely prevent installation of the overridden binaries, but if both
347 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
348 // from PRODUCT_PACKAGES.
349 Overrides []string
Alex Light9670d332019-01-29 18:07:33 -0800350}
351
352type apexTargetBundleProperties struct {
353 Target struct {
354 // Multilib properties only for android.
355 Android struct {
356 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900357 }
Jooyung Han344d5432019-08-23 11:17:39 +0900358
Alex Light9670d332019-01-29 18:07:33 -0800359 // Multilib properties only for host.
360 Host struct {
361 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900362 }
Jooyung Han344d5432019-08-23 11:17:39 +0900363
Alex Light9670d332019-01-29 18:07:33 -0800364 // Multilib properties only for host linux_bionic.
365 Linux_bionic struct {
366 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900367 }
Jooyung Han344d5432019-08-23 11:17:39 +0900368
Alex Light9670d332019-01-29 18:07:33 -0800369 // Multilib properties only for host linux_glibc.
370 Linux_glibc struct {
371 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900372 }
373 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900374}
375
Jiyong Park5d790c32019-11-15 18:40:32 +0900376type overridableProperties struct {
377 // List of APKs to package inside APEX
378 Apps []string
379}
380
Jiyong Park8fd61922018-11-08 02:50:25 +0900381type apexFileClass int
382
383const (
384 etc apexFileClass = iota
385 nativeSharedLib
386 nativeExecutable
Jiyong Park04480cf2019-02-06 00:16:29 +0900387 shBinary
Alex Light778127a2019-02-27 14:19:50 -0800388 pyBinary
389 goBinary
Jiyong Park8fd61922018-11-08 02:50:25 +0900390 javaSharedLib
Roland Levillain630846d2019-06-26 12:48:34 +0100391 nativeTest
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900392 app
Jiyong Park8fd61922018-11-08 02:50:25 +0900393)
394
Alex Light5098a612018-11-29 17:12:15 -0800395type apexPackaging int
396
397const (
398 imageApex apexPackaging = iota
399 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +0900400 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -0800401)
402
Sundong Ahnabb64432019-10-22 13:58:29 +0900403// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -0800404func (a apexPackaging) suffix() string {
405 switch a {
406 case imageApex:
407 return imageApexSuffix
408 case zipApex:
409 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -0800410 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100411 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800412 }
413}
414
415func (a apexPackaging) name() string {
416 switch a {
417 case imageApex:
418 return imageApexType
419 case zipApex:
420 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -0800421 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100422 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800423 }
424}
425
Jiyong Park8fd61922018-11-08 02:50:25 +0900426func (class apexFileClass) NameInMake() string {
427 switch class {
428 case etc:
429 return "ETC"
430 case nativeSharedLib:
431 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800432 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900433 return "EXECUTABLES"
434 case javaSharedLib:
435 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100436 case nativeTest:
437 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900438 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +0900439 // b/142537672 Why isn't this APP? We want to have full control over
440 // the paths and file names of the apk file under the flattend APEX.
441 // If this is set to APP, then the paths and file names are modified
442 // by the Make build system. For example, it is installed to
443 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
444 // /system/apex/<apexname>/app/<Appname> because the build system automatically
445 // appends module name (which is <apexname>.<Appname> to the path.
446 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +0900447 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100448 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900449 }
450}
451
452type apexFile struct {
453 builtFile android.Path
454 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900455 installDir string
456 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900457 module android.Module
Alex Light3d673592019-01-18 14:37:31 -0800458 symlinks []string
Jiyong Park8fd61922018-11-08 02:50:25 +0900459}
460
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900461type apexBundle struct {
462 android.ModuleBase
463 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +0900464 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900465 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900466
Jiyong Park5d790c32019-11-15 18:40:32 +0900467 properties apexBundleProperties
468 targetProperties apexTargetBundleProperties
469 vndkProperties apexVndkProperties
470 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900471
Colin Crossa4925902018-11-16 11:36:28 -0800472 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +0900473 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700474 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900475
Jiyong Park03b68dd2019-07-26 23:20:40 +0900476 prebuiltFileToDelete string
477
Jiyong Park42cca6c2019-04-01 11:15:50 +0900478 public_key_file android.Path
479 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900480
481 container_certificate_file android.Path
482 container_private_key_file android.Path
483
Jiyong Park8fd61922018-11-08 02:50:25 +0900484 // list of files to be included in this apex
485 filesInfo []apexFile
486
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900487 // list of module names that this APEX is depending on
488 externalDeps []string
489
Sundong Ahnabb64432019-10-22 13:58:29 +0900490 testApex bool
491 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000492 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +0900493 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +0900494
495 // intermediate path for apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +0900496 manifestJsonOut android.WritablePath
497 manifestJsonFullOut android.WritablePath
498 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +0900499
500 // list of commands to create symlinks for backward compatibility
501 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
502 // apex package itself(for unflattened build) or apex_manifest.json(for flattened build)
503 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
504 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +0900505
506 // Suffix of module name in Android.mk
507 // ".flattened", ".apex", ".zipapex", or ""
508 suffix string
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900509}
510
Jiyong Park397e55e2018-10-24 21:09:55 +0900511func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100512 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700513 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900514 // Use *FarVariation* to be able to depend on modules having
515 // conflicting variations with this module. This is required since
516 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
517 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700518 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +0900519 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900520 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900521 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700522 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900523
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700524 ctx.AddFarVariationDependencies(append(target.Variations(),
525 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
526 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100527
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700528 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100529 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100530 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700531 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900532}
533
Alex Light9670d332019-01-29 18:07:33 -0800534func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
535 if ctx.Os().Class == android.Device {
536 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
537 } else {
538 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
539 if ctx.Os().Bionic() {
540 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
541 } else {
542 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
543 }
544 }
545}
546
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900547func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +0900548 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
549 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
550 }
551
Jiyong Park397e55e2018-10-24 21:09:55 +0900552 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900553 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800554
555 a.combineProperties(ctx)
556
Jiyong Park397e55e2018-10-24 21:09:55 +0900557 has32BitTarget := false
558 for _, target := range targets {
559 if target.Arch.ArchType.Multilib == "lib32" {
560 has32BitTarget = true
561 }
562 }
563 for i, target := range targets {
564 // When multilib.* is omitted for native_shared_libs, it implies
565 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700566 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +0900567 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900568 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700569 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900570
Roland Levillain630846d2019-06-26 12:48:34 +0100571 // When multilib.* is omitted for tests, it implies
572 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700573 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100574 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100575 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700576 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +0100577
Jiyong Park397e55e2018-10-24 21:09:55 +0900578 // Add native modules targetting both ABIs
579 addDependenciesForNativeModules(ctx,
580 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100581 a.properties.Multilib.Both.Binaries,
582 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700583 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900584 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900585
Alex Light3d673592019-01-18 14:37:31 -0800586 isPrimaryAbi := i == 0
587 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900588 // When multilib.* is omitted for binaries, it implies
589 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700590 ctx.AddFarVariationDependencies(append(target.Variations(),
591 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
592 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900593
594 // Add native modules targetting the first ABI
595 addDependenciesForNativeModules(ctx,
596 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100597 a.properties.Multilib.First.Binaries,
598 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700599 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900600 a.getImageVariation(config))
Jaewoong Jungb9a11512019-01-15 10:47:05 -0800601
602 // When multilib.* is omitted for prebuilts, it implies multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700603 ctx.AddFarVariationDependencies(target.Variations(),
604 prebuiltTag, a.properties.Prebuilts...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900605 }
606
607 switch target.Arch.ArchType.Multilib {
608 case "lib32":
609 // Add native modules targetting 32-bit ABI
610 addDependenciesForNativeModules(ctx,
611 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100612 a.properties.Multilib.Lib32.Binaries,
613 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700614 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900615 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900616
617 addDependenciesForNativeModules(ctx,
618 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100619 a.properties.Multilib.Prefer32.Binaries,
620 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700621 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900622 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900623 case "lib64":
624 // Add native modules targetting 64-bit ABI
625 addDependenciesForNativeModules(ctx,
626 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100627 a.properties.Multilib.Lib64.Binaries,
628 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700629 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900630 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900631
632 if !has32BitTarget {
633 addDependenciesForNativeModules(ctx,
634 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100635 a.properties.Multilib.Prefer32.Binaries,
636 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700637 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900638 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900639 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700640
641 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
642 for _, sanitizer := range ctx.Config().SanitizeDevice() {
643 if sanitizer == "hwaddress" {
644 addDependenciesForNativeModules(ctx,
645 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700646 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700647 break
648 }
649 }
650 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900651 }
652
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900653 }
654
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700655 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
656 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900657
Jiyong Park23c52b02019-02-02 13:13:47 +0900658 if String(a.properties.Key) == "" {
659 ctx.ModuleErrorf("key is missing")
660 return
661 }
662 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900663
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900664 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900665 if cert != "" {
666 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900667 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900668
669 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
670 if len(a.properties.Uses_sdks) > 0 {
671 sdkRefs := []android.SdkRef{}
672 for _, str := range a.properties.Uses_sdks {
673 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
674 sdkRefs = append(sdkRefs, parsed)
675 }
676 a.BuildWithSdks(sdkRefs)
677 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900678}
679
Jiyong Park5d790c32019-11-15 18:40:32 +0900680func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
681 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
682 androidAppTag, a.overridableProperties.Apps...)
683}
684
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900685func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
686 // direct deps of an APEX bundle are all part of the APEX bundle
687 return true
688}
689
Colin Cross0ea8ba82019-06-06 14:33:29 -0700690func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900691 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
692 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000693 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900694 }
695 return String(a.properties.Certificate)
696}
697
Colin Cross41955e82019-05-29 14:40:35 -0700698func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
699 switch tag {
700 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +0900701 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700702 default:
703 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900704 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900705}
706
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900707func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900708 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900709}
710
Jiyong Park7c1dc612019-01-05 11:15:24 +0900711func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +0900712 if a.vndkApex {
713 return "vendor." + a.vndkVersion(config)
714 }
Jiyong Park7c1dc612019-01-05 11:15:24 +0900715 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Inseob Kim64c43952019-08-26 16:52:35 +0900716 return "vendor." + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900717 } else {
718 return "core"
719 }
720}
721
Jiyong Parkf97782b2019-02-13 20:28:58 +0900722func (a *apexBundle) EnableSanitizer(sanitizerName string) {
723 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
724 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
725 }
726}
727
Jiyong Park388ef3f2019-01-28 19:47:32 +0900728func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900729 if android.InList(sanitizerName, a.properties.SanitizerNames) {
730 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900731 }
732
733 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900734 globalSanitizerNames := []string{}
735 if a.Host() {
736 globalSanitizerNames = ctx.Config().SanitizeHost()
737 } else {
738 arches := ctx.Config().SanitizeDeviceArch()
739 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
740 globalSanitizerNames = ctx.Config().SanitizeDevice()
741 }
742 }
743 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900744}
745
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900746func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
747 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
748}
749
750func (a *apexBundle) PreventInstall() {
751 a.properties.PreventInstall = true
752}
753
754func (a *apexBundle) HideFromMake() {
755 a.properties.HideFromMake = true
756}
757
Martin Stjernholm279de572019-09-10 23:18:20 +0100758func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900759 // Decide the APEX-local directory by the multilib of the library
760 // In the future, we may query this to the module.
Martin Stjernholm279de572019-09-10 23:18:20 +0100761 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900762 case "lib32":
763 dirInApex = "lib"
764 case "lib64":
765 dirInApex = "lib64"
766 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100767 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700768 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +0100769 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900770 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100771 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) {
772 // Special case for Bionic libs and other libs installed with them. This is
773 // to prevent those libs from being included in the search path
774 // /apex/com.android.runtime/${LIB}. This exclusion is required because
775 // those libs in the Runtime APEX are available via the legacy paths in
776 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
777 // to the legacy paths and thus will be loaded into the default linker
778 // namespace (aka "platform" namespace). If the libs are directly in
779 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
780 // into the runtime linker namespace, which will result in double loading of
781 // them, which isn't supported.
782 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900783 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900784
Martin Stjernholm279de572019-09-10 23:18:20 +0100785 fileToCopy = ccMod.OutputFile().Path()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900786 return
787}
788
789func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkbd13e442019-03-15 18:10:35 +0900790 dirInApex = filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700791 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +0200792 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900793 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900794 fileToCopy = cc.OutputFile().Path()
795 return
796}
797
Alex Light778127a2019-02-27 14:19:50 -0800798func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) {
799 dirInApex = "bin"
800 fileToCopy = py.HostToolPath().Path()
801 return
802}
803func getCopyManifestForGoBinary(ctx android.ModuleContext, gb bootstrap.GoBinaryTool) (fileToCopy android.Path, dirInApex string) {
804 dirInApex = "bin"
805 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
806 if err != nil {
807 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
808 return
809 }
810 fileToCopy = android.PathForOutput(ctx, s)
811 return
812}
813
Jiyong Park04480cf2019-02-06 00:16:29 +0900814func getCopyManifestForShBinary(sh *android.ShBinary) (fileToCopy android.Path, dirInApex string) {
815 dirInApex = filepath.Join("bin", sh.SubDir())
816 fileToCopy = sh.OutputFile()
817 return
818}
819
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900820func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) {
821 dirInApex = "javalib"
Jiyong Park8fd61922018-11-08 02:50:25 +0900822 fileToCopy = java.DexJarFile()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900823 return
824}
825
Jiyong Park9e6c2422019-08-09 20:39:45 +0900826func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy android.Path, dirInApex string) {
827 dirInApex = "javalib"
828 // The output is only one, but for some reason, ImplementationJars returns Paths, not Path
829 implJars := java.ImplementationJars()
830 if len(implJars) != 1 {
831 panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s",
832 strings.Join(implJars.Strings(), ", ")))
833 }
834 fileToCopy = implJars[0]
835 return
836}
837
Jooyung Han39edb6c2019-11-06 16:53:07 +0900838func getCopyManifestForPrebuiltEtc(prebuilt android.PrebuiltEtcModule) (fileToCopy android.Path, dirInApex string) {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900839 dirInApex = filepath.Join("etc", prebuilt.SubDir())
840 fileToCopy = prebuilt.OutputFile()
841 return
842}
843
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900844func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
Jiyong Parkf7487312019-10-17 12:54:30 +0900845 appDir := "app"
846 if app.Privileged() {
847 appDir = "priv-app"
848 }
849 dirInApex = filepath.Join(appDir, pkgName)
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900850 fileToCopy = app.OutputFile()
851 return
852}
853
Dario Frenicde2a032019-10-27 00:29:22 +0100854func getCopyManifestForAndroidAppImport(app *java.AndroidAppImport, pkgName string) (fileToCopy android.Path, dirInApex string) {
855 appDir := "app"
856 if app.Privileged() {
857 appDir = "priv-app"
858 }
859 dirInApex = filepath.Join(appDir, pkgName)
860 fileToCopy = app.OutputFile()
861 return
862}
863
Roland Levillain935639d2019-08-13 14:55:28 +0100864// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
865type flattenedApexContext struct {
866 android.ModuleContext
867}
868
869func (c *flattenedApexContext) InstallBypassMake() bool {
870 return true
871}
872
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900873func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park8fd61922018-11-08 02:50:25 +0900874 filesInfo := []apexFile{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900875
Sundong Ahnabb64432019-10-22 13:58:29 +0900876 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
877 switch a.properties.ApexType {
878 case imageApex:
879 if buildFlattenedAsDefault {
880 a.suffix = imageApexSuffix
881 } else {
882 a.suffix = ""
883 a.primaryApexType = true
884 }
885 case zipApex:
886 if proptools.String(a.properties.Payload_type) == "zip" {
887 a.suffix = ""
888 a.primaryApexType = true
889 } else {
890 a.suffix = zipApexSuffix
891 }
892 case flattenedApex:
893 if buildFlattenedAsDefault {
894 a.suffix = ""
895 a.primaryApexType = true
896 } else {
897 a.suffix = flattenedSuffix
898 }
Alex Light5098a612018-11-29 17:12:15 -0800899 }
900
Roland Levillain630846d2019-06-26 12:48:34 +0100901 if len(a.properties.Tests) > 0 && !a.testApex {
902 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
903 return
904 }
905
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800906 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
907
Jooyung Hane1633032019-08-01 17:41:43 +0900908 // native lib dependencies
909 var provideNativeLibs []string
910 var requireNativeLibs []string
911
Jooyung Han5c998b92019-06-27 11:30:33 +0900912 // Check if "uses" requirements are met with dependent apexBundles
913 var providedNativeSharedLibs []string
914 useVendor := proptools.Bool(a.properties.Use_vendor)
915 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
916 if ctx.OtherModuleDependencyTag(m) != usesTag {
917 return
918 }
919 otherName := ctx.OtherModuleName(m)
920 other, ok := m.(*apexBundle)
921 if !ok {
922 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
923 return
924 }
925 if proptools.Bool(other.properties.Use_vendor) != useVendor {
926 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
927 return
928 }
929 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
930 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
931 return
932 }
933 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
934 })
935
Alex Light778127a2019-02-27 14:19:50 -0800936 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +0100937 depTag := ctx.OtherModuleDependencyTag(child)
938 depName := ctx.OtherModuleName(child)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900939 if _, ok := parent.(*apexBundle); ok {
940 // direct dependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900941 switch depTag {
942 case sharedLibTag:
943 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +0900944 if cc.HasStubsVariants() {
945 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
946 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100947 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Jiyong Park719b4462019-01-13 00:39:51 +0900948 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900949 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900950 } else {
951 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900952 }
953 case executableTag:
954 if cc, ok := child.(*cc.Module); ok {
955 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
Jiyong Park719b4462019-01-13 00:39:51 +0900956 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900957 return true
Jiyong Park04480cf2019-02-06 00:16:29 +0900958 } else if sh, ok := child.(*android.ShBinary); ok {
959 fileToCopy, dirInApex := getCopyManifestForShBinary(sh)
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700960 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()})
Alex Light778127a2019-02-27 14:19:50 -0800961 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
962 fileToCopy, dirInApex := getCopyManifestForPyBinary(py)
963 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, pyBinary, py, nil})
964 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
965 fileToCopy, dirInApex := getCopyManifestForGoBinary(ctx, gb)
966 // NB: Since go binaries are static we don't need the module for anything here, which is
967 // good since the go tool is a blueprint.Module not an android.Module like we would
968 // normally use.
969 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, goBinary, nil, nil})
Jiyong Parkff1458f2018-10-12 21:49:38 +0900970 } else {
Alex Light778127a2019-02-27 14:19:50 -0800971 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 +0900972 }
973 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +0900974 if javaLib, ok := child.(*java.Library); ok {
975 fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib)
Jiyong Park8fd61922018-11-08 02:50:25 +0900976 if fileToCopy == nil {
977 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
978 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +0900979 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
980 }
981 return true
982 } else if javaLib, ok := child.(*java.Import); ok {
983 fileToCopy, dirInApex := getCopyManifestForPrebuiltJavaLibrary(javaLib)
984 if fileToCopy == nil {
985 ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName)
986 } else {
987 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, javaSharedLib, javaLib, nil})
Jiyong Park8fd61922018-11-08 02:50:25 +0900988 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900989 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900990 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +0900991 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900992 }
993 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +0900994 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900995 fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
Jiyong Park719b4462019-01-13 00:39:51 +0900996 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900997 return true
Jiyong Parkff1458f2018-10-12 21:49:38 +0900998 } else {
999 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1000 }
Roland Levillain630846d2019-06-26 12:48:34 +01001001 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001002 if ccTest, ok := child.(*cc.Module); ok {
1003 if ccTest.IsTestPerSrcAllTestsVariation() {
1004 // Multiple-output test module (where `test_per_src: true`).
1005 //
1006 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1007 // We do not add this variation to `filesInfo`, as it has no output;
1008 // however, we do add the other variations of this module as indirect
1009 // dependencies (see below).
1010 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001011 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001012 // Single-output test module (where `test_per_src: false`).
1013 fileToCopy, dirInApex := getCopyManifestForExecutable(ccTest)
1014 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeTest, ccTest, nil})
Roland Levillain9b5fde92019-06-28 15:41:19 +01001015 }
Roland Levillain630846d2019-06-26 12:48:34 +01001016 return true
1017 } else {
1018 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1019 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001020 case keyTag:
1021 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001022 a.private_key_file = key.private_key_file
1023 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001024 return false
1025 } else {
1026 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001027 }
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001028 case certificateTag:
1029 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001030 a.container_certificate_file = dep.Certificate.Pem
1031 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001032 return false
1033 } else {
1034 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1035 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001036 case android.PrebuiltDepTag:
1037 // If the prebuilt is force disabled, remember to delete the prebuilt file
1038 // that might have been installed in the previous builds
1039 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1040 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1041 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001042 case androidAppTag:
1043 if ap, ok := child.(*java.AndroidApp); ok {
1044 fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1045 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
1046 return true
Dario Frenicde2a032019-10-27 00:29:22 +01001047 } else if ap, ok := child.(*java.AndroidAppImport); ok {
1048 fileToCopy, dirInApex := getCopyManifestForAndroidAppImport(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
1049 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001050 } else {
1051 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1052 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001053 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001054 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001055 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001056 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001057 // We cannot use a switch statement on `depTag` here as the checked
1058 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001059 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001060 if cc, ok := child.(*cc.Module); ok {
1061 if android.InList(cc.Name(), providedNativeSharedLibs) {
1062 // If we're using a shared library which is provided from other APEX,
1063 // don't include it in this APEX
1064 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001065 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001066 if !a.Host() && (cc.IsStubs() || cc.HasStubsVariants()) {
1067 // If the dependency is a stubs lib, don't include it in this APEX,
1068 // but make sure that the lib is installed on the device.
1069 // In case no APEX is having the lib, the lib is installed to the system
1070 // partition.
1071 //
1072 // Always include if we are a host-apex however since those won't have any
1073 // system libraries.
1074 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1075 a.externalDeps = append(a.externalDeps, cc.Name())
1076 }
Jooyung Hane1633032019-08-01 17:41:43 +09001077 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001078 // Don't track further
1079 return false
1080 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001081 fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs)
Roland Levillainf89cd092019-07-29 16:22:59 +01001082 filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil})
1083 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001084 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001085 } else if cc.IsTestPerSrcDepTag(depTag) {
1086 if cc, ok := child.(*cc.Module); ok {
1087 fileToCopy, dirInApex := getCopyManifestForExecutable(cc)
1088 // Handle modules created as `test_per_src` variations of a single test module:
1089 // use the name of the generated test binary (`fileToCopy`) instead of the name
1090 // of the original test module (`depName`, shared by all `test_per_src`
1091 // variations of that module).
1092 moduleName := filepath.Base(fileToCopy.String())
1093 filesInfo = append(filesInfo, apexFile{fileToCopy, moduleName, dirInApex, nativeTest, cc, nil})
1094 return true
1095 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001096 } else if java.IsJniDepTag(depTag) {
1097 // Do nothing for JNI dep. JNI libraries are always embedded in APK-in-APEX.
Jooyung Han9c80bae2019-08-20 17:30:57 +09001098 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001099 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001100 }
1101 }
1102 }
1103 return false
1104 })
1105
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001106 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
1107 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
1108 // via the global boot image config.
1109 if a.artApex {
1110 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
1111 dirInApex := filepath.Join("javalib", arch.String())
1112 for _, f := range files {
1113 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
1114 filesInfo = append(filesInfo, apexFile{f, localModule, dirInApex, etc, nil, nil})
1115 }
1116 }
1117 }
1118
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001119 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001120 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1121 return
1122 }
1123
Jiyong Park8fd61922018-11-08 02:50:25 +09001124 // remove duplicates in filesInfo
1125 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001126 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001127 result := []apexFile{}
1128 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001129 dest := filepath.Join(f.installDir, f.builtFile.Base())
1130 if !encountered[dest] {
1131 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001132 result = append(result, f)
1133 }
1134 }
1135 return result
1136 }
1137 filesInfo = removeDup(filesInfo)
1138
1139 // to have consistent build rules
1140 sort.Slice(filesInfo, func(i, j int) bool {
1141 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1142 })
1143
Jiyong Park127b40b2019-09-30 16:04:35 +09001144 // check apex_available requirements
Jiyong Park583a2262019-10-08 20:55:38 +09001145 if !ctx.Host() {
1146 for _, fi := range filesInfo {
1147 if am, ok := fi.module.(android.ApexModule); ok {
1148 if !am.AvailableFor(ctx.ModuleName()) {
1149 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
1150 return
1151 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001152 }
1153 }
1154 }
1155
Jiyong Park8fd61922018-11-08 02:50:25 +09001156 // prepend the name of this APEX to the module names. These names will be the names of
1157 // modules that will be defined if the APEX is flattened.
1158 for i := range filesInfo {
Sundong Ahnabb64432019-10-22 13:58:29 +09001159 filesInfo[i].moduleName = filesInfo[i].moduleName + "." + ctx.ModuleName() + a.suffix
Jiyong Park8fd61922018-11-08 02:50:25 +09001160 }
1161
Jiyong Park8fd61922018-11-08 02:50:25 +09001162 a.installDir = android.PathForModuleInstall(ctx, "apex")
1163 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001164
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001165 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09001166 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1167
1168 a.setCertificateAndPrivateKey(ctx)
1169 if a.properties.ApexType == flattenedApex {
1170 a.buildFlattenedApex(ctx)
1171 } else {
1172 a.buildUnflattenedApex(ctx)
1173 }
1174
1175 apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName())
1176 a.compatSymlinks = makeCompatSymlinks(apexName, ctx)
1177}
1178
Jooyung Han344d5432019-08-23 11:17:39 +09001179func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09001180 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001181 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001182 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09001183 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08001184 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001185 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1186 })
Alex Light5098a612018-11-29 17:12:15 -08001187 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001188 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001189 android.InitSdkAwareModule(module)
Jiyong Park5d790c32019-11-15 18:40:32 +09001190 android.InitOverridableModule(module, &module.properties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001191 return module
1192}
Jiyong Park30ca9372019-02-07 16:27:23 +09001193
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001194func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001195 bundle := newApexBundle()
1196 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001197 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09001198 return bundle
1199}
1200
1201func testApexBundleFactory() android.Module {
1202 bundle := newApexBundle()
1203 bundle.testApex = true
1204 return bundle
1205}
1206
Jiyong Parkd1063c12019-07-17 20:08:41 +09001207func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001208 return newApexBundle()
1209}
1210
Jiyong Park30ca9372019-02-07 16:27:23 +09001211//
1212// Defaults
1213//
1214type Defaults struct {
1215 android.ModuleBase
1216 android.DefaultsModuleBase
1217}
1218
Jiyong Park30ca9372019-02-07 16:27:23 +09001219func defaultsFactory() android.Module {
1220 return DefaultsFactory()
1221}
1222
1223func DefaultsFactory(props ...interface{}) android.Module {
1224 module := &Defaults{}
1225
1226 module.AddProperties(props...)
1227 module.AddProperties(
1228 &apexBundleProperties{},
1229 &apexTargetBundleProperties{},
1230 )
1231
1232 android.InitDefaultsModule(module)
1233 return module
1234}
Jiyong Park5d790c32019-11-15 18:40:32 +09001235
1236//
1237// OverrideApex
1238//
1239type OverrideApex struct {
1240 android.ModuleBase
1241 android.OverrideModuleBase
1242}
1243
1244func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1245 // All the overrides happen in the base module.
1246}
1247
1248// override_apex is used to create an apex module based on another apex module
1249// by overriding some of its properties.
1250func overrideApexFactory() android.Module {
1251 m := &OverrideApex{}
1252 m.AddProperties(&overridableProperties{})
1253
1254 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1255 android.InitOverrideModule(m)
1256 return m
1257}