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