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