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