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