blob: 3026b609c167056a692af87c3f6ef15a84ee013c [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
48}
49
50var (
Jiyong Parkc00cbd92018-10-30 21:20:05 +090051 sharedLibTag = dependencyTag{name: "sharedLib"}
52 executableTag = dependencyTag{name: "executable"}
53 javaLibTag = dependencyTag{name: "javaLib"}
54 prebuiltTag = dependencyTag{name: "prebuilt"}
Roland Levillain630846d2019-06-26 12:48:34 +010055 testTag = dependencyTag{name: "test"}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090056 keyTag = dependencyTag{name: "key"}
57 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090058 usesTag = dependencyTag{name: "uses"}
Sundong Ahne1f05aa2019-08-27 13:55:42 +090059 androidAppTag = dependencyTag{name: "androidApp"}
Jiyong Park48ca7dc2018-10-10 14:01:00 +090060)
61
62func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +090063 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -080064 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +090065 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +090066 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -070067 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +090068 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069
Jooyung Han31c470b2019-10-18 16:26:59 +090070 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +090071 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +090072
73 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
74 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
75 sort.Strings(*apexFileContextsInfos)
76 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
77 })
Jiyong Parkd1063c12019-07-17 20:08:41 +090078}
79
Jooyung Han31c470b2019-10-18 16:26:59 +090080func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
81 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
82 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
83}
84
Jiyong Parkd1063c12019-07-17 20:08:41 +090085func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parka308ea12019-11-15 10:38:39 +090086 ctx.BottomUp("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +090087 ctx.BottomUp("apex", apexMutator).Parallel()
88 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
89 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090090}
91
Jiyong Park48ca7dc2018-10-10 14:01:00 +090092// Mark the direct and transitive dependencies of apex bundles so that they
93// can be built for the apex bundles.
Jiyong Parka308ea12019-11-15 10:38:39 +090094func apexDepsMutator(mctx android.BottomUpMutatorContext) {
Alex Lightf98087f2019-02-04 14:45:06 -080095 if a, ok := mctx.Module().(*apexBundle); ok {
Colin Crossa4925902018-11-16 11:36:28 -080096 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090097 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +090098 depName := mctx.OtherModuleName(child)
99 // If the parent is apexBundle, this child is directly depended.
100 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -0800101 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -0800102 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
103 // non-installable apex's cannot be installed and so should not prevent libraries from being
104 // installed to the system.
105 android.UpdateApexDependency(apexBundleName, depName, directDep)
106 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900107
Jiyong Park3ff16992019-12-27 14:11:47 +0900108 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
109 (directDep || am.DepIsInSameApex(mctx, child)) {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900110 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900111 return true
112 } else {
113 return false
114 }
115 })
116 }
117}
118
119// Create apex variations if a module is included in APEX(s).
120func apexMutator(mctx android.BottomUpMutatorContext) {
121 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900122 am.CreateApexVariations(mctx)
Jooyung Han54aca7b2019-11-20 02:26:02 +0900123 } else if _, ok := mctx.Module().(*apexBundle); ok {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900124 // apex bundle itself is mutated so that it and its modules have same
125 // apex variant.
126 apexBundleName := mctx.ModuleName()
127 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900128 } else if o, ok := mctx.Module().(*OverrideApex); ok {
129 apexBundleName := o.GetOverriddenModuleName()
130 if apexBundleName == "" {
131 mctx.ModuleErrorf("base property is not set")
132 return
133 }
134 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900135 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900136
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900137}
Sundong Ahne9b55722019-09-06 17:37:42 +0900138
Jooyung Han7a78a922019-10-08 21:59:58 +0900139var (
140 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
141 apexFileContextsInfosMutex sync.Mutex
142)
143
144func apexFileContextsInfos(config android.Config) *[]string {
145 return config.Once(apexFileContextsInfosKey, func() interface{} {
146 return &[]string{}
147 }).(*[]string)
148}
149
Jooyung Han54aca7b2019-11-20 02:26:02 +0900150func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900151 apexFileContextsInfosMutex.Lock()
152 defer apexFileContextsInfosMutex.Unlock()
153 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900154 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900155}
156
Sundong Ahne9b55722019-09-06 17:37:42 +0900157func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900158 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900159 var variants []string
160 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
161 case "image":
162 variants = append(variants, imageApexType, flattenedApexType)
163 case "zip":
164 variants = append(variants, zipApexType)
165 case "both":
166 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
167 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900168 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900169 return
170 }
171
172 modules := mctx.CreateLocalVariations(variants...)
173
174 for i, v := range variants {
175 switch v {
176 case imageApexType:
177 modules[i].(*apexBundle).properties.ApexType = imageApex
178 case zipApexType:
179 modules[i].(*apexBundle).properties.ApexType = zipApex
180 case flattenedApexType:
181 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900182 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900183 modules[i].(*apexBundle).MakeAsSystemExt()
184 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900185 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900186 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900187 } else if _, ok := mctx.Module().(*OverrideApex); ok {
188 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900189 }
190}
191
Jooyung Han5c998b92019-06-27 11:30:33 +0900192func apexUsesMutator(mctx android.BottomUpMutatorContext) {
193 if ab, ok := mctx.Module().(*apexBundle); ok {
194 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
195 }
196}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900197
Jooyung Handc782442019-11-01 03:14:38 +0900198var (
199 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
200)
201
202// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
203// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
204// which may cause compatibility issues. (e.g. libbinder)
205// Even though libbinder restricts its availability via 'apex_available' property and relies on
206// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
207// to avoid similar problems.
208func useVendorWhitelist(config android.Config) []string {
209 return config.Once(useVendorWhitelistKey, func() interface{} {
210 return []string{
211 // swcodec uses "vendor" variants for smaller size
212 "com.android.media.swcodec",
213 "test_com.android.media.swcodec",
214 }
215 }).([]string)
216}
217
218// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
219// called before the first call to useVendorWhitelist()
220func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
221 config.Once(useVendorWhitelistKey, func() interface{} {
222 return whitelist
223 })
224}
225
Alex Light9670d332019-01-29 18:07:33 -0800226type apexNativeDependencies struct {
227 // List of native libraries
228 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900229
Alex Light9670d332019-01-29 18:07:33 -0800230 // List of native executables
231 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900232
Roland Levillain630846d2019-06-26 12:48:34 +0100233 // List of native tests
234 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800235}
Jooyung Han344d5432019-08-23 11:17:39 +0900236
Alex Light9670d332019-01-29 18:07:33 -0800237type apexMultilibProperties struct {
238 // Native dependencies whose compile_multilib is "first"
239 First apexNativeDependencies
240
241 // Native dependencies whose compile_multilib is "both"
242 Both apexNativeDependencies
243
244 // Native dependencies whose compile_multilib is "prefer32"
245 Prefer32 apexNativeDependencies
246
247 // Native dependencies whose compile_multilib is "32"
248 Lib32 apexNativeDependencies
249
250 // Native dependencies whose compile_multilib is "64"
251 Lib64 apexNativeDependencies
252}
253
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900254type apexBundleProperties struct {
255 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000256 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800257 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900258
Jiyong Park40e26a22019-02-08 02:53:06 +0900259 // AndroidManifest.xml file used for the zip container of this APEX bundle.
260 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800261 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900262
Roland Levillain411c5842019-09-19 16:37:20 +0100263 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
264 // device (/apex/<apex_name>).
265 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900266 Apex_name *string
267
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900268 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900269 // For platform APEXes, this should points to a file under /system/sepolicy
270 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
271 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900272
273 // List of native shared libs that are embedded inside this APEX bundle
274 Native_shared_libs []string
275
Roland Levillain630846d2019-06-26 12:48:34 +0100276 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900277 Binaries []string
278
279 // List of java libraries that are embedded inside this APEX bundle
280 Java_libs []string
281
282 // List of prebuilt files that are embedded inside this APEX bundle
283 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900284
Roland Levillain630846d2019-06-26 12:48:34 +0100285 // List of tests that are embedded inside this APEX bundle
286 Tests []string
287
Jiyong Parkff1458f2018-10-12 21:49:38 +0900288 // Name of the apex_key module that provides the private key to sign APEX
289 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900290
Alex Light5098a612018-11-29 17:12:15 -0800291 // The type of APEX to build. Controls what the APEX payload is. Either
292 // 'image', 'zip' or 'both'. Default: 'image'.
293 Payload_type *string
294
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900295 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
296 // or an android_app_certificate module name in the form ":module".
297 Certificate *string
298
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900299 // Whether this APEX is installable to one of the partitions. Default: true.
300 Installable *bool
301
Jiyong Parkda6eb592018-12-19 17:12:36 +0900302 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
303 // Default is false.
304 Use_vendor *bool
305
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800306 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
307 Ignore_system_library_special_case *bool
308
Alex Light9670d332019-01-29 18:07:33 -0800309 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900310
Jiyong Parkf97782b2019-02-13 20:28:58 +0900311 // List of sanitizer names that this APEX is enabled for
312 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900313
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900314 PreventInstall bool `blueprint:"mutated"`
315
316 HideFromMake bool `blueprint:"mutated"`
317
Jooyung Han5c998b92019-06-27 11:30:33 +0900318 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
319 Provide_cpp_shared_libs *bool
320
321 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
322 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100323
324 // A txt file containing list of files that are whitelisted to be included in this APEX.
325 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900326
Sundong Ahnabb64432019-10-22 13:58:29 +0900327 // package format of this apex variant; could be non-flattened, flattened, or zip.
328 // imageApex, zipApex or flattened
329 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +0900330
Jiyong Parkd1063c12019-07-17 20:08:41 +0900331 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
332 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
333 // is implied. This value affects all modules included in this APEX. In other words, they are
334 // also built with the SDKs specified here.
335 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +0900336
Nikita Ioffec72b5dd2019-12-07 17:30:22 +0000337 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
338 // Should be only used in tests#.
339 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +0900340
341 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
342 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
343 Legacy_android10_support *bool
Alex Light9670d332019-01-29 18:07:33 -0800344}
345
346type apexTargetBundleProperties struct {
347 Target struct {
348 // Multilib properties only for android.
349 Android struct {
350 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900351 }
Jooyung Han344d5432019-08-23 11:17:39 +0900352
Alex Light9670d332019-01-29 18:07:33 -0800353 // Multilib properties only for host.
354 Host struct {
355 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900356 }
Jooyung Han344d5432019-08-23 11:17:39 +0900357
Alex Light9670d332019-01-29 18:07:33 -0800358 // Multilib properties only for host linux_bionic.
359 Linux_bionic struct {
360 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900361 }
Jooyung Han344d5432019-08-23 11:17:39 +0900362
Alex Light9670d332019-01-29 18:07:33 -0800363 // Multilib properties only for host linux_glibc.
364 Linux_glibc struct {
365 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +0900366 }
367 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900368}
369
Jiyong Park5d790c32019-11-15 18:40:32 +0900370type overridableProperties struct {
371 // List of APKs to package inside APEX
372 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -0800373
374 // Names of modules to be overridden. Listed modules can only be other binaries
375 // (in Make or Soong).
376 // This does not completely prevent installation of the overridden binaries, but if both
377 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
378 // from PRODUCT_PACKAGES.
379 Overrides []string
Jiyong Park5d790c32019-11-15 18:40:32 +0900380}
381
Alex Light5098a612018-11-29 17:12:15 -0800382type apexPackaging int
383
384const (
385 imageApex apexPackaging = iota
386 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +0900387 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -0800388)
389
Sundong Ahnabb64432019-10-22 13:58:29 +0900390// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -0800391func (a apexPackaging) suffix() string {
392 switch a {
393 case imageApex:
394 return imageApexSuffix
395 case zipApex:
396 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -0800397 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100398 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800399 }
400}
401
402func (a apexPackaging) name() string {
403 switch a {
404 case imageApex:
405 return imageApexType
406 case zipApex:
407 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -0800408 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100409 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -0800410 }
411}
412
Jiyong Parkf653b052019-11-18 15:39:01 +0900413type apexFileClass int
414
415const (
416 etc apexFileClass = iota
417 nativeSharedLib
418 nativeExecutable
419 shBinary
420 pyBinary
421 goBinary
422 javaSharedLib
423 nativeTest
424 app
425)
426
Jiyong Park8fd61922018-11-08 02:50:25 +0900427func (class apexFileClass) NameInMake() string {
428 switch class {
429 case etc:
430 return "ETC"
431 case nativeSharedLib:
432 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -0800433 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +0900434 return "EXECUTABLES"
435 case javaSharedLib:
436 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +0100437 case nativeTest:
438 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900439 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +0900440 // b/142537672 Why isn't this APP? We want to have full control over
441 // the paths and file names of the apk file under the flattend APEX.
442 // If this is set to APP, then the paths and file names are modified
443 // by the Make build system. For example, it is installed to
444 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
445 // /system/apex/<apexname>/app/<Appname> because the build system automatically
446 // appends module name (which is <apexname>.<Appname> to the path.
447 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +0900448 default:
Roland Levillain4644b222019-07-31 14:09:17 +0100449 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +0900450 }
451}
452
Jiyong Parkf653b052019-11-18 15:39:01 +0900453// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +0900454type apexFile struct {
455 builtFile android.Path
456 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +0900457 installDir string
458 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +0900459 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +0900460 // list of symlinks that will be created in installDir that point to this apexFile
461 symlinks []string
462 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +0900463 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +0900464
465 requiredModuleNames []string
466 targetRequiredModuleNames []string
467 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +0900468
469 jacocoReportClassesFile android.Path // only for javalibs and apps
Jiyong Parkf653b052019-11-18 15:39:01 +0900470}
471
Jiyong Park1833cef2019-12-13 13:28:36 +0900472func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
473 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +0900474 builtFile: builtFile,
475 moduleName: moduleName,
476 installDir: installDir,
477 class: class,
478 module: module,
479 }
Jiyong Park1833cef2019-12-13 13:28:36 +0900480 if module != nil {
481 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +0900482 ret.requiredModuleNames = module.RequiredModuleNames()
483 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
484 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +0900485 }
486 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +0900487}
488
489func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +0900490 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +0900491}
492
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900493type apexBundle struct {
494 android.ModuleBase
495 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +0900496 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900497 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900498
Jiyong Park5d790c32019-11-15 18:40:32 +0900499 properties apexBundleProperties
500 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +0900501 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900502
Jooyung Hanf21c7972019-12-16 22:32:06 +0900503 // specific to apex_vndk modules
504 vndkProperties apexVndkProperties
505
Colin Crossa4925902018-11-16 11:36:28 -0800506 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +0900507 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -0700508 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +0900509
Jiyong Park03b68dd2019-07-26 23:20:40 +0900510 prebuiltFileToDelete string
511
Jiyong Park42cca6c2019-04-01 11:15:50 +0900512 public_key_file android.Path
513 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +0900514
515 container_certificate_file android.Path
516 container_private_key_file android.Path
517
Jooyung Han54aca7b2019-11-20 02:26:02 +0900518 fileContexts android.Path
519
Jiyong Park8fd61922018-11-08 02:50:25 +0900520 // list of files to be included in this apex
521 filesInfo []apexFile
522
Jiyong Park4513f702020-01-09 02:05:18 +0000523 // list of module names that this APEX is depending on
Jiyong Parkac2bacd2019-02-20 21:49:26 +0900524 externalDeps []string
525
Sundong Ahnabb64432019-10-22 13:58:29 +0900526 testApex bool
527 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +0000528 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +0900529 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +0900530
Jooyung Han214bf372019-11-12 13:03:50 +0900531 manifestJsonOut android.WritablePath
532 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +0900533
Jooyung Han002ab682020-01-08 01:57:58 +0900534 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +0900535 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +0900536 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +0900537 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
538 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +0900539
540 // Suffix of module name in Android.mk
541 // ".flattened", ".apex", ".zipapex", or ""
542 suffix string
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900543}
544
Jiyong Park397e55e2018-10-24 21:09:55 +0900545func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +0100546 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700547 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +0900548 // Use *FarVariation* to be able to depend on modules having
549 // conflicting variations with this module. This is required since
550 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
551 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700552 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +0900553 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +0900554 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +0900555 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700556 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900557
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700558 ctx.AddFarVariationDependencies(append(target.Variations(),
559 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
560 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +0100561
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700562 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100563 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100564 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700565 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900566}
567
Alex Light9670d332019-01-29 18:07:33 -0800568func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
569 if ctx.Os().Class == android.Device {
570 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
571 } else {
572 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
573 if ctx.Os().Bionic() {
574 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
575 } else {
576 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
577 }
578 }
579}
580
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900581func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +0900582 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
583 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
584 }
585
Jiyong Park397e55e2018-10-24 21:09:55 +0900586 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +0900587 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -0800588
589 a.combineProperties(ctx)
590
Jiyong Park397e55e2018-10-24 21:09:55 +0900591 has32BitTarget := false
592 for _, target := range targets {
593 if target.Arch.ArchType.Multilib == "lib32" {
594 has32BitTarget = true
595 }
596 }
597 for i, target := range targets {
598 // When multilib.* is omitted for native_shared_libs, it implies
599 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700600 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +0900601 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900602 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700603 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900604
Roland Levillain630846d2019-06-26 12:48:34 +0100605 // When multilib.* is omitted for tests, it implies
606 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700607 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +0100608 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +0100609 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700610 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +0100611
Jiyong Park397e55e2018-10-24 21:09:55 +0900612 // Add native modules targetting both ABIs
613 addDependenciesForNativeModules(ctx,
614 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100615 a.properties.Multilib.Both.Binaries,
616 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700617 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900618 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900619
Alex Light3d673592019-01-18 14:37:31 -0800620 isPrimaryAbi := i == 0
621 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +0900622 // When multilib.* is omitted for binaries, it implies
623 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700624 ctx.AddFarVariationDependencies(append(target.Variations(),
625 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
626 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +0900627
628 // Add native modules targetting the first ABI
629 addDependenciesForNativeModules(ctx,
630 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100631 a.properties.Multilib.First.Binaries,
632 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700633 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900634 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900635 }
636
637 switch target.Arch.ArchType.Multilib {
638 case "lib32":
639 // Add native modules targetting 32-bit ABI
640 addDependenciesForNativeModules(ctx,
641 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100642 a.properties.Multilib.Lib32.Binaries,
643 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700644 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900645 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900646
647 addDependenciesForNativeModules(ctx,
648 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100649 a.properties.Multilib.Prefer32.Binaries,
650 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700651 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900652 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900653 case "lib64":
654 // Add native modules targetting 64-bit ABI
655 addDependenciesForNativeModules(ctx,
656 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100657 a.properties.Multilib.Lib64.Binaries,
658 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700659 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900660 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900661
662 if !has32BitTarget {
663 addDependenciesForNativeModules(ctx,
664 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +0100665 a.properties.Multilib.Prefer32.Binaries,
666 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700667 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +0900668 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +0900669 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700670
671 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
672 for _, sanitizer := range ctx.Config().SanitizeDevice() {
673 if sanitizer == "hwaddress" {
674 addDependenciesForNativeModules(ctx,
675 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700676 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700677 break
678 }
679 }
680 }
Jiyong Park397e55e2018-10-24 21:09:55 +0900681 }
682
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900683 }
684
Jiyong Parkce6aadc2019-11-20 13:58:28 +0900685 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
686 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
687 // b/144532908
688 archForPrebuiltEtc := config.Arches()[0]
689 for _, arch := range config.Arches() {
690 // Prefer 64-bit arch if there is any
691 if arch.ArchType.Multilib == "lib64" {
692 archForPrebuiltEtc = arch
693 break
694 }
695 }
696 ctx.AddFarVariationDependencies([]blueprint.Variation{
697 {Mutator: "os", Variation: ctx.Os().String()},
698 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
699 }, prebuiltTag, a.properties.Prebuilts...)
700
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700701 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
702 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +0900703
Ulya Trafimovich44561882020-01-03 13:25:54 +0000704 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
705 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
706 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
707 javaLibTag, "jacocoagent")
708 }
709
Jiyong Park23c52b02019-02-02 13:13:47 +0900710 if String(a.properties.Key) == "" {
711 ctx.ModuleErrorf("key is missing")
712 return
713 }
714 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900715
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900716 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +0900717 if cert != "" {
718 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900719 }
Jiyong Parkd1063c12019-07-17 20:08:41 +0900720
721 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
722 if len(a.properties.Uses_sdks) > 0 {
723 sdkRefs := []android.SdkRef{}
724 for _, str := range a.properties.Uses_sdks {
725 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
726 sdkRefs = append(sdkRefs, parsed)
727 }
728 a.BuildWithSdks(sdkRefs)
729 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900730}
731
Jiyong Park5d790c32019-11-15 18:40:32 +0900732func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
733 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
734 androidAppTag, a.overridableProperties.Apps...)
735}
736
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900737func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
738 // direct deps of an APEX bundle are all part of the APEX bundle
739 return true
740}
741
Colin Cross0ea8ba82019-06-06 14:33:29 -0700742func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +0900743 moduleName := ctx.ModuleName()
744 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
745 // we check with the pseudo module name to see if its certificate is overridden.
746 if a.vndkApex {
747 moduleName = vndkApexName
748 }
749 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900750 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000751 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900752 }
753 return String(a.properties.Certificate)
754}
755
Colin Cross41955e82019-05-29 14:40:35 -0700756func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
757 switch tag {
758 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +0900759 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700760 default:
761 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +0900762 }
Jiyong Park74e240b2018-11-27 21:27:08 +0900763}
764
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900765func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900766 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900767}
768
Nikita Ioffec72b5dd2019-12-07 17:30:22 +0000769func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
770 return proptools.Bool(a.properties.Test_only_no_hashtree)
771}
772
Jiyong Park7c1dc612019-01-05 11:15:24 +0900773func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +0900774 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -0800775 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +0900776 }
Jiyong Park7c1dc612019-01-05 11:15:24 +0900777 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -0800778 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900779 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -0800780 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +0900781 }
782}
783
Jiyong Parkf97782b2019-02-13 20:28:58 +0900784func (a *apexBundle) EnableSanitizer(sanitizerName string) {
785 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
786 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
787 }
788}
789
Jiyong Park388ef3f2019-01-28 19:47:32 +0900790func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +0900791 if android.InList(sanitizerName, a.properties.SanitizerNames) {
792 return true
Jiyong Park235e67c2019-02-09 11:50:56 +0900793 }
794
795 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +0900796 globalSanitizerNames := []string{}
797 if a.Host() {
798 globalSanitizerNames = ctx.Config().SanitizeHost()
799 } else {
800 arches := ctx.Config().SanitizeDeviceArch()
801 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
802 globalSanitizerNames = ctx.Config().SanitizeDevice()
803 }
804 }
805 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +0900806}
807
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900808func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
809 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
810}
811
812func (a *apexBundle) PreventInstall() {
813 a.properties.PreventInstall = true
814}
815
816func (a *apexBundle) HideFromMake() {
817 a.properties.HideFromMake = true
818}
819
Jiyong Parkf653b052019-11-18 15:39:01 +0900820// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +0900821func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900822 // Decide the APEX-local directory by the multilib of the library
823 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +0900824 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +0100825 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900826 case "lib32":
827 dirInApex = "lib"
828 case "lib64":
829 dirInApex = "lib64"
830 }
Martin Stjernholm279de572019-09-10 23:18:20 +0100831 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700832 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +0100833 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900834 }
Jiyong Park1833cef2019-12-13 13:28:36 +0900835 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +0100836 // Special case for Bionic libs and other libs installed with them. This is
837 // to prevent those libs from being included in the search path
838 // /apex/com.android.runtime/${LIB}. This exclusion is required because
839 // those libs in the Runtime APEX are available via the legacy paths in
840 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
841 // to the legacy paths and thus will be loaded into the default linker
842 // namespace (aka "platform" namespace). If the libs are directly in
843 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
844 // into the runtime linker namespace, which will result in double loading of
845 // them, which isn't supported.
846 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +0900847 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900848
Jiyong Parkf653b052019-11-18 15:39:01 +0900849 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +0900850 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900851}
852
Jiyong Park1833cef2019-12-13 13:28:36 +0900853func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +0900854 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -0700855 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +0200856 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +0900857 }
Jiyong Parkf653b052019-11-18 15:39:01 +0900858 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +0900859 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +0900860 af.symlinks = cc.Symlinks()
861 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900862}
863
Jiyong Park1833cef2019-12-13 13:28:36 +0900864func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +0900865 dirInApex := "bin"
866 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +0900867 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -0800868}
Jiyong Park1833cef2019-12-13 13:28:36 +0900869func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +0900870 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -0800871 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
872 if err != nil {
873 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +0900874 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -0800875 }
Jiyong Parkf653b052019-11-18 15:39:01 +0900876 fileToCopy := android.PathForOutput(ctx, s)
877 // NB: Since go binaries are static we don't need the module for anything here, which is
878 // good since the go tool is a blueprint.Module not an android.Module like we would
879 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +0900880 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -0800881}
882
Jiyong Park1833cef2019-12-13 13:28:36 +0900883func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +0900884 dirInApex := filepath.Join("bin", sh.SubDir())
885 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +0900886 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +0900887 af.symlinks = sh.Symlinks()
888 return af
Jiyong Park04480cf2019-02-06 00:16:29 +0900889}
890
Jooyung Han58f26ab2019-12-18 15:34:32 +0900891// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
892type javaLibrary interface {
893 android.Module
894 java.Dependency
895}
896
897func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +0900898 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +0900899 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +0900900 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
901 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
902 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900903}
904
Jiyong Park1833cef2019-12-13 13:28:36 +0900905func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +0900906 dirInApex := filepath.Join("etc", prebuilt.SubDir())
907 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +0900908 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900909}
910
Jiyong Park1833cef2019-12-13 13:28:36 +0900911func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +0900912 android.Module
913 Privileged() bool
914 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +0900915 JacocoReportClassesFile() android.Path
Jiyong Parkf653b052019-11-18 15:39:01 +0900916}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +0900917 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +0900918 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +0900919 appDir = "priv-app"
920 }
Jiyong Parkf653b052019-11-18 15:39:01 +0900921 dirInApex := filepath.Join(appDir, pkgName)
922 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +0900923 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
924 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
925 return af
Dario Frenicde2a032019-10-27 00:29:22 +0100926}
927
Roland Levillain935639d2019-08-13 14:55:28 +0100928// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
929type flattenedApexContext struct {
930 android.ModuleContext
931}
932
933func (c *flattenedApexContext) InstallBypassMake() bool {
934 return true
935}
936
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900937func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +0900938 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
939 switch a.properties.ApexType {
940 case imageApex:
941 if buildFlattenedAsDefault {
942 a.suffix = imageApexSuffix
943 } else {
944 a.suffix = ""
945 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +0900946
947 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park4513f702020-01-09 02:05:18 +0000948 a.externalDeps = append(a.externalDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +0900949 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900950 }
951 case zipApex:
952 if proptools.String(a.properties.Payload_type) == "zip" {
953 a.suffix = ""
954 a.primaryApexType = true
955 } else {
956 a.suffix = zipApexSuffix
957 }
958 case flattenedApex:
959 if buildFlattenedAsDefault {
960 a.suffix = ""
961 a.primaryApexType = true
962 } else {
963 a.suffix = flattenedSuffix
964 }
Alex Light5098a612018-11-29 17:12:15 -0800965 }
966
Roland Levillain630846d2019-06-26 12:48:34 +0100967 if len(a.properties.Tests) > 0 && !a.testApex {
968 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
969 return
970 }
971
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800972 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
973
Jooyung Hane1633032019-08-01 17:41:43 +0900974 // native lib dependencies
975 var provideNativeLibs []string
976 var requireNativeLibs []string
977
Jooyung Han5c998b92019-06-27 11:30:33 +0900978 // Check if "uses" requirements are met with dependent apexBundles
979 var providedNativeSharedLibs []string
980 useVendor := proptools.Bool(a.properties.Use_vendor)
981 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
982 if ctx.OtherModuleDependencyTag(m) != usesTag {
983 return
984 }
985 otherName := ctx.OtherModuleName(m)
986 other, ok := m.(*apexBundle)
987 if !ok {
988 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
989 return
990 }
991 if proptools.Bool(other.properties.Use_vendor) != useVendor {
992 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
993 return
994 }
995 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
996 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
997 return
998 }
999 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1000 })
1001
Jiyong Parkf653b052019-11-18 15:39:01 +09001002 var filesInfo []apexFile
Alex Light778127a2019-02-27 14:19:50 -08001003 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001004 depTag := ctx.OtherModuleDependencyTag(child)
1005 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001006 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001007 switch depTag {
1008 case sharedLibTag:
1009 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09001010 if cc.HasStubsVariants() {
1011 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
1012 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001013 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, cc, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001014 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001015 } else {
1016 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001017 }
1018 case executableTag:
1019 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001020 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001021 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001022 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001023 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001024 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001025 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001026 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001027 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001028 } else {
Alex Light778127a2019-02-27 14:19:50 -08001029 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 +09001030 }
1031 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001032 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001033 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001034 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001035 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1036 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001037 filesInfo = append(filesInfo, af)
1038 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001039 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001040 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1041 af := apexFileForJavaLibrary(ctx, sdkLib)
1042 if !af.Ok() {
1043 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1044 return false
1045 }
1046 filesInfo = append(filesInfo, af)
1047
Jooyung Han624058e2019-12-24 18:38:06 +09001048 pf, _ := sdkLib.OutputFiles(".xml")
1049 if len(pf) != 1 {
Jooyung Han58f26ab2019-12-18 15:34:32 +09001050 ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
1051 return false
1052 }
Jooyung Han624058e2019-12-24 18:38:06 +09001053 filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil))
Jooyung Han58f26ab2019-12-18 15:34:32 +09001054 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001055 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001056 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001057 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001058 case androidAppTag:
1059 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1060 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001061 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001062 return true // track transitive dependencies
1063 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001064 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00001065 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
1066 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001067 } else {
1068 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1069 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001070 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001071 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001072 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001073 } else {
1074 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName)
1075 }
Roland Levillain630846d2019-06-26 12:48:34 +01001076 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001077 if ccTest, ok := child.(*cc.Module); ok {
1078 if ccTest.IsTestPerSrcAllTestsVariation() {
1079 // Multiple-output test module (where `test_per_src: true`).
1080 //
1081 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1082 // We do not add this variation to `filesInfo`, as it has no output;
1083 // however, we do add the other variations of this module as indirect
1084 // dependencies (see below).
1085 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001086 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001087 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001088 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001089 af.class = nativeTest
1090 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001091 }
Roland Levillain630846d2019-06-26 12:48:34 +01001092 } else {
1093 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1094 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001095 case keyTag:
1096 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001097 a.private_key_file = key.private_key_file
1098 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001099 } else {
1100 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001101 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001102 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001103 case certificateTag:
1104 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001105 a.container_certificate_file = dep.Certificate.Pem
1106 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001107 } else {
1108 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
1109 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09001110 case android.PrebuiltDepTag:
1111 // If the prebuilt is force disabled, remember to delete the prebuilt file
1112 // that might have been installed in the previous builds
1113 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
1114 a.prebuiltFileToDelete = prebuilt.InstallFilename()
1115 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001116 }
Jooyung Han8aee2042019-10-29 05:08:31 +09001117 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001118 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09001119 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01001120 // We cannot use a switch statement on `depTag` here as the checked
1121 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09001122 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001123 if cc, ok := child.(*cc.Module); ok {
1124 if android.InList(cc.Name(), providedNativeSharedLibs) {
1125 // If we're using a shared library which is provided from other APEX,
1126 // don't include it in this APEX
1127 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001128 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09001129 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001130 // If the dependency is a stubs lib, don't include it in this APEX,
1131 // but make sure that the lib is installed on the device.
1132 // In case no APEX is having the lib, the lib is installed to the system
1133 // partition.
1134 //
1135 // Always include if we are a host-apex however since those won't have any
1136 // system libraries.
Jiyong Park4513f702020-01-09 02:05:18 +00001137 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) {
1138 a.externalDeps = append(a.externalDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01001139 }
Jooyung Hane1633032019-08-01 17:41:43 +09001140 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01001141 // Don't track further
1142 return false
1143 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001144 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09001145 af.transitiveDep = true
1146 filesInfo = append(filesInfo, af)
1147 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09001148 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001149 } else if cc.IsTestPerSrcDepTag(depTag) {
1150 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001151 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01001152 // Handle modules created as `test_per_src` variations of a single test module:
1153 // use the name of the generated test binary (`fileToCopy`) instead of the name
1154 // of the original test module (`depName`, shared by all `test_per_src`
1155 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09001156 af.moduleName = filepath.Base(af.builtFile.String())
1157 af.transitiveDep = true
1158 filesInfo = append(filesInfo, af)
1159 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01001160 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09001161 } else if java.IsJniDepTag(depTag) {
Jiyong Park4513f702020-01-09 02:05:18 +00001162 // Do nothing for JNI dep. JNI libraries are always embedded in APK-in-APEX.
Jiyong Parkf653b052019-11-18 15:39:01 +09001163 return true
Jooyung Han9c80bae2019-08-20 17:30:57 +09001164 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01001165 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001166 }
1167 }
1168 }
1169 return false
1170 })
1171
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001172 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
1173 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
1174 // via the global boot image config.
1175 if a.artApex {
1176 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
1177 dirInApex := filepath.Join("javalib", arch.String())
1178 for _, f := range files {
1179 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09001180 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09001181 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001182 }
1183 }
1184 }
1185
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001186 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09001187 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
1188 return
1189 }
1190
Jiyong Park8fd61922018-11-08 02:50:25 +09001191 // remove duplicates in filesInfo
1192 removeDup := func(filesInfo []apexFile) []apexFile {
Jooyung Han344d5432019-08-23 11:17:39 +09001193 encountered := make(map[string]bool)
Jiyong Park8fd61922018-11-08 02:50:25 +09001194 result := []apexFile{}
1195 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09001196 dest := filepath.Join(f.installDir, f.builtFile.Base())
1197 if !encountered[dest] {
1198 encountered[dest] = true
Jiyong Park8fd61922018-11-08 02:50:25 +09001199 result = append(result, f)
1200 }
1201 }
1202 return result
1203 }
1204 filesInfo = removeDup(filesInfo)
1205
1206 // to have consistent build rules
1207 sort.Slice(filesInfo, func(i, j int) bool {
1208 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
1209 })
1210
Jiyong Park127b40b2019-09-30 16:04:35 +09001211 // check apex_available requirements
Jiyong Park3814f4d2019-12-02 13:08:53 +09001212 if !ctx.Host() && !a.testApex {
Jiyong Park583a2262019-10-08 20:55:38 +09001213 for _, fi := range filesInfo {
1214 if am, ok := fi.module.(android.ApexModule); ok {
1215 if !am.AvailableFor(ctx.ModuleName()) {
1216 ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name())
Jiyong Park3814f4d2019-12-02 13:08:53 +09001217 // don't stop so that we can report other violations in the same run
Jiyong Park583a2262019-10-08 20:55:38 +09001218 }
Jiyong Park127b40b2019-09-30 16:04:35 +09001219 }
1220 }
1221 }
1222
Jiyong Park8fd61922018-11-08 02:50:25 +09001223 // prepend the name of this APEX to the module names. These names will be the names of
1224 // modules that will be defined if the APEX is flattened.
1225 for i := range filesInfo {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08001226 filesInfo[i].moduleName = filesInfo[i].moduleName + "." + a.Name() + a.suffix
Jiyong Park8fd61922018-11-08 02:50:25 +09001227 }
1228
Jiyong Park8fd61922018-11-08 02:50:25 +09001229 a.installDir = android.PathForModuleInstall(ctx, "apex")
1230 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08001231
Jooyung Han54aca7b2019-11-20 02:26:02 +09001232 if a.properties.ApexType != zipApex {
1233 if a.properties.File_contexts == nil {
1234 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
1235 } else {
1236 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
1237 if a.Platform() {
1238 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
1239 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
1240 }
1241 }
1242 }
1243 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
1244 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
1245 return
1246 }
1247 }
1248
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001249 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09001250 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
1251
1252 a.setCertificateAndPrivateKey(ctx)
1253 if a.properties.ApexType == flattenedApex {
1254 a.buildFlattenedApex(ctx)
1255 } else {
1256 a.buildUnflattenedApex(ctx)
1257 }
1258
Jooyung Han002ab682020-01-08 01:57:58 +09001259 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09001260}
1261
Jooyung Han344d5432019-08-23 11:17:39 +09001262func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09001263 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001264 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08001265 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09001266 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08001267 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09001268 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
1269 })
Alex Light5098a612018-11-29 17:12:15 -08001270 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001271 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001272 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001273 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001274 return module
1275}
Jiyong Park30ca9372019-02-07 16:27:23 +09001276
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001277func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001278 bundle := newApexBundle()
1279 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001280 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09001281 return bundle
1282}
1283
1284func testApexBundleFactory() android.Module {
1285 bundle := newApexBundle()
1286 bundle.testApex = true
1287 return bundle
1288}
1289
Jiyong Parkd1063c12019-07-17 20:08:41 +09001290func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09001291 return newApexBundle()
1292}
1293
Jiyong Park30ca9372019-02-07 16:27:23 +09001294//
1295// Defaults
1296//
1297type Defaults struct {
1298 android.ModuleBase
1299 android.DefaultsModuleBase
1300}
1301
Jiyong Park30ca9372019-02-07 16:27:23 +09001302func defaultsFactory() android.Module {
1303 return DefaultsFactory()
1304}
1305
1306func DefaultsFactory(props ...interface{}) android.Module {
1307 module := &Defaults{}
1308
1309 module.AddProperties(props...)
1310 module.AddProperties(
1311 &apexBundleProperties{},
1312 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09001313 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09001314 )
1315
1316 android.InitDefaultsModule(module)
1317 return module
1318}
Jiyong Park5d790c32019-11-15 18:40:32 +09001319
1320//
1321// OverrideApex
1322//
1323type OverrideApex struct {
1324 android.ModuleBase
1325 android.OverrideModuleBase
1326}
1327
1328func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1329 // All the overrides happen in the base module.
1330}
1331
1332// override_apex is used to create an apex module based on another apex module
1333// by overriding some of its properties.
1334func overrideApexFactory() android.Module {
1335 m := &OverrideApex{}
1336 m.AddProperties(&overridableProperties{})
1337
1338 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1339 android.InitOverrideModule(m)
1340 return m
1341}