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