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