Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 19 | "path/filepath" |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 20 | "sort" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 21 | "strings" |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 22 | "sync" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 23 | |
| 24 | "android/soong/android" |
| 25 | "android/soong/cc" |
| 26 | "android/soong/java" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 27 | "android/soong/python" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 28 | |
| 29 | "github.com/google/blueprint" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 30 | "github.com/google/blueprint/bootstrap" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 31 | "github.com/google/blueprint/proptools" |
| 32 | ) |
| 33 | |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 34 | const ( |
| 35 | imageApexSuffix = ".apex" |
| 36 | zipApexSuffix = ".zipapex" |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 37 | flattenedSuffix = ".flattened" |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 38 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 39 | imageApexType = "image" |
| 40 | zipApexType = "zip" |
| 41 | flattenedApexType = "flattened" |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 42 | ) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 43 | |
| 44 | type dependencyTag struct { |
| 45 | blueprint.BaseDependencyTag |
| 46 | name string |
| 47 | } |
| 48 | |
| 49 | var ( |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 50 | sharedLibTag = dependencyTag{name: "sharedLib"} |
| 51 | executableTag = dependencyTag{name: "executable"} |
| 52 | javaLibTag = dependencyTag{name: "javaLib"} |
| 53 | prebuiltTag = dependencyTag{name: "prebuilt"} |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 54 | testTag = dependencyTag{name: "test"} |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 55 | keyTag = dependencyTag{name: "key"} |
| 56 | certificateTag = dependencyTag{name: "certificate"} |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 57 | usesTag = dependencyTag{name: "uses"} |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 58 | androidAppTag = dependencyTag{name: "androidApp"} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 59 | ) |
| 60 | |
| 61 | func init() { |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 62 | android.RegisterModuleType("apex", BundleFactory) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 63 | android.RegisterModuleType("apex_test", testApexBundleFactory) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 64 | android.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 65 | android.RegisterModuleType("apex_defaults", defaultsFactory) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 66 | android.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 67 | android.RegisterModuleType("override_apex", overrideApexFactory) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 68 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 69 | android.PreDepsMutators(RegisterPreDepsMutators) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 70 | android.PostDepsMutators(RegisterPostDepsMutators) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 71 | |
| 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 Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 77 | } |
| 78 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 79 | func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { |
| 80 | ctx.TopDown("apex_vndk", apexVndkMutator).Parallel() |
| 81 | ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel() |
| 82 | } |
| 83 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 84 | func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { |
Jiyong Park | a308ea1 | 2019-11-15 10:38:39 +0900 | [diff] [blame] | 85 | ctx.BottomUp("apex_deps", apexDepsMutator) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 86 | ctx.BottomUp("apex", apexMutator).Parallel() |
| 87 | ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel() |
| 88 | ctx.BottomUp("apex_uses", apexUsesMutator).Parallel() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 89 | } |
| 90 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 91 | // Mark the direct and transitive dependencies of apex bundles so that they |
| 92 | // can be built for the apex bundles. |
Jiyong Park | a308ea1 | 2019-11-15 10:38:39 +0900 | [diff] [blame] | 93 | func apexDepsMutator(mctx android.BottomUpMutatorContext) { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 94 | if a, ok := mctx.Module().(*apexBundle); ok { |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 95 | apexBundleName := mctx.ModuleName() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 96 | mctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 97 | depName := mctx.OtherModuleName(child) |
| 98 | // If the parent is apexBundle, this child is directly depended. |
| 99 | _, directDep := parent.(*apexBundle) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 100 | if a.installable() && !a.testApex { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 101 | // 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 Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 106 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 107 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 108 | am.BuildForApex(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 109 | return true |
| 110 | } else { |
| 111 | return false |
| 112 | } |
| 113 | }) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // Create apex variations if a module is included in APEX(s). |
| 118 | func apexMutator(mctx android.BottomUpMutatorContext) { |
| 119 | if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 120 | am.CreateApexVariations(mctx) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 121 | } else if a, ok := mctx.Module().(*apexBundle); ok { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 122 | // 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 Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 126 | |
| 127 | // collects APEX list |
| 128 | if mctx.Device() && a.installable() { |
| 129 | addApexFileContextsInfos(mctx, a) |
| 130 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 131 | } 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 Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 138 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 139 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 140 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 141 | |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 142 | var ( |
| 143 | apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey") |
| 144 | apexFileContextsInfosMutex sync.Mutex |
| 145 | ) |
| 146 | |
| 147 | func apexFileContextsInfos(config android.Config) *[]string { |
| 148 | return config.Once(apexFileContextsInfosKey, func() interface{} { |
| 149 | return &[]string{} |
| 150 | }).(*[]string) |
| 151 | } |
| 152 | |
| 153 | func 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 Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 163 | func apexFlattenedMutator(mctx android.BottomUpMutatorContext) { |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 164 | if ab, ok := mctx.Module().(*apexBundle); ok { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 165 | 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 Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 174 | mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 175 | 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 Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 188 | if !mctx.Config().FlattenApex() { |
| 189 | modules[i].(*apexBundle).MakeAsSystemExt() |
| 190 | } |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 191 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 192 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 193 | } else if _, ok := mctx.Module().(*OverrideApex); ok { |
| 194 | mctx.CreateVariations(imageApexType, flattenedApexType) |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 198 | func apexUsesMutator(mctx android.BottomUpMutatorContext) { |
| 199 | if ab, ok := mctx.Module().(*apexBundle); ok { |
| 200 | mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...) |
| 201 | } |
| 202 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 203 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 204 | var ( |
| 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. |
| 214 | func 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() |
| 226 | func setUseVendorWhitelistForTest(config android.Config, whitelist []string) { |
| 227 | config.Once(useVendorWhitelistKey, func() interface{} { |
| 228 | return whitelist |
| 229 | }) |
| 230 | } |
| 231 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 232 | type apexNativeDependencies struct { |
| 233 | // List of native libraries |
| 234 | Native_shared_libs []string |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 235 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 236 | // List of native executables |
| 237 | Binaries []string |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 238 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 239 | // List of native tests |
| 240 | Tests []string |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 241 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 242 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 243 | type 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 Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 260 | type apexBundleProperties struct { |
| 261 | // Json manifest file describing meta info of this APEX bundle. Default: |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 262 | // "apex_manifest.json" |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 263 | Manifest *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 264 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 265 | // AndroidManifest.xml file used for the zip container of this APEX bundle. |
| 266 | // If unspecified, a default one is automatically generated. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 267 | AndroidManifest *string `android:"path"` |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 268 | |
Roland Levillain | 411c584 | 2019-09-19 16:37:20 +0100 | [diff] [blame] | 269 | // 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 Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 272 | Apex_name *string |
| 273 | |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 274 | // 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 Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 278 | File_contexts *string |
| 279 | |
| 280 | // List of native shared libs that are embedded inside this APEX bundle |
| 281 | Native_shared_libs []string |
| 282 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 283 | // List of executables that are embedded inside this APEX bundle |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 284 | 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 Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 291 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 292 | // List of tests that are embedded inside this APEX bundle |
| 293 | Tests []string |
| 294 | |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 295 | // Name of the apex_key module that provides the private key to sign APEX |
| 296 | Key *string |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 297 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 298 | // 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 Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 302 | // 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 Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 306 | // Whether this APEX is installable to one of the partitions. Default: true. |
| 307 | Installable *bool |
| 308 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 309 | // 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 Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 313 | // 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 Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 316 | Multilib apexMultilibProperties |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 317 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 318 | // List of sanitizer names that this APEX is enabled for |
| 319 | SanitizerNames []string `blueprint:"mutated"` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 320 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 321 | PreventInstall bool `blueprint:"mutated"` |
| 322 | |
| 323 | HideFromMake bool `blueprint:"mutated"` |
| 324 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 325 | // 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 Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 330 | |
| 331 | // A txt file containing list of files that are whitelisted to be included in this APEX. |
| 332 | Whitelisted_files *string |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 333 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 334 | // package format of this apex variant; could be non-flattened, flattened, or zip. |
| 335 | // imageApex, zipApex or flattened |
| 336 | ApexType apexPackaging `blueprint:"mutated"` |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 337 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 338 | // 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 Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 343 | |
| 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 Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | type apexTargetBundleProperties struct { |
| 353 | Target struct { |
| 354 | // Multilib properties only for android. |
| 355 | Android struct { |
| 356 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 357 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 358 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 359 | // Multilib properties only for host. |
| 360 | Host struct { |
| 361 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 362 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 363 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 364 | // Multilib properties only for host linux_bionic. |
| 365 | Linux_bionic struct { |
| 366 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 367 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 368 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 369 | // Multilib properties only for host linux_glibc. |
| 370 | Linux_glibc struct { |
| 371 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 372 | } |
| 373 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 374 | } |
| 375 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 376 | type overridableProperties struct { |
| 377 | // List of APKs to package inside APEX |
| 378 | Apps []string |
| 379 | } |
| 380 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 381 | type apexFileClass int |
| 382 | |
| 383 | const ( |
| 384 | etc apexFileClass = iota |
| 385 | nativeSharedLib |
| 386 | nativeExecutable |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 387 | shBinary |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 388 | pyBinary |
| 389 | goBinary |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 390 | javaSharedLib |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 391 | nativeTest |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 392 | app |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 393 | ) |
| 394 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 395 | type apexPackaging int |
| 396 | |
| 397 | const ( |
| 398 | imageApex apexPackaging = iota |
| 399 | zipApex |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 400 | flattenedApex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 401 | ) |
| 402 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 403 | // The suffix for the output "file", not the module |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 404 | func (a apexPackaging) suffix() string { |
| 405 | switch a { |
| 406 | case imageApex: |
| 407 | return imageApexSuffix |
| 408 | case zipApex: |
| 409 | return zipApexSuffix |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 410 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 411 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
| 415 | func (a apexPackaging) name() string { |
| 416 | switch a { |
| 417 | case imageApex: |
| 418 | return imageApexType |
| 419 | case zipApex: |
| 420 | return zipApexType |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 421 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 422 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 426 | func (class apexFileClass) NameInMake() string { |
| 427 | switch class { |
| 428 | case etc: |
| 429 | return "ETC" |
| 430 | case nativeSharedLib: |
| 431 | return "SHARED_LIBRARIES" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 432 | case nativeExecutable, shBinary, pyBinary, goBinary: |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 433 | return "EXECUTABLES" |
| 434 | case javaSharedLib: |
| 435 | return "JAVA_LIBRARIES" |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 436 | case nativeTest: |
| 437 | return "NATIVE_TESTS" |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 438 | case app: |
Jiyong Park | f383f7c | 2019-10-11 20:46:25 +0900 | [diff] [blame] | 439 | // 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 Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 447 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 448 | panic(fmt.Errorf("unknown class %d", class)) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
| 452 | type apexFile struct { |
| 453 | builtFile android.Path |
| 454 | moduleName string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 455 | installDir string |
| 456 | class apexFileClass |
Jiyong Park | a889484 | 2018-12-19 17:36:39 +0900 | [diff] [blame] | 457 | module android.Module |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 458 | symlinks []string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 459 | } |
| 460 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 461 | type apexBundle struct { |
| 462 | android.ModuleBase |
| 463 | android.DefaultableModuleBase |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 464 | android.OverridableModuleBase |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 465 | android.SdkBase |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 466 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 467 | properties apexBundleProperties |
| 468 | targetProperties apexTargetBundleProperties |
| 469 | vndkProperties apexVndkProperties |
| 470 | overridableProperties overridableProperties |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 471 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 472 | bundleModuleFile android.WritablePath |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 473 | outputFile android.WritablePath |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 474 | installDir android.InstallPath |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 475 | |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 476 | prebuiltFileToDelete string |
| 477 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 478 | public_key_file android.Path |
| 479 | private_key_file android.Path |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 480 | |
| 481 | container_certificate_file android.Path |
| 482 | container_private_key_file android.Path |
| 483 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 484 | // list of files to be included in this apex |
| 485 | filesInfo []apexFile |
| 486 | |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 487 | // list of module names that this APEX is depending on |
| 488 | externalDeps []string |
| 489 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 490 | testApex bool |
| 491 | vndkApex bool |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 492 | artApex bool |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 493 | primaryApexType bool |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 494 | |
| 495 | // intermediate path for apex_manifest.json |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 496 | manifestJsonOut android.WritablePath |
| 497 | manifestJsonFullOut android.WritablePath |
| 498 | manifestPbOut android.WritablePath |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 499 | |
| 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 Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 505 | |
| 506 | // Suffix of module name in Android.mk |
| 507 | // ".flattened", ".apex", ".zipapex", or "" |
| 508 | suffix string |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 509 | } |
| 510 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 511 | func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 512 | native_shared_libs []string, binaries []string, tests []string, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 513 | target android.Target, imageVariation string) { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 514 | // 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 Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 518 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 519 | {Mutator: "image", Variation: imageVariation}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 520 | {Mutator: "link", Variation: "shared"}, |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 521 | {Mutator: "version", Variation: ""}, // "" is the non-stub variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 522 | }...), sharedLibTag, native_shared_libs...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 523 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 524 | ctx.AddFarVariationDependencies(append(target.Variations(), |
| 525 | blueprint.Variation{Mutator: "image", Variation: imageVariation}), |
| 526 | executableTag, binaries...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 527 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 528 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 529 | {Mutator: "image", Variation: imageVariation}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 530 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 531 | }...), testTag, tests...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 532 | } |
| 533 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 534 | func (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 Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 547 | func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 548 | 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 Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 552 | targets := ctx.MultiTargets() |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 553 | config := ctx.DeviceConfig() |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 554 | |
| 555 | a.combineProperties(ctx) |
| 556 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 557 | 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 Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 566 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 567 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 568 | {Mutator: "link", Variation: "shared"}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 569 | }...), sharedLibTag, a.properties.Native_shared_libs...) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 570 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 571 | // When multilib.* is omitted for tests, it implies |
| 572 | // multilib.both. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 573 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 574 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 575 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 576 | }...), testTag, a.properties.Tests...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 577 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 578 | // Add native modules targetting both ABIs |
| 579 | addDependenciesForNativeModules(ctx, |
| 580 | a.properties.Multilib.Both.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 581 | a.properties.Multilib.Both.Binaries, |
| 582 | a.properties.Multilib.Both.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 583 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 584 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 585 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 586 | isPrimaryAbi := i == 0 |
| 587 | if isPrimaryAbi { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 588 | // When multilib.* is omitted for binaries, it implies |
| 589 | // multilib.first. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 590 | ctx.AddFarVariationDependencies(append(target.Variations(), |
| 591 | blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}), |
| 592 | executableTag, a.properties.Binaries...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 593 | |
| 594 | // Add native modules targetting the first ABI |
| 595 | addDependenciesForNativeModules(ctx, |
| 596 | a.properties.Multilib.First.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 597 | a.properties.Multilib.First.Binaries, |
| 598 | a.properties.Multilib.First.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 599 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 600 | a.getImageVariation(config)) |
Jaewoong Jung | b9a1151 | 2019-01-15 10:47:05 -0800 | [diff] [blame] | 601 | |
| 602 | // When multilib.* is omitted for prebuilts, it implies multilib.first. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 603 | ctx.AddFarVariationDependencies(target.Variations(), |
| 604 | prebuiltTag, a.properties.Prebuilts...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 605 | } |
| 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 Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 612 | a.properties.Multilib.Lib32.Binaries, |
| 613 | a.properties.Multilib.Lib32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 614 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 615 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 616 | |
| 617 | addDependenciesForNativeModules(ctx, |
| 618 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 619 | a.properties.Multilib.Prefer32.Binaries, |
| 620 | a.properties.Multilib.Prefer32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 621 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 622 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 623 | case "lib64": |
| 624 | // Add native modules targetting 64-bit ABI |
| 625 | addDependenciesForNativeModules(ctx, |
| 626 | a.properties.Multilib.Lib64.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 627 | a.properties.Multilib.Lib64.Binaries, |
| 628 | a.properties.Multilib.Lib64.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 629 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 630 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 631 | |
| 632 | if !has32BitTarget { |
| 633 | addDependenciesForNativeModules(ctx, |
| 634 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 635 | a.properties.Multilib.Prefer32.Binaries, |
| 636 | a.properties.Multilib.Prefer32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 637 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 638 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 639 | } |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 640 | |
| 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 Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 646 | nil, nil, target, a.getImageVariation(config)) |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 647 | break |
| 648 | } |
| 649 | } |
| 650 | } |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 651 | } |
| 652 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 653 | } |
| 654 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 655 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 656 | javaLibTag, a.properties.Java_libs...) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 657 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 658 | 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 Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 663 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 664 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 665 | if cert != "" { |
| 666 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 667 | } |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 668 | |
| 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 Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 678 | } |
| 679 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 680 | func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { |
| 681 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 682 | androidAppTag, a.overridableProperties.Apps...) |
| 683 | } |
| 684 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 685 | func (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 Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 690 | func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 691 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName()) |
| 692 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 693 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 694 | } |
| 695 | return String(a.properties.Certificate) |
| 696 | } |
| 697 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 698 | func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) { |
| 699 | switch tag { |
| 700 | case "": |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 701 | return android.Paths{a.outputFile}, nil |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 702 | default: |
| 703 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Jiyong Park | 5a83202 | 2018-12-20 09:54:35 +0900 | [diff] [blame] | 704 | } |
Jiyong Park | 74e240b | 2018-11-27 21:27:08 +0900 | [diff] [blame] | 705 | } |
| 706 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 707 | func (a *apexBundle) installable() bool { |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 708 | return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable)) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 709 | } |
| 710 | |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 711 | func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 712 | if a.vndkApex { |
| 713 | return "vendor." + a.vndkVersion(config) |
| 714 | } |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 715 | if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) { |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 716 | return "vendor." + config.PlatformVndkVersion() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 717 | } else { |
| 718 | return "core" |
| 719 | } |
| 720 | } |
| 721 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 722 | func (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 Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 728 | func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 729 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 730 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | // Then follow the global setting |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 734 | 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 Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 744 | } |
| 745 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 746 | func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 747 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 748 | } |
| 749 | |
| 750 | func (a *apexBundle) PreventInstall() { |
| 751 | a.properties.PreventInstall = true |
| 752 | } |
| 753 | |
| 754 | func (a *apexBundle) HideFromMake() { |
| 755 | a.properties.HideFromMake = true |
| 756 | } |
| 757 | |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 758 | func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, handleSpecialLibs bool) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 759 | // Decide the APEX-local directory by the multilib of the library |
| 760 | // In the future, we may query this to the module. |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 761 | switch ccMod.Arch().ArchType.Multilib { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 762 | case "lib32": |
| 763 | dirInApex = "lib" |
| 764 | case "lib64": |
| 765 | dirInApex = "lib64" |
| 766 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 767 | dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 768 | if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 769 | dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 770 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 771 | 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 Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 783 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 784 | |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 785 | fileToCopy = ccMod.OutputFile().Path() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 786 | return |
| 787 | } |
| 788 | |
| 789 | func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 790 | dirInApex = filepath.Join("bin", cc.RelativeInstallPath()) |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 791 | if cc.Target().NativeBridge == android.NativeBridgeEnabled { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 792 | dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) |
Jiyong Park | acbf6c7 | 2019-07-09 16:19:16 +0900 | [diff] [blame] | 793 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 794 | fileToCopy = cc.OutputFile().Path() |
| 795 | return |
| 796 | } |
| 797 | |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 798 | func getCopyManifestForPyBinary(py *python.Module) (fileToCopy android.Path, dirInApex string) { |
| 799 | dirInApex = "bin" |
| 800 | fileToCopy = py.HostToolPath().Path() |
| 801 | return |
| 802 | } |
| 803 | func 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 Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 814 | func 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 Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 820 | func getCopyManifestForJavaLibrary(java *java.Library) (fileToCopy android.Path, dirInApex string) { |
| 821 | dirInApex = "javalib" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 822 | fileToCopy = java.DexJarFile() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 823 | return |
| 824 | } |
| 825 | |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 826 | func 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 Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 838 | func getCopyManifestForPrebuiltEtc(prebuilt android.PrebuiltEtcModule) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 839 | dirInApex = filepath.Join("etc", prebuilt.SubDir()) |
| 840 | fileToCopy = prebuilt.OutputFile() |
| 841 | return |
| 842 | } |
| 843 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 844 | func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 845 | appDir := "app" |
| 846 | if app.Privileged() { |
| 847 | appDir = "priv-app" |
| 848 | } |
| 849 | dirInApex = filepath.Join(appDir, pkgName) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 850 | fileToCopy = app.OutputFile() |
| 851 | return |
| 852 | } |
| 853 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 854 | func 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 Levillain | 935639d | 2019-08-13 14:55:28 +0100 | [diff] [blame] | 864 | // Context "decorator", overriding the InstallBypassMake method to always reply `true`. |
| 865 | type flattenedApexContext struct { |
| 866 | android.ModuleContext |
| 867 | } |
| 868 | |
| 869 | func (c *flattenedApexContext) InstallBypassMake() bool { |
| 870 | return true |
| 871 | } |
| 872 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 873 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 874 | filesInfo := []apexFile{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 875 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 876 | 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 Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 899 | } |
| 900 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 901 | if len(a.properties.Tests) > 0 && !a.testApex { |
| 902 | ctx.PropertyErrorf("tests", "property not allowed in apex module type") |
| 903 | return |
| 904 | } |
| 905 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 906 | handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case) |
| 907 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 908 | // native lib dependencies |
| 909 | var provideNativeLibs []string |
| 910 | var requireNativeLibs []string |
| 911 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 912 | // 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 Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 936 | ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 937 | depTag := ctx.OtherModuleDependencyTag(child) |
| 938 | depName := ctx.OtherModuleName(child) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 939 | if _, ok := parent.(*apexBundle); ok { |
| 940 | // direct dependencies |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 941 | switch depTag { |
| 942 | case sharedLibTag: |
| 943 | if cc, ok := child.(*cc.Module); ok { |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 944 | if cc.HasStubsVariants() { |
| 945 | provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base()) |
| 946 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 947 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 948 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 949 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 950 | } else { |
| 951 | ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 952 | } |
| 953 | case executableTag: |
| 954 | if cc, ok := child.(*cc.Module); ok { |
| 955 | fileToCopy, dirInApex := getCopyManifestForExecutable(cc) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 956 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeExecutable, cc, cc.Symlinks()}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 957 | return true |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 958 | } else if sh, ok := child.(*android.ShBinary); ok { |
| 959 | fileToCopy, dirInApex := getCopyManifestForShBinary(sh) |
Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 960 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, shBinary, sh, sh.Symlinks()}) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 961 | } 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 Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 970 | } else { |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 971 | ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 972 | } |
| 973 | case javaLibTag: |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 974 | if javaLib, ok := child.(*java.Library); ok { |
| 975 | fileToCopy, dirInApex := getCopyManifestForJavaLibrary(javaLib) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 976 | if fileToCopy == nil { |
| 977 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 978 | } else { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 979 | 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 Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 988 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 989 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 990 | } else { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 991 | ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 992 | } |
| 993 | case prebuiltTag: |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 994 | if prebuilt, ok := child.(android.PrebuiltEtcModule); ok { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 995 | fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt) |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 996 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil}) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 997 | return true |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 998 | } else { |
| 999 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
| 1000 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1001 | case testTag: |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1002 | 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 Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1011 | } else { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1012 | // 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 Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1015 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1016 | return true |
| 1017 | } else { |
| 1018 | ctx.PropertyErrorf("tests", "%q is not a cc module", depName) |
| 1019 | } |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1020 | case keyTag: |
| 1021 | if key, ok := child.(*apexKey); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1022 | a.private_key_file = key.private_key_file |
| 1023 | a.public_key_file = key.public_key_file |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1024 | return false |
| 1025 | } else { |
| 1026 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1027 | } |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1028 | case certificateTag: |
| 1029 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1030 | a.container_certificate_file = dep.Certificate.Pem |
| 1031 | a.container_private_key_file = dep.Certificate.Key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1032 | return false |
| 1033 | } else { |
| 1034 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 1035 | } |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1036 | 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 Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 1042 | 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 Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 1047 | } 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 Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 1050 | } else { |
| 1051 | ctx.PropertyErrorf("apps", "%q is not an android_app module", depName) |
| 1052 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1053 | } |
Jooyung Han | 8aee204 | 2019-10-29 05:08:31 +0900 | [diff] [blame] | 1054 | } else if !a.vndkApex { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1055 | // indirect dependencies |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1056 | if am, ok := child.(android.ApexModule); ok { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1057 | // We cannot use a switch statement on `depTag` here as the checked |
| 1058 | // tags used below are private (e.g. `cc.sharedDepTag`). |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1059 | if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1060 | 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 Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 1065 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1066 | 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 Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1077 | requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base()) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1078 | // Don't track further |
| 1079 | return false |
| 1080 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1081 | fileToCopy, dirInApex := getCopyManifestForNativeLibrary(cc, ctx.Config(), handleSpecialLibs) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1082 | filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, nativeSharedLib, cc, nil}) |
| 1083 | return true |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1084 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1085 | } 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 Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1096 | } else if java.IsJniDepTag(depTag) { |
| 1097 | // Do nothing for JNI dep. JNI libraries are always embedded in APK-in-APEX. |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1098 | } else if am.CanHaveApexVariants() && am.IsInstallableToApex() { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1099 | ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | return false |
| 1104 | }) |
| 1105 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1106 | // 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 Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1119 | if a.private_key_file == nil { |
Jiyong Park | fa0a373 | 2018-11-09 05:52:26 +0900 | [diff] [blame] | 1120 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key)) |
| 1121 | return |
| 1122 | } |
| 1123 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1124 | // remove duplicates in filesInfo |
| 1125 | removeDup := func(filesInfo []apexFile) []apexFile { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1126 | encountered := make(map[string]bool) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1127 | result := []apexFile{} |
| 1128 | for _, f := range filesInfo { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1129 | dest := filepath.Join(f.installDir, f.builtFile.Base()) |
| 1130 | if !encountered[dest] { |
| 1131 | encountered[dest] = true |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1132 | 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 Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 1144 | // check apex_available requirements |
Jiyong Park | 583a226 | 2019-10-08 20:55:38 +0900 | [diff] [blame] | 1145 | 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 Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1156 | // 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 Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1159 | filesInfo[i].moduleName = filesInfo[i].moduleName + "." + ctx.ModuleName() + a.suffix |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1160 | } |
| 1161 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1162 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 1163 | a.filesInfo = filesInfo |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1164 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1165 | // prepare apex_manifest.json |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1166 | 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 Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1179 | func newApexBundle() *apexBundle { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1180 | module := &apexBundle{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1181 | module.AddProperties(&module.properties) |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1182 | module.AddProperties(&module.targetProperties) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 1183 | module.AddProperties(&module.overridableProperties) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1184 | module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 1185 | return class == android.Device && ctx.Config().DevicePrefer32BitExecutables() |
| 1186 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1187 | android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1188 | android.InitDefaultableModule(module) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1189 | android.InitSdkAwareModule(module) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 1190 | android.InitOverridableModule(module, &module.properties.Overrides) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1191 | return module |
| 1192 | } |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1193 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1194 | func ApexBundleFactory(testApex bool, artApex bool) android.Module { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1195 | bundle := newApexBundle() |
| 1196 | bundle.testApex = testApex |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1197 | bundle.artApex = artApex |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1198 | return bundle |
| 1199 | } |
| 1200 | |
| 1201 | func testApexBundleFactory() android.Module { |
| 1202 | bundle := newApexBundle() |
| 1203 | bundle.testApex = true |
| 1204 | return bundle |
| 1205 | } |
| 1206 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1207 | func BundleFactory() android.Module { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1208 | return newApexBundle() |
| 1209 | } |
| 1210 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1211 | // |
| 1212 | // Defaults |
| 1213 | // |
| 1214 | type Defaults struct { |
| 1215 | android.ModuleBase |
| 1216 | android.DefaultsModuleBase |
| 1217 | } |
| 1218 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1219 | func defaultsFactory() android.Module { |
| 1220 | return DefaultsFactory() |
| 1221 | } |
| 1222 | |
| 1223 | func 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 Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame^] | 1235 | |
| 1236 | // |
| 1237 | // OverrideApex |
| 1238 | // |
| 1239 | type OverrideApex struct { |
| 1240 | android.ModuleBase |
| 1241 | android.OverrideModuleBase |
| 1242 | } |
| 1243 | |
| 1244 | func (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. |
| 1250 | func 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 | } |