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