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