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" |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 19 | "path" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 20 | "path/filepath" |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 21 | "sort" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 22 | "strings" |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 23 | "sync" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/cc" |
| 27 | "android/soong/java" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 28 | "android/soong/python" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 29 | |
| 30 | "github.com/google/blueprint" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 31 | "github.com/google/blueprint/bootstrap" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 32 | "github.com/google/blueprint/proptools" |
| 33 | ) |
| 34 | |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 35 | const ( |
| 36 | imageApexSuffix = ".apex" |
| 37 | zipApexSuffix = ".zipapex" |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 38 | flattenedSuffix = ".flattened" |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 39 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 40 | imageApexType = "image" |
| 41 | zipApexType = "zip" |
| 42 | flattenedApexType = "flattened" |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 43 | ) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 44 | |
| 45 | type dependencyTag struct { |
| 46 | blueprint.BaseDependencyTag |
| 47 | name string |
| 48 | } |
| 49 | |
| 50 | var ( |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 51 | sharedLibTag = dependencyTag{name: "sharedLib"} |
| 52 | executableTag = dependencyTag{name: "executable"} |
| 53 | javaLibTag = dependencyTag{name: "javaLib"} |
| 54 | prebuiltTag = dependencyTag{name: "prebuilt"} |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 55 | testTag = dependencyTag{name: "test"} |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 56 | keyTag = dependencyTag{name: "key"} |
| 57 | certificateTag = dependencyTag{name: "certificate"} |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 58 | usesTag = dependencyTag{name: "uses"} |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 59 | androidAppTag = dependencyTag{name: "androidApp"} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 60 | ) |
| 61 | |
| 62 | func init() { |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 63 | android.RegisterModuleType("apex", BundleFactory) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 64 | android.RegisterModuleType("apex_test", testApexBundleFactory) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 65 | android.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 66 | android.RegisterModuleType("apex_defaults", defaultsFactory) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 67 | android.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 68 | android.RegisterModuleType("override_apex", overrideApexFactory) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 69 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 70 | android.PreDepsMutators(RegisterPreDepsMutators) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 71 | android.PostDepsMutators(RegisterPostDepsMutators) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 72 | |
| 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 Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 78 | } |
| 79 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 80 | func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { |
| 81 | ctx.TopDown("apex_vndk", apexVndkMutator).Parallel() |
| 82 | ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel() |
| 83 | } |
| 84 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 85 | func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { |
Jiyong Park | a308ea1 | 2019-11-15 10:38:39 +0900 | [diff] [blame] | 86 | ctx.BottomUp("apex_deps", apexDepsMutator) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 87 | ctx.BottomUp("apex", apexMutator).Parallel() |
| 88 | ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel() |
| 89 | ctx.BottomUp("apex_uses", apexUsesMutator).Parallel() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 90 | } |
| 91 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 92 | // Mark the direct and transitive dependencies of apex bundles so that they |
| 93 | // can be built for the apex bundles. |
Jiyong Park | a308ea1 | 2019-11-15 10:38:39 +0900 | [diff] [blame] | 94 | func apexDepsMutator(mctx android.BottomUpMutatorContext) { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 95 | if a, ok := mctx.Module().(*apexBundle); ok { |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 96 | apexBundleName := mctx.ModuleName() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 97 | mctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 98 | depName := mctx.OtherModuleName(child) |
| 99 | // If the parent is apexBundle, this child is directly depended. |
| 100 | _, directDep := parent.(*apexBundle) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 101 | if a.installable() && !a.testApex { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 102 | // 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 Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 107 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 108 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 109 | am.BuildForApex(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 110 | return true |
| 111 | } else { |
| 112 | return false |
| 113 | } |
| 114 | }) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // Create apex variations if a module is included in APEX(s). |
| 119 | func apexMutator(mctx android.BottomUpMutatorContext) { |
| 120 | if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 121 | am.CreateApexVariations(mctx) |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 122 | } else if _, ok := mctx.Module().(*apexBundle); ok { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 123 | // apex bundle itself is mutated so that it and its modules have same |
| 124 | // apex variant. |
| 125 | apexBundleName := mctx.ModuleName() |
| 126 | mctx.CreateVariations(apexBundleName) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 127 | } else if o, ok := mctx.Module().(*OverrideApex); ok { |
| 128 | apexBundleName := o.GetOverriddenModuleName() |
| 129 | if apexBundleName == "" { |
| 130 | mctx.ModuleErrorf("base property is not set") |
| 131 | return |
| 132 | } |
| 133 | mctx.CreateVariations(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 134 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 135 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 136 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 137 | |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 138 | var ( |
| 139 | apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey") |
| 140 | apexFileContextsInfosMutex sync.Mutex |
| 141 | ) |
| 142 | |
| 143 | func apexFileContextsInfos(config android.Config) *[]string { |
| 144 | return config.Once(apexFileContextsInfosKey, func() interface{} { |
| 145 | return &[]string{} |
| 146 | }).(*[]string) |
| 147 | } |
| 148 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 149 | func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) { |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 150 | apexFileContextsInfosMutex.Lock() |
| 151 | defer apexFileContextsInfosMutex.Unlock() |
| 152 | apexFileContextsInfos := apexFileContextsInfos(ctx.Config()) |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 153 | *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 154 | } |
| 155 | |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 156 | func apexFlattenedMutator(mctx android.BottomUpMutatorContext) { |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 157 | if ab, ok := mctx.Module().(*apexBundle); ok { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 158 | var variants []string |
| 159 | switch proptools.StringDefault(ab.properties.Payload_type, "image") { |
| 160 | case "image": |
| 161 | variants = append(variants, imageApexType, flattenedApexType) |
| 162 | case "zip": |
| 163 | variants = append(variants, zipApexType) |
| 164 | case "both": |
| 165 | variants = append(variants, imageApexType, zipApexType, flattenedApexType) |
| 166 | default: |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 167 | 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] | 168 | return |
| 169 | } |
| 170 | |
| 171 | modules := mctx.CreateLocalVariations(variants...) |
| 172 | |
| 173 | for i, v := range variants { |
| 174 | switch v { |
| 175 | case imageApexType: |
| 176 | modules[i].(*apexBundle).properties.ApexType = imageApex |
| 177 | case zipApexType: |
| 178 | modules[i].(*apexBundle).properties.ApexType = zipApex |
| 179 | case flattenedApexType: |
| 180 | modules[i].(*apexBundle).properties.ApexType = flattenedApex |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 181 | if !mctx.Config().FlattenApex() && ab.Platform() { |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 182 | modules[i].(*apexBundle).MakeAsSystemExt() |
| 183 | } |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 184 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 185 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 186 | } else if _, ok := mctx.Module().(*OverrideApex); ok { |
| 187 | mctx.CreateVariations(imageApexType, flattenedApexType) |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 191 | func apexUsesMutator(mctx android.BottomUpMutatorContext) { |
| 192 | if ab, ok := mctx.Module().(*apexBundle); ok { |
| 193 | mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...) |
| 194 | } |
| 195 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 196 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 197 | var ( |
| 198 | useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist") |
| 199 | ) |
| 200 | |
| 201 | // useVendorWhitelist returns the list of APEXes which are allowed to use_vendor. |
| 202 | // When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__, |
| 203 | // which may cause compatibility issues. (e.g. libbinder) |
| 204 | // Even though libbinder restricts its availability via 'apex_available' property and relies on |
| 205 | // yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules |
| 206 | // to avoid similar problems. |
| 207 | func useVendorWhitelist(config android.Config) []string { |
| 208 | return config.Once(useVendorWhitelistKey, func() interface{} { |
| 209 | return []string{ |
| 210 | // swcodec uses "vendor" variants for smaller size |
| 211 | "com.android.media.swcodec", |
| 212 | "test_com.android.media.swcodec", |
| 213 | } |
| 214 | }).([]string) |
| 215 | } |
| 216 | |
| 217 | // setUseVendorWhitelistForTest overrides useVendorWhitelist and must be |
| 218 | // called before the first call to useVendorWhitelist() |
| 219 | func setUseVendorWhitelistForTest(config android.Config, whitelist []string) { |
| 220 | config.Once(useVendorWhitelistKey, func() interface{} { |
| 221 | return whitelist |
| 222 | }) |
| 223 | } |
| 224 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 225 | type apexNativeDependencies struct { |
| 226 | // List of native libraries |
| 227 | Native_shared_libs []string |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 228 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 229 | // List of native executables |
| 230 | Binaries []string |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 231 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 232 | // List of native tests |
| 233 | Tests []string |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 234 | } |
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 | type apexMultilibProperties struct { |
| 237 | // Native dependencies whose compile_multilib is "first" |
| 238 | First apexNativeDependencies |
| 239 | |
| 240 | // Native dependencies whose compile_multilib is "both" |
| 241 | Both apexNativeDependencies |
| 242 | |
| 243 | // Native dependencies whose compile_multilib is "prefer32" |
| 244 | Prefer32 apexNativeDependencies |
| 245 | |
| 246 | // Native dependencies whose compile_multilib is "32" |
| 247 | Lib32 apexNativeDependencies |
| 248 | |
| 249 | // Native dependencies whose compile_multilib is "64" |
| 250 | Lib64 apexNativeDependencies |
| 251 | } |
| 252 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 253 | type apexBundleProperties struct { |
| 254 | // Json manifest file describing meta info of this APEX bundle. Default: |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 255 | // "apex_manifest.json" |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 256 | Manifest *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 257 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 258 | // AndroidManifest.xml file used for the zip container of this APEX bundle. |
| 259 | // If unspecified, a default one is automatically generated. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 260 | AndroidManifest *string `android:"path"` |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 261 | |
Roland Levillain | 411c584 | 2019-09-19 16:37:20 +0100 | [diff] [blame] | 262 | // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on |
| 263 | // device (/apex/<apex_name>). |
| 264 | // If unspecified, defaults to the value of name. |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 265 | Apex_name *string |
| 266 | |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 267 | // Determines the file contexts file for setting security context to each file in this APEX bundle. |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 268 | // For platform APEXes, this should points to a file under /system/sepolicy |
| 269 | // Default: /system/sepolicy/apex/<module_name>_file_contexts. |
| 270 | File_contexts *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 271 | |
| 272 | // List of native shared libs that are embedded inside this APEX bundle |
| 273 | Native_shared_libs []string |
| 274 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 275 | // List of executables that are embedded inside this APEX bundle |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 276 | Binaries []string |
| 277 | |
| 278 | // List of java libraries that are embedded inside this APEX bundle |
| 279 | Java_libs []string |
| 280 | |
| 281 | // List of prebuilt files that are embedded inside this APEX bundle |
| 282 | Prebuilts []string |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 283 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 284 | // List of tests that are embedded inside this APEX bundle |
| 285 | Tests []string |
| 286 | |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 287 | // Name of the apex_key module that provides the private key to sign APEX |
| 288 | Key *string |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 289 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 290 | // The type of APEX to build. Controls what the APEX payload is. Either |
| 291 | // 'image', 'zip' or 'both'. Default: 'image'. |
| 292 | Payload_type *string |
| 293 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 294 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 295 | // or an android_app_certificate module name in the form ":module". |
| 296 | Certificate *string |
| 297 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 298 | // Whether this APEX is installable to one of the partitions. Default: true. |
| 299 | Installable *bool |
| 300 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 301 | // For native libraries and binaries, use the vendor variant instead of the core (platform) variant. |
| 302 | // Default is false. |
| 303 | Use_vendor *bool |
| 304 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 305 | // For telling the apex to ignore special handling for system libraries such as bionic. Default is false. |
| 306 | Ignore_system_library_special_case *bool |
| 307 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 308 | Multilib apexMultilibProperties |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 309 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 310 | // List of sanitizer names that this APEX is enabled for |
| 311 | SanitizerNames []string `blueprint:"mutated"` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 312 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 313 | PreventInstall bool `blueprint:"mutated"` |
| 314 | |
| 315 | HideFromMake bool `blueprint:"mutated"` |
| 316 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 317 | // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false. |
| 318 | Provide_cpp_shared_libs *bool |
| 319 | |
| 320 | // List of providing APEXes' names so that this APEX can depend on provided shared libraries. |
| 321 | Uses []string |
Nikita Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 322 | |
| 323 | // A txt file containing list of files that are whitelisted to be included in this APEX. |
| 324 | Whitelisted_files *string |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 325 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 326 | // package format of this apex variant; could be non-flattened, flattened, or zip. |
| 327 | // imageApex, zipApex or flattened |
| 328 | ApexType apexPackaging `blueprint:"mutated"` |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 329 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 330 | // List of SDKs that are used to build this APEX. A reference to an SDK should be either |
| 331 | // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current` |
| 332 | // is implied. This value affects all modules included in this APEX. In other words, they are |
| 333 | // also built with the SDKs specified here. |
| 334 | Uses_sdks []string |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 335 | |
| 336 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 337 | // (in Make or Soong). |
| 338 | // This does not completely prevent installation of the overridden binaries, but if both |
| 339 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 340 | // from PRODUCT_PACKAGES. |
| 341 | Overrides []string |
Nikita Ioffe | c72b5dd | 2019-12-07 17:30:22 +0000 | [diff] [blame] | 342 | |
| 343 | // Whenever apex_payload.img of the APEX should include dm-verity hashtree. |
| 344 | // Should be only used in tests#. |
| 345 | Test_only_no_hashtree *bool |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 346 | |
| 347 | // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well |
| 348 | // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb |
| 349 | Legacy_android10_support *bool |
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 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 381 | type apexPackaging int |
| 382 | |
| 383 | const ( |
| 384 | imageApex apexPackaging = iota |
| 385 | zipApex |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 386 | flattenedApex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 387 | ) |
| 388 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 389 | // The suffix for the output "file", not the module |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 390 | func (a apexPackaging) suffix() string { |
| 391 | switch a { |
| 392 | case imageApex: |
| 393 | return imageApexSuffix |
| 394 | case zipApex: |
| 395 | return zipApexSuffix |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 396 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 397 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
| 401 | func (a apexPackaging) name() string { |
| 402 | switch a { |
| 403 | case imageApex: |
| 404 | return imageApexType |
| 405 | case zipApex: |
| 406 | return zipApexType |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 407 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 408 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 412 | type apexFileClass int |
| 413 | |
| 414 | const ( |
| 415 | etc apexFileClass = iota |
| 416 | nativeSharedLib |
| 417 | nativeExecutable |
| 418 | shBinary |
| 419 | pyBinary |
| 420 | goBinary |
| 421 | javaSharedLib |
| 422 | nativeTest |
| 423 | app |
| 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 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 452 | // apexFile represents a file in an APEX bundle |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 453 | type apexFile struct { |
| 454 | builtFile android.Path |
| 455 | moduleName string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 456 | installDir string |
| 457 | class apexFileClass |
Jiyong Park | a889484 | 2018-12-19 17:36:39 +0900 | [diff] [blame] | 458 | module android.Module |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 459 | // list of symlinks that will be created in installDir that point to this apexFile |
| 460 | symlinks []string |
| 461 | transitiveDep bool |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 462 | moduleDir string |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 463 | } |
| 464 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 465 | func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile { |
| 466 | ret := apexFile{ |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 467 | builtFile: builtFile, |
| 468 | moduleName: moduleName, |
| 469 | installDir: installDir, |
| 470 | class: class, |
| 471 | module: module, |
| 472 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 473 | if module != nil { |
| 474 | ret.moduleDir = ctx.OtherModuleDir(module) |
| 475 | } |
| 476 | return ret |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | func (af *apexFile) Ok() bool { |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 480 | return af.builtFile != nil && af.builtFile.String() != "" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 481 | } |
| 482 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 483 | type apexBundle struct { |
| 484 | android.ModuleBase |
| 485 | android.DefaultableModuleBase |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 486 | android.OverridableModuleBase |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 487 | android.SdkBase |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 488 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 489 | properties apexBundleProperties |
| 490 | targetProperties apexTargetBundleProperties |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 491 | overridableProperties overridableProperties |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 492 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 493 | // specific to apex_vndk modules |
| 494 | vndkProperties apexVndkProperties |
| 495 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 496 | bundleModuleFile android.WritablePath |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 497 | outputFile android.WritablePath |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 498 | installDir android.InstallPath |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 499 | |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 500 | prebuiltFileToDelete string |
| 501 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 502 | public_key_file android.Path |
| 503 | private_key_file android.Path |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 504 | |
| 505 | container_certificate_file android.Path |
| 506 | container_private_key_file android.Path |
| 507 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 508 | fileContexts android.Path |
| 509 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 510 | // list of files to be included in this apex |
| 511 | filesInfo []apexFile |
| 512 | |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 513 | // list of module names that this APEX is depending on |
| 514 | externalDeps []string |
| 515 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 516 | testApex bool |
| 517 | vndkApex bool |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 518 | artApex bool |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 519 | primaryApexType bool |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 520 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 521 | manifestJsonOut android.WritablePath |
| 522 | manifestPbOut android.WritablePath |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 523 | |
| 524 | // list of commands to create symlinks for backward compatibility |
| 525 | // these commands will be attached as LOCAL_POST_INSTALL_CMD to |
| 526 | // apex package itself(for unflattened build) or apex_manifest.json(for flattened build) |
| 527 | // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting. |
| 528 | compatSymlinks []string |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 529 | |
| 530 | // Suffix of module name in Android.mk |
| 531 | // ".flattened", ".apex", ".zipapex", or "" |
| 532 | suffix string |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 533 | } |
| 534 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 535 | func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 536 | native_shared_libs []string, binaries []string, tests []string, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 537 | target android.Target, imageVariation string) { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 538 | // Use *FarVariation* to be able to depend on modules having |
| 539 | // conflicting variations with this module. This is required since |
| 540 | // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64' |
| 541 | // for native shared libs. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 542 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 543 | {Mutator: "image", Variation: imageVariation}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 544 | {Mutator: "link", Variation: "shared"}, |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 545 | {Mutator: "version", Variation: ""}, // "" is the non-stub variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 546 | }...), sharedLibTag, native_shared_libs...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 547 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 548 | ctx.AddFarVariationDependencies(append(target.Variations(), |
| 549 | blueprint.Variation{Mutator: "image", Variation: imageVariation}), |
| 550 | executableTag, binaries...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 551 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 552 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 553 | {Mutator: "image", Variation: imageVariation}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 554 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 555 | }...), testTag, tests...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 556 | } |
| 557 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 558 | func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { |
| 559 | if ctx.Os().Class == android.Device { |
| 560 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil) |
| 561 | } else { |
| 562 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil) |
| 563 | if ctx.Os().Bionic() { |
| 564 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil) |
| 565 | } else { |
| 566 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil) |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 571 | func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 572 | if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) { |
| 573 | ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true") |
| 574 | } |
| 575 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 576 | targets := ctx.MultiTargets() |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 577 | config := ctx.DeviceConfig() |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 578 | |
| 579 | a.combineProperties(ctx) |
| 580 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 581 | has32BitTarget := false |
| 582 | for _, target := range targets { |
| 583 | if target.Arch.ArchType.Multilib == "lib32" { |
| 584 | has32BitTarget = true |
| 585 | } |
| 586 | } |
| 587 | for i, target := range targets { |
| 588 | // When multilib.* is omitted for native_shared_libs, it implies |
| 589 | // multilib.both. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 590 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 591 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 592 | {Mutator: "link", Variation: "shared"}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 593 | }...), sharedLibTag, a.properties.Native_shared_libs...) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 594 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 595 | // When multilib.* is omitted for tests, it implies |
| 596 | // multilib.both. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 597 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 598 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 599 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 600 | }...), testTag, a.properties.Tests...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 601 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 602 | // Add native modules targetting both ABIs |
| 603 | addDependenciesForNativeModules(ctx, |
| 604 | a.properties.Multilib.Both.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 605 | a.properties.Multilib.Both.Binaries, |
| 606 | a.properties.Multilib.Both.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 607 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 608 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 609 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 610 | isPrimaryAbi := i == 0 |
| 611 | if isPrimaryAbi { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 612 | // When multilib.* is omitted for binaries, it implies |
| 613 | // multilib.first. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 614 | ctx.AddFarVariationDependencies(append(target.Variations(), |
| 615 | blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}), |
| 616 | executableTag, a.properties.Binaries...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 617 | |
| 618 | // Add native modules targetting the first ABI |
| 619 | addDependenciesForNativeModules(ctx, |
| 620 | a.properties.Multilib.First.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 621 | a.properties.Multilib.First.Binaries, |
| 622 | a.properties.Multilib.First.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 623 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 624 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | switch target.Arch.ArchType.Multilib { |
| 628 | case "lib32": |
| 629 | // Add native modules targetting 32-bit ABI |
| 630 | addDependenciesForNativeModules(ctx, |
| 631 | a.properties.Multilib.Lib32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 632 | a.properties.Multilib.Lib32.Binaries, |
| 633 | a.properties.Multilib.Lib32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 634 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 635 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 636 | |
| 637 | addDependenciesForNativeModules(ctx, |
| 638 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 639 | a.properties.Multilib.Prefer32.Binaries, |
| 640 | a.properties.Multilib.Prefer32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 641 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 642 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 643 | case "lib64": |
| 644 | // Add native modules targetting 64-bit ABI |
| 645 | addDependenciesForNativeModules(ctx, |
| 646 | a.properties.Multilib.Lib64.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 647 | a.properties.Multilib.Lib64.Binaries, |
| 648 | a.properties.Multilib.Lib64.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 649 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 650 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 651 | |
| 652 | if !has32BitTarget { |
| 653 | addDependenciesForNativeModules(ctx, |
| 654 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 655 | a.properties.Multilib.Prefer32.Binaries, |
| 656 | a.properties.Multilib.Prefer32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 657 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 658 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 659 | } |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 660 | |
| 661 | if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device { |
| 662 | for _, sanitizer := range ctx.Config().SanitizeDevice() { |
| 663 | if sanitizer == "hwaddress" { |
| 664 | addDependenciesForNativeModules(ctx, |
| 665 | []string{"libclang_rt.hwasan-aarch64-android"}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 666 | nil, nil, target, a.getImageVariation(config)) |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 667 | break |
| 668 | } |
| 669 | } |
| 670 | } |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 671 | } |
| 672 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 673 | } |
| 674 | |
Jiyong Park | ce6aadc | 2019-11-20 13:58:28 +0900 | [diff] [blame] | 675 | // For prebuilt_etc, use the first variant (64 on 64/32bit device, |
| 676 | // 32 on 32bit device) regardless of the TARGET_PREFER_* setting. |
| 677 | // b/144532908 |
| 678 | archForPrebuiltEtc := config.Arches()[0] |
| 679 | for _, arch := range config.Arches() { |
| 680 | // Prefer 64-bit arch if there is any |
| 681 | if arch.ArchType.Multilib == "lib64" { |
| 682 | archForPrebuiltEtc = arch |
| 683 | break |
| 684 | } |
| 685 | } |
| 686 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 687 | {Mutator: "os", Variation: ctx.Os().String()}, |
| 688 | {Mutator: "arch", Variation: archForPrebuiltEtc.String()}, |
| 689 | }, prebuiltTag, a.properties.Prebuilts...) |
| 690 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 691 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 692 | javaLibTag, a.properties.Java_libs...) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 693 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 694 | if String(a.properties.Key) == "" { |
| 695 | ctx.ModuleErrorf("key is missing") |
| 696 | return |
| 697 | } |
| 698 | ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key)) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 699 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 700 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 701 | if cert != "" { |
| 702 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 703 | } |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 704 | |
| 705 | // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks |
| 706 | if len(a.properties.Uses_sdks) > 0 { |
| 707 | sdkRefs := []android.SdkRef{} |
| 708 | for _, str := range a.properties.Uses_sdks { |
| 709 | parsed := android.ParseSdkRef(ctx, str, "uses_sdks") |
| 710 | sdkRefs = append(sdkRefs, parsed) |
| 711 | } |
| 712 | a.BuildWithSdks(sdkRefs) |
| 713 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 714 | } |
| 715 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 716 | func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { |
| 717 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 718 | androidAppTag, a.overridableProperties.Apps...) |
| 719 | } |
| 720 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 721 | func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 722 | // direct deps of an APEX bundle are all part of the APEX bundle |
| 723 | return true |
| 724 | } |
| 725 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 726 | func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string { |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 727 | moduleName := ctx.ModuleName() |
| 728 | // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list, |
| 729 | // we check with the pseudo module name to see if its certificate is overridden. |
| 730 | if a.vndkApex { |
| 731 | moduleName = vndkApexName |
| 732 | } |
| 733 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName) |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 734 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 735 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 736 | } |
| 737 | return String(a.properties.Certificate) |
| 738 | } |
| 739 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 740 | func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) { |
| 741 | switch tag { |
| 742 | case "": |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 743 | return android.Paths{a.outputFile}, nil |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 744 | default: |
| 745 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Jiyong Park | 5a83202 | 2018-12-20 09:54:35 +0900 | [diff] [blame] | 746 | } |
Jiyong Park | 74e240b | 2018-11-27 21:27:08 +0900 | [diff] [blame] | 747 | } |
| 748 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 749 | func (a *apexBundle) installable() bool { |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 750 | 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] | 751 | } |
| 752 | |
Nikita Ioffe | c72b5dd | 2019-12-07 17:30:22 +0000 | [diff] [blame] | 753 | func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool { |
| 754 | return proptools.Bool(a.properties.Test_only_no_hashtree) |
| 755 | } |
| 756 | |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 757 | func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 758 | if a.vndkApex { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 759 | return cc.VendorVariationPrefix + a.vndkVersion(config) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 760 | } |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 761 | if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 762 | return cc.VendorVariationPrefix + config.PlatformVndkVersion() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 763 | } else { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 764 | return android.CoreVariation |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 768 | func (a *apexBundle) EnableSanitizer(sanitizerName string) { |
| 769 | if !android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 770 | a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName) |
| 771 | } |
| 772 | } |
| 773 | |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 774 | func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 775 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 776 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | // Then follow the global setting |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 780 | globalSanitizerNames := []string{} |
| 781 | if a.Host() { |
| 782 | globalSanitizerNames = ctx.Config().SanitizeHost() |
| 783 | } else { |
| 784 | arches := ctx.Config().SanitizeDeviceArch() |
| 785 | if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { |
| 786 | globalSanitizerNames = ctx.Config().SanitizeDevice() |
| 787 | } |
| 788 | } |
| 789 | return android.InList(sanitizerName, globalSanitizerNames) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 790 | } |
| 791 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 792 | func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 793 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 794 | } |
| 795 | |
| 796 | func (a *apexBundle) PreventInstall() { |
| 797 | a.properties.PreventInstall = true |
| 798 | } |
| 799 | |
| 800 | func (a *apexBundle) HideFromMake() { |
| 801 | a.properties.HideFromMake = true |
| 802 | } |
| 803 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 804 | // TODO(jiyong) move apexFileFor* close to the apexFile type definition |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 805 | func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 806 | // Decide the APEX-local directory by the multilib of the library |
| 807 | // In the future, we may query this to the module. |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 808 | var dirInApex string |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 809 | switch ccMod.Arch().ArchType.Multilib { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 810 | case "lib32": |
| 811 | dirInApex = "lib" |
| 812 | case "lib64": |
| 813 | dirInApex = "lib64" |
| 814 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 815 | dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 816 | if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 817 | dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 818 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 819 | if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) { |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 820 | // Special case for Bionic libs and other libs installed with them. This is |
| 821 | // to prevent those libs from being included in the search path |
| 822 | // /apex/com.android.runtime/${LIB}. This exclusion is required because |
| 823 | // those libs in the Runtime APEX are available via the legacy paths in |
| 824 | // /system/lib/. By the init process, the libs in the APEX are bind-mounted |
| 825 | // to the legacy paths and thus will be loaded into the default linker |
| 826 | // namespace (aka "platform" namespace). If the libs are directly in |
| 827 | // /apex/com.android.runtime/${LIB} then the same libs will be loaded again |
| 828 | // into the runtime linker namespace, which will result in double loading of |
| 829 | // them, which isn't supported. |
| 830 | dirInApex = filepath.Join(dirInApex, "bionic") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 831 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 832 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 833 | fileToCopy := ccMod.OutputFile().Path() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 834 | return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 835 | } |
| 836 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 837 | func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 838 | dirInApex := filepath.Join("bin", cc.RelativeInstallPath()) |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 839 | if cc.Target().NativeBridge == android.NativeBridgeEnabled { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 840 | dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) |
Jiyong Park | acbf6c7 | 2019-07-09 16:19:16 +0900 | [diff] [blame] | 841 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 842 | fileToCopy := cc.OutputFile().Path() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 843 | af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 844 | af.symlinks = cc.Symlinks() |
| 845 | return af |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 846 | } |
| 847 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 848 | func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 849 | dirInApex := "bin" |
| 850 | fileToCopy := py.HostToolPath().Path() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 851 | return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 852 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 853 | func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 854 | dirInApex := "bin" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 855 | s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) |
| 856 | if err != nil { |
| 857 | ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath()) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 858 | return apexFile{} |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 859 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 860 | fileToCopy := android.PathForOutput(ctx, s) |
| 861 | // NB: Since go binaries are static we don't need the module for anything here, which is |
| 862 | // good since the go tool is a blueprint.Module not an android.Module like we would |
| 863 | // normally use. |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 864 | return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 865 | } |
| 866 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 867 | func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 868 | dirInApex := filepath.Join("bin", sh.SubDir()) |
| 869 | fileToCopy := sh.OutputFile() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 870 | af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 871 | af.symlinks = sh.Symlinks() |
| 872 | return af |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 873 | } |
| 874 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame^] | 875 | // TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency |
| 876 | type javaLibrary interface { |
| 877 | android.Module |
| 878 | java.Dependency |
| 879 | } |
| 880 | |
| 881 | func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 882 | dirInApex := "javalib" |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame^] | 883 | fileToCopy := lib.DexJar() |
| 884 | return newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 885 | } |
| 886 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 887 | func apexFileForPrebuiltJavaLibrary(ctx android.BaseModuleContext, java *java.Import) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 888 | dirInApex := "javalib" |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 889 | // The output is only one, but for some reason, ImplementationJars returns Paths, not Path |
| 890 | implJars := java.ImplementationJars() |
| 891 | if len(implJars) != 1 { |
| 892 | panic(fmt.Errorf("java.ImplementationJars() must return single Path, but got: %s", |
| 893 | strings.Join(implJars.Strings(), ", "))) |
| 894 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 895 | fileToCopy := implJars[0] |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 896 | return newApexFile(ctx, fileToCopy, java.Name(), dirInApex, javaSharedLib, java) |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 897 | } |
| 898 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 899 | func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 900 | dirInApex := filepath.Join("etc", prebuilt.SubDir()) |
| 901 | fileToCopy := prebuilt.OutputFile() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 902 | return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 903 | } |
| 904 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 905 | func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 906 | android.Module |
| 907 | Privileged() bool |
| 908 | OutputFile() android.Path |
| 909 | }, pkgName string) apexFile { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 910 | appDir := "app" |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 911 | if aapp.Privileged() { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 912 | appDir = "priv-app" |
| 913 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 914 | dirInApex := filepath.Join(appDir, pkgName) |
| 915 | fileToCopy := aapp.OutputFile() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 916 | return newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp) |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 917 | } |
| 918 | |
Roland Levillain | 935639d | 2019-08-13 14:55:28 +0100 | [diff] [blame] | 919 | // Context "decorator", overriding the InstallBypassMake method to always reply `true`. |
| 920 | type flattenedApexContext struct { |
| 921 | android.ModuleContext |
| 922 | } |
| 923 | |
| 924 | func (c *flattenedApexContext) InstallBypassMake() bool { |
| 925 | return true |
| 926 | } |
| 927 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 928 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 929 | buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild() |
| 930 | switch a.properties.ApexType { |
| 931 | case imageApex: |
| 932 | if buildFlattenedAsDefault { |
| 933 | a.suffix = imageApexSuffix |
| 934 | } else { |
| 935 | a.suffix = "" |
| 936 | a.primaryApexType = true |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 937 | |
| 938 | if ctx.Config().InstallExtraFlattenedApexes() { |
| 939 | a.externalDeps = append(a.externalDeps, a.Name()+flattenedSuffix) |
| 940 | } |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 941 | } |
| 942 | case zipApex: |
| 943 | if proptools.String(a.properties.Payload_type) == "zip" { |
| 944 | a.suffix = "" |
| 945 | a.primaryApexType = true |
| 946 | } else { |
| 947 | a.suffix = zipApexSuffix |
| 948 | } |
| 949 | case flattenedApex: |
| 950 | if buildFlattenedAsDefault { |
| 951 | a.suffix = "" |
| 952 | a.primaryApexType = true |
| 953 | } else { |
| 954 | a.suffix = flattenedSuffix |
| 955 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 956 | } |
| 957 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 958 | if len(a.properties.Tests) > 0 && !a.testApex { |
| 959 | ctx.PropertyErrorf("tests", "property not allowed in apex module type") |
| 960 | return |
| 961 | } |
| 962 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 963 | handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case) |
| 964 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 965 | // native lib dependencies |
| 966 | var provideNativeLibs []string |
| 967 | var requireNativeLibs []string |
| 968 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 969 | // Check if "uses" requirements are met with dependent apexBundles |
| 970 | var providedNativeSharedLibs []string |
| 971 | useVendor := proptools.Bool(a.properties.Use_vendor) |
| 972 | ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) { |
| 973 | if ctx.OtherModuleDependencyTag(m) != usesTag { |
| 974 | return |
| 975 | } |
| 976 | otherName := ctx.OtherModuleName(m) |
| 977 | other, ok := m.(*apexBundle) |
| 978 | if !ok { |
| 979 | ctx.PropertyErrorf("uses", "%q is not a provider", otherName) |
| 980 | return |
| 981 | } |
| 982 | if proptools.Bool(other.properties.Use_vendor) != useVendor { |
| 983 | ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName) |
| 984 | return |
| 985 | } |
| 986 | if !proptools.Bool(other.properties.Provide_cpp_shared_libs) { |
| 987 | ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName) |
| 988 | return |
| 989 | } |
| 990 | providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...) |
| 991 | }) |
| 992 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 993 | var filesInfo []apexFile |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 994 | ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 995 | depTag := ctx.OtherModuleDependencyTag(child) |
| 996 | depName := ctx.OtherModuleName(child) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 997 | if _, isDirectDep := parent.(*apexBundle); isDirectDep { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 998 | switch depTag { |
| 999 | case sharedLibTag: |
| 1000 | if cc, ok := child.(*cc.Module); ok { |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1001 | if cc.HasStubsVariants() { |
| 1002 | provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base()) |
| 1003 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1004 | filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1005 | return true // track transitive dependencies |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1006 | } else { |
| 1007 | 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] | 1008 | } |
| 1009 | case executableTag: |
| 1010 | if cc, ok := child.(*cc.Module); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1011 | filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1012 | return true // track transitive dependencies |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1013 | } else if sh, ok := child.(*android.ShBinary); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1014 | filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh)) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1015 | } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1016 | filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py)) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1017 | } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1018 | filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb)) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1019 | } else { |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1020 | 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] | 1021 | } |
| 1022 | case javaLibTag: |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1023 | if javaLib, ok := child.(*java.Library); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1024 | af := apexFileForJavaLibrary(ctx, javaLib) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1025 | if !af.Ok() { |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1026 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 1027 | } else { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1028 | filesInfo = append(filesInfo, af) |
| 1029 | return true // track transitive dependencies |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1030 | } |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame^] | 1031 | } else if sdkLib, ok := child.(*java.SdkLibrary); ok { |
| 1032 | af := apexFileForJavaLibrary(ctx, sdkLib) |
| 1033 | if !af.Ok() { |
| 1034 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 1035 | return false |
| 1036 | } |
| 1037 | filesInfo = append(filesInfo, af) |
| 1038 | |
| 1039 | pf := sdkLib.PermissionFile() |
| 1040 | if pf == nil { |
| 1041 | ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName) |
| 1042 | return false |
| 1043 | } |
| 1044 | filesInfo = append(filesInfo, newApexFile(ctx, pf, pf.Base(), "etc/permissions", etc, nil)) |
| 1045 | return true // track transitive dependencies |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1046 | } else if javaLib, ok := child.(*java.Import); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1047 | af := apexFileForPrebuiltJavaLibrary(ctx, javaLib) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1048 | if !af.Ok() { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1049 | ctx.PropertyErrorf("java_libs", "%q does not have a jar output", depName) |
| 1050 | } else { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1051 | filesInfo = append(filesInfo, af) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1052 | } |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1053 | } else { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1054 | 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] | 1055 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1056 | case androidAppTag: |
| 1057 | pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName) |
| 1058 | if ap, ok := child.(*java.AndroidApp); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1059 | filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1060 | return true // track transitive dependencies |
| 1061 | } else if ap, ok := child.(*java.AndroidAppImport); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1062 | filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1063 | } else { |
| 1064 | ctx.PropertyErrorf("apps", "%q is not an android_app module", depName) |
| 1065 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1066 | case prebuiltTag: |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1067 | if prebuilt, ok := child.(android.PrebuiltEtcModule); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1068 | filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName)) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1069 | } else { |
| 1070 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
| 1071 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1072 | case testTag: |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1073 | if ccTest, ok := child.(*cc.Module); ok { |
| 1074 | if ccTest.IsTestPerSrcAllTestsVariation() { |
| 1075 | // Multiple-output test module (where `test_per_src: true`). |
| 1076 | // |
| 1077 | // `ccTest` is the "" ("all tests") variation of a `test_per_src` module. |
| 1078 | // We do not add this variation to `filesInfo`, as it has no output; |
| 1079 | // however, we do add the other variations of this module as indirect |
| 1080 | // dependencies (see below). |
| 1081 | return true |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1082 | } else { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1083 | // Single-output test module (where `test_per_src: false`). |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1084 | af := apexFileForExecutable(ctx, ccTest) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1085 | af.class = nativeTest |
| 1086 | filesInfo = append(filesInfo, af) |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1087 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1088 | } else { |
| 1089 | ctx.PropertyErrorf("tests", "%q is not a cc module", depName) |
| 1090 | } |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1091 | case keyTag: |
| 1092 | if key, ok := child.(*apexKey); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1093 | a.private_key_file = key.private_key_file |
| 1094 | a.public_key_file = key.public_key_file |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1095 | } else { |
| 1096 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1097 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1098 | return false |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1099 | case certificateTag: |
| 1100 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1101 | a.container_certificate_file = dep.Certificate.Pem |
| 1102 | a.container_private_key_file = dep.Certificate.Key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1103 | } else { |
| 1104 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 1105 | } |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1106 | case android.PrebuiltDepTag: |
| 1107 | // If the prebuilt is force disabled, remember to delete the prebuilt file |
| 1108 | // that might have been installed in the previous builds |
| 1109 | if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() { |
| 1110 | a.prebuiltFileToDelete = prebuilt.InstallFilename() |
| 1111 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1112 | } |
Jooyung Han | 8aee204 | 2019-10-29 05:08:31 +0900 | [diff] [blame] | 1113 | } else if !a.vndkApex { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1114 | // indirect dependencies |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1115 | if am, ok := child.(android.ApexModule); ok { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1116 | // We cannot use a switch statement on `depTag` here as the checked |
| 1117 | // tags used below are private (e.g. `cc.sharedDepTag`). |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1118 | if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1119 | if cc, ok := child.(*cc.Module); ok { |
| 1120 | if android.InList(cc.Name(), providedNativeSharedLibs) { |
| 1121 | // If we're using a shared library which is provided from other APEX, |
| 1122 | // don't include it in this APEX |
| 1123 | return false |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 1124 | } |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 1125 | if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1126 | // If the dependency is a stubs lib, don't include it in this APEX, |
| 1127 | // but make sure that the lib is installed on the device. |
| 1128 | // In case no APEX is having the lib, the lib is installed to the system |
| 1129 | // partition. |
| 1130 | // |
| 1131 | // Always include if we are a host-apex however since those won't have any |
| 1132 | // system libraries. |
| 1133 | if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.externalDeps) { |
| 1134 | a.externalDeps = append(a.externalDeps, cc.Name()) |
| 1135 | } |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1136 | requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base()) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1137 | // Don't track further |
| 1138 | return false |
| 1139 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1140 | af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1141 | af.transitiveDep = true |
| 1142 | filesInfo = append(filesInfo, af) |
| 1143 | return true // track transitive dependencies |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1144 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1145 | } else if cc.IsTestPerSrcDepTag(depTag) { |
| 1146 | if cc, ok := child.(*cc.Module); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1147 | af := apexFileForExecutable(ctx, cc) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1148 | // Handle modules created as `test_per_src` variations of a single test module: |
| 1149 | // use the name of the generated test binary (`fileToCopy`) instead of the name |
| 1150 | // of the original test module (`depName`, shared by all `test_per_src` |
| 1151 | // variations of that module). |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1152 | af.moduleName = filepath.Base(af.builtFile.String()) |
| 1153 | af.transitiveDep = true |
| 1154 | filesInfo = append(filesInfo, af) |
| 1155 | return true // track transitive dependencies |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1156 | } |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1157 | } else if java.IsJniDepTag(depTag) { |
| 1158 | // Do nothing for JNI dep. JNI libraries are always embedded in APK-in-APEX. |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1159 | return true |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1160 | } else if am.CanHaveApexVariants() && am.IsInstallableToApex() { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1161 | ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | return false |
| 1166 | }) |
| 1167 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1168 | // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries. |
| 1169 | // Build rules are generated by the dexpreopt singleton, and here we access build artifacts |
| 1170 | // via the global boot image config. |
| 1171 | if a.artApex { |
| 1172 | for arch, files := range java.DexpreoptedArtApexJars(ctx) { |
| 1173 | dirInApex := filepath.Join("javalib", arch.String()) |
| 1174 | for _, f := range files { |
| 1175 | localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String()) |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1176 | af := newApexFile(ctx, f, localModule, dirInApex, etc, nil) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1177 | filesInfo = append(filesInfo, af) |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | } |
| 1181 | |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1182 | if a.private_key_file == nil { |
Jiyong Park | fa0a373 | 2018-11-09 05:52:26 +0900 | [diff] [blame] | 1183 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key)) |
| 1184 | return |
| 1185 | } |
| 1186 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1187 | // remove duplicates in filesInfo |
| 1188 | removeDup := func(filesInfo []apexFile) []apexFile { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1189 | encountered := make(map[string]bool) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1190 | result := []apexFile{} |
| 1191 | for _, f := range filesInfo { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1192 | dest := filepath.Join(f.installDir, f.builtFile.Base()) |
| 1193 | if !encountered[dest] { |
| 1194 | encountered[dest] = true |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1195 | result = append(result, f) |
| 1196 | } |
| 1197 | } |
| 1198 | return result |
| 1199 | } |
| 1200 | filesInfo = removeDup(filesInfo) |
| 1201 | |
| 1202 | // to have consistent build rules |
| 1203 | sort.Slice(filesInfo, func(i, j int) bool { |
| 1204 | return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String() |
| 1205 | }) |
| 1206 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 1207 | // check apex_available requirements |
Jiyong Park | 3814f4d | 2019-12-02 13:08:53 +0900 | [diff] [blame] | 1208 | if !ctx.Host() && !a.testApex { |
Jiyong Park | 583a226 | 2019-10-08 20:55:38 +0900 | [diff] [blame] | 1209 | for _, fi := range filesInfo { |
| 1210 | if am, ok := fi.module.(android.ApexModule); ok { |
| 1211 | if !am.AvailableFor(ctx.ModuleName()) { |
| 1212 | ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name()) |
Jiyong Park | 3814f4d | 2019-12-02 13:08:53 +0900 | [diff] [blame] | 1213 | // don't stop so that we can report other violations in the same run |
Jiyong Park | 583a226 | 2019-10-08 20:55:38 +0900 | [diff] [blame] | 1214 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1219 | // prepend the name of this APEX to the module names. These names will be the names of |
| 1220 | // modules that will be defined if the APEX is flattened. |
| 1221 | for i := range filesInfo { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 1222 | filesInfo[i].moduleName = filesInfo[i].moduleName + "." + a.Name() + a.suffix |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1223 | } |
| 1224 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1225 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 1226 | a.filesInfo = filesInfo |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1227 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1228 | if a.properties.ApexType != zipApex { |
| 1229 | if a.properties.File_contexts == nil { |
| 1230 | a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") |
| 1231 | } else { |
| 1232 | a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) |
| 1233 | if a.Platform() { |
| 1234 | if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched { |
| 1235 | ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts) |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() { |
| 1240 | ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts) |
| 1241 | return |
| 1242 | } |
| 1243 | } |
| 1244 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1245 | // prepare apex_manifest.json |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1246 | a.buildManifest(ctx, provideNativeLibs, requireNativeLibs) |
| 1247 | |
| 1248 | a.setCertificateAndPrivateKey(ctx) |
| 1249 | if a.properties.ApexType == flattenedApex { |
| 1250 | a.buildFlattenedApex(ctx) |
| 1251 | } else { |
| 1252 | a.buildUnflattenedApex(ctx) |
| 1253 | } |
| 1254 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 1255 | apexName := proptools.StringDefault(a.properties.Apex_name, a.Name()) |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1256 | a.compatSymlinks = makeCompatSymlinks(apexName, ctx) |
| 1257 | } |
| 1258 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1259 | func newApexBundle() *apexBundle { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1260 | module := &apexBundle{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1261 | module.AddProperties(&module.properties) |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1262 | module.AddProperties(&module.targetProperties) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1263 | module.AddProperties(&module.overridableProperties) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1264 | 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] | 1265 | return class == android.Device && ctx.Config().DevicePrefer32BitExecutables() |
| 1266 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1267 | android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1268 | android.InitDefaultableModule(module) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1269 | android.InitSdkAwareModule(module) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1270 | android.InitOverridableModule(module, &module.properties.Overrides) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1271 | return module |
| 1272 | } |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1273 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1274 | func ApexBundleFactory(testApex bool, artApex bool) android.Module { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1275 | bundle := newApexBundle() |
| 1276 | bundle.testApex = testApex |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1277 | bundle.artApex = artApex |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1278 | return bundle |
| 1279 | } |
| 1280 | |
| 1281 | func testApexBundleFactory() android.Module { |
| 1282 | bundle := newApexBundle() |
| 1283 | bundle.testApex = true |
| 1284 | return bundle |
| 1285 | } |
| 1286 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1287 | func BundleFactory() android.Module { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1288 | return newApexBundle() |
| 1289 | } |
| 1290 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1291 | // |
| 1292 | // Defaults |
| 1293 | // |
| 1294 | type Defaults struct { |
| 1295 | android.ModuleBase |
| 1296 | android.DefaultsModuleBase |
| 1297 | } |
| 1298 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1299 | func defaultsFactory() android.Module { |
| 1300 | return DefaultsFactory() |
| 1301 | } |
| 1302 | |
| 1303 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1304 | module := &Defaults{} |
| 1305 | |
| 1306 | module.AddProperties(props...) |
| 1307 | module.AddProperties( |
| 1308 | &apexBundleProperties{}, |
| 1309 | &apexTargetBundleProperties{}, |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 1310 | &overridableProperties{}, |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1311 | ) |
| 1312 | |
| 1313 | android.InitDefaultsModule(module) |
| 1314 | return module |
| 1315 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1316 | |
| 1317 | // |
| 1318 | // OverrideApex |
| 1319 | // |
| 1320 | type OverrideApex struct { |
| 1321 | android.ModuleBase |
| 1322 | android.OverrideModuleBase |
| 1323 | } |
| 1324 | |
| 1325 | func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1326 | // All the overrides happen in the base module. |
| 1327 | } |
| 1328 | |
| 1329 | // override_apex is used to create an apex module based on another apex module |
| 1330 | // by overriding some of its properties. |
| 1331 | func overrideApexFactory() android.Module { |
| 1332 | m := &OverrideApex{} |
| 1333 | m.AddProperties(&overridableProperties{}) |
| 1334 | |
| 1335 | android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 1336 | android.InitOverrideModule(m) |
| 1337 | return m |
| 1338 | } |