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