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 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 15 | // package apex implements build rules for creating the APEX files which are container for |
| 16 | // lower-level system components. See https://source.android.com/devices/tech/ota/apex |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 17 | package apex |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 21 | "path/filepath" |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 22 | "sort" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 23 | "strings" |
| 24 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 26 | "github.com/google/blueprint/bootstrap" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 28 | |
| 29 | "android/soong/android" |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 30 | "android/soong/bazel" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 31 | "android/soong/bpf" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 32 | "android/soong/cc" |
| 33 | prebuilt_etc "android/soong/etc" |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 34 | "android/soong/filesystem" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 35 | "android/soong/java" |
| 36 | "android/soong/python" |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 37 | "android/soong/rust" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 38 | "android/soong/sh" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 39 | ) |
| 40 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 41 | func init() { |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 42 | registerApexBuildComponents(android.InitRegistrationContext) |
| 43 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 44 | |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 45 | func registerApexBuildComponents(ctx android.RegistrationContext) { |
| 46 | ctx.RegisterModuleType("apex", BundleFactory) |
| 47 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 48 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 49 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 50 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 51 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
| 52 | ctx.RegisterModuleType("apex_set", apexSetFactory) |
| 53 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 54 | ctx.PreArchMutators(registerPreArchMutators) |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 55 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 56 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 57 | |
| 58 | android.RegisterBp2BuildMutator("apex", ApexBundleBp2Build) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 59 | } |
| 60 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 61 | func registerPreArchMutators(ctx android.RegisterMutatorsContext) { |
| 62 | ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel() |
| 63 | } |
| 64 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 65 | func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { |
| 66 | ctx.TopDown("apex_vndk", apexVndkMutator).Parallel() |
| 67 | ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel() |
| 68 | } |
| 69 | |
| 70 | func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 71 | ctx.TopDown("apex_info", apexInfoMutator).Parallel() |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 72 | ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel() |
| 73 | ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel() |
| 74 | ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel() |
Paul Duffin | 28bf7ee | 2021-05-12 16:41:35 +0100 | [diff] [blame] | 75 | // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether |
| 76 | // it should create a platform variant. |
| 77 | ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel() |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 78 | ctx.BottomUp("apex", apexMutator).Parallel() |
| 79 | ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel() |
| 80 | ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel() |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | type apexBundleProperties struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 84 | // Json manifest file describing meta info of this APEX bundle. Refer to |
| 85 | // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json" |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 86 | Manifest *string `android:"path"` |
| 87 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 88 | // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified, |
| 89 | // a default one is automatically generated. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 90 | AndroidManifest *string `android:"path"` |
| 91 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 92 | // Canonical name of this APEX bundle. Used to determine the path to the activated APEX on |
| 93 | // device (/apex/<apex_name>). If unspecified, follows the name property. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 94 | Apex_name *string |
| 95 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 96 | // Determines the file contexts file for setting the security contexts to files in this APEX |
| 97 | // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default: |
| 98 | // /system/sepolicy/apex/<module_name>_file_contexts. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 99 | File_contexts *string `android:"path"` |
| 100 | |
| 101 | ApexNativeDependencies |
| 102 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 103 | Multilib apexMultilibProperties |
| 104 | |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 105 | // List of bootclasspath fragments that are embedded inside this APEX bundle. |
| 106 | Bootclasspath_fragments []string |
| 107 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 108 | // List of systemserverclasspath fragments that are embedded inside this APEX bundle. |
| 109 | Systemserverclasspath_fragments []string |
| 110 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 111 | // List of java libraries that are embedded inside this APEX bundle. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 112 | Java_libs []string |
| 113 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 114 | // List of prebuilt files that are embedded inside this APEX bundle. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 115 | Prebuilts []string |
| 116 | |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 117 | // List of platform_compat_config files that are embedded inside this APEX bundle. |
| 118 | Compat_configs []string |
| 119 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 120 | // List of BPF programs inside this APEX bundle. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 121 | Bpfs []string |
| 122 | |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 123 | // List of filesystem images that are embedded inside this APEX bundle. |
| 124 | Filesystems []string |
| 125 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 126 | // The minimum SDK version that this APEX must support at minimum. This is usually set to |
| 127 | // the SDK version that the APEX was first introduced. |
| 128 | Min_sdk_version *string |
| 129 | |
| 130 | // Whether this APEX is considered updatable or not. When set to true, this will enforce |
| 131 | // additional rules for making sure that the APEX is truly updatable. To be updatable, |
| 132 | // min_sdk_version should be set as well. This will also disable the size optimizations like |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 133 | // symlinking to the system libs. Default is true. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 134 | Updatable *bool |
| 135 | |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 136 | // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable: |
| 137 | // false`. Default is false. |
| 138 | Platform_apis *bool |
| 139 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 140 | // Whether this APEX is installable to one of the partitions like system, vendor, etc. |
| 141 | // Default: true. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 142 | Installable *bool |
| 143 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 144 | // Whether this APEX can be compressed or not. Setting this property to false means this |
| 145 | // APEX will never be compressed. When set to true, APEX will be compressed if other |
| 146 | // conditions, e.g, target device needs to support APEX compression, are also fulfilled. |
| 147 | // Default: true. |
| 148 | Compressible *bool |
| 149 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 150 | // For native libraries and binaries, use the vendor variant instead of the core (platform) |
| 151 | // variant. Default is false. DO NOT use this for APEXes that are installed to the system or |
| 152 | // system_ext partition. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 153 | Use_vendor *bool |
| 154 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 155 | // If set true, VNDK libs are considered as stable libs and are not included in this APEX. |
| 156 | // Should be only used in non-system apexes (e.g. vendor: true). Default is false. |
| 157 | Use_vndk_as_stable *bool |
| 158 | |
| 159 | // List of SDKs that are used to build this APEX. A reference to an SDK should be either |
| 160 | // `name#version` or `name` which is an alias for `name#current`. If left empty, |
| 161 | // `platform#current` is implied. This value affects all modules included in this APEX. In |
| 162 | // other words, they are also built with the SDKs specified here. |
| 163 | Uses_sdks []string |
| 164 | |
| 165 | // The type of APEX to build. Controls what the APEX payload is. Either 'image', 'zip' or |
| 166 | // 'both'. When set to image, contents are stored in a filesystem image inside a zip |
| 167 | // container. When set to zip, contents are stored in a zip container directly. This type is |
| 168 | // mostly for host-side debugging. When set to both, the two types are both built. Default |
| 169 | // is 'image'. |
| 170 | Payload_type *string |
| 171 | |
| 172 | // The type of filesystem to use when the payload_type is 'image'. Either 'ext4' or 'f2fs'. |
| 173 | // Default 'ext4'. |
| 174 | Payload_fs_type *string |
| 175 | |
| 176 | // For telling the APEX to ignore special handling for system libraries such as bionic. |
| 177 | // Default is false. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 178 | Ignore_system_library_special_case *bool |
| 179 | |
Nikita Ioffe | 9d9960f | 2021-06-09 19:43:46 +0100 | [diff] [blame] | 180 | // Whenever apex_payload.img of the APEX should include dm-verity hashtree. |
Nikita Ioffe | e261ae6 | 2021-06-16 18:15:03 +0100 | [diff] [blame] | 181 | // Default value is true. |
Nikita Ioffe | 9d9960f | 2021-06-09 19:43:46 +0100 | [diff] [blame] | 182 | Generate_hashtree *bool |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 183 | |
| 184 | // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only |
| 185 | // used in tests. |
| 186 | Test_only_unsigned_payload *bool |
| 187 | |
Mohammad Samiul Islam | a8008f9 | 2020-12-22 10:47:50 +0000 | [diff] [blame] | 188 | // Whenever apex should be compressed, regardless of product flag used. Should be only |
| 189 | // used in tests. |
| 190 | Test_only_force_compression *bool |
| 191 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 192 | // Canonical name of this APEX bundle. Used to determine the path to the |
| 193 | // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the |
| 194 | // apex mutator variations. For override_apex modules, this is the name of the |
| 195 | // overridden base module. |
| 196 | ApexVariationName string `blueprint:"mutated"` |
| 197 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 198 | IsCoverageVariant bool `blueprint:"mutated"` |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 199 | |
| 200 | // List of sanitizer names that this APEX is enabled for |
| 201 | SanitizerNames []string `blueprint:"mutated"` |
| 202 | |
| 203 | PreventInstall bool `blueprint:"mutated"` |
| 204 | |
| 205 | HideFromMake bool `blueprint:"mutated"` |
| 206 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 207 | // Internal package method for this APEX. When payload_type is image, this can be either |
| 208 | // imageApex or flattenedApex depending on Config.FlattenApex(). When payload_type is zip, |
| 209 | // this becomes zipApex. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 210 | ApexType apexPackaging `blueprint:"mutated"` |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | type ApexNativeDependencies struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 214 | // List of native libraries that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 215 | Native_shared_libs []string |
| 216 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 217 | // List of JNI libraries that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 218 | Jni_libs []string |
| 219 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 220 | // List of rust dyn libraries |
| 221 | Rust_dyn_libs []string |
| 222 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 223 | // List of native executables that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 224 | Binaries []string |
| 225 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 226 | // List of native tests that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 227 | Tests []string |
Jiyong Park | 0671146 | 2021-02-15 17:54:43 +0900 | [diff] [blame] | 228 | |
| 229 | // List of filesystem images that are embedded inside this APEX bundle. |
| 230 | Filesystems []string |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | type apexMultilibProperties struct { |
| 234 | // Native dependencies whose compile_multilib is "first" |
| 235 | First ApexNativeDependencies |
| 236 | |
| 237 | // Native dependencies whose compile_multilib is "both" |
| 238 | Both ApexNativeDependencies |
| 239 | |
| 240 | // Native dependencies whose compile_multilib is "prefer32" |
| 241 | Prefer32 ApexNativeDependencies |
| 242 | |
| 243 | // Native dependencies whose compile_multilib is "32" |
| 244 | Lib32 ApexNativeDependencies |
| 245 | |
| 246 | // Native dependencies whose compile_multilib is "64" |
| 247 | Lib64 ApexNativeDependencies |
| 248 | } |
| 249 | |
| 250 | type apexTargetBundleProperties struct { |
| 251 | Target struct { |
| 252 | // Multilib properties only for android. |
| 253 | Android struct { |
| 254 | Multilib apexMultilibProperties |
| 255 | } |
| 256 | |
| 257 | // Multilib properties only for host. |
| 258 | Host struct { |
| 259 | Multilib apexMultilibProperties |
| 260 | } |
| 261 | |
| 262 | // Multilib properties only for host linux_bionic. |
| 263 | Linux_bionic struct { |
| 264 | Multilib apexMultilibProperties |
| 265 | } |
| 266 | |
| 267 | // Multilib properties only for host linux_glibc. |
| 268 | Linux_glibc struct { |
| 269 | Multilib apexMultilibProperties |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 274 | type apexArchBundleProperties struct { |
| 275 | Arch struct { |
| 276 | Arm struct { |
| 277 | ApexNativeDependencies |
| 278 | } |
| 279 | Arm64 struct { |
| 280 | ApexNativeDependencies |
| 281 | } |
| 282 | X86 struct { |
| 283 | ApexNativeDependencies |
| 284 | } |
| 285 | X86_64 struct { |
| 286 | ApexNativeDependencies |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 291 | // These properties can be used in override_apex to override the corresponding properties in the |
| 292 | // base apex. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 293 | type overridableProperties struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 294 | // List of APKs that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 295 | Apps []string |
| 296 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 297 | // List of runtime resource overlays (RROs) that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 298 | Rros []string |
| 299 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 300 | // Names of modules to be overridden. Listed modules can only be other binaries (in Make or |
| 301 | // Soong). This does not completely prevent installation of the overridden binaries, but if |
| 302 | // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will |
| 303 | // be removed from PRODUCT_PACKAGES. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 304 | Overrides []string |
| 305 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 306 | // Logging parent value. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 307 | Logging_parent string |
| 308 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 309 | // Apex Container package name. Override value for attribute package:name in |
| 310 | // AndroidManifest.xml |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 311 | Package_name string |
| 312 | |
| 313 | // A txt file containing list of files that are allowed to be included in this APEX. |
| 314 | Allowed_files *string `android:"path"` |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 315 | |
| 316 | // Name of the apex_key module that provides the private key to sign this APEX bundle. |
| 317 | Key *string |
| 318 | |
| 319 | // Specifies the certificate and the private key to sign the zip container of this APEX. If |
| 320 | // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used |
| 321 | // as the certificate and the private key, respectively. If this is ":module", then the |
| 322 | // certificate and the private key are provided from the android_app_certificate module |
| 323 | // named "module". |
| 324 | Certificate *string |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | type apexBundle struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 328 | // Inherited structs |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 329 | android.ModuleBase |
| 330 | android.DefaultableModuleBase |
| 331 | android.OverridableModuleBase |
| 332 | android.SdkBase |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 333 | android.BazelModuleBase |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 334 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 335 | // Properties |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 336 | properties apexBundleProperties |
| 337 | targetProperties apexTargetBundleProperties |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 338 | archProperties apexArchBundleProperties |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 339 | overridableProperties overridableProperties |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 340 | vndkProperties apexVndkProperties // only for apex_vndk modules |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 341 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 342 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 343 | // Inputs |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 344 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 345 | // Keys for apex_paylaod.img |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 346 | publicKeyFile android.Path |
| 347 | privateKeyFile android.Path |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 348 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 349 | // Cert/priv-key for the zip container |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 350 | containerCertificateFile android.Path |
| 351 | containerPrivateKeyFile android.Path |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 352 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 353 | // Flags for special variants of APEX |
| 354 | testApex bool |
| 355 | vndkApex bool |
| 356 | artApex bool |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 357 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 358 | // Tells whether this variant of the APEX bundle is the primary one or not. Only the primary |
| 359 | // one gets installed to the device. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 360 | primaryApexType bool |
| 361 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 362 | // Suffix of module name in Android.mk ".flattened", ".apex", ".zipapex", or "" |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 363 | suffix string |
| 364 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 365 | // File system type of apex_payload.img |
| 366 | payloadFsType fsType |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 367 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 368 | // Whether to create symlink to the system file instead of having a file inside the apex or |
| 369 | // not |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 370 | linkToSystemLib bool |
| 371 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 372 | // List of files to be included in this APEX. This is filled in the first part of |
| 373 | // GenerateAndroidBuildActions. |
| 374 | filesInfo []apexFile |
| 375 | |
| 376 | // List of other module names that should be installed when this APEX gets installed. |
| 377 | requiredDeps []string |
| 378 | |
| 379 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 380 | // Outputs (final and intermediates) |
| 381 | |
| 382 | // Processed apex manifest in JSONson format (for Q) |
| 383 | manifestJsonOut android.WritablePath |
| 384 | |
| 385 | // Processed apex manifest in PB format (for R+) |
| 386 | manifestPbOut android.WritablePath |
| 387 | |
| 388 | // Processed file_contexts files |
| 389 | fileContexts android.WritablePath |
| 390 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 391 | // Struct holding the merged notice file paths in different formats |
| 392 | mergedNotices android.NoticeOutputs |
| 393 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 394 | // The built APEX file. This is the main product. |
| 395 | outputFile android.WritablePath |
| 396 | |
| 397 | // The built APEX file in app bundle format. This file is not directly installed to the |
| 398 | // device. For an APEX, multiple app bundles are created each of which is for a specific ABI |
| 399 | // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build |
| 400 | // system) to be merged into a single app bundle file that Play accepts. See |
| 401 | // vendor/google/build/build_unbundled_mainline_module.sh for more detail. |
| 402 | bundleModuleFile android.WritablePath |
| 403 | |
| 404 | // Target path to install this APEX. Usually out/target/product/<device>/<partition>/apex. |
| 405 | installDir android.InstallPath |
| 406 | |
| 407 | // List of commands to create symlinks for backward compatibility. These commands will be |
| 408 | // attached as LOCAL_POST_INSTALL_CMD to apex package itself (for unflattened build) or |
| 409 | // apex_manifest (for flattened build) so that compat symlinks are always installed |
| 410 | // regardless of TARGET_FLATTEN_APEX setting. |
| 411 | compatSymlinks []string |
| 412 | |
| 413 | // Text file having the list of individual files that are included in this APEX. Used for |
| 414 | // debugging purpose. |
| 415 | installedFilesFile android.WritablePath |
| 416 | |
| 417 | // List of module names that this APEX is including (to be shown via *-deps-info target). |
| 418 | // Used for debugging purpose. |
| 419 | android.ApexBundleDepsInfo |
| 420 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 421 | // Optional list of lint report zip files for apexes that contain java or app modules |
| 422 | lintReports android.Paths |
| 423 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 424 | prebuiltFileToDelete string |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 425 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 426 | isCompressed bool |
| 427 | |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 428 | // Path of API coverage generate file |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 429 | apisUsedByModuleFile android.ModuleOutPath |
| 430 | apisBackedByModuleFile android.ModuleOutPath |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 431 | |
| 432 | // Collect the module directory for IDE info in java/jdeps.go. |
| 433 | modulePaths []string |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 434 | } |
| 435 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 436 | // apexFileClass represents a type of file that can be included in APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 437 | type apexFileClass int |
| 438 | |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 439 | const ( |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 440 | app apexFileClass = iota |
| 441 | appSet |
| 442 | etc |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 443 | goBinary |
| 444 | javaSharedLib |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 445 | nativeExecutable |
| 446 | nativeSharedLib |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 447 | nativeTest |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 448 | pyBinary |
| 449 | shBinary |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 450 | ) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 451 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 452 | // apexFile represents a file in an APEX bundle. This is created during the first half of |
| 453 | // GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half |
| 454 | // of the function, this is used to create commands that copies the files into a staging directory, |
| 455 | // where they are packaged into the APEX file. This struct is also used for creating Make modules |
| 456 | // for each of the files in case when the APEX is flattened. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 457 | type apexFile struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 458 | // buildFile is put in the installDir inside the APEX. |
| 459 | builtFile android.Path |
| 460 | noticeFiles android.Paths |
| 461 | installDir string |
| 462 | customStem string |
| 463 | symlinks []string // additional symlinks |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 464 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 465 | // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk |
| 466 | // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex |
| 467 | // suffix>] |
| 468 | androidMkModuleName string // becomes LOCAL_MODULE |
| 469 | class apexFileClass // becomes LOCAL_MODULE_CLASS |
| 470 | moduleDir string // becomes LOCAL_PATH |
| 471 | requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES |
| 472 | targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES |
| 473 | hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES |
| 474 | dataPaths []android.DataPath // becomes LOCAL_TEST_DATA |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 475 | |
| 476 | jacocoReportClassesFile android.Path // only for javalibs and apps |
| 477 | lintDepSets java.LintDepSets // only for javalibs and apps |
| 478 | certificate java.Certificate // only for apps |
| 479 | overriddenPackageName string // only for apps |
| 480 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 481 | transitiveDep bool |
| 482 | isJniLib bool |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 483 | |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 484 | multilib string |
| 485 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 486 | // TODO(jiyong): remove this |
| 487 | module android.Module |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 488 | } |
| 489 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 490 | // TODO(jiyong): shorten the arglist using an option struct |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 491 | func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile { |
| 492 | ret := apexFile{ |
| 493 | builtFile: builtFile, |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 494 | installDir: installDir, |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 495 | androidMkModuleName: androidMkModuleName, |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 496 | class: class, |
| 497 | module: module, |
| 498 | } |
| 499 | if module != nil { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 500 | ret.noticeFiles = module.NoticeFiles() |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 501 | ret.moduleDir = ctx.OtherModuleDir(module) |
| 502 | ret.requiredModuleNames = module.RequiredModuleNames() |
| 503 | ret.targetRequiredModuleNames = module.TargetRequiredModuleNames() |
| 504 | ret.hostRequiredModuleNames = module.HostRequiredModuleNames() |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 505 | ret.multilib = module.Target().Arch.ArchType.Multilib |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 506 | } |
| 507 | return ret |
| 508 | } |
| 509 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 510 | func (af *apexFile) ok() bool { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 511 | return af.builtFile != nil && af.builtFile.String() != "" |
| 512 | } |
| 513 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 514 | // apexRelativePath returns the relative path of the given path from the install directory of this |
| 515 | // apexFile. |
| 516 | // TODO(jiyong): rename this |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 517 | func (af *apexFile) apexRelativePath(path string) string { |
| 518 | return filepath.Join(af.installDir, path) |
| 519 | } |
| 520 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 521 | // path returns path of this apex file relative to the APEX root |
| 522 | func (af *apexFile) path() string { |
| 523 | return af.apexRelativePath(af.stem()) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 524 | } |
| 525 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 526 | // stem returns the base filename of this apex file |
| 527 | func (af *apexFile) stem() string { |
| 528 | if af.customStem != "" { |
| 529 | return af.customStem |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 530 | } |
| 531 | return af.builtFile.Base() |
| 532 | } |
| 533 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 534 | // symlinkPaths returns paths of the symlinks (if any) relative to the APEX root |
| 535 | func (af *apexFile) symlinkPaths() []string { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 536 | var ret []string |
| 537 | for _, symlink := range af.symlinks { |
| 538 | ret = append(ret, af.apexRelativePath(symlink)) |
| 539 | } |
| 540 | return ret |
| 541 | } |
| 542 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 543 | // availableToPlatform tests whether this apexFile is from a module that can be installed to the |
| 544 | // platform. |
| 545 | func (af *apexFile) availableToPlatform() bool { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 546 | if af.module == nil { |
| 547 | return false |
| 548 | } |
| 549 | if am, ok := af.module.(android.ApexModule); ok { |
| 550 | return am.AvailableFor(android.AvailableToPlatform) |
| 551 | } |
| 552 | return false |
| 553 | } |
| 554 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 555 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 556 | // Mutators |
| 557 | // |
| 558 | // Brief description about mutators for APEX. The following three mutators are the most important |
| 559 | // ones. |
| 560 | // |
| 561 | // 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added |
| 562 | // to the (direct) dependencies of this APEX bundle. |
| 563 | // |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 564 | // 2) apexInfoMutator: this is a post-deps mutator, so runs after DepsMutator. Its goal is to |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 565 | // collect modules that are direct and transitive dependencies of each APEX bundle. The collected |
| 566 | // modules are marked as being included in the APEX via BuildForApex(). |
| 567 | // |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 568 | // 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that |
| 569 | // are marked by the apexInfoMutator, apex variations are created using CreateApexVariations(). |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 570 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 571 | type dependencyTag struct { |
| 572 | blueprint.BaseDependencyTag |
| 573 | name string |
| 574 | |
| 575 | // Determines if the dependent will be part of the APEX payload. Can be false for the |
| 576 | // dependencies to the signing key module, etc. |
| 577 | payload bool |
Paul Duffin | 8c535da | 2021-03-17 14:51:03 +0000 | [diff] [blame] | 578 | |
| 579 | // True if the dependent can only be a source module, false if a prebuilt module is a suitable |
| 580 | // replacement. This is needed because some prebuilt modules do not provide all the information |
| 581 | // needed by the apex. |
| 582 | sourceOnly bool |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 583 | } |
| 584 | |
Paul Duffin | 8c535da | 2021-03-17 14:51:03 +0000 | [diff] [blame] | 585 | func (d dependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 586 | return !d.sourceOnly |
| 587 | } |
| 588 | |
| 589 | var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{} |
| 590 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 591 | var ( |
Paul Duffin | 0b81778 | 2021-03-17 15:02:19 +0000 | [diff] [blame] | 592 | androidAppTag = dependencyTag{name: "androidApp", payload: true} |
| 593 | bpfTag = dependencyTag{name: "bpf", payload: true} |
| 594 | certificateTag = dependencyTag{name: "certificate"} |
| 595 | executableTag = dependencyTag{name: "executable", payload: true} |
| 596 | fsTag = dependencyTag{name: "filesystem", payload: true} |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 597 | bcpfTag = dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true} |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 598 | sscpfTag = dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true} |
Paul Duffin | 1b29e00 | 2021-03-16 15:06:54 +0000 | [diff] [blame] | 599 | compatConfigTag = dependencyTag{name: "compatConfig", payload: true, sourceOnly: true} |
Paul Duffin | 0b81778 | 2021-03-17 15:02:19 +0000 | [diff] [blame] | 600 | javaLibTag = dependencyTag{name: "javaLib", payload: true} |
| 601 | jniLibTag = dependencyTag{name: "jniLib", payload: true} |
| 602 | keyTag = dependencyTag{name: "key"} |
| 603 | prebuiltTag = dependencyTag{name: "prebuilt", payload: true} |
| 604 | rroTag = dependencyTag{name: "rro", payload: true} |
| 605 | sharedLibTag = dependencyTag{name: "sharedLib", payload: true} |
| 606 | testForTag = dependencyTag{name: "test for"} |
| 607 | testTag = dependencyTag{name: "test", payload: true} |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 608 | ) |
| 609 | |
| 610 | // TODO(jiyong): shorten this function signature |
| 611 | func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 612 | binVariations := target.Variations() |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 613 | libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 614 | rustLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 615 | |
| 616 | if ctx.Device() { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 617 | binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation}) |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 618 | libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation}) |
| 619 | rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation}) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 620 | } |
| 621 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 622 | // Use *FarVariation* to be able to depend on modules having conflicting variations with |
| 623 | // this module. This is required since arch variant of an APEX bundle is 'common' but it is |
| 624 | // 'arm' or 'arm64' for native shared libs. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 625 | ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 626 | ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 627 | ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...) |
| 628 | ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 629 | ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...) |
Jiyong Park | 0671146 | 2021-02-15 17:54:43 +0900 | [diff] [blame] | 630 | ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 634 | if ctx.Device() { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 635 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil) |
| 636 | } else { |
| 637 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil) |
| 638 | if ctx.Os().Bionic() { |
| 639 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil) |
| 640 | } else { |
| 641 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil) |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 646 | // getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply |
| 647 | // android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX. |
| 648 | func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string { |
| 649 | deviceConfig := ctx.DeviceConfig() |
| 650 | if a.vndkApex { |
| 651 | return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 652 | } |
| 653 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 654 | var prefix string |
| 655 | var vndkVersion string |
| 656 | if deviceConfig.VndkVersion() != "" { |
| 657 | if proptools.Bool(a.properties.Use_vendor) { |
| 658 | prefix = cc.VendorVariationPrefix |
| 659 | vndkVersion = deviceConfig.PlatformVndkVersion() |
| 660 | } else if a.SocSpecific() || a.DeviceSpecific() { |
| 661 | prefix = cc.VendorVariationPrefix |
| 662 | vndkVersion = deviceConfig.VndkVersion() |
| 663 | } else if a.ProductSpecific() { |
| 664 | prefix = cc.ProductVariationPrefix |
| 665 | vndkVersion = deviceConfig.ProductVndkVersion() |
| 666 | } |
| 667 | } |
| 668 | if vndkVersion == "current" { |
| 669 | vndkVersion = deviceConfig.PlatformVndkVersion() |
| 670 | } |
| 671 | if vndkVersion != "" { |
| 672 | return prefix + vndkVersion |
| 673 | } |
| 674 | |
| 675 | return android.CoreVariation // The usual case |
| 676 | } |
| 677 | |
| 678 | func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 679 | // TODO(jiyong): move this kind of checks to GenerateAndroidBuildActions? |
| 680 | checkUseVendorProperty(ctx, a) |
| 681 | |
| 682 | // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'. |
| 683 | // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For |
| 684 | // each target os/architectures, appropriate dependencies are selected by their |
| 685 | // target.<os>.multilib.<type> groups and are added as (direct) dependencies. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 686 | targets := ctx.MultiTargets() |
| 687 | config := ctx.DeviceConfig() |
| 688 | imageVariation := a.getImageVariation(ctx) |
| 689 | |
| 690 | a.combineProperties(ctx) |
| 691 | |
| 692 | has32BitTarget := false |
| 693 | for _, target := range targets { |
| 694 | if target.Arch.ArchType.Multilib == "lib32" { |
| 695 | has32BitTarget = true |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 698 | for i, target := range targets { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 699 | // Don't include artifacts for the host cross targets because there is no way for us |
| 700 | // to run those artifacts natively on host |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 701 | if target.HostCross { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 702 | continue |
| 703 | } |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 704 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 705 | var depsList []ApexNativeDependencies |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 706 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 707 | // Add native modules targeting both ABIs. When multilib.* is omitted for |
| 708 | // native_shared_libs/jni_libs/tests, it implies multilib.both |
| 709 | depsList = append(depsList, a.properties.Multilib.Both) |
| 710 | depsList = append(depsList, ApexNativeDependencies{ |
| 711 | Native_shared_libs: a.properties.Native_shared_libs, |
| 712 | Tests: a.properties.Tests, |
| 713 | Jni_libs: a.properties.Jni_libs, |
| 714 | Binaries: nil, |
| 715 | }) |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 716 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 717 | // Add native modules targeting the first ABI When multilib.* is omitted for |
| 718 | // binaries, it implies multilib.first |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 719 | isPrimaryAbi := i == 0 |
| 720 | if isPrimaryAbi { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 721 | depsList = append(depsList, a.properties.Multilib.First) |
| 722 | depsList = append(depsList, ApexNativeDependencies{ |
| 723 | Native_shared_libs: nil, |
| 724 | Tests: nil, |
| 725 | Jni_libs: nil, |
| 726 | Binaries: a.properties.Binaries, |
| 727 | }) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 728 | } |
| 729 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 730 | // Add native modules targeting either 32-bit or 64-bit ABI |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 731 | switch target.Arch.ArchType.Multilib { |
| 732 | case "lib32": |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 733 | depsList = append(depsList, a.properties.Multilib.Lib32) |
| 734 | depsList = append(depsList, a.properties.Multilib.Prefer32) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 735 | case "lib64": |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 736 | depsList = append(depsList, a.properties.Multilib.Lib64) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 737 | if !has32BitTarget { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 738 | depsList = append(depsList, a.properties.Multilib.Prefer32) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 739 | } |
| 740 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 741 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 742 | // Add native modules targeting a specific arch variant |
| 743 | switch target.Arch.ArchType { |
| 744 | case android.Arm: |
| 745 | depsList = append(depsList, a.archProperties.Arch.Arm.ApexNativeDependencies) |
| 746 | case android.Arm64: |
| 747 | depsList = append(depsList, a.archProperties.Arch.Arm64.ApexNativeDependencies) |
| 748 | case android.X86: |
| 749 | depsList = append(depsList, a.archProperties.Arch.X86.ApexNativeDependencies) |
| 750 | case android.X86_64: |
| 751 | depsList = append(depsList, a.archProperties.Arch.X86_64.ApexNativeDependencies) |
| 752 | default: |
| 753 | panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType)) |
| 754 | } |
| 755 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 756 | for _, d := range depsList { |
| 757 | addDependenciesForNativeModules(ctx, d, target, imageVariation) |
| 758 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 759 | } |
| 760 | |
Martin Stjernholm | df298b3 | 2021-05-21 20:57:29 +0100 | [diff] [blame] | 761 | if prebuilts := a.properties.Prebuilts; len(prebuilts) > 0 { |
| 762 | // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device) |
| 763 | // regardless of the TARGET_PREFER_* setting. See b/144532908 |
| 764 | archForPrebuiltEtc := config.Arches()[0] |
| 765 | for _, arch := range config.Arches() { |
| 766 | // Prefer 64-bit arch if there is any |
| 767 | if arch.ArchType.Multilib == "lib64" { |
| 768 | archForPrebuiltEtc = arch |
| 769 | break |
| 770 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 771 | } |
Martin Stjernholm | df298b3 | 2021-05-21 20:57:29 +0100 | [diff] [blame] | 772 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 773 | {Mutator: "os", Variation: ctx.Os().String()}, |
| 774 | {Mutator: "arch", Variation: archForPrebuiltEtc.String()}, |
| 775 | }, prebuiltTag, prebuilts...) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 776 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 777 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 778 | // Common-arch dependencies come next |
| 779 | commonVariation := ctx.Config().AndroidCommonTarget.Variations() |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 780 | ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...) |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 781 | ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 782 | ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...) |
| 783 | ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.properties.Bpfs...) |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 784 | ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...) |
Paul Duffin | 0b81778 | 2021-03-17 15:02:19 +0000 | [diff] [blame] | 785 | ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 786 | |
Ulya Trafimovich | a4a1c4e | 2021-01-15 18:40:04 +0000 | [diff] [blame] | 787 | if a.artApex { |
| 788 | // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library. |
| 789 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { |
| 790 | ctx.AddFarVariationDependencies(commonVariation, javaLibTag, "jacocoagent") |
| 791 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 792 | } |
| 793 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 794 | // Marks that this APEX (in fact all the modules in it) has to be built with the given SDKs. |
| 795 | // This field currently isn't used. |
| 796 | // TODO(jiyong): consider dropping this feature |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 797 | // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks |
| 798 | if len(a.properties.Uses_sdks) > 0 { |
| 799 | sdkRefs := []android.SdkRef{} |
| 800 | for _, str := range a.properties.Uses_sdks { |
| 801 | parsed := android.ParseSdkRef(ctx, str, "uses_sdks") |
| 802 | sdkRefs = append(sdkRefs, parsed) |
| 803 | } |
| 804 | a.BuildWithSdks(sdkRefs) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 808 | // DepsMutator for the overridden properties. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 809 | func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { |
| 810 | if a.overridableProperties.Allowed_files != nil { |
| 811 | android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 812 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 813 | |
| 814 | commonVariation := ctx.Config().AndroidCommonTarget.Variations() |
| 815 | ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...) |
| 816 | ctx.AddFarVariationDependencies(commonVariation, rroTag, a.overridableProperties.Rros...) |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 817 | |
| 818 | // Dependencies for signing |
| 819 | if String(a.overridableProperties.Key) == "" { |
| 820 | ctx.PropertyErrorf("key", "missing") |
| 821 | return |
| 822 | } |
| 823 | ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key)) |
| 824 | |
| 825 | cert := android.SrcIsModule(a.getCertString(ctx)) |
| 826 | if cert != "" { |
| 827 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 828 | // empty cert is not an error. Cert and private keys will be directly found under |
| 829 | // PRODUCT_DEFAULT_DEV_CERTIFICATE |
| 830 | } |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 831 | } |
| 832 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 833 | type ApexBundleInfo struct { |
| 834 | Contents *android.ApexContents |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 835 | } |
| 836 | |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 837 | var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info") |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 838 | |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 839 | var _ ApexInfoMutator = (*apexBundle)(nil) |
| 840 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 841 | func (a *apexBundle) ApexVariationName() string { |
| 842 | return a.properties.ApexVariationName |
| 843 | } |
| 844 | |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 845 | // ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 846 | // identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and |
| 847 | // indirect) dependencies are collected. But a few types of modules that shouldn't be included in |
| 848 | // the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended |
| 849 | // on by multiple apexBundles. In that case, the module is collected for all of the apexBundles. |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 850 | // |
| 851 | // For each dependency between an apex and an ApexModule an ApexInfo object describing the apex |
| 852 | // is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list. |
| 853 | // The apexMutator uses that list to create module variants for the apexes to which it belongs. |
| 854 | // The relationship between module variants and apexes is not one-to-one as variants will be |
| 855 | // shared between compatible apexes. |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 856 | func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) { |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 857 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 858 | // The VNDK APEX is special. For the APEX, the membership is described in a very different |
| 859 | // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK |
| 860 | // libraries are self-identified by their vndk.enabled properties. There is no need to run |
| 861 | // this mutator for the APEX as nothing will be collected. So, let's return fast. |
| 862 | if a.vndkApex { |
| 863 | return |
| 864 | } |
| 865 | |
| 866 | // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are |
| 867 | // provided with a property named use_vndk_as_stable, which when set to true doesn't collect |
| 868 | // VNDK libraries as transitive dependencies. This option is useful for reducing the size of |
| 869 | // the non-system APEXes because the VNDK libraries won't be included (and duped) in the |
| 870 | // APEX, but shared across APEXes via the VNDK APEX. |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 871 | useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface()) |
| 872 | excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) |
| 873 | if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) { |
| 874 | mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes") |
| 875 | return |
| 876 | } |
| 877 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 878 | continueApexDepsWalk := func(child, parent android.Module) bool { |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 879 | am, ok := child.(android.ApexModule) |
| 880 | if !ok || !am.CanHaveApexVariants() { |
| 881 | return false |
Jiyong Park | f760cae | 2020-02-12 07:53:12 +0900 | [diff] [blame] | 882 | } |
Paul Duffin | 573989d | 2021-03-17 13:25:29 +0000 | [diff] [blame] | 883 | depTag := mctx.OtherModuleDependencyTag(child) |
| 884 | |
| 885 | // Check to see if the tag always requires that the child module has an apex variant for every |
| 886 | // apex variant of the parent module. If it does not then it is still possible for something |
| 887 | // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required. |
| 888 | if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() { |
| 889 | return true |
| 890 | } |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 891 | if !android.IsDepInSameApex(mctx, parent, child) { |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 892 | return false |
| 893 | } |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 894 | if excludeVndkLibs { |
| 895 | if c, ok := child.(*cc.Module); ok && c.IsVndk() { |
| 896 | return false |
| 897 | } |
| 898 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 899 | // By default, all the transitive dependencies are collected, unless filtered out |
| 900 | // above. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 901 | return true |
| 902 | } |
| 903 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 904 | // Records whether a certain module is included in this apexBundle via direct dependency or |
| 905 | // inndirect dependency. |
| 906 | contents := make(map[string]android.ApexMembership) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 907 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 908 | if !continueApexDepsWalk(child, parent) { |
| 909 | return false |
| 910 | } |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 911 | // If the parent is apexBundle, this child is directly depended. |
| 912 | _, directDep := parent.(*apexBundle) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 913 | depName := mctx.OtherModuleName(child) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 914 | contents[depName] = contents[depName].Add(directDep) |
| 915 | return true |
| 916 | }) |
| 917 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 918 | // The membership information is saved for later access |
Jiyong Park | e4758ed | 2020-11-18 01:34:22 +0900 | [diff] [blame] | 919 | apexContents := android.NewApexContents(contents) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 920 | mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{ |
| 921 | Contents: apexContents, |
| 922 | }) |
| 923 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 924 | minSdkVersion := a.minSdkVersion(mctx) |
| 925 | // When min_sdk_version is not set, the apex is built against FutureApiLevel. |
| 926 | if minSdkVersion.IsNone() { |
| 927 | minSdkVersion = android.FutureApiLevel |
| 928 | } |
| 929 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 930 | // This is the main part of this mutator. Mark the collected dependencies that they need to |
| 931 | // be built for this apexBundle. |
Jiyong Park | 78349b5 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 932 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 933 | apexVariationName := proptools.StringDefault(a.properties.Apex_name, mctx.ModuleName()) // could be com.android.foo |
| 934 | a.properties.ApexVariationName = apexVariationName |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 935 | apexInfo := android.ApexInfo{ |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 936 | ApexVariationName: apexVariationName, |
Jiyong Park | 4eab21d | 2021-04-15 15:17:54 +0900 | [diff] [blame] | 937 | MinSdkVersion: minSdkVersion, |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 938 | RequiredSdks: a.RequiredSdks(), |
| 939 | Updatable: a.Updatable(), |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 940 | UsePlatformApis: a.UsePlatformApis(), |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 941 | InApexVariants: []string{apexVariationName}, |
| 942 | InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 943 | ApexContents: []*android.ApexContents{apexContents}, |
| 944 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 945 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 946 | if !continueApexDepsWalk(child, parent) { |
| 947 | return false |
| 948 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 949 | child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark! |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 950 | return true |
Jiyong Park | f760cae | 2020-02-12 07:53:12 +0900 | [diff] [blame] | 951 | }) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 952 | } |
| 953 | |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 954 | type ApexInfoMutator interface { |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 955 | // ApexVariationName returns the name of the APEX variation to use in the apex |
| 956 | // mutator etc. It is the same name as ApexInfo.ApexVariationName. |
| 957 | ApexVariationName() string |
| 958 | |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 959 | // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are |
| 960 | // depended upon by an apex and which require an apex specific variant. |
| 961 | ApexInfoMutator(android.TopDownMutatorContext) |
| 962 | } |
| 963 | |
| 964 | // apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex |
| 965 | // specific variant to modules that support the ApexInfoMutator. |
| 966 | func apexInfoMutator(mctx android.TopDownMutatorContext) { |
| 967 | if !mctx.Module().Enabled() { |
| 968 | return |
| 969 | } |
| 970 | |
| 971 | if a, ok := mctx.Module().(ApexInfoMutator); ok { |
| 972 | a.ApexInfoMutator(mctx) |
| 973 | return |
| 974 | } |
| 975 | } |
| 976 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 977 | // apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use |
| 978 | // unique apex variations for this module. See android/apex.go for more about unique apex variant. |
| 979 | // TODO(jiyong): move this to android/apex.go? |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 980 | func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) { |
| 981 | if !mctx.Module().Enabled() { |
| 982 | return |
| 983 | } |
| 984 | if am, ok := mctx.Module().(android.ApexModule); ok { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 985 | android.UpdateUniqueApexVariationsForDeps(mctx, am) |
| 986 | } |
| 987 | } |
| 988 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 989 | // apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on |
| 990 | // the apex in order to retrieve its contents later. |
| 991 | // TODO(jiyong): move this to android/apex.go? |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 992 | func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) { |
| 993 | if !mctx.Module().Enabled() { |
| 994 | return |
| 995 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 996 | if am, ok := mctx.Module().(android.ApexModule); ok { |
| 997 | if testFor := am.TestFor(); len(testFor) > 0 { |
| 998 | mctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 999 | {Mutator: "os", Variation: am.Target().OsVariation()}, |
| 1000 | {"arch", "common"}, |
| 1001 | }, testForTag, testFor...) |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1006 | // TODO(jiyong): move this to android/apex.go? |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1007 | func apexTestForMutator(mctx android.BottomUpMutatorContext) { |
| 1008 | if !mctx.Module().Enabled() { |
| 1009 | return |
| 1010 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1011 | if _, ok := mctx.Module().(android.ApexModule); ok { |
| 1012 | var contents []*android.ApexContents |
| 1013 | for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) { |
| 1014 | abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo) |
| 1015 | contents = append(contents, abInfo.Contents) |
| 1016 | } |
| 1017 | mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{ |
| 1018 | ApexContents: contents, |
| 1019 | }) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1023 | // markPlatformAvailability marks whether or not a module can be available to platform. A module |
| 1024 | // cannot be available to platform if 1) it is explicitly marked as not available (i.e. |
| 1025 | // "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't |
| 1026 | // be) available to platform |
| 1027 | // TODO(jiyong): move this to android/apex.go? |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1028 | func markPlatformAvailability(mctx android.BottomUpMutatorContext) { |
| 1029 | // Host and recovery are not considered as platform |
| 1030 | if mctx.Host() || mctx.Module().InstallInRecovery() { |
| 1031 | return |
| 1032 | } |
| 1033 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1034 | am, ok := mctx.Module().(android.ApexModule) |
| 1035 | if !ok { |
| 1036 | return |
| 1037 | } |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1038 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1039 | availableToPlatform := am.AvailableFor(android.AvailableToPlatform) |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1040 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1041 | // If any of the dep is not available to platform, this module is also considered as being |
| 1042 | // not available to platform even if it has "//apex_available:platform" |
| 1043 | mctx.VisitDirectDeps(func(child android.Module) { |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 1044 | if !android.IsDepInSameApex(mctx, am, child) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1045 | // if the dependency crosses apex boundary, don't consider it |
| 1046 | return |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1047 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1048 | if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() { |
| 1049 | availableToPlatform = false |
| 1050 | // TODO(b/154889534) trigger an error when 'am' has |
| 1051 | // "//apex_available:platform" |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1052 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1053 | }) |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1054 | |
Paul Duffin | b5769c1 | 2021-05-12 16:16:51 +0100 | [diff] [blame] | 1055 | // Exception 1: check to see if the module always requires it. |
| 1056 | if am.AlwaysRequiresPlatformApexVariant() { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1057 | availableToPlatform = true |
| 1058 | } |
| 1059 | |
| 1060 | // Exception 2: bootstrap bionic libraries are also always available to platform |
| 1061 | if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) { |
| 1062 | availableToPlatform = true |
| 1063 | } |
| 1064 | |
| 1065 | if !availableToPlatform { |
| 1066 | am.SetNotAvailableForPlatform() |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1070 | // apexMutator visits each module and creates apex variations if the module was marked in the |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 1071 | // previous run of apexInfoMutator. |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1072 | func apexMutator(mctx android.BottomUpMutatorContext) { |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 1073 | if !mctx.Module().Enabled() { |
| 1074 | return |
| 1075 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1076 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1077 | // This is the usual path. |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1078 | if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1079 | android.CreateApexVariations(mctx, am) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1080 | return |
| 1081 | } |
| 1082 | |
| 1083 | // apexBundle itself is mutated so that it and its dependencies have the same apex variant. |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1084 | if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) { |
| 1085 | apexBundleName := ai.ApexVariationName() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1086 | mctx.CreateVariations(apexBundleName) |
Martin Stjernholm | ec00900 | 2021-03-27 15:18:31 +0000 | [diff] [blame] | 1087 | if strings.HasPrefix(apexBundleName, "com.android.art") { |
| 1088 | // Create an alias from the platform variant. This is done to make |
| 1089 | // test_for dependencies work for modules that are split by the APEX |
| 1090 | // mutator, since test_for dependencies always go to the platform variant. |
| 1091 | // This doesn't happen for normal APEXes that are disjunct, so only do |
| 1092 | // this for the overlapping ART APEXes. |
| 1093 | // TODO(b/183882457): Remove this if the test_for functionality is |
| 1094 | // refactored to depend on the proper APEX variants instead of platform. |
| 1095 | mctx.CreateAliasVariation("", apexBundleName) |
| 1096 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1097 | } else if o, ok := mctx.Module().(*OverrideApex); ok { |
| 1098 | apexBundleName := o.GetOverriddenModuleName() |
| 1099 | if apexBundleName == "" { |
| 1100 | mctx.ModuleErrorf("base property is not set") |
| 1101 | return |
| 1102 | } |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1103 | // Workaround the issue reported in b/191269918 by using the unprefixed module name of this |
| 1104 | // module as the default variation to use if dependencies of this module do not have the correct |
| 1105 | // apex variant name. This name matches the name used to create the variations of modules for |
| 1106 | // which apexModuleTypeRequiresVariant return true. |
| 1107 | // TODO(b/191269918): Remove this workaround. |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1108 | unprefixedModuleName := android.RemoveOptionalPrebuiltPrefix(mctx.ModuleName()) |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1109 | mctx.SetDefaultDependencyVariation(&unprefixedModuleName) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1110 | mctx.CreateVariations(apexBundleName) |
Martin Stjernholm | ec00900 | 2021-03-27 15:18:31 +0000 | [diff] [blame] | 1111 | if strings.HasPrefix(apexBundleName, "com.android.art") { |
| 1112 | // TODO(b/183882457): See note for CreateAliasVariation above. |
| 1113 | mctx.CreateAliasVariation("", apexBundleName) |
| 1114 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1115 | } |
| 1116 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 1117 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1118 | // apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific |
| 1119 | // variant. |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1120 | func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool { |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1121 | if a, ok := module.(*apexBundle); ok { |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1122 | // TODO(jiyong): document the reason why the VNDK APEX is an exception here. |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1123 | return !a.vndkApex |
| 1124 | } |
| 1125 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1126 | return true |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1129 | // See android.UpdateDirectlyInAnyApex |
| 1130 | // TODO(jiyong): move this to android/apex.go? |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1131 | func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) { |
| 1132 | if !mctx.Module().Enabled() { |
| 1133 | return |
| 1134 | } |
| 1135 | if am, ok := mctx.Module().(android.ApexModule); ok { |
| 1136 | android.UpdateDirectlyInAnyApex(mctx, am) |
| 1137 | } |
| 1138 | } |
| 1139 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1140 | // apexPackaging represents a specific packaging method for an APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1141 | type apexPackaging int |
| 1142 | |
| 1143 | const ( |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1144 | // imageApex is a packaging method where contents are included in a filesystem image which |
| 1145 | // is then included in a zip container. This is the most typical way of packaging. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1146 | imageApex apexPackaging = iota |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1147 | |
| 1148 | // zipApex is a packaging method where contents are directly included in the zip container. |
| 1149 | // This is used for host-side testing - because the contents are easily accessible by |
| 1150 | // unzipping the container. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1151 | zipApex |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1152 | |
| 1153 | // flattendApex is a packaging method where contents are not included in the APEX file, but |
| 1154 | // installed to /apex/<apexname> directory on the device. This packaging method is used for |
| 1155 | // old devices where the filesystem-based APEX file can't be supported. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1156 | flattenedApex |
| 1157 | ) |
| 1158 | |
| 1159 | const ( |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1160 | // File extensions of an APEX for different packaging methods |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1161 | imageApexSuffix = ".apex" |
| 1162 | zipApexSuffix = ".zipapex" |
| 1163 | flattenedSuffix = ".flattened" |
| 1164 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1165 | // variant names each of which is for a packaging method |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1166 | imageApexType = "image" |
| 1167 | zipApexType = "zip" |
| 1168 | flattenedApexType = "flattened" |
| 1169 | |
| 1170 | ext4FsType = "ext4" |
| 1171 | f2fsFsType = "f2fs" |
| 1172 | ) |
| 1173 | |
| 1174 | // The suffix for the output "file", not the module |
| 1175 | func (a apexPackaging) suffix() string { |
| 1176 | switch a { |
| 1177 | case imageApex: |
| 1178 | return imageApexSuffix |
| 1179 | case zipApex: |
| 1180 | return zipApexSuffix |
| 1181 | default: |
| 1182 | panic(fmt.Errorf("unknown APEX type %d", a)) |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | func (a apexPackaging) name() string { |
| 1187 | switch a { |
| 1188 | case imageApex: |
| 1189 | return imageApexType |
| 1190 | case zipApex: |
| 1191 | return zipApexType |
| 1192 | default: |
| 1193 | panic(fmt.Errorf("unknown APEX type %d", a)) |
| 1194 | } |
| 1195 | } |
| 1196 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1197 | // apexFlattenedMutator creates one or more variations each of which is for a packaging method. |
| 1198 | // TODO(jiyong): give a better name to this mutator |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 1199 | func apexFlattenedMutator(mctx android.BottomUpMutatorContext) { |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 1200 | if !mctx.Module().Enabled() { |
| 1201 | return |
| 1202 | } |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 1203 | if ab, ok := mctx.Module().(*apexBundle); ok { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1204 | var variants []string |
| 1205 | switch proptools.StringDefault(ab.properties.Payload_type, "image") { |
| 1206 | case "image": |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1207 | // This is the normal case. Note that both image and flattend APEXes are |
| 1208 | // created. The image type is installed to the system partition, while the |
| 1209 | // flattened APEX is (optionally) installed to the system_ext partition. |
| 1210 | // This is mostly for GSI which has to support wide range of devices. If GSI |
| 1211 | // is installed on a newer (APEX-capable) device, the image APEX in the |
| 1212 | // system will be used. However, if the same GSI is installed on an old |
| 1213 | // device which can't support image APEX, the flattened APEX in the |
| 1214 | // system_ext partion (which still is part of GSI) is used instead. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1215 | variants = append(variants, imageApexType, flattenedApexType) |
| 1216 | case "zip": |
| 1217 | variants = append(variants, zipApexType) |
| 1218 | case "both": |
| 1219 | variants = append(variants, imageApexType, zipApexType, flattenedApexType) |
| 1220 | default: |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1221 | mctx.PropertyErrorf("payload_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] | 1222 | return |
| 1223 | } |
| 1224 | |
| 1225 | modules := mctx.CreateLocalVariations(variants...) |
| 1226 | |
| 1227 | for i, v := range variants { |
| 1228 | switch v { |
| 1229 | case imageApexType: |
| 1230 | modules[i].(*apexBundle).properties.ApexType = imageApex |
| 1231 | case zipApexType: |
| 1232 | modules[i].(*apexBundle).properties.ApexType = zipApex |
| 1233 | case flattenedApexType: |
| 1234 | modules[i].(*apexBundle).properties.ApexType = flattenedApex |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1235 | // See the comment above for why system_ext. |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 1236 | if !mctx.Config().FlattenApex() && ab.Platform() { |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 1237 | modules[i].(*apexBundle).MakeAsSystemExt() |
| 1238 | } |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1239 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 1240 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1241 | } else if _, ok := mctx.Module().(*OverrideApex); ok { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1242 | // payload_type is forcibly overridden to "image" |
| 1243 | // TODO(jiyong): is this the right decision? |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1244 | mctx.CreateVariations(imageApexType, flattenedApexType) |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1248 | // checkUseVendorProperty checks if the use of `use_vendor` property is allowed for the given APEX. |
| 1249 | // When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__, |
| 1250 | // which may cause compatibility issues. (e.g. libbinder) Even though libbinder restricts its |
| 1251 | // availability via 'apex_available' property and relies on yet another macro |
| 1252 | // __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules to avoid |
| 1253 | // similar problems. |
| 1254 | func checkUseVendorProperty(ctx android.BottomUpMutatorContext, a *apexBundle) { |
| 1255 | if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) { |
| 1256 | ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true") |
| 1257 | } |
| 1258 | } |
| 1259 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1260 | var ( |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1261 | useVendorAllowListKey = android.NewOnceKey("useVendorAllowList") |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1262 | ) |
| 1263 | |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1264 | func useVendorAllowList(config android.Config) []string { |
| 1265 | return config.Once(useVendorAllowListKey, func() interface{} { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1266 | return []string{ |
| 1267 | // swcodec uses "vendor" variants for smaller size |
| 1268 | "com.android.media.swcodec", |
| 1269 | "test_com.android.media.swcodec", |
| 1270 | } |
| 1271 | }).([]string) |
| 1272 | } |
| 1273 | |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1274 | // setUseVendorAllowListForTest returns a FixturePreparer that overrides useVendorAllowList and |
| 1275 | // must be called before the first call to useVendorAllowList() |
| 1276 | func setUseVendorAllowListForTest(allowList []string) android.FixturePreparer { |
| 1277 | return android.FixtureModifyConfig(func(config android.Config) { |
| 1278 | config.Once(useVendorAllowListKey, func() interface{} { |
| 1279 | return allowList |
| 1280 | }) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1281 | }) |
| 1282 | } |
| 1283 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1284 | var _ android.DepIsInSameApex = (*apexBundle)(nil) |
Theotime Combes | 4ba38c1 | 2020-06-12 12:46:59 +0000 | [diff] [blame] | 1285 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1286 | // Implements android.DepInInSameApex |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 1287 | func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1288 | // direct deps of an APEX bundle are all part of the APEX bundle |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1289 | // TODO(jiyong): shouldn't we look into the payload field of the dependencyTag? |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 1290 | return true |
| 1291 | } |
| 1292 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1293 | var _ android.OutputFileProducer = (*apexBundle)(nil) |
| 1294 | |
| 1295 | // Implements android.OutputFileProducer |
| 1296 | func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) { |
| 1297 | switch tag { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 1298 | case "", android.DefaultDistTag: |
| 1299 | // This is the default dist path. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1300 | return android.Paths{a.outputFile}, nil |
| 1301 | default: |
| 1302 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | var _ cc.Coverage = (*apexBundle)(nil) |
| 1307 | |
| 1308 | // Implements cc.Coverage |
| 1309 | func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 1310 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 1311 | } |
| 1312 | |
| 1313 | // Implements cc.Coverage |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 1314 | func (a *apexBundle) SetPreventInstall() { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1315 | a.properties.PreventInstall = true |
| 1316 | } |
| 1317 | |
| 1318 | // Implements cc.Coverage |
| 1319 | func (a *apexBundle) HideFromMake() { |
| 1320 | a.properties.HideFromMake = true |
Colin Cross | e6a83e6 | 2020-12-17 18:22:34 -0800 | [diff] [blame] | 1321 | // This HideFromMake is shadowing the ModuleBase one, call through to it for now. |
| 1322 | // TODO(ccross): untangle these |
| 1323 | a.ModuleBase.HideFromMake() |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | // Implements cc.Coverage |
| 1327 | func (a *apexBundle) MarkAsCoverageVariant(coverage bool) { |
| 1328 | a.properties.IsCoverageVariant = coverage |
| 1329 | } |
| 1330 | |
| 1331 | // Implements cc.Coverage |
| 1332 | func (a *apexBundle) EnableCoverageIfNeeded() {} |
| 1333 | |
| 1334 | var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil) |
| 1335 | |
| 1336 | // Implements android.ApexBudleDepsInfoIntf |
| 1337 | func (a *apexBundle) Updatable() bool { |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1338 | return proptools.BoolDefault(a.properties.Updatable, true) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1339 | } |
| 1340 | |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 1341 | func (a *apexBundle) UsePlatformApis() bool { |
| 1342 | return proptools.BoolDefault(a.properties.Platform_apis, false) |
| 1343 | } |
| 1344 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1345 | // getCertString returns the name of the cert that should be used to sign this APEX. This is |
| 1346 | // basically from the "certificate" property, but could be overridden by the device config. |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1347 | func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string { |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 1348 | moduleName := ctx.ModuleName() |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1349 | // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the |
| 1350 | // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is |
| 1351 | // overridden. |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 1352 | if a.vndkApex { |
| 1353 | moduleName = vndkApexName |
| 1354 | } |
| 1355 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName) |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1356 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 1357 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1358 | } |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 1359 | return String(a.overridableProperties.Certificate) |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1360 | } |
| 1361 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1362 | // See the installable property |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1363 | func (a *apexBundle) installable() bool { |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 1364 | 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] | 1365 | } |
| 1366 | |
Nikita Ioffe | 9d9960f | 2021-06-09 19:43:46 +0100 | [diff] [blame] | 1367 | // See the generate_hashtree property |
| 1368 | func (a *apexBundle) shouldGenerateHashtree() bool { |
Nikita Ioffe | e261ae6 | 2021-06-16 18:15:03 +0100 | [diff] [blame] | 1369 | return proptools.BoolDefault(a.properties.Generate_hashtree, true) |
Nikita Ioffe | c72b5dd | 2019-12-07 17:30:22 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1372 | // See the test_only_unsigned_payload property |
Dario Freni | ca91339 | 2020-04-27 18:21:11 +0100 | [diff] [blame] | 1373 | func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool { |
| 1374 | return proptools.Bool(a.properties.Test_only_unsigned_payload) |
| 1375 | } |
| 1376 | |
Mohammad Samiul Islam | a8008f9 | 2020-12-22 10:47:50 +0000 | [diff] [blame] | 1377 | // See the test_only_force_compression property |
| 1378 | func (a *apexBundle) testOnlyShouldForceCompression() bool { |
| 1379 | return proptools.Bool(a.properties.Test_only_force_compression) |
| 1380 | } |
| 1381 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1382 | // These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its |
| 1383 | // members) can be sanitized, either forcibly, or by the global configuration. For some of the |
| 1384 | // sanitizers, extra dependencies can be forcibly added as well. |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1385 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 1386 | func (a *apexBundle) EnableSanitizer(sanitizerName string) { |
| 1387 | if !android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 1388 | a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName) |
| 1389 | } |
| 1390 | } |
| 1391 | |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 1392 | func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 1393 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 1394 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | // Then follow the global setting |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 1398 | globalSanitizerNames := []string{} |
| 1399 | if a.Host() { |
| 1400 | globalSanitizerNames = ctx.Config().SanitizeHost() |
| 1401 | } else { |
| 1402 | arches := ctx.Config().SanitizeDeviceArch() |
| 1403 | if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { |
| 1404 | globalSanitizerNames = ctx.Config().SanitizeDevice() |
| 1405 | } |
| 1406 | } |
| 1407 | return android.InList(sanitizerName, globalSanitizerNames) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1408 | } |
| 1409 | |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1410 | func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1411 | // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go |
| 1412 | // Keep only the mechanism here. |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1413 | if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1414 | imageVariation := a.getImageVariation(ctx) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1415 | for _, target := range ctx.MultiTargets() { |
| 1416 | if target.Arch.ArchType.Multilib == "lib64" { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1417 | addDependenciesForNativeModules(ctx, ApexNativeDependencies{ |
| 1418 | Native_shared_libs: []string{"libclang_rt.hwasan-aarch64-android"}, |
| 1419 | Tests: nil, |
| 1420 | Jni_libs: nil, |
| 1421 | Binaries: nil, |
| 1422 | }, target, imageVariation) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1423 | break |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1429 | // apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The |
| 1430 | // returned apexFile saves information about the Soong module that will be used for creating the |
| 1431 | // build rules. |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1432 | func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1433 | // Decide the APEX-local directory by the multilib of the library In the future, we may |
| 1434 | // query this to the module. |
| 1435 | // TODO(jiyong): use the new PackagingSpec |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1436 | var dirInApex string |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1437 | switch ccMod.Arch().ArchType.Multilib { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1438 | case "lib32": |
| 1439 | dirInApex = "lib" |
| 1440 | case "lib64": |
| 1441 | dirInApex = "lib64" |
| 1442 | } |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1443 | if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1444 | dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1445 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 1446 | dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1447 | if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1448 | // Special case for Bionic libs and other libs installed with them. This is to |
| 1449 | // prevent those libs from being included in the search path |
| 1450 | // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs |
| 1451 | // in the Runtime APEX are available via the legacy paths in /system/lib/. By the |
| 1452 | // init process, the libs in the APEX are bind-mounted to the legacy paths and thus |
| 1453 | // will be loaded into the default linker namespace (aka "platform" namespace). If |
| 1454 | // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will |
| 1455 | // be loaded again into the runtime linker namespace, which will result in double |
| 1456 | // loading of them, which isn't supported. |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1457 | dirInApex = filepath.Join(dirInApex, "bionic") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1458 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1459 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1460 | fileToCopy := ccMod.OutputFile().Path() |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1461 | androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName |
| 1462 | return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1463 | } |
| 1464 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1465 | func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile { |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 1466 | dirInApex := "bin" |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1467 | if cc.Target().NativeBridge == android.NativeBridgeEnabled { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1468 | dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) |
Jiyong Park | acbf6c7 | 2019-07-09 16:19:16 +0900 | [diff] [blame] | 1469 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 1470 | dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath()) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1471 | fileToCopy := cc.OutputFile().Path() |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1472 | androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName |
| 1473 | af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1474 | af.symlinks = cc.Symlinks() |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 1475 | af.dataPaths = cc.DataPaths() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1476 | return af |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1477 | } |
| 1478 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1479 | func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile { |
| 1480 | dirInApex := "bin" |
| 1481 | if rustm.Target().NativeBridge == android.NativeBridgeEnabled { |
| 1482 | dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath) |
| 1483 | } |
| 1484 | fileToCopy := rustm.OutputFile().Path() |
| 1485 | androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName |
| 1486 | af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm) |
| 1487 | return af |
| 1488 | } |
| 1489 | |
| 1490 | func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile { |
| 1491 | // Decide the APEX-local directory by the multilib of the library |
| 1492 | // In the future, we may query this to the module. |
| 1493 | var dirInApex string |
| 1494 | switch rustm.Arch().ArchType.Multilib { |
| 1495 | case "lib32": |
| 1496 | dirInApex = "lib" |
| 1497 | case "lib64": |
| 1498 | dirInApex = "lib64" |
| 1499 | } |
| 1500 | if rustm.Target().NativeBridge == android.NativeBridgeEnabled { |
| 1501 | dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath) |
| 1502 | } |
| 1503 | fileToCopy := rustm.OutputFile().Path() |
| 1504 | androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName |
| 1505 | return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm) |
| 1506 | } |
| 1507 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1508 | func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1509 | dirInApex := "bin" |
| 1510 | fileToCopy := py.HostToolPath().Path() |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1511 | return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1512 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1513 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1514 | func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1515 | dirInApex := "bin" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1516 | s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) |
| 1517 | if err != nil { |
| 1518 | ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath()) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1519 | return apexFile{} |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1520 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1521 | fileToCopy := android.PathForOutput(ctx, s) |
| 1522 | // NB: Since go binaries are static we don't need the module for anything here, which is |
| 1523 | // good since the go tool is a blueprint.Module not an android.Module like we would |
| 1524 | // normally use. |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1525 | return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1526 | } |
| 1527 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 1528 | func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1529 | dirInApex := filepath.Join("bin", sh.SubDir()) |
| 1530 | fileToCopy := sh.OutputFile() |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1531 | af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1532 | af.symlinks = sh.Symlinks() |
| 1533 | return af |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1534 | } |
| 1535 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 1536 | func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile { |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 1537 | dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir()) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1538 | fileToCopy := prebuilt.OutputFile() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1539 | return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1540 | } |
| 1541 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 1542 | func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile { |
| 1543 | dirInApex := filepath.Join("etc", config.SubDir()) |
| 1544 | fileToCopy := config.CompatConfig() |
| 1545 | return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config) |
| 1546 | } |
| 1547 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1548 | // javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same |
| 1549 | // way. |
| 1550 | type javaModule interface { |
| 1551 | android.Module |
| 1552 | BaseModuleName() string |
| 1553 | DexJarBuildPath() android.Path |
| 1554 | JacocoReportClassesFile() android.Path |
| 1555 | LintDepSets() java.LintDepSets |
| 1556 | Stem() string |
| 1557 | } |
| 1558 | |
| 1559 | var _ javaModule = (*java.Library)(nil) |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 1560 | var _ javaModule = (*java.Import)(nil) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1561 | var _ javaModule = (*java.SdkLibrary)(nil) |
| 1562 | var _ javaModule = (*java.DexImport)(nil) |
| 1563 | var _ javaModule = (*java.SdkLibraryImport)(nil) |
| 1564 | |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 1565 | // apexFileForJavaModule creates an apexFile for a java module's dex implementation jar. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1566 | func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile { |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 1567 | return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath()) |
| 1568 | } |
| 1569 | |
| 1570 | // apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file. |
| 1571 | func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1572 | dirInApex := "javalib" |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 1573 | af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1574 | af.jacocoReportClassesFile = module.JacocoReportClassesFile() |
| 1575 | af.lintDepSets = module.LintDepSets() |
| 1576 | af.customStem = module.Stem() + ".jar" |
| 1577 | return af |
| 1578 | } |
| 1579 | |
| 1580 | // androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in |
| 1581 | // the same way. |
| 1582 | type androidApp interface { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1583 | android.Module |
| 1584 | Privileged() bool |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 1585 | InstallApkName() string |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1586 | OutputFile() android.Path |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1587 | JacocoReportClassesFile() android.Path |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 1588 | Certificate() java.Certificate |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1589 | BaseModuleName() string |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | var _ androidApp = (*java.AndroidApp)(nil) |
| 1593 | var _ androidApp = (*java.AndroidAppImport)(nil) |
| 1594 | |
| 1595 | func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 1596 | appDir := "app" |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1597 | if aapp.Privileged() { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 1598 | appDir = "priv-app" |
| 1599 | } |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 1600 | dirInApex := filepath.Join(appDir, aapp.InstallApkName()) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1601 | fileToCopy := aapp.OutputFile() |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1602 | af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp) |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1603 | af.jacocoReportClassesFile = aapp.JacocoReportClassesFile() |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 1604 | af.certificate = aapp.Certificate() |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 1605 | |
| 1606 | if app, ok := aapp.(interface { |
| 1607 | OverriddenManifestPackageName() string |
| 1608 | }); ok { |
| 1609 | af.overriddenPackageName = app.OverriddenManifestPackageName() |
| 1610 | } |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1611 | return af |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 1612 | } |
| 1613 | |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 1614 | func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile { |
| 1615 | rroDir := "overlay" |
| 1616 | dirInApex := filepath.Join(rroDir, rro.Theme()) |
| 1617 | fileToCopy := rro.OutputFile() |
| 1618 | af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro) |
| 1619 | af.certificate = rro.Certificate() |
| 1620 | |
| 1621 | if a, ok := rro.(interface { |
| 1622 | OverriddenManifestPackageName() string |
| 1623 | }); ok { |
| 1624 | af.overriddenPackageName = a.OverriddenManifestPackageName() |
| 1625 | } |
| 1626 | return af |
| 1627 | } |
| 1628 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 1629 | func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile { |
| 1630 | dirInApex := filepath.Join("etc", "bpf") |
| 1631 | return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram) |
| 1632 | } |
| 1633 | |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 1634 | func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile { |
| 1635 | dirInApex := filepath.Join("etc", "fs") |
| 1636 | return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs) |
| 1637 | } |
| 1638 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1639 | // WalkPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1640 | // visited module, the `do` callback is executed. Returning true in the callback continues the visit |
| 1641 | // to the child modules. Returning false makes the visit to continue in the sibling or the parent |
| 1642 | // modules. This is used in check* functions below. |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1643 | func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) { |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 1644 | ctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1645 | am, ok := child.(android.ApexModule) |
| 1646 | if !ok || !am.CanHaveApexVariants() { |
| 1647 | return false |
| 1648 | } |
| 1649 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1650 | // Filter-out unwanted depedendencies |
| 1651 | depTag := ctx.OtherModuleDependencyTag(child) |
| 1652 | if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok { |
| 1653 | return false |
| 1654 | } |
| 1655 | if dt, ok := depTag.(dependencyTag); ok && !dt.payload { |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 1656 | return false |
| 1657 | } |
| 1658 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1659 | ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo) |
Jiyong Park | ab50b07 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 1660 | externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1661 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1662 | // Visit actually |
| 1663 | return do(ctx, parent, am, externalDep) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1664 | }) |
| 1665 | } |
| 1666 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1667 | // filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported. |
| 1668 | type fsType int |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1669 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1670 | const ( |
| 1671 | ext4 fsType = iota |
| 1672 | f2fs |
| 1673 | ) |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 1674 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1675 | func (f fsType) string() string { |
| 1676 | switch f { |
| 1677 | case ext4: |
| 1678 | return ext4FsType |
| 1679 | case f2fs: |
| 1680 | return f2fsFsType |
| 1681 | default: |
| 1682 | panic(fmt.Errorf("unknown APEX payload type %d", f)) |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1686 | // Creates build rules for an APEX. It consists of the following major steps: |
| 1687 | // |
| 1688 | // 1) do some validity checks such as apex_available, min_sdk_version, etc. |
| 1689 | // 2) traverse the dependency tree to collect apexFile structs from them. |
| 1690 | // 3) some fields in apexBundle struct are configured |
| 1691 | // 4) generate the build rules to create the APEX. This is mostly done in builder.go. |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1692 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1693 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 1694 | // 1) do some validity checks such as apex_available, min_sdk_version, etc. |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1695 | a.checkApexAvailability(ctx) |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 1696 | a.checkUpdatable(ctx) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1697 | a.checkMinSdkVersion(ctx) |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 1698 | a.checkStaticLinkingToStubLibraries(ctx) |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame^] | 1699 | a.checkStaticExecutables(ctx) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1700 | if len(a.properties.Tests) > 0 && !a.testApex { |
| 1701 | ctx.PropertyErrorf("tests", "property allowed only in apex_test module type") |
| 1702 | return |
| 1703 | } |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1704 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1705 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 1706 | // 2) traverse the dependency tree to collect apexFile structs from them. |
| 1707 | |
| 1708 | // all the files that will be included in this APEX |
| 1709 | var filesInfo []apexFile |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 1710 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1711 | // native lib dependencies |
| 1712 | var provideNativeLibs []string |
| 1713 | var requireNativeLibs []string |
| 1714 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1715 | handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case) |
| 1716 | |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 1717 | // Collect the module directory for IDE info in java/jdeps.go. |
| 1718 | a.modulePaths = append(a.modulePaths, ctx.ModuleDir()) |
| 1719 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1720 | // TODO(jiyong): do this using WalkPayloadDeps |
| 1721 | // TODO(jiyong): make this clean!!! |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1722 | ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1723 | depTag := ctx.OtherModuleDependencyTag(child) |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 1724 | if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok { |
| 1725 | return false |
| 1726 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1727 | depName := ctx.OtherModuleName(child) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1728 | if _, isDirectDep := parent.(*apexBundle); isDirectDep { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1729 | switch depTag { |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 1730 | case sharedLibTag, jniLibTag: |
| 1731 | isJniLib := depTag == jniLibTag |
Jooyung Han | faa2d5f | 2020-02-06 17:42:40 +0900 | [diff] [blame] | 1732 | if c, ok := child.(*cc.Module); ok { |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 1733 | fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs) |
| 1734 | fi.isJniLib = isJniLib |
| 1735 | filesInfo = append(filesInfo, fi) |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 1736 | // Collect the list of stub-providing libs except: |
| 1737 | // - VNDK libs are only for vendors |
| 1738 | // - bootstrap bionic libs are treated as provided by system |
| 1739 | if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1740 | provideNativeLibs = append(provideNativeLibs, fi.stem()) |
Jiyong Park | f1493cc | 2020-05-29 21:29:20 +0900 | [diff] [blame] | 1741 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1742 | return true // track transitive dependencies |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 1743 | } else if r, ok := child.(*rust.Module); ok { |
| 1744 | fi := apexFileForRustLibrary(ctx, r) |
| 1745 | filesInfo = append(filesInfo, fi) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1746 | } else { |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 1747 | propertyName := "native_shared_libs" |
| 1748 | if isJniLib { |
| 1749 | propertyName = "jni_libs" |
| 1750 | } |
| 1751 | ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1752 | } |
| 1753 | case executableTag: |
| 1754 | if cc, ok := child.(*cc.Module); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1755 | filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1756 | return true // track transitive dependencies |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 1757 | } else if sh, ok := child.(*sh.ShBinary); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1758 | filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh)) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1759 | } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1760 | filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py)) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1761 | } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1762 | filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb)) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1763 | } else if rust, ok := child.(*rust.Module); ok { |
| 1764 | filesInfo = append(filesInfo, apexFileForRustExecutable(ctx, rust)) |
| 1765 | return true // track transitive dependencies |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1766 | } else { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1767 | ctx.PropertyErrorf("binaries", "%q is neither cc_binary, rust_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] | 1768 | } |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 1769 | case bcpfTag: |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 1770 | { |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 1771 | if _, ok := child.(*java.BootclasspathFragmentModule); !ok { |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 1772 | ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 1773 | return false |
| 1774 | } |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 1775 | |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 1776 | filesToAdd := apexBootclasspathFragmentFiles(ctx, child) |
| 1777 | filesInfo = append(filesInfo, filesToAdd...) |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 1778 | return true |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 1779 | } |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 1780 | case sscpfTag: |
| 1781 | { |
| 1782 | if _, ok := child.(*java.SystemServerClasspathModule); !ok { |
| 1783 | ctx.PropertyErrorf("systemserverclasspath_fragments", "%q is not a systemserverclasspath_fragment module", depName) |
| 1784 | return false |
| 1785 | } |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 1786 | if af := apexClasspathFragmentProtoFile(ctx, child); af != nil { |
| 1787 | filesInfo = append(filesInfo, *af) |
| 1788 | } |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 1789 | return true |
| 1790 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1791 | case javaLibTag: |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 1792 | switch child.(type) { |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 1793 | case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import: |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1794 | af := apexFileForJavaModule(ctx, child.(javaModule)) |
| 1795 | if !af.ok() { |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1796 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 1797 | return false |
| 1798 | } |
| 1799 | filesInfo = append(filesInfo, af) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1800 | return true // track transitive dependencies |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 1801 | default: |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1802 | 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] | 1803 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1804 | case androidAppTag: |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1805 | if ap, ok := child.(*java.AndroidApp); ok { |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 1806 | filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1807 | return true // track transitive dependencies |
| 1808 | } else if ap, ok := child.(*java.AndroidAppImport); ok { |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 1809 | filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap)) |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 1810 | } else if ap, ok := child.(*java.AndroidTestHelperApp); ok { |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 1811 | filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap)) |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 1812 | } else if ap, ok := child.(*java.AndroidAppSet); ok { |
| 1813 | appDir := "app" |
| 1814 | if ap.Privileged() { |
| 1815 | appDir = "priv-app" |
| 1816 | } |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1817 | af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 1818 | filepath.Join(appDir, ap.BaseModuleName()), appSet, ap) |
| 1819 | af.certificate = java.PresignedCertificate |
| 1820 | filesInfo = append(filesInfo, af) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1821 | } else { |
| 1822 | ctx.PropertyErrorf("apps", "%q is not an android_app module", depName) |
| 1823 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 1824 | case rroTag: |
| 1825 | if rro, ok := child.(java.RuntimeResourceOverlayModule); ok { |
| 1826 | filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro)) |
| 1827 | } else { |
| 1828 | ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName) |
| 1829 | } |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 1830 | case bpfTag: |
| 1831 | if bpfProgram, ok := child.(bpf.BpfModule); ok { |
| 1832 | filesToCopy, _ := bpfProgram.OutputFiles("") |
| 1833 | for _, bpfFile := range filesToCopy { |
| 1834 | filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram)) |
| 1835 | } |
| 1836 | } else { |
| 1837 | ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName) |
| 1838 | } |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 1839 | case fsTag: |
| 1840 | if fs, ok := child.(filesystem.Filesystem); ok { |
| 1841 | filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs)) |
| 1842 | } else { |
| 1843 | ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName) |
| 1844 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1845 | case prebuiltTag: |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 1846 | if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1847 | filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName)) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1848 | } else { |
Paul Duffin | 1bc21dc | 2021-03-15 19:43:17 +0000 | [diff] [blame] | 1849 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1850 | } |
Paul Duffin | 0b81778 | 2021-03-17 15:02:19 +0000 | [diff] [blame] | 1851 | case compatConfigTag: |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 1852 | if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok { |
| 1853 | filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName)) |
| 1854 | } else { |
| 1855 | ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName) |
| 1856 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1857 | case testTag: |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1858 | if ccTest, ok := child.(*cc.Module); ok { |
| 1859 | if ccTest.IsTestPerSrcAllTestsVariation() { |
| 1860 | // Multiple-output test module (where `test_per_src: true`). |
| 1861 | // |
| 1862 | // `ccTest` is the "" ("all tests") variation of a `test_per_src` module. |
| 1863 | // We do not add this variation to `filesInfo`, as it has no output; |
| 1864 | // however, we do add the other variations of this module as indirect |
| 1865 | // dependencies (see below). |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1866 | } else { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1867 | // Single-output test module (where `test_per_src: false`). |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1868 | af := apexFileForExecutable(ctx, ccTest) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1869 | af.class = nativeTest |
| 1870 | filesInfo = append(filesInfo, af) |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1871 | } |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 1872 | return true // track transitive dependencies |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1873 | } else { |
| 1874 | ctx.PropertyErrorf("tests", "%q is not a cc module", depName) |
| 1875 | } |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1876 | case keyTag: |
| 1877 | if key, ok := child.(*apexKey); ok { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1878 | a.privateKeyFile = key.privateKeyFile |
| 1879 | a.publicKeyFile = key.publicKeyFile |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1880 | } else { |
| 1881 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1882 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1883 | return false |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1884 | case certificateTag: |
| 1885 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1886 | a.containerCertificateFile = dep.Certificate.Pem |
| 1887 | a.containerPrivateKeyFile = dep.Certificate.Key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1888 | } else { |
| 1889 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 1890 | } |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1891 | case android.PrebuiltDepTag: |
| 1892 | // If the prebuilt is force disabled, remember to delete the prebuilt file |
| 1893 | // that might have been installed in the previous builds |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 1894 | if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() { |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1895 | a.prebuiltFileToDelete = prebuilt.InstallFilename() |
| 1896 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1897 | } |
Jooyung Han | 8aee204 | 2019-10-29 05:08:31 +0900 | [diff] [blame] | 1898 | } else if !a.vndkApex { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1899 | // indirect dependencies |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1900 | if am, ok := child.(android.ApexModule); ok { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1901 | // We cannot use a switch statement on `depTag` here as the checked |
| 1902 | // tags used below are private (e.g. `cc.sharedDepTag`). |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1903 | if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1904 | if cc, ok := child.(*cc.Module); ok { |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 1905 | if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() { |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 1906 | requireNativeLibs = append(requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 1907 | return false |
| 1908 | } |
Jiyong Park | f1493cc | 2020-05-29 21:29:20 +0900 | [diff] [blame] | 1909 | af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs) |
| 1910 | af.transitiveDep = true |
Martin Stjernholm | f2635ec | 2020-12-16 01:01:59 +0000 | [diff] [blame] | 1911 | |
| 1912 | // Always track transitive dependencies for host. |
| 1913 | if a.Host() { |
| 1914 | filesInfo = append(filesInfo, af) |
| 1915 | return true |
| 1916 | } |
| 1917 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1918 | abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo) |
Martin Stjernholm | f2635ec | 2020-12-16 01:01:59 +0000 | [diff] [blame] | 1919 | if !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1920 | // If the dependency is a stubs lib, don't include it in this APEX, |
| 1921 | // but make sure that the lib is installed on the device. |
| 1922 | // In case no APEX is having the lib, the lib is installed to the system |
| 1923 | // partition. |
| 1924 | // |
| 1925 | // Always include if we are a host-apex however since those won't have any |
| 1926 | // system libraries. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1927 | if !am.DirectlyInAnyApex() { |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 1928 | // we need a module name for Make |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 1929 | name := cc.ImplementationModuleNameForMake(ctx) |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1930 | |
| 1931 | if !proptools.Bool(a.properties.Use_vendor) { |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 1932 | // we don't use subName(.vendor) for a "use_vendor: true" apex |
| 1933 | // which is supposed to be installed in /system |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1934 | name += cc.Properties.SubName |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 1935 | } |
| 1936 | if !android.InList(name, a.requiredDeps) { |
| 1937 | a.requiredDeps = append(a.requiredDeps, name) |
| 1938 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1939 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1940 | requireNativeLibs = append(requireNativeLibs, af.stem()) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1941 | // Don't track further |
| 1942 | return false |
| 1943 | } |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 1944 | |
| 1945 | // If the dep is not considered to be in the same |
| 1946 | // apex, don't add it to filesInfo so that it is not |
| 1947 | // included in this APEX. |
| 1948 | // TODO(jiyong): move this to at the top of the |
| 1949 | // else-if clause for the indirect dependencies. |
| 1950 | // Currently, that's impossible because we would |
| 1951 | // like to record requiredNativeLibs even when |
Martin Stjernholm | f2635ec | 2020-12-16 01:01:59 +0000 | [diff] [blame] | 1952 | // DepIsInSameAPex is false. We also shouldn't do |
| 1953 | // this for host. |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 1954 | // |
| 1955 | // TODO(jiyong): explain why the same module is passed in twice. |
| 1956 | // Switching the first am to parent breaks lots of tests. |
| 1957 | if !android.IsDepInSameApex(ctx, am, am) { |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 1958 | return false |
| 1959 | } |
| 1960 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1961 | filesInfo = append(filesInfo, af) |
| 1962 | return true // track transitive dependencies |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 1963 | } else if rm, ok := child.(*rust.Module); ok { |
| 1964 | af := apexFileForRustLibrary(ctx, rm) |
| 1965 | af.transitiveDep = true |
| 1966 | filesInfo = append(filesInfo, af) |
| 1967 | return true // track transitive dependencies |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1968 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1969 | } else if cc.IsTestPerSrcDepTag(depTag) { |
| 1970 | if cc, ok := child.(*cc.Module); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1971 | af := apexFileForExecutable(ctx, cc) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1972 | // Handle modules created as `test_per_src` variations of a single test module: |
| 1973 | // use the name of the generated test binary (`fileToCopy`) instead of the name |
| 1974 | // of the original test module (`depName`, shared by all `test_per_src` |
| 1975 | // variations of that module). |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1976 | af.androidMkModuleName = filepath.Base(af.builtFile.String()) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1977 | // these are not considered transitive dep |
| 1978 | af.transitiveDep = false |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1979 | filesInfo = append(filesInfo, af) |
| 1980 | return true // track transitive dependencies |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1981 | } |
Jiyong Park | 1ad8e16 | 2020-12-01 23:40:09 +0900 | [diff] [blame] | 1982 | } else if cc.IsHeaderDepTag(depTag) { |
| 1983 | // nothing |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1984 | } else if java.IsJniDepTag(depTag) { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 1985 | // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps |
| 1986 | return false |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1987 | } else if java.IsXmlPermissionsFileDepTag(depTag) { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 1988 | if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1989 | filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName)) |
| 1990 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1991 | } else if rust.IsDylibDepTag(depTag) { |
| 1992 | if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() { |
| 1993 | af := apexFileForRustLibrary(ctx, rustm) |
| 1994 | af.transitiveDep = true |
| 1995 | filesInfo = append(filesInfo, af) |
| 1996 | return true // track transitive dependencies |
| 1997 | } |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 1998 | } else if rust.IsRlibDepTag(depTag) { |
| 1999 | // Rlib is statically linked, but it might have shared lib |
| 2000 | // dependencies. Track them. |
| 2001 | return true |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 2002 | } else if java.IsBootclasspathFragmentContentDepTag(depTag) { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 2003 | // Add the contents of the bootclasspath fragment to the apex. |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 2004 | switch child.(type) { |
| 2005 | case *java.Library, *java.SdkLibrary: |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2006 | javaModule := child.(javaModule) |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 2007 | af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule) |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 2008 | if !af.ok() { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 2009 | ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q is not configured to be compiled into dex", depName) |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 2010 | return false |
| 2011 | } |
| 2012 | filesInfo = append(filesInfo, af) |
| 2013 | return true // track transitive dependencies |
| 2014 | default: |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 2015 | ctx.PropertyErrorf("bootclasspath_fragments", "bootclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 2016 | } |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 2017 | } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) { |
| 2018 | // Add the contents of the systemserverclasspath fragment to the apex. |
| 2019 | switch child.(type) { |
| 2020 | case *java.Library, *java.SdkLibrary: |
| 2021 | af := apexFileForJavaModule(ctx, child.(javaModule)) |
| 2022 | filesInfo = append(filesInfo, af) |
| 2023 | return true // track transitive dependencies |
| 2024 | default: |
| 2025 | ctx.PropertyErrorf("systemserverclasspath_fragments", "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
| 2026 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2027 | } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok { |
| 2028 | // nothing |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 2029 | } else if am.CanHaveApexVariants() && am.IsInstallableToApex() { |
Jiyong Park | 1c7e962 | 2020-05-07 16:12:13 +0900 | [diff] [blame] | 2030 | ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 2031 | } |
| 2032 | } |
| 2033 | } |
| 2034 | return false |
| 2035 | }) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2036 | if a.privateKeyFile == nil { |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 2037 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key)) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2038 | return |
| 2039 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 2040 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2041 | // Remove duplicates in filesInfo |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 2042 | removeDup := func(filesInfo []apexFile) []apexFile { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2043 | encountered := make(map[string]apexFile) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 2044 | for _, f := range filesInfo { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2045 | dest := filepath.Join(f.installDir, f.builtFile.Base()) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2046 | if e, ok := encountered[dest]; !ok { |
| 2047 | encountered[dest] = f |
| 2048 | } else { |
| 2049 | // If a module is directly included and also transitively depended on |
| 2050 | // consider it as directly included. |
| 2051 | e.transitiveDep = e.transitiveDep && f.transitiveDep |
| 2052 | encountered[dest] = e |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 2053 | } |
| 2054 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2055 | var result []apexFile |
| 2056 | for _, v := range encountered { |
| 2057 | result = append(result, v) |
| 2058 | } |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 2059 | return result |
| 2060 | } |
| 2061 | filesInfo = removeDup(filesInfo) |
| 2062 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2063 | // Sort to have consistent build rules |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 2064 | sort.Slice(filesInfo, func(i, j int) bool { |
Paul Duffin | 5606029 | 2021-05-15 19:34:05 +0100 | [diff] [blame] | 2065 | // Sort by destination path so as to ensure consistent ordering even if the source of the files |
| 2066 | // changes. |
| 2067 | return filesInfo[i].path() < filesInfo[j].path() |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 2068 | }) |
| 2069 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2070 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 2071 | // 3) some fields in apexBundle struct are configured |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 2072 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 2073 | a.filesInfo = filesInfo |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 2074 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2075 | // Set suffix and primaryApexType depending on the ApexType |
Martin Stjernholm | cb3ff1e | 2021-05-25 00:28:27 +0100 | [diff] [blame] | 2076 | buildFlattenedAsDefault := ctx.Config().FlattenApex() |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2077 | switch a.properties.ApexType { |
| 2078 | case imageApex: |
| 2079 | if buildFlattenedAsDefault { |
| 2080 | a.suffix = imageApexSuffix |
| 2081 | } else { |
| 2082 | a.suffix = "" |
| 2083 | a.primaryApexType = true |
| 2084 | |
| 2085 | if ctx.Config().InstallExtraFlattenedApexes() { |
| 2086 | a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix) |
| 2087 | } |
| 2088 | } |
| 2089 | case zipApex: |
| 2090 | if proptools.String(a.properties.Payload_type) == "zip" { |
| 2091 | a.suffix = "" |
| 2092 | a.primaryApexType = true |
| 2093 | } else { |
| 2094 | a.suffix = zipApexSuffix |
| 2095 | } |
| 2096 | case flattenedApex: |
| 2097 | if buildFlattenedAsDefault { |
| 2098 | a.suffix = "" |
| 2099 | a.primaryApexType = true |
| 2100 | } else { |
| 2101 | a.suffix = flattenedSuffix |
| 2102 | } |
| 2103 | } |
| 2104 | |
Theotime Combes | 4ba38c1 | 2020-06-12 12:46:59 +0000 | [diff] [blame] | 2105 | switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) { |
| 2106 | case ext4FsType: |
| 2107 | a.payloadFsType = ext4 |
| 2108 | case f2fsFsType: |
| 2109 | a.payloadFsType = f2fs |
| 2110 | default: |
| 2111 | ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type) |
| 2112 | } |
| 2113 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2114 | // Optimization. If we are building bundled APEX, for the files that are gathered due to the |
| 2115 | // transitive dependencies, don't place them inside the APEX, but place a symlink pointing |
| 2116 | // the same library in the system partition, thus effectively sharing the same libraries |
| 2117 | // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed |
| 2118 | // in the APEX. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2119 | a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable() && !proptools.Bool(a.properties.Use_vendor) |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2120 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2121 | // APEXes targeting other than system/system_ext partitions use vendor/product variants. |
| 2122 | // So we can't link them to /system/lib libs which are core variants. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2123 | if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2124 | a.linkToSystemLib = false |
| 2125 | } |
| 2126 | |
Jiyong Park | 4da0797 | 2021-01-05 21:01:11 +0900 | [diff] [blame] | 2127 | forced := ctx.Config().ForceApexSymlinkOptimization() |
| 2128 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 2129 | // We don't need the optimization for updatable APEXes, as it might give false signal |
Jiyong Park | 4da0797 | 2021-01-05 21:01:11 +0900 | [diff] [blame] | 2130 | // to the system health when the APEXes are still bundled (b/149805758). |
| 2131 | if !forced && a.Updatable() && a.properties.ApexType == imageApex { |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 2132 | a.linkToSystemLib = false |
| 2133 | } |
| 2134 | |
Jiyong Park | 638d30e | 2020-02-26 18:27:19 +0900 | [diff] [blame] | 2135 | // We also don't want the optimization for host APEXes, because it doesn't make sense. |
| 2136 | if ctx.Host() { |
| 2137 | a.linkToSystemLib = false |
| 2138 | } |
| 2139 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2140 | a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx) |
| 2141 | |
| 2142 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 2143 | // 4) generate the build rules to create the APEX. This is done in builder.go. |
| 2144 | a.buildManifest(ctx, provideNativeLibs, requireNativeLibs) |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 2145 | if a.properties.ApexType == flattenedApex { |
| 2146 | a.buildFlattenedApex(ctx) |
| 2147 | } else { |
| 2148 | a.buildUnflattenedApex(ctx) |
| 2149 | } |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 2150 | a.buildApexDependencyInfo(ctx) |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2151 | a.buildLintReports(ctx) |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 2152 | |
| 2153 | // Append meta-files to the filesInfo list so that they are reflected in Android.mk as well. |
| 2154 | if a.installable() { |
| 2155 | // For flattened APEX, make sure that APEX manifest and apex_pubkey are also copied |
| 2156 | // along with other ordinary files. (Note that this is done by apexer for |
| 2157 | // non-flattened APEXes) |
| 2158 | a.filesInfo = append(a.filesInfo, newApexFile(ctx, a.manifestPbOut, "apex_manifest.pb", ".", etc, nil)) |
| 2159 | |
| 2160 | // Place the public key as apex_pubkey. This is also done by apexer for |
| 2161 | // non-flattened APEXes case. |
| 2162 | // TODO(jiyong): Why do we need this CP rule? |
| 2163 | copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey") |
| 2164 | ctx.Build(pctx, android.BuildParams{ |
| 2165 | Rule: android.Cp, |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2166 | Input: a.publicKeyFile, |
Jiyong Park | b81b990 | 2020-11-24 19:51:18 +0900 | [diff] [blame] | 2167 | Output: copiedPubkey, |
| 2168 | }) |
| 2169 | a.filesInfo = append(a.filesInfo, newApexFile(ctx, copiedPubkey, "apex_pubkey", ".", etc, nil)) |
| 2170 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 2171 | } |
| 2172 | |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2173 | // apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that |
| 2174 | // the bootclasspath_fragment contributes to the apex. |
| 2175 | func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile { |
| 2176 | bootclasspathFragmentInfo := ctx.OtherModuleProvider(module, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 2177 | var filesToAdd []apexFile |
| 2178 | |
| 2179 | // Add the boot image files, e.g. .art, .oat and .vdex files. |
| 2180 | for arch, files := range bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() { |
| 2181 | dirInApex := filepath.Join("javalib", arch.String()) |
| 2182 | for _, f := range files { |
| 2183 | androidMkModuleName := "javalib_" + arch.String() + "_" + filepath.Base(f.String()) |
| 2184 | // TODO(b/177892522) - consider passing in the bootclasspath fragment module here instead of nil |
| 2185 | af := newApexFile(ctx, f, androidMkModuleName, dirInApex, etc, nil) |
| 2186 | filesToAdd = append(filesToAdd, af) |
| 2187 | } |
| 2188 | } |
| 2189 | |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 2190 | // Add classpaths.proto config. |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2191 | if af := apexClasspathFragmentProtoFile(ctx, module); af != nil { |
| 2192 | filesToAdd = append(filesToAdd, *af) |
| 2193 | } |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 2194 | |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2195 | return filesToAdd |
| 2196 | } |
| 2197 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2198 | // apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that |
| 2199 | // the module contributes to the apex; or nil if the proto config was not generated. |
| 2200 | func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile { |
| 2201 | info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo) |
| 2202 | if !info.ClasspathFragmentProtoGenerated { |
| 2203 | return nil |
| 2204 | } |
| 2205 | classpathProtoOutput := info.ClasspathFragmentProtoOutput |
| 2206 | af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil) |
| 2207 | return &af |
satayev | 14e4913 | 2021-05-17 21:03:07 +0100 | [diff] [blame] | 2208 | } |
| 2209 | |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2210 | // apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment |
| 2211 | // content module, i.e. a library that is part of the bootclasspath. |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 2212 | func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile { |
| 2213 | bootclasspathFragmentInfo := ctx.OtherModuleProvider(fragmentModule, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 2214 | |
| 2215 | // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the |
| 2216 | // hidden API encpding. |
Paul Duffin | 1a8010a | 2021-05-15 12:39:23 +0100 | [diff] [blame] | 2217 | dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule) |
| 2218 | if err != nil { |
| 2219 | ctx.ModuleErrorf("%s", err) |
| 2220 | } |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 2221 | |
| 2222 | // Create an apexFile as for a normal java module but with the dex boot jar provided by the |
| 2223 | // bootclasspath_fragment. |
| 2224 | af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar) |
| 2225 | return af |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2226 | } |
| 2227 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2228 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2229 | // Factory functions |
| 2230 | // |
| 2231 | |
| 2232 | func newApexBundle() *apexBundle { |
| 2233 | module := &apexBundle{} |
| 2234 | |
| 2235 | module.AddProperties(&module.properties) |
| 2236 | module.AddProperties(&module.targetProperties) |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 2237 | module.AddProperties(&module.archProperties) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2238 | module.AddProperties(&module.overridableProperties) |
| 2239 | |
| 2240 | android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
| 2241 | android.InitDefaultableModule(module) |
| 2242 | android.InitSdkAwareModule(module) |
| 2243 | android.InitOverridableModule(module, &module.overridableProperties.Overrides) |
Jingwen Chen | f59a8e1 | 2021-07-16 09:28:53 +0000 | [diff] [blame] | 2244 | android.InitBazelModule(module) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2245 | return module |
| 2246 | } |
| 2247 | |
| 2248 | func ApexBundleFactory(testApex bool, artApex bool) android.Module { |
| 2249 | bundle := newApexBundle() |
| 2250 | bundle.testApex = testApex |
| 2251 | bundle.artApex = artApex |
| 2252 | return bundle |
| 2253 | } |
| 2254 | |
| 2255 | // apex_test is an APEX for testing. The difference from the ordinary apex module type is that |
| 2256 | // certain compatibility checks such as apex_available are not done for apex_test. |
| 2257 | func testApexBundleFactory() android.Module { |
| 2258 | bundle := newApexBundle() |
| 2259 | bundle.testApex = true |
| 2260 | return bundle |
| 2261 | } |
| 2262 | |
| 2263 | // apex packages other modules into an APEX file which is a packaging format for system-level |
| 2264 | // components like binaries, shared libraries, etc. |
| 2265 | func BundleFactory() android.Module { |
| 2266 | return newApexBundle() |
| 2267 | } |
| 2268 | |
| 2269 | type Defaults struct { |
| 2270 | android.ModuleBase |
| 2271 | android.DefaultsModuleBase |
| 2272 | } |
| 2273 | |
| 2274 | // apex_defaults provides defaultable properties to other apex modules. |
| 2275 | func defaultsFactory() android.Module { |
| 2276 | return DefaultsFactory() |
| 2277 | } |
| 2278 | |
| 2279 | func DefaultsFactory(props ...interface{}) android.Module { |
| 2280 | module := &Defaults{} |
| 2281 | |
| 2282 | module.AddProperties(props...) |
| 2283 | module.AddProperties( |
| 2284 | &apexBundleProperties{}, |
| 2285 | &apexTargetBundleProperties{}, |
| 2286 | &overridableProperties{}, |
| 2287 | ) |
| 2288 | |
| 2289 | android.InitDefaultsModule(module) |
| 2290 | return module |
| 2291 | } |
| 2292 | |
| 2293 | type OverrideApex struct { |
| 2294 | android.ModuleBase |
| 2295 | android.OverrideModuleBase |
| 2296 | } |
| 2297 | |
| 2298 | func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 2299 | // All the overrides happen in the base module. |
| 2300 | } |
| 2301 | |
| 2302 | // override_apex is used to create an apex module based on another apex module by overriding some of |
| 2303 | // its properties. |
| 2304 | func overrideApexFactory() android.Module { |
| 2305 | m := &OverrideApex{} |
| 2306 | |
| 2307 | m.AddProperties(&overridableProperties{}) |
| 2308 | |
| 2309 | android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 2310 | android.InitOverrideModule(m) |
| 2311 | return m |
| 2312 | } |
| 2313 | |
| 2314 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2315 | // Vality check routines |
| 2316 | // |
| 2317 | // These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when |
| 2318 | // certain conditions are not met. |
| 2319 | // |
| 2320 | // TODO(jiyong): move these checks to a separate go file. |
| 2321 | |
| 2322 | // Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version |
| 2323 | // of this apexBundle. |
| 2324 | func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) { |
| 2325 | if a.testApex || a.vndkApex { |
| 2326 | return |
| 2327 | } |
| 2328 | // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets |
| 2329 | if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" { |
| 2330 | return |
| 2331 | } |
| 2332 | // apexBundle::minSdkVersion reports its own errors. |
| 2333 | minSdkVersion := a.minSdkVersion(ctx) |
| 2334 | android.CheckMinSdkVersion(a, ctx, minSdkVersion) |
| 2335 | } |
| 2336 | |
| 2337 | func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel { |
| 2338 | ver := proptools.String(a.properties.Min_sdk_version) |
| 2339 | if ver == "" { |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2340 | return android.NoneApiLevel |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2341 | } |
| 2342 | apiLevel, err := android.ApiLevelFromUser(ctx, ver) |
| 2343 | if err != nil { |
| 2344 | ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) |
| 2345 | return android.NoneApiLevel |
| 2346 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2347 | return apiLevel |
| 2348 | } |
| 2349 | |
| 2350 | // Ensures that a lib providing stub isn't statically linked |
| 2351 | func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) { |
| 2352 | // Practically, we only care about regular APEXes on the device. |
| 2353 | if ctx.Host() || a.testApex || a.vndkApex { |
| 2354 | return |
| 2355 | } |
| 2356 | |
| 2357 | abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo) |
| 2358 | |
| 2359 | a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { |
| 2360 | if ccm, ok := to.(*cc.Module); ok { |
| 2361 | apexName := ctx.ModuleName() |
| 2362 | fromName := ctx.OtherModuleName(from) |
| 2363 | toName := ctx.OtherModuleName(to) |
| 2364 | |
| 2365 | // If `to` is not actually in the same APEX as `from` then it does not need |
| 2366 | // apex_available and neither do any of its dependencies. |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 2367 | // |
| 2368 | // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps(). |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2369 | if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) { |
| 2370 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 2371 | return false |
| 2372 | } |
| 2373 | |
| 2374 | // The dynamic linker and crash_dump tool in the runtime APEX is the only |
| 2375 | // exception to this rule. It can't make the static dependencies dynamic |
| 2376 | // because it can't do the dynamic linking for itself. |
Kiyoung Kim | 4098c7e | 2020-11-30 14:42:14 +0900 | [diff] [blame] | 2377 | // Same rule should be applied to linkerconfig, because it should be executed |
| 2378 | // only with static linked libraries before linker is available with ld.config.txt |
| 2379 | if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2380 | return false |
| 2381 | } |
| 2382 | |
| 2383 | isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName) |
| 2384 | if isStubLibraryFromOtherApex && !externalDep { |
| 2385 | ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+ |
| 2386 | "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false)) |
| 2387 | } |
| 2388 | |
| 2389 | } |
| 2390 | return true |
| 2391 | }) |
| 2392 | } |
| 2393 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2394 | // checkUpdatable enforces APEX and its transitive dep properties to have desired values for updatable APEXes. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2395 | func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) { |
| 2396 | if a.Updatable() { |
| 2397 | if String(a.properties.Min_sdk_version) == "" { |
| 2398 | ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well") |
| 2399 | } |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 2400 | if a.UsePlatformApis() { |
| 2401 | ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs") |
| 2402 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2403 | a.checkJavaStableSdkVersion(ctx) |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2404 | a.checkClasspathFragments(ctx) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2408 | // checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config. |
| 2409 | func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) { |
| 2410 | ctx.VisitDirectDeps(func(module android.Module) { |
| 2411 | if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag { |
| 2412 | info := ctx.OtherModuleProvider(module, java.ClasspathFragmentProtoContentInfoProvider).(java.ClasspathFragmentProtoContentInfo) |
| 2413 | if !info.ClasspathFragmentProtoGenerated { |
| 2414 | ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName()) |
| 2415 | } |
| 2416 | } |
| 2417 | }) |
| 2418 | } |
| 2419 | |
| 2420 | // checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile. |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2421 | func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2422 | // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs, |
| 2423 | // java's checkLinkType guarantees correct usage for transitive deps |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2424 | ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) { |
| 2425 | tag := ctx.OtherModuleDependencyTag(module) |
| 2426 | switch tag { |
| 2427 | case javaLibTag, androidAppTag: |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2428 | if m, ok := module.(interface { |
| 2429 | CheckStableSdkVersion(ctx android.BaseModuleContext) error |
| 2430 | }); ok { |
| 2431 | if err := m.CheckStableSdkVersion(ctx); err != nil { |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2432 | ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err) |
| 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | }) |
| 2437 | } |
| 2438 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2439 | // checkApexAvailability ensures that the all the dependencies are marked as available for this APEX. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2440 | func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) { |
| 2441 | // Let's be practical. Availability for test, host, and the VNDK apex isn't important |
| 2442 | if ctx.Host() || a.testApex || a.vndkApex { |
| 2443 | return |
| 2444 | } |
| 2445 | |
| 2446 | // Because APEXes targeting other than system/system_ext partitions can't set |
| 2447 | // apex_available, we skip checks for these APEXes |
| 2448 | if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { |
| 2449 | return |
| 2450 | } |
| 2451 | |
| 2452 | // Coverage build adds additional dependencies for the coverage-only runtime libraries. |
| 2453 | // Requiring them and their transitive depencies with apex_available is not right |
| 2454 | // because they just add noise. |
| 2455 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) { |
| 2456 | return |
| 2457 | } |
| 2458 | |
| 2459 | a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { |
| 2460 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 2461 | if externalDep { |
| 2462 | return false |
| 2463 | } |
| 2464 | |
| 2465 | apexName := ctx.ModuleName() |
| 2466 | fromName := ctx.OtherModuleName(from) |
| 2467 | toName := ctx.OtherModuleName(to) |
| 2468 | |
| 2469 | // If `to` is not actually in the same APEX as `from` then it does not need |
| 2470 | // apex_available and neither do any of its dependencies. |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 2471 | // |
| 2472 | // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps(). |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2473 | if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) { |
| 2474 | // As soon as the dependency graph crosses the APEX boundary, don't go |
| 2475 | // further. |
| 2476 | return false |
| 2477 | } |
| 2478 | |
| 2479 | if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) { |
| 2480 | return true |
| 2481 | } |
Jiyong Park | 767dbd9 | 2021-03-04 13:03:10 +0900 | [diff] [blame] | 2482 | ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+ |
| 2483 | "\n\nDependency path:%s\n\n"+ |
| 2484 | "Consider adding %q to 'apex_available' property of %q", |
| 2485 | fromName, toName, ctx.GetPathString(true), apexName, toName) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2486 | // Visit this module's dependencies to check and report any issues with their availability. |
| 2487 | return true |
| 2488 | }) |
| 2489 | } |
| 2490 | |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame^] | 2491 | // checkStaticExecutable ensures that executables in an APEX are not static. |
| 2492 | func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) { |
| 2493 | ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) { |
| 2494 | if ctx.OtherModuleDependencyTag(module) != executableTag { |
| 2495 | return |
| 2496 | } |
| 2497 | if cc, ok := module.(*cc.Module); ok && cc.StaticExecutable() { |
| 2498 | apex := a.ApexVariationName() |
| 2499 | exec := ctx.OtherModuleName(module) |
| 2500 | if isStaticExecutableAllowed(apex, exec) { |
| 2501 | return |
| 2502 | } |
| 2503 | ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module)) |
| 2504 | } |
| 2505 | }) |
| 2506 | } |
| 2507 | |
| 2508 | // A small list of exceptions where static executables are allowed in APEXes. |
| 2509 | func isStaticExecutableAllowed(apex string, exec string) bool { |
| 2510 | m := map[string][]string{ |
| 2511 | "com.android.runtime": []string{ |
| 2512 | "linker", |
| 2513 | "linkerconfig", |
| 2514 | }, |
| 2515 | } |
| 2516 | execNames, ok := m[apex] |
| 2517 | return ok && android.InList(exec, execNames) |
| 2518 | } |
| 2519 | |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 2520 | // Collect information for opening IDE project files in java/jdeps.go. |
| 2521 | func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) { |
| 2522 | dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...) |
| 2523 | dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...) |
| 2524 | dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...) |
| 2525 | dpInfo.Paths = append(dpInfo.Paths, a.modulePaths...) |
| 2526 | } |
| 2527 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2528 | var ( |
| 2529 | apexAvailBaseline = makeApexAvailableBaseline() |
| 2530 | inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline) |
| 2531 | ) |
| 2532 | |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2533 | func baselineApexAvailable(apex, moduleName string) bool { |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2534 | key := apex |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 2535 | moduleName = normalizeModuleName(moduleName) |
| 2536 | |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2537 | if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) { |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 2538 | return true |
| 2539 | } |
| 2540 | |
| 2541 | key = android.AvailableToAnyApex |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2542 | if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) { |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 2543 | return true |
| 2544 | } |
| 2545 | |
| 2546 | return false |
| 2547 | } |
| 2548 | |
| 2549 | func normalizeModuleName(moduleName string) string { |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2550 | // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build |
| 2551 | // system. Trim the prefix for the check since they are confusing |
Paul Duffin | d23c726 | 2020-12-11 18:13:08 +0000 | [diff] [blame] | 2552 | moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2553 | if strings.HasPrefix(moduleName, "libclang_rt.") { |
| 2554 | // This module has many arch variants that depend on the product being built. |
| 2555 | // We don't want to list them all |
| 2556 | moduleName = "libclang_rt" |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2557 | } |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 2558 | if strings.HasPrefix(moduleName, "androidx.") { |
| 2559 | // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries |
| 2560 | moduleName = "androidx" |
| 2561 | } |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 2562 | return moduleName |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2565 | // Transform the map of apex -> modules to module -> apexes. |
| 2566 | func invertApexBaseline(m map[string][]string) map[string][]string { |
| 2567 | r := make(map[string][]string) |
| 2568 | for apex, modules := range m { |
| 2569 | for _, module := range modules { |
| 2570 | r[module] = append(r[module], apex) |
| 2571 | } |
| 2572 | } |
| 2573 | return r |
| 2574 | } |
| 2575 | |
| 2576 | // Retrieve the baseline of apexes to which the supplied module belongs. |
| 2577 | func BaselineApexAvailable(moduleName string) []string { |
| 2578 | return inverseApexAvailBaseline[normalizeModuleName(moduleName)] |
| 2579 | } |
| 2580 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2581 | // This is a map from apex to modules, which overrides the apex_available setting for that |
| 2582 | // particular module to make it available for the apex regardless of its setting. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2583 | // TODO(b/147364041): remove this |
| 2584 | func makeApexAvailableBaseline() map[string][]string { |
| 2585 | // The "Module separator"s below are employed to minimize merge conflicts. |
| 2586 | m := make(map[string][]string) |
| 2587 | // |
| 2588 | // Module separator |
| 2589 | // |
| 2590 | m["com.android.appsearch"] = []string{ |
| 2591 | "icing-java-proto-lite", |
| 2592 | "libprotobuf-java-lite", |
| 2593 | } |
| 2594 | // |
| 2595 | // Module separator |
| 2596 | // |
| 2597 | m["com.android.bluetooth.updatable"] = []string{ |
| 2598 | "android.hardware.audio.common@5.0", |
| 2599 | "android.hardware.bluetooth.a2dp@1.0", |
| 2600 | "android.hardware.bluetooth.audio@2.0", |
| 2601 | "android.hardware.bluetooth@1.0", |
| 2602 | "android.hardware.bluetooth@1.1", |
| 2603 | "android.hardware.graphics.bufferqueue@1.0", |
| 2604 | "android.hardware.graphics.bufferqueue@2.0", |
| 2605 | "android.hardware.graphics.common@1.0", |
| 2606 | "android.hardware.graphics.common@1.1", |
| 2607 | "android.hardware.graphics.common@1.2", |
| 2608 | "android.hardware.media@1.0", |
| 2609 | "android.hidl.safe_union@1.0", |
| 2610 | "android.hidl.token@1.0", |
| 2611 | "android.hidl.token@1.0-utils", |
| 2612 | "avrcp-target-service", |
| 2613 | "avrcp_headers", |
| 2614 | "bluetooth-protos-lite", |
| 2615 | "bluetooth.mapsapi", |
| 2616 | "com.android.vcard", |
| 2617 | "dnsresolver_aidl_interface-V2-java", |
| 2618 | "ipmemorystore-aidl-interfaces-V5-java", |
| 2619 | "ipmemorystore-aidl-interfaces-java", |
| 2620 | "internal_include_headers", |
| 2621 | "lib-bt-packets", |
| 2622 | "lib-bt-packets-avrcp", |
| 2623 | "lib-bt-packets-base", |
| 2624 | "libFraunhoferAAC", |
| 2625 | "libaudio-a2dp-hw-utils", |
| 2626 | "libaudio-hearing-aid-hw-utils", |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2627 | "libbluetooth", |
| 2628 | "libbluetooth-types", |
| 2629 | "libbluetooth-types-header", |
| 2630 | "libbluetooth_gd", |
| 2631 | "libbluetooth_headers", |
| 2632 | "libbluetooth_jni", |
| 2633 | "libbt-audio-hal-interface", |
| 2634 | "libbt-bta", |
| 2635 | "libbt-common", |
| 2636 | "libbt-hci", |
| 2637 | "libbt-platform-protos-lite", |
| 2638 | "libbt-protos-lite", |
| 2639 | "libbt-sbc-decoder", |
| 2640 | "libbt-sbc-encoder", |
| 2641 | "libbt-stack", |
| 2642 | "libbt-utils", |
| 2643 | "libbtcore", |
| 2644 | "libbtdevice", |
| 2645 | "libbte", |
| 2646 | "libbtif", |
| 2647 | "libchrome", |
| 2648 | "libevent", |
| 2649 | "libfmq", |
| 2650 | "libg722codec", |
| 2651 | "libgui_headers", |
| 2652 | "libmedia_headers", |
| 2653 | "libmodpb64", |
| 2654 | "libosi", |
| 2655 | "libstagefright_foundation_headers", |
| 2656 | "libstagefright_headers", |
| 2657 | "libstatslog", |
| 2658 | "libstatssocket", |
| 2659 | "libtinyxml2", |
| 2660 | "libudrv-uipc", |
| 2661 | "libz", |
| 2662 | "media_plugin_headers", |
| 2663 | "net-utils-services-common", |
| 2664 | "netd_aidl_interface-unstable-java", |
| 2665 | "netd_event_listener_interface-java", |
| 2666 | "netlink-client", |
| 2667 | "networkstack-client", |
| 2668 | "sap-api-java-static", |
| 2669 | "services.net", |
| 2670 | } |
| 2671 | // |
| 2672 | // Module separator |
| 2673 | // |
| 2674 | m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"} |
| 2675 | // |
| 2676 | // Module separator |
| 2677 | // |
| 2678 | m["com.android.extservices"] = []string{ |
| 2679 | "error_prone_annotations", |
| 2680 | "ExtServices-core", |
| 2681 | "ExtServices", |
| 2682 | "libtextclassifier-java", |
| 2683 | "libz_current", |
| 2684 | "textclassifier-statsd", |
| 2685 | "TextClassifierNotificationLibNoManifest", |
| 2686 | "TextClassifierServiceLibNoManifest", |
| 2687 | } |
| 2688 | // |
| 2689 | // Module separator |
| 2690 | // |
| 2691 | m["com.android.neuralnetworks"] = []string{ |
| 2692 | "android.hardware.neuralnetworks@1.0", |
| 2693 | "android.hardware.neuralnetworks@1.1", |
| 2694 | "android.hardware.neuralnetworks@1.2", |
| 2695 | "android.hardware.neuralnetworks@1.3", |
| 2696 | "android.hidl.allocator@1.0", |
| 2697 | "android.hidl.memory.token@1.0", |
| 2698 | "android.hidl.memory@1.0", |
| 2699 | "android.hidl.safe_union@1.0", |
| 2700 | "libarect", |
| 2701 | "libbuildversion", |
| 2702 | "libmath", |
| 2703 | "libprocpartition", |
| 2704 | "libsync", |
| 2705 | } |
| 2706 | // |
| 2707 | // Module separator |
| 2708 | // |
| 2709 | m["com.android.media"] = []string{ |
| 2710 | "android.frameworks.bufferhub@1.0", |
| 2711 | "android.hardware.cas.native@1.0", |
| 2712 | "android.hardware.cas@1.0", |
| 2713 | "android.hardware.configstore-utils", |
| 2714 | "android.hardware.configstore@1.0", |
| 2715 | "android.hardware.configstore@1.1", |
| 2716 | "android.hardware.graphics.allocator@2.0", |
| 2717 | "android.hardware.graphics.allocator@3.0", |
| 2718 | "android.hardware.graphics.bufferqueue@1.0", |
| 2719 | "android.hardware.graphics.bufferqueue@2.0", |
| 2720 | "android.hardware.graphics.common@1.0", |
| 2721 | "android.hardware.graphics.common@1.1", |
| 2722 | "android.hardware.graphics.common@1.2", |
| 2723 | "android.hardware.graphics.mapper@2.0", |
| 2724 | "android.hardware.graphics.mapper@2.1", |
| 2725 | "android.hardware.graphics.mapper@3.0", |
| 2726 | "android.hardware.media.omx@1.0", |
| 2727 | "android.hardware.media@1.0", |
| 2728 | "android.hidl.allocator@1.0", |
| 2729 | "android.hidl.memory.token@1.0", |
| 2730 | "android.hidl.memory@1.0", |
| 2731 | "android.hidl.token@1.0", |
| 2732 | "android.hidl.token@1.0-utils", |
| 2733 | "bionic_libc_platform_headers", |
| 2734 | "exoplayer2-extractor", |
| 2735 | "exoplayer2-extractor-annotation-stubs", |
| 2736 | "gl_headers", |
| 2737 | "jsr305", |
| 2738 | "libEGL", |
| 2739 | "libEGL_blobCache", |
| 2740 | "libEGL_getProcAddress", |
| 2741 | "libFLAC", |
| 2742 | "libFLAC-config", |
| 2743 | "libFLAC-headers", |
| 2744 | "libGLESv2", |
| 2745 | "libaacextractor", |
| 2746 | "libamrextractor", |
| 2747 | "libarect", |
| 2748 | "libaudio_system_headers", |
| 2749 | "libaudioclient", |
| 2750 | "libaudioclient_headers", |
| 2751 | "libaudiofoundation", |
| 2752 | "libaudiofoundation_headers", |
| 2753 | "libaudiomanager", |
| 2754 | "libaudiopolicy", |
| 2755 | "libaudioutils", |
| 2756 | "libaudioutils_fixedfft", |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2757 | "libbluetooth-types-header", |
| 2758 | "libbufferhub", |
| 2759 | "libbufferhub_headers", |
| 2760 | "libbufferhubqueue", |
| 2761 | "libc_malloc_debug_backtrace", |
| 2762 | "libcamera_client", |
| 2763 | "libcamera_metadata", |
| 2764 | "libdvr_headers", |
| 2765 | "libexpat", |
| 2766 | "libfifo", |
| 2767 | "libflacextractor", |
| 2768 | "libgrallocusage", |
| 2769 | "libgraphicsenv", |
| 2770 | "libgui", |
| 2771 | "libgui_headers", |
| 2772 | "libhardware_headers", |
| 2773 | "libinput", |
| 2774 | "liblzma", |
| 2775 | "libmath", |
| 2776 | "libmedia", |
| 2777 | "libmedia_codeclist", |
| 2778 | "libmedia_headers", |
| 2779 | "libmedia_helper", |
| 2780 | "libmedia_helper_headers", |
| 2781 | "libmedia_midiiowrapper", |
| 2782 | "libmedia_omx", |
| 2783 | "libmediautils", |
| 2784 | "libmidiextractor", |
| 2785 | "libmkvextractor", |
| 2786 | "libmp3extractor", |
| 2787 | "libmp4extractor", |
| 2788 | "libmpeg2extractor", |
| 2789 | "libnativebase_headers", |
| 2790 | "libnativewindow_headers", |
| 2791 | "libnblog", |
| 2792 | "liboggextractor", |
| 2793 | "libpackagelistparser", |
| 2794 | "libpdx", |
| 2795 | "libpdx_default_transport", |
| 2796 | "libpdx_headers", |
| 2797 | "libpdx_uds", |
| 2798 | "libprocinfo", |
| 2799 | "libspeexresampler", |
| 2800 | "libspeexresampler", |
| 2801 | "libstagefright_esds", |
| 2802 | "libstagefright_flacdec", |
| 2803 | "libstagefright_flacdec", |
| 2804 | "libstagefright_foundation", |
| 2805 | "libstagefright_foundation_headers", |
| 2806 | "libstagefright_foundation_without_imemory", |
| 2807 | "libstagefright_headers", |
| 2808 | "libstagefright_id3", |
| 2809 | "libstagefright_metadatautils", |
| 2810 | "libstagefright_mpeg2extractor", |
| 2811 | "libstagefright_mpeg2support", |
| 2812 | "libsync", |
| 2813 | "libui", |
| 2814 | "libui_headers", |
| 2815 | "libunwindstack", |
| 2816 | "libvibrator", |
| 2817 | "libvorbisidec", |
| 2818 | "libwavextractor", |
| 2819 | "libwebm", |
| 2820 | "media_ndk_headers", |
| 2821 | "media_plugin_headers", |
| 2822 | "updatable-media", |
| 2823 | } |
| 2824 | // |
| 2825 | // Module separator |
| 2826 | // |
| 2827 | m["com.android.media.swcodec"] = []string{ |
| 2828 | "android.frameworks.bufferhub@1.0", |
| 2829 | "android.hardware.common-ndk_platform", |
| 2830 | "android.hardware.configstore-utils", |
| 2831 | "android.hardware.configstore@1.0", |
| 2832 | "android.hardware.configstore@1.1", |
| 2833 | "android.hardware.graphics.allocator@2.0", |
| 2834 | "android.hardware.graphics.allocator@3.0", |
| 2835 | "android.hardware.graphics.allocator@4.0", |
| 2836 | "android.hardware.graphics.bufferqueue@1.0", |
| 2837 | "android.hardware.graphics.bufferqueue@2.0", |
| 2838 | "android.hardware.graphics.common-ndk_platform", |
| 2839 | "android.hardware.graphics.common@1.0", |
| 2840 | "android.hardware.graphics.common@1.1", |
| 2841 | "android.hardware.graphics.common@1.2", |
| 2842 | "android.hardware.graphics.mapper@2.0", |
| 2843 | "android.hardware.graphics.mapper@2.1", |
| 2844 | "android.hardware.graphics.mapper@3.0", |
| 2845 | "android.hardware.graphics.mapper@4.0", |
| 2846 | "android.hardware.media.bufferpool@2.0", |
| 2847 | "android.hardware.media.c2@1.0", |
| 2848 | "android.hardware.media.c2@1.1", |
| 2849 | "android.hardware.media.omx@1.0", |
| 2850 | "android.hardware.media@1.0", |
| 2851 | "android.hardware.media@1.0", |
| 2852 | "android.hidl.memory.token@1.0", |
| 2853 | "android.hidl.memory@1.0", |
| 2854 | "android.hidl.safe_union@1.0", |
| 2855 | "android.hidl.token@1.0", |
| 2856 | "android.hidl.token@1.0-utils", |
| 2857 | "libEGL", |
| 2858 | "libFLAC", |
| 2859 | "libFLAC-config", |
| 2860 | "libFLAC-headers", |
| 2861 | "libFraunhoferAAC", |
| 2862 | "libLibGuiProperties", |
| 2863 | "libarect", |
| 2864 | "libaudio_system_headers", |
| 2865 | "libaudioutils", |
| 2866 | "libaudioutils", |
| 2867 | "libaudioutils_fixedfft", |
| 2868 | "libavcdec", |
| 2869 | "libavcenc", |
| 2870 | "libavservices_minijail", |
| 2871 | "libavservices_minijail", |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2872 | "libbinderthreadstateutils", |
| 2873 | "libbluetooth-types-header", |
| 2874 | "libbufferhub_headers", |
| 2875 | "libcodec2", |
| 2876 | "libcodec2_headers", |
| 2877 | "libcodec2_hidl@1.0", |
| 2878 | "libcodec2_hidl@1.1", |
| 2879 | "libcodec2_internal", |
| 2880 | "libcodec2_soft_aacdec", |
| 2881 | "libcodec2_soft_aacenc", |
| 2882 | "libcodec2_soft_amrnbdec", |
| 2883 | "libcodec2_soft_amrnbenc", |
| 2884 | "libcodec2_soft_amrwbdec", |
| 2885 | "libcodec2_soft_amrwbenc", |
| 2886 | "libcodec2_soft_av1dec_gav1", |
| 2887 | "libcodec2_soft_avcdec", |
| 2888 | "libcodec2_soft_avcenc", |
| 2889 | "libcodec2_soft_common", |
| 2890 | "libcodec2_soft_flacdec", |
| 2891 | "libcodec2_soft_flacenc", |
| 2892 | "libcodec2_soft_g711alawdec", |
| 2893 | "libcodec2_soft_g711mlawdec", |
| 2894 | "libcodec2_soft_gsmdec", |
| 2895 | "libcodec2_soft_h263dec", |
| 2896 | "libcodec2_soft_h263enc", |
| 2897 | "libcodec2_soft_hevcdec", |
| 2898 | "libcodec2_soft_hevcenc", |
| 2899 | "libcodec2_soft_mp3dec", |
| 2900 | "libcodec2_soft_mpeg2dec", |
| 2901 | "libcodec2_soft_mpeg4dec", |
| 2902 | "libcodec2_soft_mpeg4enc", |
| 2903 | "libcodec2_soft_opusdec", |
| 2904 | "libcodec2_soft_opusenc", |
| 2905 | "libcodec2_soft_rawdec", |
| 2906 | "libcodec2_soft_vorbisdec", |
| 2907 | "libcodec2_soft_vp8dec", |
| 2908 | "libcodec2_soft_vp8enc", |
| 2909 | "libcodec2_soft_vp9dec", |
| 2910 | "libcodec2_soft_vp9enc", |
| 2911 | "libcodec2_vndk", |
| 2912 | "libdvr_headers", |
| 2913 | "libfmq", |
| 2914 | "libfmq", |
| 2915 | "libgav1", |
| 2916 | "libgralloctypes", |
| 2917 | "libgrallocusage", |
| 2918 | "libgraphicsenv", |
| 2919 | "libgsm", |
| 2920 | "libgui_bufferqueue_static", |
| 2921 | "libgui_headers", |
| 2922 | "libhardware", |
| 2923 | "libhardware_headers", |
| 2924 | "libhevcdec", |
| 2925 | "libhevcenc", |
| 2926 | "libion", |
| 2927 | "libjpeg", |
| 2928 | "liblzma", |
| 2929 | "libmath", |
| 2930 | "libmedia_codecserviceregistrant", |
| 2931 | "libmedia_headers", |
| 2932 | "libmpeg2dec", |
| 2933 | "libnativebase_headers", |
| 2934 | "libnativewindow_headers", |
| 2935 | "libpdx_headers", |
| 2936 | "libscudo_wrapper", |
| 2937 | "libsfplugin_ccodec_utils", |
| 2938 | "libspeexresampler", |
| 2939 | "libstagefright_amrnb_common", |
| 2940 | "libstagefright_amrnbdec", |
| 2941 | "libstagefright_amrnbenc", |
| 2942 | "libstagefright_amrwbdec", |
| 2943 | "libstagefright_amrwbenc", |
| 2944 | "libstagefright_bufferpool@2.0.1", |
| 2945 | "libstagefright_bufferqueue_helper", |
| 2946 | "libstagefright_enc_common", |
| 2947 | "libstagefright_flacdec", |
| 2948 | "libstagefright_foundation", |
| 2949 | "libstagefright_foundation_headers", |
| 2950 | "libstagefright_headers", |
| 2951 | "libstagefright_m4vh263dec", |
| 2952 | "libstagefright_m4vh263enc", |
| 2953 | "libstagefright_mp3dec", |
| 2954 | "libsync", |
| 2955 | "libui", |
| 2956 | "libui_headers", |
| 2957 | "libunwindstack", |
| 2958 | "libvorbisidec", |
| 2959 | "libvpx", |
| 2960 | "libyuv", |
| 2961 | "libyuv_static", |
| 2962 | "media_ndk_headers", |
| 2963 | "media_plugin_headers", |
| 2964 | "mediaswcodec", |
| 2965 | } |
| 2966 | // |
| 2967 | // Module separator |
| 2968 | // |
| 2969 | m["com.android.mediaprovider"] = []string{ |
| 2970 | "MediaProvider", |
| 2971 | "MediaProviderGoogle", |
| 2972 | "fmtlib_ndk", |
| 2973 | "libbase_ndk", |
| 2974 | "libfuse", |
| 2975 | "libfuse_jni", |
| 2976 | } |
| 2977 | // |
| 2978 | // Module separator |
| 2979 | // |
| 2980 | m["com.android.permission"] = []string{ |
| 2981 | "car-ui-lib", |
| 2982 | "iconloader", |
| 2983 | "kotlin-annotations", |
| 2984 | "kotlin-stdlib", |
| 2985 | "kotlin-stdlib-jdk7", |
| 2986 | "kotlin-stdlib-jdk8", |
| 2987 | "kotlinx-coroutines-android", |
| 2988 | "kotlinx-coroutines-android-nodeps", |
| 2989 | "kotlinx-coroutines-core", |
| 2990 | "kotlinx-coroutines-core-nodeps", |
| 2991 | "permissioncontroller-statsd", |
| 2992 | "GooglePermissionController", |
| 2993 | "PermissionController", |
| 2994 | "SettingsLibActionBarShadow", |
| 2995 | "SettingsLibAppPreference", |
| 2996 | "SettingsLibBarChartPreference", |
| 2997 | "SettingsLibLayoutPreference", |
| 2998 | "SettingsLibProgressBar", |
| 2999 | "SettingsLibSearchWidget", |
| 3000 | "SettingsLibSettingsTheme", |
| 3001 | "SettingsLibRestrictedLockUtils", |
| 3002 | "SettingsLibHelpUtils", |
| 3003 | } |
| 3004 | // |
| 3005 | // Module separator |
| 3006 | // |
| 3007 | m["com.android.runtime"] = []string{ |
| 3008 | "bionic_libc_platform_headers", |
| 3009 | "libarm-optimized-routines-math", |
| 3010 | "libc_aeabi", |
| 3011 | "libc_bionic", |
| 3012 | "libc_bionic_ndk", |
| 3013 | "libc_bootstrap", |
| 3014 | "libc_common", |
| 3015 | "libc_common_shared", |
| 3016 | "libc_common_static", |
| 3017 | "libc_dns", |
| 3018 | "libc_dynamic_dispatch", |
| 3019 | "libc_fortify", |
| 3020 | "libc_freebsd", |
| 3021 | "libc_freebsd_large_stack", |
| 3022 | "libc_gdtoa", |
| 3023 | "libc_init_dynamic", |
| 3024 | "libc_init_static", |
| 3025 | "libc_jemalloc_wrapper", |
| 3026 | "libc_netbsd", |
| 3027 | "libc_nomalloc", |
| 3028 | "libc_nopthread", |
| 3029 | "libc_openbsd", |
| 3030 | "libc_openbsd_large_stack", |
| 3031 | "libc_openbsd_ndk", |
| 3032 | "libc_pthread", |
| 3033 | "libc_static_dispatch", |
| 3034 | "libc_syscalls", |
| 3035 | "libc_tzcode", |
| 3036 | "libc_unwind_static", |
| 3037 | "libdebuggerd", |
| 3038 | "libdebuggerd_common_headers", |
| 3039 | "libdebuggerd_handler_core", |
| 3040 | "libdebuggerd_handler_fallback", |
| 3041 | "libdl_static", |
| 3042 | "libjemalloc5", |
| 3043 | "liblinker_main", |
| 3044 | "liblinker_malloc", |
| 3045 | "liblz4", |
| 3046 | "liblzma", |
| 3047 | "libprocinfo", |
| 3048 | "libpropertyinfoparser", |
| 3049 | "libscudo", |
| 3050 | "libstdc++", |
| 3051 | "libsystemproperties", |
| 3052 | "libtombstoned_client_static", |
| 3053 | "libunwindstack", |
| 3054 | "libz", |
| 3055 | "libziparchive", |
| 3056 | } |
| 3057 | // |
| 3058 | // Module separator |
| 3059 | // |
| 3060 | m["com.android.tethering"] = []string{ |
| 3061 | "android.hardware.tetheroffload.config-V1.0-java", |
| 3062 | "android.hardware.tetheroffload.control-V1.0-java", |
| 3063 | "android.hidl.base-V1.0-java", |
| 3064 | "libcgrouprc", |
| 3065 | "libcgrouprc_format", |
| 3066 | "libtetherutilsjni", |
| 3067 | "libvndksupport", |
| 3068 | "net-utils-framework-common", |
| 3069 | "netd_aidl_interface-V3-java", |
| 3070 | "netlink-client", |
| 3071 | "networkstack-aidl-interfaces-java", |
| 3072 | "tethering-aidl-interfaces-java", |
| 3073 | "TetheringApiCurrentLib", |
| 3074 | } |
| 3075 | // |
| 3076 | // Module separator |
| 3077 | // |
| 3078 | m["com.android.wifi"] = []string{ |
| 3079 | "PlatformProperties", |
| 3080 | "android.hardware.wifi-V1.0-java", |
| 3081 | "android.hardware.wifi-V1.0-java-constants", |
| 3082 | "android.hardware.wifi-V1.1-java", |
| 3083 | "android.hardware.wifi-V1.2-java", |
| 3084 | "android.hardware.wifi-V1.3-java", |
| 3085 | "android.hardware.wifi-V1.4-java", |
| 3086 | "android.hardware.wifi.hostapd-V1.0-java", |
| 3087 | "android.hardware.wifi.hostapd-V1.1-java", |
| 3088 | "android.hardware.wifi.hostapd-V1.2-java", |
| 3089 | "android.hardware.wifi.supplicant-V1.0-java", |
| 3090 | "android.hardware.wifi.supplicant-V1.1-java", |
| 3091 | "android.hardware.wifi.supplicant-V1.2-java", |
| 3092 | "android.hardware.wifi.supplicant-V1.3-java", |
| 3093 | "android.hidl.base-V1.0-java", |
| 3094 | "android.hidl.manager-V1.0-java", |
| 3095 | "android.hidl.manager-V1.1-java", |
| 3096 | "android.hidl.manager-V1.2-java", |
| 3097 | "bouncycastle-unbundled", |
| 3098 | "dnsresolver_aidl_interface-V2-java", |
| 3099 | "error_prone_annotations", |
| 3100 | "framework-wifi-pre-jarjar", |
| 3101 | "framework-wifi-util-lib", |
| 3102 | "ipmemorystore-aidl-interfaces-V3-java", |
| 3103 | "ipmemorystore-aidl-interfaces-java", |
| 3104 | "ksoap2", |
| 3105 | "libnanohttpd", |
| 3106 | "libwifi-jni", |
| 3107 | "net-utils-services-common", |
| 3108 | "netd_aidl_interface-V2-java", |
| 3109 | "netd_aidl_interface-unstable-java", |
| 3110 | "netd_event_listener_interface-java", |
| 3111 | "netlink-client", |
| 3112 | "networkstack-client", |
| 3113 | "services.net", |
| 3114 | "wifi-lite-protos", |
| 3115 | "wifi-nano-protos", |
| 3116 | "wifi-service-pre-jarjar", |
| 3117 | "wifi-service-resources", |
| 3118 | } |
| 3119 | // |
| 3120 | // Module separator |
| 3121 | // |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3122 | m["com.android.os.statsd"] = []string{ |
| 3123 | "libstatssocket", |
| 3124 | } |
| 3125 | // |
| 3126 | // Module separator |
| 3127 | // |
| 3128 | m[android.AvailableToAnyApex] = []string{ |
| 3129 | // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries |
| 3130 | "androidx", |
| 3131 | "androidx-constraintlayout_constraintlayout", |
| 3132 | "androidx-constraintlayout_constraintlayout-nodeps", |
| 3133 | "androidx-constraintlayout_constraintlayout-solver", |
| 3134 | "androidx-constraintlayout_constraintlayout-solver-nodeps", |
| 3135 | "com.google.android.material_material", |
| 3136 | "com.google.android.material_material-nodeps", |
| 3137 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3138 | "libclang_rt", |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3139 | "libprofile-clang-extras", |
| 3140 | "libprofile-clang-extras_ndk", |
| 3141 | "libprofile-extras", |
| 3142 | "libprofile-extras_ndk", |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 3143 | "libunwind", |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3144 | } |
| 3145 | return m |
| 3146 | } |
| 3147 | |
| 3148 | func init() { |
| 3149 | android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...) |
| 3150 | android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...) |
| 3151 | } |
| 3152 | |
| 3153 | func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule { |
| 3154 | rules := make([]android.Rule, 0, len(modules_packages)) |
| 3155 | for module_name, module_packages := range modules_packages { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 3156 | permittedPackagesRule := android.NeverAllow(). |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3157 | BootclasspathJar(). |
| 3158 | With("apex_available", module_name). |
| 3159 | WithMatcher("permitted_packages", android.NotInList(module_packages)). |
| 3160 | Because("jars that are part of the " + module_name + |
| 3161 | " module may only allow these packages: " + strings.Join(module_packages, ",") + |
| 3162 | ". Please jarjar or move code around.") |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 3163 | rules = append(rules, permittedPackagesRule) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3164 | } |
| 3165 | return rules |
| 3166 | } |
| 3167 | |
| 3168 | // DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART. |
| 3169 | // Adding code to the bootclasspath in new packages will cause issues on module update. |
| 3170 | func qModulesPackages() map[string][]string { |
| 3171 | return map[string][]string{ |
| 3172 | "com.android.conscrypt": []string{ |
| 3173 | "android.net.ssl", |
| 3174 | "com.android.org.conscrypt", |
| 3175 | }, |
| 3176 | "com.android.media": []string{ |
| 3177 | "android.media", |
| 3178 | }, |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | // DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART. |
| 3183 | // Adding code to the bootclasspath in new packages will cause issues on module update. |
| 3184 | func rModulesPackages() map[string][]string { |
| 3185 | return map[string][]string{ |
| 3186 | "com.android.mediaprovider": []string{ |
| 3187 | "android.provider", |
| 3188 | }, |
| 3189 | "com.android.permission": []string{ |
| 3190 | "android.permission", |
| 3191 | "android.app.role", |
| 3192 | "com.android.permission", |
| 3193 | "com.android.role", |
| 3194 | }, |
| 3195 | "com.android.sdkext": []string{ |
| 3196 | "android.os.ext", |
| 3197 | }, |
| 3198 | "com.android.os.statsd": []string{ |
| 3199 | "android.app", |
| 3200 | "android.os", |
| 3201 | "android.util", |
| 3202 | "com.android.internal.statsd", |
| 3203 | "com.android.server.stats", |
| 3204 | }, |
| 3205 | "com.android.wifi": []string{ |
| 3206 | "com.android.server.wifi", |
| 3207 | "com.android.wifi.x", |
| 3208 | "android.hardware.wifi", |
| 3209 | "android.net.wifi", |
| 3210 | }, |
| 3211 | "com.android.tethering": []string{ |
| 3212 | "android.net", |
| 3213 | }, |
| 3214 | } |
| 3215 | } |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 3216 | |
| 3217 | // For Bazel / bp2build |
| 3218 | |
| 3219 | type bazelApexBundleAttributes struct { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 3220 | Manifest bazel.LabelAttribute |
| 3221 | Android_manifest bazel.LabelAttribute |
| 3222 | File_contexts bazel.LabelAttribute |
| 3223 | Key bazel.LabelAttribute |
| 3224 | Certificate bazel.LabelAttribute |
| 3225 | Min_sdk_version string |
| 3226 | Updatable bazel.BoolAttribute |
| 3227 | Installable bazel.BoolAttribute |
| 3228 | Native_shared_libs bazel.LabelListAttribute |
| 3229 | Binaries bazel.StringListAttribute |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | type bazelApexBundle struct { |
| 3233 | android.BazelTargetModuleBase |
| 3234 | bazelApexBundleAttributes |
| 3235 | } |
| 3236 | |
| 3237 | func BazelApexBundleFactory() android.Module { |
| 3238 | module := &bazelApexBundle{} |
| 3239 | module.AddProperties(&module.bazelApexBundleAttributes) |
| 3240 | android.InitBazelTargetModule(module) |
| 3241 | return module |
| 3242 | } |
| 3243 | |
| 3244 | func ApexBundleBp2Build(ctx android.TopDownMutatorContext) { |
| 3245 | module, ok := ctx.Module().(*apexBundle) |
| 3246 | if !ok { |
| 3247 | // Not an APEX bundle |
| 3248 | return |
| 3249 | } |
| 3250 | if !module.ConvertWithBp2build(ctx) { |
| 3251 | return |
| 3252 | } |
| 3253 | if ctx.ModuleType() != "apex" { |
| 3254 | return |
| 3255 | } |
| 3256 | |
| 3257 | apexBundleBp2BuildInternal(ctx, module) |
| 3258 | } |
| 3259 | |
| 3260 | func apexBundleBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexBundle) { |
| 3261 | var manifestLabelAttribute bazel.LabelAttribute |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 3262 | if module.properties.Manifest != nil { |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 3263 | manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Manifest)) |
| 3264 | } |
| 3265 | |
| 3266 | var androidManifestLabelAttribute bazel.LabelAttribute |
| 3267 | if module.properties.AndroidManifest != nil { |
| 3268 | androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.AndroidManifest)) |
| 3269 | } |
| 3270 | |
| 3271 | var fileContextsLabelAttribute bazel.LabelAttribute |
| 3272 | if module.properties.File_contexts != nil { |
| 3273 | fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.properties.File_contexts)) |
| 3274 | } |
| 3275 | |
| 3276 | var minSdkVersion string |
| 3277 | if module.properties.Min_sdk_version != nil { |
| 3278 | minSdkVersion = *module.properties.Min_sdk_version |
| 3279 | } |
| 3280 | |
| 3281 | var keyLabelAttribute bazel.LabelAttribute |
| 3282 | if module.overridableProperties.Key != nil { |
| 3283 | keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Key)) |
| 3284 | } |
| 3285 | |
| 3286 | var certificateLabelAttribute bazel.LabelAttribute |
| 3287 | if module.overridableProperties.Certificate != nil { |
| 3288 | certificateLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *module.overridableProperties.Certificate)) |
| 3289 | } |
| 3290 | |
| 3291 | nativeSharedLibs := module.properties.ApexNativeDependencies.Native_shared_libs |
| 3292 | nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs) |
| 3293 | nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList) |
| 3294 | |
| 3295 | binaries := module.properties.ApexNativeDependencies.Binaries |
| 3296 | binariesStringListAttribute := bazel.MakeStringListAttribute(binaries) |
| 3297 | |
| 3298 | var updatableAttribute bazel.BoolAttribute |
| 3299 | if module.properties.Updatable != nil { |
| 3300 | updatableAttribute.Value = module.properties.Updatable |
| 3301 | } |
| 3302 | |
| 3303 | var installableAttribute bazel.BoolAttribute |
| 3304 | if module.properties.Installable != nil { |
| 3305 | installableAttribute.Value = module.properties.Installable |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | attrs := &bazelApexBundleAttributes{ |
Rupert Shuttleworth | 6e4950a | 2021-07-27 01:34:59 -0400 | [diff] [blame] | 3309 | Manifest: manifestLabelAttribute, |
| 3310 | Android_manifest: androidManifestLabelAttribute, |
| 3311 | File_contexts: fileContextsLabelAttribute, |
| 3312 | Min_sdk_version: minSdkVersion, |
| 3313 | Key: keyLabelAttribute, |
| 3314 | Certificate: certificateLabelAttribute, |
| 3315 | Updatable: updatableAttribute, |
| 3316 | Installable: installableAttribute, |
| 3317 | Native_shared_libs: nativeSharedLibsLabelListAttribute, |
| 3318 | Binaries: binariesStringListAttribute, |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | props := bazel.BazelTargetModuleProperties{ |
| 3322 | Rule_class: "apex", |
| 3323 | Bzl_load_location: "//build/bazel/rules:apex.bzl", |
| 3324 | } |
| 3325 | |
| 3326 | ctx.CreateBazelTargetModule(BazelApexBundleFactory, module.Name(), props, attrs) |
| 3327 | } |
| 3328 | |
| 3329 | func (m *bazelApexBundle) Name() string { |
| 3330 | return m.BaseModuleName() |
| 3331 | } |
| 3332 | |
| 3333 | func (m *bazelApexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {} |