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