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" |
Kiyoung Kim | cbe2ba0 | 2023-09-07 16:00:04 +0900 | [diff] [blame] | 21 | "log" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 22 | "path/filepath" |
Oriol Prieto Gasco | 17e2290 | 2022-05-05 13:52:25 +0000 | [diff] [blame] | 23 | "regexp" |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 24 | "sort" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 25 | "strings" |
| 26 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 27 | "github.com/google/blueprint" |
| 28 | "github.com/google/blueprint/proptools" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 29 | |
| 30 | "android/soong/android" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 31 | "android/soong/bpf" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 32 | "android/soong/cc" |
| 33 | prebuilt_etc "android/soong/etc" |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 34 | "android/soong/filesystem" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 35 | "android/soong/java" |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 36 | "android/soong/multitree" |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 37 | "android/soong/rust" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 38 | "android/soong/sh" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 39 | ) |
| 40 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 41 | func init() { |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 42 | registerApexBuildComponents(android.InitRegistrationContext) |
| 43 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 44 | |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 45 | func registerApexBuildComponents(ctx android.RegistrationContext) { |
| 46 | ctx.RegisterModuleType("apex", BundleFactory) |
Yu Liu | 4c212ce | 2022-10-14 12:20:20 -0700 | [diff] [blame] | 47 | ctx.RegisterModuleType("apex_test", TestApexBundleFactory) |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 48 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 49 | ctx.RegisterModuleType("apex_defaults", DefaultsFactory) |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 50 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 51 | ctx.RegisterModuleType("override_apex", OverrideApexFactory) |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 52 | ctx.RegisterModuleType("apex_set", apexSetFactory) |
| 53 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 54 | ctx.PreArchMutators(registerPreArchMutators) |
Paul Duffin | 667893c | 2021-03-09 22:34:13 +0000 | [diff] [blame] | 55 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 56 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 57 | } |
| 58 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 59 | func registerPreArchMutators(ctx android.RegisterMutatorsContext) { |
| 60 | ctx.TopDown("prebuilt_apex_module_creator", prebuiltApexModuleCreatorMutator).Parallel() |
| 61 | } |
| 62 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 63 | func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { |
| 64 | ctx.TopDown("apex_vndk", apexVndkMutator).Parallel() |
| 65 | ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel() |
| 66 | } |
| 67 | |
| 68 | func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 69 | ctx.TopDown("apex_info", apexInfoMutator).Parallel() |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 70 | ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel() |
| 71 | ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel() |
| 72 | ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel() |
Paul Duffin | 28bf7ee | 2021-05-12 16:41:35 +0100 | [diff] [blame] | 73 | // Run mark_platform_availability before the apexMutator as the apexMutator needs to know whether |
| 74 | // it should create a platform variant. |
| 75 | ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel() |
Colin Cross | 7c03506 | 2024-03-28 12:18:42 -0700 | [diff] [blame] | 76 | ctx.Transition("apex", &apexTransitionMutator{}) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 77 | ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel() |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 78 | ctx.BottomUp("apex_dcla_deps", apexDCLADepsMutator).Parallel() |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 79 | // Register after apex_info mutator so that it can use ApexVariationName |
| 80 | ctx.TopDown("apex_strict_updatability_lint", apexStrictUpdatibilityLintMutator).Parallel() |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | type apexBundleProperties struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 84 | // Json manifest file describing meta info of this APEX bundle. Refer to |
| 85 | // system/apex/proto/apex_manifest.proto for the schema. Default: "apex_manifest.json" |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 86 | Manifest *string `android:"path"` |
| 87 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 88 | // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified, |
| 89 | // a default one is automatically generated. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 90 | AndroidManifest *string `android:"path"` |
| 91 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 92 | // Determines the file contexts file for setting the security contexts to files in this APEX |
| 93 | // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default: |
| 94 | // /system/sepolicy/apex/<module_name>_file_contexts. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 95 | File_contexts *string `android:"path"` |
| 96 | |
Jooyung Han | af73095 | 2023-02-28 14:13:38 +0900 | [diff] [blame] | 97 | // By default, file_contexts is amended by force-labelling / and /apex_manifest.pb as system_file |
| 98 | // to avoid mistakes. When set as true, no force-labelling. |
| 99 | Use_file_contexts_as_is *bool |
| 100 | |
Jingwen Chen | dea7a64 | 2023-03-28 11:30:50 +0000 | [diff] [blame] | 101 | // Path to the canned fs config file for customizing file's |
| 102 | // uid/gid/mod/capabilities. The content of this file is appended to the |
| 103 | // default config, so that the custom entries are preferred. The format is |
| 104 | // /<path_or_glob> <uid> <gid> <mode> [capabilities=0x<cap>], where |
| 105 | // path_or_glob is a path or glob pattern for a file or set of files, |
| 106 | // uid/gid are numerial values of user ID and group ID, mode is octal value |
| 107 | // for the file mode, and cap is hexadecimal value for the capability. |
Jiyong Park | 038e852 | 2021-12-13 23:56:35 +0900 | [diff] [blame] | 108 | Canned_fs_config *string `android:"path"` |
| 109 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 110 | ApexNativeDependencies |
| 111 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 112 | Multilib apexMultilibProperties |
| 113 | |
Anton Hansson | 72e7ffe | 2023-02-24 11:12:31 +0000 | [diff] [blame] | 114 | // List of runtime resource overlays (RROs) that are embedded inside this APEX. |
| 115 | Rros []string |
| 116 | |
Anton Hansson | e754585 | 2023-02-24 11:06:07 +0000 | [diff] [blame] | 117 | // List of bootclasspath fragments that are embedded inside this APEX bundle. |
| 118 | Bootclasspath_fragments []string |
| 119 | |
| 120 | // List of systemserverclasspath fragments that are embedded inside this APEX bundle. |
| 121 | Systemserverclasspath_fragments []string |
| 122 | |
| 123 | // List of java libraries that are embedded inside this APEX bundle. |
| 124 | Java_libs []string |
| 125 | |
Sundong Ahn | 80c0489 | 2021-11-23 00:57:19 +0000 | [diff] [blame] | 126 | // List of sh binaries that are embedded inside this APEX bundle. |
| 127 | Sh_binaries []string |
| 128 | |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 129 | // List of platform_compat_config files that are embedded inside this APEX bundle. |
| 130 | Compat_configs []string |
| 131 | |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 132 | // List of filesystem images that are embedded inside this APEX bundle. |
| 133 | Filesystems []string |
| 134 | |
Jooyung Han | a8bd72a | 2023-11-02 11:56:48 +0900 | [diff] [blame] | 135 | // List of module names which we don't want to add as transitive deps. This can be used as |
| 136 | // a workaround when the current implementation collects more than necessary. For example, |
| 137 | // Rust binaries with prefer_rlib:true add unnecessary dependencies. |
| 138 | Unwanted_transitive_deps []string |
| 139 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 140 | // Whether this APEX is considered updatable or not. When set to true, this will enforce |
| 141 | // additional rules for making sure that the APEX is truly updatable. To be updatable, |
| 142 | // min_sdk_version should be set as well. This will also disable the size optimizations like |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 143 | // symlinking to the system libs. Default is true. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 144 | Updatable *bool |
| 145 | |
Jiyong Park | f402058 | 2021-11-29 12:37:10 +0900 | [diff] [blame] | 146 | // Marks that this APEX is designed to be updatable in the future, although it's not |
| 147 | // updatable yet. This is used to mimic some of the build behaviors that are applied only to |
| 148 | // updatable APEXes. Currently, this disables the size optimization, so that the size of |
| 149 | // APEX will not increase when the APEX is actually marked as truly updatable. Default is |
| 150 | // false. |
| 151 | Future_updatable *bool |
| 152 | |
Jiyong Park | 1bc8412 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 153 | // Whether this APEX can use platform APIs or not. Can be set to true only when `updatable: |
| 154 | // false`. Default is false. |
| 155 | Platform_apis *bool |
| 156 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 157 | // Whether this APEX is installable to one of the partitions like system, vendor, etc. |
| 158 | // Default: true. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 159 | Installable *bool |
| 160 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 161 | // If set true, VNDK libs are considered as stable libs and are not included in this APEX. |
| 162 | // Should be only used in non-system apexes (e.g. vendor: true). Default is false. |
| 163 | Use_vndk_as_stable *bool |
| 164 | |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 165 | // The type of filesystem to use. Either 'ext4', 'f2fs' or 'erofs'. Default 'ext4'. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 166 | Payload_fs_type *string |
| 167 | |
| 168 | // For telling the APEX to ignore special handling for system libraries such as bionic. |
| 169 | // Default is false. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 170 | Ignore_system_library_special_case *bool |
| 171 | |
Nikita Ioffe | da6dc31 | 2021-06-09 19:43:46 +0100 | [diff] [blame] | 172 | // Whenever apex_payload.img of the APEX should include dm-verity hashtree. |
Nikita Ioffe | e261ae6 | 2021-06-16 18:15:03 +0100 | [diff] [blame] | 173 | // Default value is true. |
Nikita Ioffe | da6dc31 | 2021-06-09 19:43:46 +0100 | [diff] [blame] | 174 | Generate_hashtree *bool |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 175 | |
| 176 | // Whenever apex_payload.img of the APEX should not be dm-verity signed. Should be only |
| 177 | // used in tests. |
| 178 | Test_only_unsigned_payload *bool |
| 179 | |
Mohammad Samiul Islam | a8008f9 | 2020-12-22 10:47:50 +0000 | [diff] [blame] | 180 | // Whenever apex should be compressed, regardless of product flag used. Should be only |
| 181 | // used in tests. |
| 182 | Test_only_force_compression *bool |
| 183 | |
Jooyung Han | 09c11ad | 2021-10-27 03:45:31 +0900 | [diff] [blame] | 184 | // Put extra tags (signer=<value>) to apexkeys.txt, so that release tools can sign this apex |
| 185 | // with the tool to sign payload contents. |
| 186 | Custom_sign_tool *string |
| 187 | |
Dennis Shen | af41bc1 | 2022-08-03 16:46:43 +0000 | [diff] [blame] | 188 | // Whether this is a dynamic common lib apex, if so the native shared libs will be placed |
| 189 | // in a special way that include the digest of the lib file under /lib(64)? |
| 190 | Dynamic_common_lib_apex *bool |
| 191 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 192 | // Canonical name of this APEX bundle. Used to determine the path to the |
| 193 | // activated APEX on device (i.e. /apex/<apexVariationName>), and used for the |
| 194 | // apex mutator variations. For override_apex modules, this is the name of the |
| 195 | // overridden base module. |
| 196 | ApexVariationName string `blueprint:"mutated"` |
| 197 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 198 | IsCoverageVariant bool `blueprint:"mutated"` |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 199 | |
| 200 | // List of sanitizer names that this APEX is enabled for |
| 201 | SanitizerNames []string `blueprint:"mutated"` |
| 202 | |
| 203 | PreventInstall bool `blueprint:"mutated"` |
| 204 | |
| 205 | HideFromMake bool `blueprint:"mutated"` |
| 206 | |
Sam Delmerico | ca81653 | 2023-06-02 14:09:50 -0400 | [diff] [blame] | 207 | // 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] | 208 | // 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] | 209 | Apex_available_name *string |
Sam Delmerico | 6d65a0f | 2023-06-05 15:55:57 -0400 | [diff] [blame] | 210 | |
| 211 | // Variant version of the mainline module. Must be an integer between 0-9 |
| 212 | Variant_version *string |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | type ApexNativeDependencies struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 216 | // List of native libraries that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 217 | Native_shared_libs []string |
| 218 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 219 | // List of JNI libraries that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 220 | Jni_libs []string |
| 221 | |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 222 | // List of rust dyn libraries that are embedded inside this APEX. |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 223 | Rust_dyn_libs []string |
| 224 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 225 | // List of native executables that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 226 | Binaries []string |
| 227 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 228 | // List of native tests that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 229 | Tests []string |
Jiyong Park | 0671146 | 2021-02-15 17:54:43 +0900 | [diff] [blame] | 230 | |
| 231 | // List of filesystem images that are embedded inside this APEX bundle. |
| 232 | Filesystems []string |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 233 | |
Alice Wang | 4fab2dc | 2023-10-20 12:05:08 +0000 | [diff] [blame] | 234 | // List of prebuilt_etcs that are embedded inside this APEX bundle. |
| 235 | Prebuilts []string |
| 236 | |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 237 | // List of native libraries to exclude from this APEX. |
| 238 | Exclude_native_shared_libs []string |
| 239 | |
| 240 | // List of JNI libraries to exclude from this APEX. |
| 241 | Exclude_jni_libs []string |
| 242 | |
| 243 | // List of rust dyn libraries to exclude from this APEX. |
| 244 | Exclude_rust_dyn_libs []string |
| 245 | |
| 246 | // List of native executables to exclude from this APEX. |
| 247 | Exclude_binaries []string |
| 248 | |
| 249 | // List of native tests to exclude from this APEX. |
| 250 | Exclude_tests []string |
| 251 | |
| 252 | // List of filesystem images to exclude from this APEX bundle. |
| 253 | Exclude_filesystems []string |
Alice Wang | 4fab2dc | 2023-10-20 12:05:08 +0000 | [diff] [blame] | 254 | |
| 255 | // List of prebuilt_etcs to exclude from this APEX bundle. |
| 256 | Exclude_prebuilts []string |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // Merge combines another ApexNativeDependencies into this one |
| 260 | func (a *ApexNativeDependencies) Merge(b ApexNativeDependencies) { |
| 261 | a.Native_shared_libs = append(a.Native_shared_libs, b.Native_shared_libs...) |
| 262 | a.Jni_libs = append(a.Jni_libs, b.Jni_libs...) |
| 263 | a.Rust_dyn_libs = append(a.Rust_dyn_libs, b.Rust_dyn_libs...) |
| 264 | a.Binaries = append(a.Binaries, b.Binaries...) |
| 265 | a.Tests = append(a.Tests, b.Tests...) |
| 266 | a.Filesystems = append(a.Filesystems, b.Filesystems...) |
Alice Wang | 4fab2dc | 2023-10-20 12:05:08 +0000 | [diff] [blame] | 267 | a.Prebuilts = append(a.Prebuilts, b.Prebuilts...) |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 268 | |
| 269 | a.Exclude_native_shared_libs = append(a.Exclude_native_shared_libs, b.Exclude_native_shared_libs...) |
| 270 | a.Exclude_jni_libs = append(a.Exclude_jni_libs, b.Exclude_jni_libs...) |
| 271 | a.Exclude_rust_dyn_libs = append(a.Exclude_rust_dyn_libs, b.Exclude_rust_dyn_libs...) |
| 272 | a.Exclude_binaries = append(a.Exclude_binaries, b.Exclude_binaries...) |
| 273 | a.Exclude_tests = append(a.Exclude_tests, b.Exclude_tests...) |
| 274 | a.Exclude_filesystems = append(a.Exclude_filesystems, b.Exclude_filesystems...) |
Alice Wang | 4fab2dc | 2023-10-20 12:05:08 +0000 | [diff] [blame] | 275 | a.Exclude_prebuilts = append(a.Exclude_prebuilts, b.Exclude_prebuilts...) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | type apexMultilibProperties struct { |
| 279 | // Native dependencies whose compile_multilib is "first" |
| 280 | First ApexNativeDependencies |
| 281 | |
| 282 | // Native dependencies whose compile_multilib is "both" |
| 283 | Both ApexNativeDependencies |
| 284 | |
| 285 | // Native dependencies whose compile_multilib is "prefer32" |
| 286 | Prefer32 ApexNativeDependencies |
| 287 | |
| 288 | // Native dependencies whose compile_multilib is "32" |
| 289 | Lib32 ApexNativeDependencies |
| 290 | |
| 291 | // Native dependencies whose compile_multilib is "64" |
| 292 | Lib64 ApexNativeDependencies |
| 293 | } |
| 294 | |
| 295 | type apexTargetBundleProperties struct { |
| 296 | Target struct { |
| 297 | // Multilib properties only for android. |
| 298 | Android struct { |
| 299 | Multilib apexMultilibProperties |
| 300 | } |
| 301 | |
| 302 | // Multilib properties only for host. |
| 303 | Host struct { |
| 304 | Multilib apexMultilibProperties |
| 305 | } |
| 306 | |
| 307 | // Multilib properties only for host linux_bionic. |
| 308 | Linux_bionic struct { |
| 309 | Multilib apexMultilibProperties |
| 310 | } |
| 311 | |
| 312 | // Multilib properties only for host linux_glibc. |
| 313 | Linux_glibc struct { |
| 314 | Multilib apexMultilibProperties |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 319 | type apexArchBundleProperties struct { |
| 320 | Arch struct { |
| 321 | Arm struct { |
| 322 | ApexNativeDependencies |
| 323 | } |
| 324 | Arm64 struct { |
| 325 | ApexNativeDependencies |
| 326 | } |
Colin Cross | a2aaa2f | 2022-10-03 12:41:50 -0700 | [diff] [blame] | 327 | Riscv64 struct { |
| 328 | ApexNativeDependencies |
| 329 | } |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 330 | X86 struct { |
| 331 | ApexNativeDependencies |
| 332 | } |
| 333 | X86_64 struct { |
| 334 | ApexNativeDependencies |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 339 | // These properties can be used in override_apex to override the corresponding properties in the |
| 340 | // base apex. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 341 | type overridableProperties struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 342 | // List of APKs that are embedded inside this APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 343 | Apps []string |
| 344 | |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 345 | // List of prebuilt files that are embedded inside this APEX bundle. |
| 346 | Prebuilts []string |
| 347 | |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 348 | // List of BPF programs inside this APEX bundle. |
| 349 | Bpfs []string |
| 350 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 351 | // Names of modules to be overridden. Listed modules can only be other binaries (in Make or |
| 352 | // Soong). This does not completely prevent installation of the overridden binaries, but if |
| 353 | // both binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will |
| 354 | // be removed from PRODUCT_PACKAGES. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 355 | Overrides []string |
| 356 | |
Jesse Melhuish | ec60e25 | 2024-03-29 19:08:20 +0000 | [diff] [blame] | 357 | Multilib apexMultilibProperties |
| 358 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 359 | // Logging parent value. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 360 | Logging_parent string |
| 361 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 362 | // Apex Container package name. Override value for attribute package:name in |
| 363 | // AndroidManifest.xml |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 364 | Package_name string |
| 365 | |
| 366 | // A txt file containing list of files that are allowed to be included in this APEX. |
| 367 | Allowed_files *string `android:"path"` |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 368 | |
| 369 | // Name of the apex_key module that provides the private key to sign this APEX bundle. |
| 370 | Key *string |
| 371 | |
| 372 | // Specifies the certificate and the private key to sign the zip container of this APEX. If |
| 373 | // this is "foo", foo.x509.pem and foo.pk8 under PRODUCT_DEFAULT_DEV_CERTIFICATE are used |
| 374 | // as the certificate and the private key, respectively. If this is ":module", then the |
| 375 | // certificate and the private key are provided from the android_app_certificate module |
| 376 | // named "module". |
| 377 | Certificate *string |
Oriol Prieto Gasco | a07099d | 2021-10-14 15:33:41 -0400 | [diff] [blame] | 378 | |
| 379 | // Whether this APEX can be compressed or not. Setting this property to false means this |
| 380 | // APEX will never be compressed. When set to true, APEX will be compressed if other |
| 381 | // conditions, e.g., target device needs to support APEX compression, are also fulfilled. |
| 382 | // Default: false. |
| 383 | Compressible *bool |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 384 | |
| 385 | // Trim against a specific Dynamic Common Lib APEX |
| 386 | Trim_against *string |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 387 | |
| 388 | // The minimum SDK version that this APEX must support at minimum. This is usually set to |
| 389 | // the SDK version that the APEX was first introduced. |
| 390 | Min_sdk_version *string |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | type apexBundle struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 394 | // Inherited structs |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 395 | android.ModuleBase |
| 396 | android.DefaultableModuleBase |
| 397 | android.OverridableModuleBase |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 398 | multitree.ExportableModuleBase |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 399 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 400 | // Properties |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 401 | properties apexBundleProperties |
| 402 | targetProperties apexTargetBundleProperties |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 403 | archProperties apexArchBundleProperties |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 404 | overridableProperties overridableProperties |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 405 | vndkProperties apexVndkProperties // only for apex_vndk modules |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 406 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 407 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 408 | // Inputs |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 409 | |
Nicolas Geoffray | 036ff9a | 2023-05-15 10:46:38 +0100 | [diff] [blame] | 410 | // Keys for apex_payload.img |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 411 | publicKeyFile android.Path |
| 412 | privateKeyFile android.Path |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 413 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 414 | // Cert/priv-key for the zip container |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 415 | containerCertificateFile android.Path |
| 416 | containerPrivateKeyFile android.Path |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 417 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 418 | // Flags for special variants of APEX |
| 419 | testApex bool |
| 420 | vndkApex bool |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 421 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 422 | // File system type of apex_payload.img |
| 423 | payloadFsType fsType |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 424 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 425 | // Whether to create symlink to the system file instead of having a file inside the apex or |
| 426 | // not |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 427 | linkToSystemLib bool |
| 428 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 429 | // List of files to be included in this APEX. This is filled in the first part of |
| 430 | // GenerateAndroidBuildActions. |
| 431 | filesInfo []apexFile |
| 432 | |
Jingwen Chen | 29743c8 | 2023-01-25 17:49:46 +0000 | [diff] [blame] | 433 | // List of other module names that should be installed when this APEX gets installed (LOCAL_REQUIRED_MODULES). |
| 434 | makeModulesToInstall []string |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 435 | |
| 436 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 437 | // Outputs (final and intermediates) |
| 438 | |
| 439 | // Processed apex manifest in JSONson format (for Q) |
| 440 | manifestJsonOut android.WritablePath |
| 441 | |
| 442 | // Processed apex manifest in PB format (for R+) |
| 443 | manifestPbOut android.WritablePath |
| 444 | |
| 445 | // Processed file_contexts files |
| 446 | fileContexts android.WritablePath |
| 447 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 448 | // The built APEX file. This is the main product. |
Jooyung Han | a6d3667 | 2022-02-24 13:58:07 +0900 | [diff] [blame] | 449 | // Could be .apex or .capex |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 450 | outputFile android.WritablePath |
| 451 | |
Jooyung Han | a6d3667 | 2022-02-24 13:58:07 +0900 | [diff] [blame] | 452 | // The built uncompressed .apex file. |
| 453 | outputApexFile android.WritablePath |
| 454 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 455 | // The built APEX file in app bundle format. This file is not directly installed to the |
| 456 | // device. For an APEX, multiple app bundles are created each of which is for a specific ABI |
| 457 | // like arm, arm64, x86, etc. Then they are processed again (outside of the Android build |
| 458 | // system) to be merged into a single app bundle file that Play accepts. See |
| 459 | // vendor/google/build/build_unbundled_mainline_module.sh for more detail. |
| 460 | bundleModuleFile android.WritablePath |
| 461 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 462 | // 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] | 463 | installDir android.InstallPath |
| 464 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 465 | // Path where this APEX was installed. |
| 466 | installedFile android.InstallPath |
| 467 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 468 | // fragment for this apex for apexkeys.txt |
| 469 | apexKeysPath android.WritablePath |
| 470 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 471 | // Installed locations of symlinks for backward compatibility. |
| 472 | compatSymlinks android.InstallPaths |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 473 | |
| 474 | // Text file having the list of individual files that are included in this APEX. Used for |
| 475 | // debugging purpose. |
| 476 | installedFilesFile android.WritablePath |
| 477 | |
| 478 | // List of module names that this APEX is including (to be shown via *-deps-info target). |
| 479 | // Used for debugging purpose. |
| 480 | android.ApexBundleDepsInfo |
| 481 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 482 | // Optional list of lint report zip files for apexes that contain java or app modules |
| 483 | lintReports android.Paths |
| 484 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 485 | isCompressed bool |
| 486 | |
sophiez | c80a2b3 | 2020-11-12 16:39:19 +0000 | [diff] [blame] | 487 | // Path of API coverage generate file |
sophiez | 0234737 | 2021-11-02 17:58:02 -0700 | [diff] [blame] | 488 | nativeApisUsedByModuleFile android.ModuleOutPath |
| 489 | nativeApisBackedByModuleFile android.ModuleOutPath |
| 490 | javaApisUsedByModuleFile android.ModuleOutPath |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 491 | |
| 492 | aconfigFiles []android.Path |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 493 | } |
| 494 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 495 | // apexFileClass represents a type of file that can be included in APEX. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 496 | type apexFileClass int |
| 497 | |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 498 | const ( |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 499 | app apexFileClass = iota |
| 500 | appSet |
| 501 | etc |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 502 | javaSharedLib |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 503 | nativeExecutable |
| 504 | nativeSharedLib |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 505 | nativeTest |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 506 | shBinary |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 507 | ) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 508 | |
Jingwen Chen | 2d37b64 | 2023-03-14 16:11:38 +0000 | [diff] [blame] | 509 | var ( |
| 510 | classes = map[string]apexFileClass{ |
| 511 | "app": app, |
| 512 | "appSet": appSet, |
| 513 | "etc": etc, |
Jingwen Chen | 2d37b64 | 2023-03-14 16:11:38 +0000 | [diff] [blame] | 514 | "javaSharedLib": javaSharedLib, |
| 515 | "nativeExecutable": nativeExecutable, |
| 516 | "nativeSharedLib": nativeSharedLib, |
| 517 | "nativeTest": nativeTest, |
Jingwen Chen | 2d37b64 | 2023-03-14 16:11:38 +0000 | [diff] [blame] | 518 | "shBinary": shBinary, |
| 519 | } |
| 520 | ) |
| 521 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 522 | // apexFile represents a file in an APEX bundle. This is created during the first half of |
| 523 | // GenerateAndroidBuildActions by traversing the dependencies of the APEX. Then in the second half |
| 524 | // 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] | 525 | // where they are packaged into the APEX file. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 526 | type apexFile struct { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 527 | // buildFile is put in the installDir inside the APEX. |
Bob Badour | de6a087 | 2022-04-01 18:00:00 +0000 | [diff] [blame] | 528 | builtFile android.Path |
| 529 | installDir string |
Jiyong Park | ce24363 | 2023-02-17 18:22:25 +0900 | [diff] [blame] | 530 | partition string |
Bob Badour | de6a087 | 2022-04-01 18:00:00 +0000 | [diff] [blame] | 531 | customStem string |
| 532 | symlinks []string // additional symlinks |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 533 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 534 | // Info for Android.mk Module name of `module` in AndroidMk. Note the generated AndroidMk |
| 535 | // module for apexFile is named something like <AndroidMk module name>.<apex name>[<apex |
| 536 | // suffix>] |
| 537 | androidMkModuleName string // becomes LOCAL_MODULE |
| 538 | class apexFileClass // becomes LOCAL_MODULE_CLASS |
| 539 | moduleDir string // becomes LOCAL_PATH |
| 540 | requiredModuleNames []string // becomes LOCAL_REQUIRED_MODULES |
| 541 | targetRequiredModuleNames []string // becomes LOCAL_TARGET_REQUIRED_MODULES |
| 542 | hostRequiredModuleNames []string // becomes LOCAL_HOST_REQUIRED_MODULES |
| 543 | dataPaths []android.DataPath // becomes LOCAL_TEST_DATA |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 544 | |
| 545 | jacocoReportClassesFile android.Path // only for javalibs and apps |
| 546 | lintDepSets java.LintDepSets // only for javalibs and apps |
| 547 | certificate java.Certificate // only for apps |
| 548 | overriddenPackageName string // only for apps |
| 549 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 550 | transitiveDep bool |
| 551 | isJniLib bool |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 552 | |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 553 | multilib string |
| 554 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 555 | // TODO(jiyong): remove this |
| 556 | module android.Module |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 557 | } |
| 558 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 559 | // TODO(jiyong): shorten the arglist using an option struct |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 560 | func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile { |
| 561 | ret := apexFile{ |
| 562 | builtFile: builtFile, |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 563 | installDir: installDir, |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 564 | androidMkModuleName: androidMkModuleName, |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 565 | class: class, |
| 566 | module: module, |
| 567 | } |
| 568 | if module != nil { |
| 569 | ret.moduleDir = ctx.OtherModuleDir(module) |
Jiyong Park | ce24363 | 2023-02-17 18:22:25 +0900 | [diff] [blame] | 570 | ret.partition = module.PartitionTag(ctx.DeviceConfig()) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 571 | ret.requiredModuleNames = module.RequiredModuleNames() |
| 572 | ret.targetRequiredModuleNames = module.TargetRequiredModuleNames() |
| 573 | ret.hostRequiredModuleNames = module.HostRequiredModuleNames() |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 574 | ret.multilib = module.Target().Arch.ArchType.Multilib |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 575 | } |
| 576 | return ret |
| 577 | } |
| 578 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 579 | func (af *apexFile) ok() bool { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 580 | return af.builtFile != nil && af.builtFile.String() != "" |
| 581 | } |
| 582 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 583 | // apexRelativePath returns the relative path of the given path from the install directory of this |
| 584 | // apexFile. |
| 585 | // TODO(jiyong): rename this |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 586 | func (af *apexFile) apexRelativePath(path string) string { |
| 587 | return filepath.Join(af.installDir, path) |
| 588 | } |
| 589 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 590 | // path returns path of this apex file relative to the APEX root |
| 591 | func (af *apexFile) path() string { |
| 592 | return af.apexRelativePath(af.stem()) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 593 | } |
| 594 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 595 | // stem returns the base filename of this apex file |
| 596 | func (af *apexFile) stem() string { |
| 597 | if af.customStem != "" { |
| 598 | return af.customStem |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 599 | } |
| 600 | return af.builtFile.Base() |
| 601 | } |
| 602 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 603 | // symlinkPaths returns paths of the symlinks (if any) relative to the APEX root |
| 604 | func (af *apexFile) symlinkPaths() []string { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 605 | var ret []string |
| 606 | for _, symlink := range af.symlinks { |
| 607 | ret = append(ret, af.apexRelativePath(symlink)) |
| 608 | } |
| 609 | return ret |
| 610 | } |
| 611 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 612 | // availableToPlatform tests whether this apexFile is from a module that can be installed to the |
| 613 | // platform. |
| 614 | func (af *apexFile) availableToPlatform() bool { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 615 | if af.module == nil { |
| 616 | return false |
| 617 | } |
| 618 | if am, ok := af.module.(android.ApexModule); ok { |
| 619 | return am.AvailableFor(android.AvailableToPlatform) |
| 620 | } |
| 621 | return false |
| 622 | } |
| 623 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 624 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 625 | // Mutators |
| 626 | // |
| 627 | // Brief description about mutators for APEX. The following three mutators are the most important |
| 628 | // ones. |
| 629 | // |
| 630 | // 1) DepsMutator: from the properties like native_shared_libs, java_libs, etc., modules are added |
| 631 | // to the (direct) dependencies of this APEX bundle. |
| 632 | // |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 633 | // 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] | 634 | // collect modules that are direct and transitive dependencies of each APEX bundle. The collected |
| 635 | // modules are marked as being included in the APEX via BuildForApex(). |
| 636 | // |
Paul Duffin | 949abc0 | 2020-12-08 10:34:30 +0000 | [diff] [blame] | 637 | // 3) apexMutator: this is a post-deps mutator that runs after apexInfoMutator. For each module that |
| 638 | // are marked by the apexInfoMutator, apex variations are created using CreateApexVariations(). |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 639 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 640 | type dependencyTag struct { |
| 641 | blueprint.BaseDependencyTag |
| 642 | name string |
| 643 | |
| 644 | // Determines if the dependent will be part of the APEX payload. Can be false for the |
| 645 | // dependencies to the signing key module, etc. |
| 646 | payload bool |
Paul Duffin | 8c535da | 2021-03-17 14:51:03 +0000 | [diff] [blame] | 647 | |
| 648 | // True if the dependent can only be a source module, false if a prebuilt module is a suitable |
| 649 | // replacement. This is needed because some prebuilt modules do not provide all the information |
| 650 | // needed by the apex. |
| 651 | sourceOnly bool |
Paul Duffin | 4e7d1c4 | 2022-05-13 13:12:19 +0000 | [diff] [blame] | 652 | |
| 653 | // If not-nil and an APEX is a member of an SDK then dependencies of that APEX with this tag will |
| 654 | // also be added as exported members of that SDK. |
| 655 | memberType android.SdkMemberType |
| 656 | } |
| 657 | |
| 658 | func (d *dependencyTag) SdkMemberType(_ android.Module) android.SdkMemberType { |
| 659 | return d.memberType |
| 660 | } |
| 661 | |
| 662 | func (d *dependencyTag) ExportMember() bool { |
| 663 | return true |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 664 | } |
| 665 | |
Paul Duffin | 520917a | 2022-05-13 13:01:59 +0000 | [diff] [blame] | 666 | func (d *dependencyTag) String() string { |
| 667 | return fmt.Sprintf("apex.dependencyTag{%q}", d.name) |
| 668 | } |
| 669 | |
| 670 | func (d *dependencyTag) ReplaceSourceWithPrebuilt() bool { |
Paul Duffin | 8c535da | 2021-03-17 14:51:03 +0000 | [diff] [blame] | 671 | return !d.sourceOnly |
| 672 | } |
| 673 | |
| 674 | var _ android.ReplaceSourceWithPrebuilt = &dependencyTag{} |
Paul Duffin | 4e7d1c4 | 2022-05-13 13:12:19 +0000 | [diff] [blame] | 675 | var _ android.SdkMemberDependencyTag = &dependencyTag{} |
Paul Duffin | 8c535da | 2021-03-17 14:51:03 +0000 | [diff] [blame] | 676 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 677 | var ( |
Paul Duffin | 520917a | 2022-05-13 13:01:59 +0000 | [diff] [blame] | 678 | androidAppTag = &dependencyTag{name: "androidApp", payload: true} |
| 679 | bpfTag = &dependencyTag{name: "bpf", payload: true} |
| 680 | certificateTag = &dependencyTag{name: "certificate"} |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 681 | dclaTag = &dependencyTag{name: "dcla"} |
Paul Duffin | 520917a | 2022-05-13 13:01:59 +0000 | [diff] [blame] | 682 | executableTag = &dependencyTag{name: "executable", payload: true} |
| 683 | fsTag = &dependencyTag{name: "filesystem", payload: true} |
Paul Duffin | 4e7d1c4 | 2022-05-13 13:12:19 +0000 | [diff] [blame] | 684 | bcpfTag = &dependencyTag{name: "bootclasspathFragment", payload: true, sourceOnly: true, memberType: java.BootclasspathFragmentSdkMemberType} |
| 685 | sscpfTag = &dependencyTag{name: "systemserverclasspathFragment", payload: true, sourceOnly: true, memberType: java.SystemServerClasspathFragmentSdkMemberType} |
Paul Duffin | fcf7985 | 2022-07-20 14:18:24 +0000 | [diff] [blame] | 686 | compatConfigTag = &dependencyTag{name: "compatConfig", payload: true, sourceOnly: true, memberType: java.CompatConfigSdkMemberType} |
Paul Duffin | 520917a | 2022-05-13 13:01:59 +0000 | [diff] [blame] | 687 | javaLibTag = &dependencyTag{name: "javaLib", payload: true} |
| 688 | jniLibTag = &dependencyTag{name: "jniLib", payload: true} |
| 689 | keyTag = &dependencyTag{name: "key"} |
| 690 | prebuiltTag = &dependencyTag{name: "prebuilt", payload: true} |
| 691 | rroTag = &dependencyTag{name: "rro", payload: true} |
| 692 | sharedLibTag = &dependencyTag{name: "sharedLib", payload: true} |
| 693 | testForTag = &dependencyTag{name: "test for"} |
| 694 | testTag = &dependencyTag{name: "test", payload: true} |
| 695 | shBinaryTag = &dependencyTag{name: "shBinary", payload: true} |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 696 | ) |
| 697 | |
| 698 | // TODO(jiyong): shorten this function signature |
| 699 | func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeModules ApexNativeDependencies, target android.Target, imageVariation string) { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 700 | binVariations := target.Variations() |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 701 | libVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 702 | rustLibVariations := append( |
| 703 | target.Variations(), []blueprint.Variation{ |
| 704 | {Mutator: "rust_libraries", Variation: "dylib"}, |
| 705 | {Mutator: "link", Variation: ""}, |
| 706 | }..., |
| 707 | ) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 708 | |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 709 | // Append "image" variation |
| 710 | binVariations = append(binVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation}) |
| 711 | libVariations = append(libVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation}) |
| 712 | rustLibVariations = append(rustLibVariations, blueprint.Variation{Mutator: "image", Variation: imageVariation}) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 713 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 714 | // Use *FarVariation* to be able to depend on modules having conflicting variations with |
| 715 | // this module. This is required since arch variant of an APEX bundle is 'common' but it is |
| 716 | // 'arm' or 'arm64' for native shared libs. |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 717 | ctx.AddFarVariationDependencies(binVariations, executableTag, |
| 718 | android.RemoveListFromList(nativeModules.Binaries, nativeModules.Exclude_binaries)...) |
| 719 | ctx.AddFarVariationDependencies(binVariations, testTag, |
| 720 | android.RemoveListFromList(nativeModules.Tests, nativeModules.Exclude_tests)...) |
| 721 | ctx.AddFarVariationDependencies(libVariations, jniLibTag, |
| 722 | android.RemoveListFromList(nativeModules.Jni_libs, nativeModules.Exclude_jni_libs)...) |
| 723 | ctx.AddFarVariationDependencies(libVariations, sharedLibTag, |
| 724 | android.RemoveListFromList(nativeModules.Native_shared_libs, nativeModules.Exclude_native_shared_libs)...) |
| 725 | ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, |
| 726 | android.RemoveListFromList(nativeModules.Rust_dyn_libs, nativeModules.Exclude_rust_dyn_libs)...) |
| 727 | ctx.AddFarVariationDependencies(target.Variations(), fsTag, |
| 728 | android.RemoveListFromList(nativeModules.Filesystems, nativeModules.Exclude_filesystems)...) |
Alice Wang | 4fab2dc | 2023-10-20 12:05:08 +0000 | [diff] [blame] | 729 | ctx.AddFarVariationDependencies(target.Variations(), prebuiltTag, |
| 730 | android.RemoveListFromList(nativeModules.Prebuilts, nativeModules.Exclude_prebuilts)...) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 734 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 735 | } |
| 736 | |
Jooyung Han | d045ebc | 2022-12-06 15:23:57 +0900 | [diff] [blame] | 737 | // getImageVariationPair returns a pair for the image variation name as its |
| 738 | // prefix and suffix. The prefix indicates whether it's core/vendor/product and the |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 739 | // suffix indicates the vndk version for vendor/product if vndk is enabled. |
Jooyung Han | d045ebc | 2022-12-06 15:23:57 +0900 | [diff] [blame] | 740 | // getImageVariation can simply join the result of this function to get the |
| 741 | // image variation name. |
Kiyoung Kim | 4e765b1 | 2024-04-04 17:33:42 +0900 | [diff] [blame] | 742 | func (a *apexBundle) getImageVariationPair() (string, string) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 743 | if a.vndkApex { |
Kiyoung Kim | fa13ff1 | 2024-03-18 16:01:19 +0900 | [diff] [blame] | 744 | return cc.VendorVariationPrefix, a.vndkVersion() |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 745 | } |
| 746 | |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 747 | prefix := android.CoreVariation |
Kiyoung Kim | 4e765b1 | 2024-04-04 17:33:42 +0900 | [diff] [blame] | 748 | if a.SocSpecific() || a.DeviceSpecific() { |
| 749 | prefix = cc.VendorVariation |
| 750 | } else if a.ProductSpecific() { |
| 751 | prefix = cc.ProductVariation |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 752 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 753 | |
Kiyoung Kim | 4e765b1 | 2024-04-04 17:33:42 +0900 | [diff] [blame] | 754 | return prefix, "" |
Jooyung Han | d045ebc | 2022-12-06 15:23:57 +0900 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | // getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply |
| 758 | // android.CoreVariation, but gets complicated for the vendor APEXes and the VNDK APEX. |
Kiyoung Kim | 4e765b1 | 2024-04-04 17:33:42 +0900 | [diff] [blame] | 759 | func (a *apexBundle) getImageVariation() string { |
| 760 | prefix, vndkVersion := a.getImageVariationPair() |
Jooyung Han | d045ebc | 2022-12-06 15:23:57 +0900 | [diff] [blame] | 761 | return prefix + vndkVersion |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 765 | // apexBundle is a multi-arch targets module. Arch variant of apexBundle is set to 'common'. |
| 766 | // arch-specific targets are enabled by the compile_multilib setting of the apex bundle. For |
| 767 | // each target os/architectures, appropriate dependencies are selected by their |
| 768 | // target.<os>.multilib.<type> groups and are added as (direct) dependencies. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 769 | targets := ctx.MultiTargets() |
Kiyoung Kim | 4e765b1 | 2024-04-04 17:33:42 +0900 | [diff] [blame] | 770 | imageVariation := a.getImageVariation() |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 771 | |
| 772 | a.combineProperties(ctx) |
| 773 | |
| 774 | has32BitTarget := false |
| 775 | for _, target := range targets { |
| 776 | if target.Arch.ArchType.Multilib == "lib32" { |
| 777 | has32BitTarget = true |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 778 | } |
| 779 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 780 | for i, target := range targets { |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 781 | var deps ApexNativeDependencies |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 782 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 783 | // Add native modules targeting both ABIs. When multilib.* is omitted for |
| 784 | // native_shared_libs/jni_libs/tests, it implies multilib.both |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 785 | deps.Merge(a.properties.Multilib.Both) |
| 786 | deps.Merge(ApexNativeDependencies{ |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 787 | Native_shared_libs: a.properties.Native_shared_libs, |
| 788 | Tests: a.properties.Tests, |
| 789 | Jni_libs: a.properties.Jni_libs, |
| 790 | Binaries: nil, |
| 791 | }) |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 792 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 793 | // Add native modules targeting the first ABI When multilib.* is omitted for |
| 794 | // binaries, it implies multilib.first |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 795 | isPrimaryAbi := i == 0 |
| 796 | if isPrimaryAbi { |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 797 | deps.Merge(a.properties.Multilib.First) |
| 798 | deps.Merge(ApexNativeDependencies{ |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 799 | Native_shared_libs: nil, |
| 800 | Tests: nil, |
| 801 | Jni_libs: nil, |
| 802 | Binaries: a.properties.Binaries, |
| 803 | }) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 804 | } |
| 805 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 806 | // Add native modules targeting either 32-bit or 64-bit ABI |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 807 | switch target.Arch.ArchType.Multilib { |
| 808 | case "lib32": |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 809 | deps.Merge(a.properties.Multilib.Lib32) |
| 810 | deps.Merge(a.properties.Multilib.Prefer32) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 811 | case "lib64": |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 812 | deps.Merge(a.properties.Multilib.Lib64) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 813 | if !has32BitTarget { |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 814 | deps.Merge(a.properties.Multilib.Prefer32) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 815 | } |
| 816 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 817 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 818 | // Add native modules targeting a specific arch variant |
| 819 | switch target.Arch.ArchType { |
| 820 | case android.Arm: |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 821 | deps.Merge(a.archProperties.Arch.Arm.ApexNativeDependencies) |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 822 | case android.Arm64: |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 823 | deps.Merge(a.archProperties.Arch.Arm64.ApexNativeDependencies) |
Colin Cross | a2aaa2f | 2022-10-03 12:41:50 -0700 | [diff] [blame] | 824 | case android.Riscv64: |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 825 | deps.Merge(a.archProperties.Arch.Riscv64.ApexNativeDependencies) |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 826 | case android.X86: |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 827 | deps.Merge(a.archProperties.Arch.X86.ApexNativeDependencies) |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 828 | case android.X86_64: |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 829 | deps.Merge(a.archProperties.Arch.X86_64.ApexNativeDependencies) |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 830 | default: |
| 831 | panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType)) |
| 832 | } |
| 833 | |
Colin Cross | 70572ed | 2022-11-02 13:14:20 -0700 | [diff] [blame] | 834 | addDependenciesForNativeModules(ctx, deps, target, imageVariation) |
Riya Thakur | 654461c | 2024-02-27 07:21:05 +0000 | [diff] [blame] | 835 | if isPrimaryAbi { |
| 836 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 837 | {Mutator: "os", Variation: target.OsVariation()}, |
| 838 | {Mutator: "arch", Variation: target.ArchVariation()}, |
| 839 | }, shBinaryTag, a.properties.Sh_binaries...) |
| 840 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 841 | } |
| 842 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 843 | // Common-arch dependencies come next |
| 844 | commonVariation := ctx.Config().AndroidCommonTarget.Variations() |
Anton Hansson | 72e7ffe | 2023-02-24 11:12:31 +0000 | [diff] [blame] | 845 | ctx.AddFarVariationDependencies(commonVariation, rroTag, a.properties.Rros...) |
Anton Hansson | e754585 | 2023-02-24 11:06:07 +0000 | [diff] [blame] | 846 | ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...) |
| 847 | ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...) |
| 848 | ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...) |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 849 | ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...) |
Paul Duffin | 0b81778 | 2021-03-17 15:02:19 +0000 | [diff] [blame] | 850 | ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 851 | } |
| 852 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 853 | // DepsMutator for the overridden properties. |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 854 | func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { |
| 855 | if a.overridableProperties.Allowed_files != nil { |
| 856 | android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 857 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 858 | |
| 859 | commonVariation := ctx.Config().AndroidCommonTarget.Variations() |
| 860 | ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...) |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 861 | ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...) |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 862 | if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 { |
| 863 | // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device) |
| 864 | // regardless of the TARGET_PREFER_* setting. See b/144532908 |
| 865 | arches := ctx.DeviceConfig().Arches() |
| 866 | if len(arches) != 0 { |
| 867 | archForPrebuiltEtc := arches[0] |
| 868 | for _, arch := range arches { |
| 869 | // Prefer 64-bit arch if there is any |
| 870 | if arch.ArchType.Multilib == "lib64" { |
| 871 | archForPrebuiltEtc = arch |
| 872 | break |
| 873 | } |
| 874 | } |
| 875 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 876 | {Mutator: "os", Variation: ctx.Os().String()}, |
| 877 | {Mutator: "arch", Variation: archForPrebuiltEtc.String()}, |
| 878 | }, prebuiltTag, prebuilts...) |
| 879 | } |
| 880 | } |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 881 | |
| 882 | // Dependencies for signing |
| 883 | if String(a.overridableProperties.Key) == "" { |
| 884 | ctx.PropertyErrorf("key", "missing") |
| 885 | return |
| 886 | } |
| 887 | ctx.AddDependency(ctx.Module(), keyTag, String(a.overridableProperties.Key)) |
| 888 | |
| 889 | cert := android.SrcIsModule(a.getCertString(ctx)) |
| 890 | if cert != "" { |
| 891 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 892 | // empty cert is not an error. Cert and private keys will be directly found under |
| 893 | // PRODUCT_DEFAULT_DEV_CERTIFICATE |
| 894 | } |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 895 | } |
| 896 | |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 897 | func apexDCLADepsMutator(mctx android.BottomUpMutatorContext) { |
| 898 | if !mctx.Config().ApexTrimEnabled() { |
| 899 | return |
| 900 | } |
| 901 | if a, ok := mctx.Module().(*apexBundle); ok && a.overridableProperties.Trim_against != nil { |
| 902 | commonVariation := mctx.Config().AndroidCommonTarget.Variations() |
| 903 | mctx.AddFarVariationDependencies(commonVariation, dclaTag, String(a.overridableProperties.Trim_against)) |
| 904 | } else if o, ok := mctx.Module().(*OverrideApex); ok { |
| 905 | for _, p := range o.GetProperties() { |
| 906 | properties, ok := p.(*overridableProperties) |
| 907 | if !ok { |
| 908 | continue |
| 909 | } |
| 910 | if properties.Trim_against != nil { |
| 911 | commonVariation := mctx.Config().AndroidCommonTarget.Variations() |
| 912 | mctx.AddFarVariationDependencies(commonVariation, dclaTag, String(properties.Trim_against)) |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | type DCLAInfo struct { |
| 919 | ProvidedLibs []string |
| 920 | } |
| 921 | |
Colin Cross | bc7d76c | 2023-12-12 16:39:03 -0800 | [diff] [blame] | 922 | var DCLAInfoProvider = blueprint.NewMutatorProvider[DCLAInfo]("apex_info") |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 923 | |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 924 | var _ ApexInfoMutator = (*apexBundle)(nil) |
| 925 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 926 | func (a *apexBundle) ApexVariationName() string { |
| 927 | return a.properties.ApexVariationName |
| 928 | } |
| 929 | |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 930 | // 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] | 931 | // identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and |
| 932 | // indirect) dependencies are collected. But a few types of modules that shouldn't be included in |
| 933 | // the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended |
| 934 | // 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] | 935 | // |
| 936 | // For each dependency between an apex and an ApexModule an ApexInfo object describing the apex |
| 937 | // is passed to that module's BuildForApex(ApexInfo) method which collates them all in a list. |
| 938 | // The apexMutator uses that list to create module variants for the apexes to which it belongs. |
| 939 | // The relationship between module variants and apexes is not one-to-one as variants will be |
| 940 | // shared between compatible apexes. |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 941 | func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) { |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 942 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 943 | // The VNDK APEX is special. For the APEX, the membership is described in a very different |
| 944 | // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK |
| 945 | // libraries are self-identified by their vndk.enabled properties. There is no need to run |
| 946 | // this mutator for the APEX as nothing will be collected. So, let's return fast. |
| 947 | if a.vndkApex { |
| 948 | return |
| 949 | } |
| 950 | |
| 951 | // Special casing for APEXes on non-system (e.g., vendor, odm, etc.) partitions. They are |
| 952 | // provided with a property named use_vndk_as_stable, which when set to true doesn't collect |
| 953 | // VNDK libraries as transitive dependencies. This option is useful for reducing the size of |
| 954 | // the non-system APEXes because the VNDK libraries won't be included (and duped) in the |
| 955 | // APEX, but shared across APEXes via the VNDK APEX. |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 956 | useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface()) |
Kiyoung Kim | 8269cee | 2023-07-26 12:39:19 +0900 | [diff] [blame] | 957 | excludeVndkLibs := useVndk && a.useVndkAsStable(mctx) |
Jooyung Han | c5a9676 | 2022-02-04 11:54:50 +0900 | [diff] [blame] | 958 | if proptools.Bool(a.properties.Use_vndk_as_stable) { |
| 959 | if !useVndk { |
| 960 | mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes") |
| 961 | } |
Jooyung Han | 02873da | 2023-03-22 17:41:03 +0900 | [diff] [blame] | 962 | if a.minSdkVersionValue(mctx) != "" { |
| 963 | mctx.PropertyErrorf("use_vndk_as_stable", "not supported when min_sdk_version is set") |
| 964 | } |
Jooyung Han | c5a9676 | 2022-02-04 11:54:50 +0900 | [diff] [blame] | 965 | mctx.VisitDirectDepsWithTag(sharedLibTag, func(dep android.Module) { |
| 966 | if c, ok := dep.(*cc.Module); ok && c.IsVndk() { |
| 967 | mctx.PropertyErrorf("use_vndk_as_stable", "Trying to include a VNDK library(%s) while use_vndk_as_stable is true.", dep.Name()) |
| 968 | } |
| 969 | }) |
| 970 | if mctx.Failed() { |
| 971 | return |
| 972 | } |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 973 | } |
| 974 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 975 | continueApexDepsWalk := func(child, parent android.Module) bool { |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 976 | am, ok := child.(android.ApexModule) |
| 977 | if !ok || !am.CanHaveApexVariants() { |
| 978 | return false |
Jiyong Park | f760cae | 2020-02-12 07:53:12 +0900 | [diff] [blame] | 979 | } |
Paul Duffin | 573989d | 2021-03-17 13:25:29 +0000 | [diff] [blame] | 980 | depTag := mctx.OtherModuleDependencyTag(child) |
| 981 | |
| 982 | // Check to see if the tag always requires that the child module has an apex variant for every |
| 983 | // apex variant of the parent module. If it does not then it is still possible for something |
| 984 | // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required. |
| 985 | if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() { |
| 986 | return true |
| 987 | } |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 988 | if !android.IsDepInSameApex(mctx, parent, child) { |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 989 | return false |
| 990 | } |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 991 | if excludeVndkLibs { |
| 992 | if c, ok := child.(*cc.Module); ok && c.IsVndk() { |
| 993 | return false |
| 994 | } |
| 995 | } |
Kiyoung Kim | cbe2ba0 | 2023-09-07 16:00:04 +0900 | [diff] [blame] | 996 | |
| 997 | //TODO: b/296491928 Vendor APEX should use libbinder.ndk instead of libbinder once VNDK is fully deprecated. |
| 998 | if useVndk && mctx.Config().IsVndkDeprecated() && child.Name() == "libbinder" { |
| 999 | log.Print("Libbinder is linked from Vendor APEX ", a.Name(), " with module ", parent.Name()) |
| 1000 | return false |
| 1001 | } |
| 1002 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1003 | // By default, all the transitive dependencies are collected, unless filtered out |
| 1004 | // above. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1005 | return true |
| 1006 | } |
| 1007 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1008 | // Records whether a certain module is included in this apexBundle via direct dependency or |
| 1009 | // inndirect dependency. |
| 1010 | contents := make(map[string]android.ApexMembership) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1011 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 1012 | if !continueApexDepsWalk(child, parent) { |
| 1013 | return false |
| 1014 | } |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 1015 | // If the parent is apexBundle, this child is directly depended. |
| 1016 | _, directDep := parent.(*apexBundle) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1017 | depName := mctx.OtherModuleName(child) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1018 | contents[depName] = contents[depName].Add(directDep) |
| 1019 | return true |
| 1020 | }) |
| 1021 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1022 | // The membership information is saved for later access |
Jiyong Park | e4758ed | 2020-11-18 01:34:22 +0900 | [diff] [blame] | 1023 | apexContents := android.NewApexContents(contents) |
Spandan Das | f5e03f1 | 2024-01-25 19:25:42 +0000 | [diff] [blame] | 1024 | android.SetProvider(mctx, android.ApexBundleInfoProvider, android.ApexBundleInfo{ |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1025 | Contents: apexContents, |
| 1026 | }) |
| 1027 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 1028 | minSdkVersion := a.minSdkVersion(mctx) |
| 1029 | // When min_sdk_version is not set, the apex is built against FutureApiLevel. |
| 1030 | if minSdkVersion.IsNone() { |
| 1031 | minSdkVersion = android.FutureApiLevel |
| 1032 | } |
| 1033 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1034 | // This is the main part of this mutator. Mark the collected dependencies that they need to |
| 1035 | // be built for this apexBundle. |
Jiyong Park | 78349b5 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 1036 | |
Jooyung Han | 63dff46 | 2023-02-09 00:11:27 +0000 | [diff] [blame] | 1037 | apexVariationName := mctx.ModuleName() // could be com.android.foo |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 1038 | if overridable, ok := mctx.Module().(android.OverridableModule); ok && overridable.GetOverriddenBy() != "" { |
| 1039 | // use the overridden name com.mycompany.android.foo |
| 1040 | apexVariationName = overridable.GetOverriddenBy() |
| 1041 | } |
| 1042 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1043 | a.properties.ApexVariationName = apexVariationName |
Spandan Das | e8173a8 | 2023-04-12 17:14:11 +0000 | [diff] [blame] | 1044 | testApexes := []string{} |
| 1045 | if a.testApex { |
| 1046 | testApexes = []string{apexVariationName} |
| 1047 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1048 | apexInfo := android.ApexInfo{ |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1049 | ApexVariationName: apexVariationName, |
Jiyong Park | 4eab21d | 2021-04-15 15:17:54 +0900 | [diff] [blame] | 1050 | MinSdkVersion: minSdkVersion, |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1051 | Updatable: a.Updatable(), |
Jiyong Park | 1bc8412 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 1052 | UsePlatformApis: a.UsePlatformApis(), |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1053 | InApexVariants: []string{apexVariationName}, |
| 1054 | InApexModules: []string{a.Name()}, // could be com.mycompany.android.foo |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1055 | ApexContents: []*android.ApexContents{apexContents}, |
Spandan Das | e8173a8 | 2023-04-12 17:14:11 +0000 | [diff] [blame] | 1056 | TestApexes: testApexes, |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1057 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1058 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 1059 | if !continueApexDepsWalk(child, parent) { |
| 1060 | return false |
| 1061 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1062 | child.(android.ApexModule).BuildForApex(apexInfo) // leave a mark! |
Jooyung Han | 698dd9f | 2020-07-22 15:17:19 +0900 | [diff] [blame] | 1063 | return true |
Jiyong Park | f760cae | 2020-02-12 07:53:12 +0900 | [diff] [blame] | 1064 | }) |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 1065 | |
| 1066 | if a.dynamic_common_lib_apex() { |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1067 | android.SetProvider(mctx, DCLAInfoProvider, DCLAInfo{ |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 1068 | ProvidedLibs: a.properties.Native_shared_libs, |
| 1069 | }) |
| 1070 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1071 | } |
| 1072 | |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 1073 | type ApexInfoMutator interface { |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1074 | // ApexVariationName returns the name of the APEX variation to use in the apex |
| 1075 | // mutator etc. It is the same name as ApexInfo.ApexVariationName. |
| 1076 | ApexVariationName() string |
| 1077 | |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 1078 | // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are |
| 1079 | // depended upon by an apex and which require an apex specific variant. |
| 1080 | ApexInfoMutator(android.TopDownMutatorContext) |
| 1081 | } |
| 1082 | |
| 1083 | // apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex |
| 1084 | // specific variant to modules that support the ApexInfoMutator. |
Spandan Das | 42e8950 | 2022-05-06 22:12:55 +0000 | [diff] [blame] | 1085 | // It also propagates updatable=true to apps of updatable apexes |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 1086 | func apexInfoMutator(mctx android.TopDownMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1087 | if !mctx.Module().Enabled(mctx) { |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 1088 | return |
| 1089 | } |
| 1090 | |
| 1091 | if a, ok := mctx.Module().(ApexInfoMutator); ok { |
| 1092 | a.ApexInfoMutator(mctx) |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 1093 | } |
Colin Cross | 7c03506 | 2024-03-28 12:18:42 -0700 | [diff] [blame] | 1094 | |
| 1095 | if am, ok := mctx.Module().(android.ApexModule); ok { |
| 1096 | android.ApexInfoMutator(mctx, am) |
| 1097 | } |
Spandan Das | 42e8950 | 2022-05-06 22:12:55 +0000 | [diff] [blame] | 1098 | enforceAppUpdatability(mctx) |
Paul Duffin | a7d6a89 | 2020-12-07 17:39:59 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 1101 | // apexStrictUpdatibilityLintMutator propagates strict_updatability_linting to transitive deps of a mainline module |
| 1102 | // This check is enforced for updatable modules |
| 1103 | func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1104 | if !mctx.Module().Enabled(mctx) { |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 1105 | return |
| 1106 | } |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 1107 | if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting(mctx) { |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 1108 | mctx.WalkDeps(func(child, parent android.Module) bool { |
Spandan Das | d9c23ab | 2022-02-10 02:34:13 +0000 | [diff] [blame] | 1109 | // b/208656169 Do not propagate strict updatability linting to libcore/ |
| 1110 | // These libs are available on the classpath during compilation |
| 1111 | // These libs are transitive deps of the sdk. See java/sdk.go:decodeSdkDep |
| 1112 | // Only skip libraries defined in libcore root, not subdirectories |
| 1113 | if mctx.OtherModuleDir(child) == "libcore" { |
| 1114 | // Do not traverse transitive deps of libcore/ libs |
| 1115 | return false |
| 1116 | } |
Spandan Das | 2cf278e | 2022-03-24 20:19:35 +0000 | [diff] [blame] | 1117 | if android.InList(child.Name(), skipLintJavalibAllowlist) { |
| 1118 | return false |
| 1119 | } |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 1120 | if lintable, ok := child.(java.LintDepSetsIntf); ok { |
| 1121 | lintable.SetStrictUpdatabilityLinting(true) |
| 1122 | } |
| 1123 | // visit transitive deps |
| 1124 | return true |
| 1125 | }) |
| 1126 | } |
| 1127 | } |
| 1128 | |
Spandan Das | 42e8950 | 2022-05-06 22:12:55 +0000 | [diff] [blame] | 1129 | // enforceAppUpdatability propagates updatable=true to apps of updatable apexes |
| 1130 | func enforceAppUpdatability(mctx android.TopDownMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1131 | if !mctx.Module().Enabled(mctx) { |
Spandan Das | 42e8950 | 2022-05-06 22:12:55 +0000 | [diff] [blame] | 1132 | return |
| 1133 | } |
| 1134 | if apex, ok := mctx.Module().(*apexBundle); ok && apex.Updatable() { |
| 1135 | // checking direct deps is sufficient since apex->apk is a direct edge, even when inherited via apex_defaults |
| 1136 | mctx.VisitDirectDeps(func(module android.Module) { |
| 1137 | // ignore android_test_app |
| 1138 | if app, ok := module.(*java.AndroidApp); ok { |
| 1139 | app.SetUpdatable(true) |
| 1140 | } |
| 1141 | }) |
| 1142 | } |
| 1143 | } |
| 1144 | |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1145 | // TODO: b/215736885 Whittle the denylist |
| 1146 | // Transitive deps of certain mainline modules baseline NewApi errors |
| 1147 | // Skip these mainline modules for now |
| 1148 | var ( |
| 1149 | skipStrictUpdatabilityLintAllowlist = []string{ |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1150 | // go/keep-sorted start |
| 1151 | "PackageManagerTestApex", |
| 1152 | "com.android.adservices", |
| 1153 | "com.android.appsearch", |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1154 | "com.android.art", |
| 1155 | "com.android.art.debug", |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1156 | "com.android.btservices", |
| 1157 | "com.android.cellbroadcast", |
| 1158 | "com.android.configinfrastructure", |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1159 | "com.android.conscrypt", |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1160 | "com.android.extservices", |
| 1161 | "com.android.extservices_tplus", |
| 1162 | "com.android.healthfitness", |
| 1163 | "com.android.ipsec", |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1164 | "com.android.media", |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1165 | "com.android.mediaprovider", |
| 1166 | "com.android.ondevicepersonalization", |
| 1167 | "com.android.os.statsd", |
| 1168 | "com.android.permission", |
Yisroel Forta | 154796c | 2024-02-13 00:16:36 +0000 | [diff] [blame] | 1169 | "com.android.profiling", |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1170 | "com.android.rkpd", |
| 1171 | "com.android.scheduling", |
| 1172 | "com.android.tethering", |
| 1173 | "com.android.uwb", |
| 1174 | "com.android.wifi", |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1175 | "test_com.android.art", |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1176 | "test_com.android.cellbroadcast", |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1177 | "test_com.android.conscrypt", |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1178 | "test_com.android.extservices", |
| 1179 | "test_com.android.ipsec", |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1180 | "test_com.android.media", |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1181 | "test_com.android.mediaprovider", |
| 1182 | "test_com.android.os.statsd", |
| 1183 | "test_com.android.permission", |
| 1184 | "test_com.android.wifi", |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1185 | "test_jitzygote_com.android.art", |
Cole Faust | e17f93a | 2024-01-18 11:25:59 -0800 | [diff] [blame] | 1186 | // go/keep-sorted end |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1187 | } |
Spandan Das | 2cf278e | 2022-03-24 20:19:35 +0000 | [diff] [blame] | 1188 | |
| 1189 | // TODO: b/215736885 Remove this list |
| 1190 | skipLintJavalibAllowlist = []string{ |
| 1191 | "conscrypt.module.platform.api.stubs", |
| 1192 | "conscrypt.module.public.api.stubs", |
| 1193 | "conscrypt.module.public.api.stubs.system", |
| 1194 | "conscrypt.module.public.api.stubs.module_lib", |
| 1195 | "framework-media.stubs", |
| 1196 | "framework-media.stubs.system", |
| 1197 | "framework-media.stubs.module_lib", |
| 1198 | } |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1199 | ) |
| 1200 | |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 1201 | func (a *apexBundle) checkStrictUpdatabilityLinting(mctx android.TopDownMutatorContext) bool { |
| 1202 | // The allowlist contains the base apex name, so use that instead of the ApexVariationName |
| 1203 | return a.Updatable() && !android.InList(mctx.ModuleName(), skipStrictUpdatabilityLintAllowlist) |
Spandan Das | 08c911f | 2022-01-21 22:07:26 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1206 | // apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use |
| 1207 | // unique apex variations for this module. See android/apex.go for more about unique apex variant. |
| 1208 | // TODO(jiyong): move this to android/apex.go? |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1209 | func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1210 | if !mctx.Module().Enabled(mctx) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1211 | return |
| 1212 | } |
| 1213 | if am, ok := mctx.Module().(android.ApexModule); ok { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1214 | android.UpdateUniqueApexVariationsForDeps(mctx, am) |
| 1215 | } |
| 1216 | } |
| 1217 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1218 | // apexTestForDepsMutator checks if this module is a test for an apex. If so, add a dependency on |
| 1219 | // the apex in order to retrieve its contents later. |
| 1220 | // TODO(jiyong): move this to android/apex.go? |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1221 | func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1222 | if !mctx.Module().Enabled(mctx) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1223 | return |
| 1224 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1225 | if am, ok := mctx.Module().(android.ApexModule); ok { |
| 1226 | if testFor := am.TestFor(); len(testFor) > 0 { |
| 1227 | mctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 1228 | {Mutator: "os", Variation: am.Target().OsVariation()}, |
| 1229 | {"arch", "common"}, |
| 1230 | }, testForTag, testFor...) |
| 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1235 | // TODO(jiyong): move this to android/apex.go? |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1236 | func apexTestForMutator(mctx android.BottomUpMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1237 | if !mctx.Module().Enabled(mctx) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1238 | return |
| 1239 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1240 | if _, ok := mctx.Module().(android.ApexModule); ok { |
| 1241 | var contents []*android.ApexContents |
| 1242 | for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) { |
Spandan Das | f5e03f1 | 2024-01-25 19:25:42 +0000 | [diff] [blame] | 1243 | abInfo, _ := android.OtherModuleProvider(mctx, testFor, android.ApexBundleInfoProvider) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1244 | contents = append(contents, abInfo.Contents) |
| 1245 | } |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1246 | android.SetProvider(mctx, android.ApexTestForInfoProvider, android.ApexTestForInfo{ |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1247 | ApexContents: contents, |
| 1248 | }) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1252 | // markPlatformAvailability marks whether or not a module can be available to platform. A module |
| 1253 | // cannot be available to platform if 1) it is explicitly marked as not available (i.e. |
| 1254 | // "//apex_available:platform" is absent) or 2) it depends on another module that isn't (or can't |
| 1255 | // be) available to platform |
| 1256 | // TODO(jiyong): move this to android/apex.go? |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1257 | func markPlatformAvailability(mctx android.BottomUpMutatorContext) { |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 1258 | // Recovery is not considered as platform |
| 1259 | if mctx.Module().InstallInRecovery() { |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1260 | return |
| 1261 | } |
| 1262 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1263 | am, ok := mctx.Module().(android.ApexModule) |
| 1264 | if !ok { |
| 1265 | return |
| 1266 | } |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1267 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1268 | availableToPlatform := am.AvailableFor(android.AvailableToPlatform) |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1269 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1270 | // If any of the dep is not available to platform, this module is also considered as being |
| 1271 | // not available to platform even if it has "//apex_available:platform" |
| 1272 | mctx.VisitDirectDeps(func(child android.Module) { |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 1273 | if !android.IsDepInSameApex(mctx, am, child) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1274 | // if the dependency crosses apex boundary, don't consider it |
| 1275 | return |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1276 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1277 | if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() { |
| 1278 | availableToPlatform = false |
| 1279 | // TODO(b/154889534) trigger an error when 'am' has |
| 1280 | // "//apex_available:platform" |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1281 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1282 | }) |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1283 | |
Paul Duffin | b5769c1 | 2021-05-12 16:16:51 +0100 | [diff] [blame] | 1284 | // Exception 1: check to see if the module always requires it. |
| 1285 | if am.AlwaysRequiresPlatformApexVariant() { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1286 | availableToPlatform = true |
| 1287 | } |
| 1288 | |
| 1289 | // Exception 2: bootstrap bionic libraries are also always available to platform |
| 1290 | if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) { |
| 1291 | availableToPlatform = true |
| 1292 | } |
| 1293 | |
| 1294 | if !availableToPlatform { |
| 1295 | am.SetNotAvailableForPlatform() |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | |
Colin Cross | 7c03506 | 2024-03-28 12:18:42 -0700 | [diff] [blame] | 1299 | type apexTransitionMutator struct{} |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1300 | |
Colin Cross | 7c03506 | 2024-03-28 12:18:42 -0700 | [diff] [blame] | 1301 | func (a *apexTransitionMutator) Split(ctx android.BaseModuleContext) []string { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1302 | // apexBundle itself is mutated so that it and its dependencies have the same apex variant. |
Colin Cross | 7c03506 | 2024-03-28 12:18:42 -0700 | [diff] [blame] | 1303 | if ai, ok := ctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) { |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 1304 | if overridable, ok := ctx.Module().(android.OverridableModule); ok && overridable.GetOverriddenBy() != "" { |
| 1305 | return []string{overridable.GetOverriddenBy()} |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1306 | } |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 1307 | return []string{ai.ApexVariationName()} |
| 1308 | } else if _, ok := ctx.Module().(*OverrideApex); ok { |
| 1309 | return []string{ctx.ModuleName()} |
Colin Cross | 7c03506 | 2024-03-28 12:18:42 -0700 | [diff] [blame] | 1310 | } |
| 1311 | return []string{""} |
| 1312 | } |
| 1313 | |
| 1314 | func (a *apexTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { |
| 1315 | return sourceVariation |
| 1316 | } |
| 1317 | |
| 1318 | func (a *apexTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string { |
| 1319 | if am, ok := ctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
| 1320 | return android.IncomingApexTransition(ctx, incomingVariation) |
| 1321 | } else if ai, ok := ctx.Module().(ApexInfoMutator); ok { |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 1322 | if overridable, ok := ctx.Module().(android.OverridableModule); ok && overridable.GetOverriddenBy() != "" { |
| 1323 | return overridable.GetOverriddenBy() |
| 1324 | } |
Colin Cross | 7c03506 | 2024-03-28 12:18:42 -0700 | [diff] [blame] | 1325 | return ai.ApexVariationName() |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 1326 | } else if _, ok := ctx.Module().(*OverrideApex); ok { |
| 1327 | return ctx.Module().Name() |
Colin Cross | 7c03506 | 2024-03-28 12:18:42 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | return "" |
| 1331 | } |
| 1332 | |
| 1333 | func (a *apexTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) { |
| 1334 | if am, ok := ctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
| 1335 | android.MutateApexTransition(ctx, variation) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1336 | } |
| 1337 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 1338 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1339 | // apexModuleTypeRequiresVariant determines whether the module supplied requires an apex specific |
| 1340 | // variant. |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1341 | func apexModuleTypeRequiresVariant(module ApexInfoMutator) bool { |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1342 | if a, ok := module.(*apexBundle); ok { |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1343 | // 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] | 1344 | return !a.vndkApex |
| 1345 | } |
| 1346 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 1347 | return true |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 1348 | } |
| 1349 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1350 | // See android.UpdateDirectlyInAnyApex |
| 1351 | // TODO(jiyong): move this to android/apex.go? |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1352 | func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1353 | if !mctx.Module().Enabled(mctx) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1354 | return |
| 1355 | } |
| 1356 | if am, ok := mctx.Module().(android.ApexModule); ok { |
| 1357 | android.UpdateDirectlyInAnyApex(mctx, am) |
| 1358 | } |
| 1359 | } |
| 1360 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1361 | const ( |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1362 | // File extensions of an APEX for different packaging methods |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 1363 | imageApexSuffix = ".apex" |
| 1364 | imageCapexSuffix = ".capex" |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1365 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1366 | // variant names each of which is for a packaging method |
Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 1367 | imageApexType = "image" |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1368 | |
Dan Willemsen | 47e1a75 | 2021-10-16 18:36:13 -0700 | [diff] [blame] | 1369 | ext4FsType = "ext4" |
| 1370 | f2fsFsType = "f2fs" |
Huang Jianan | 13cac63 | 2021-08-02 15:02:17 +0800 | [diff] [blame] | 1371 | erofsFsType = "erofs" |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 1372 | ) |
| 1373 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1374 | var _ android.DepIsInSameApex = (*apexBundle)(nil) |
Theotime Combes | 4ba38c1 | 2020-06-12 12:46:59 +0000 | [diff] [blame] | 1375 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1376 | // Implements android.DepInInSameApex |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1377 | func (a *apexBundle) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool { |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 1378 | // 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] | 1379 | // 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] | 1380 | return true |
| 1381 | } |
| 1382 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1383 | var _ android.OutputFileProducer = (*apexBundle)(nil) |
| 1384 | |
| 1385 | // Implements android.OutputFileProducer |
| 1386 | func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) { |
| 1387 | switch tag { |
Paul Duffin | 74f0559 | 2020-11-25 16:37:46 +0000 | [diff] [blame] | 1388 | case "", android.DefaultDistTag: |
| 1389 | // This is the default dist path. |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1390 | return android.Paths{a.outputFile}, nil |
Jooyung Han | a6d3667 | 2022-02-24 13:58:07 +0900 | [diff] [blame] | 1391 | case imageApexSuffix: |
| 1392 | // uncompressed one |
| 1393 | if a.outputApexFile != nil { |
| 1394 | return android.Paths{a.outputApexFile}, nil |
| 1395 | } |
| 1396 | fallthrough |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1397 | default: |
| 1398 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 1399 | } |
| 1400 | } |
| 1401 | |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 1402 | var _ multitree.Exportable = (*apexBundle)(nil) |
| 1403 | |
| 1404 | func (a *apexBundle) Exportable() bool { |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 1405 | return true |
| 1406 | } |
| 1407 | |
| 1408 | func (a *apexBundle) TaggedOutputs() map[string]android.Paths { |
| 1409 | ret := make(map[string]android.Paths) |
| 1410 | ret["apex"] = android.Paths{a.outputFile} |
| 1411 | return ret |
| 1412 | } |
| 1413 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1414 | var _ cc.Coverage = (*apexBundle)(nil) |
| 1415 | |
| 1416 | // Implements cc.Coverage |
Colin Cross | f5f4ad3 | 2024-01-19 15:41:48 -0800 | [diff] [blame] | 1417 | func (a *apexBundle) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 1418 | return ctx.DeviceConfig().NativeCoverageEnabled() |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | // Implements cc.Coverage |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 1422 | func (a *apexBundle) SetPreventInstall() { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1423 | a.properties.PreventInstall = true |
| 1424 | } |
| 1425 | |
| 1426 | // Implements cc.Coverage |
| 1427 | func (a *apexBundle) HideFromMake() { |
| 1428 | a.properties.HideFromMake = true |
Colin Cross | e6a83e6 | 2020-12-17 18:22:34 -0800 | [diff] [blame] | 1429 | // This HideFromMake is shadowing the ModuleBase one, call through to it for now. |
| 1430 | // TODO(ccross): untangle these |
| 1431 | a.ModuleBase.HideFromMake() |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | // Implements cc.Coverage |
| 1435 | func (a *apexBundle) MarkAsCoverageVariant(coverage bool) { |
| 1436 | a.properties.IsCoverageVariant = coverage |
| 1437 | } |
| 1438 | |
| 1439 | // Implements cc.Coverage |
| 1440 | func (a *apexBundle) EnableCoverageIfNeeded() {} |
| 1441 | |
| 1442 | var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil) |
| 1443 | |
Oriol Prieto Gasco | a07099d | 2021-10-14 15:33:41 -0400 | [diff] [blame] | 1444 | // Implements android.ApexBundleDepsInfoIntf |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1445 | func (a *apexBundle) Updatable() bool { |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1446 | return proptools.BoolDefault(a.properties.Updatable, true) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1447 | } |
| 1448 | |
Jiyong Park | f402058 | 2021-11-29 12:37:10 +0900 | [diff] [blame] | 1449 | func (a *apexBundle) FutureUpdatable() bool { |
| 1450 | return proptools.BoolDefault(a.properties.Future_updatable, false) |
| 1451 | } |
| 1452 | |
Jiyong Park | 1bc8412 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 1453 | func (a *apexBundle) UsePlatformApis() bool { |
| 1454 | return proptools.BoolDefault(a.properties.Platform_apis, false) |
| 1455 | } |
| 1456 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1457 | // getCertString returns the name of the cert that should be used to sign this APEX. This is |
| 1458 | // 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] | 1459 | func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string { |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 1460 | moduleName := ctx.ModuleName() |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1461 | // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the |
| 1462 | // OVERRIDE_* list, we check with the pseudo module name to see if its certificate is |
| 1463 | // overridden. |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 1464 | if a.vndkApex { |
| 1465 | moduleName = vndkApexName |
| 1466 | } |
| 1467 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName) |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1468 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 1469 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1470 | } |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 1471 | return String(a.overridableProperties.Certificate) |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1472 | } |
| 1473 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1474 | // See the installable property |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1475 | func (a *apexBundle) installable() bool { |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 1476 | 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] | 1477 | } |
| 1478 | |
Nikita Ioffe | da6dc31 | 2021-06-09 19:43:46 +0100 | [diff] [blame] | 1479 | // See the generate_hashtree property |
| 1480 | func (a *apexBundle) shouldGenerateHashtree() bool { |
Nikita Ioffe | e261ae6 | 2021-06-16 18:15:03 +0100 | [diff] [blame] | 1481 | return proptools.BoolDefault(a.properties.Generate_hashtree, true) |
Nikita Ioffe | c72b5dd | 2019-12-07 17:30:22 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1484 | // See the test_only_unsigned_payload property |
Dario Freni | ca91339 | 2020-04-27 18:21:11 +0100 | [diff] [blame] | 1485 | func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool { |
| 1486 | return proptools.Bool(a.properties.Test_only_unsigned_payload) |
| 1487 | } |
| 1488 | |
Mohammad Samiul Islam | a8008f9 | 2020-12-22 10:47:50 +0000 | [diff] [blame] | 1489 | // See the test_only_force_compression property |
| 1490 | func (a *apexBundle) testOnlyShouldForceCompression() bool { |
| 1491 | return proptools.Bool(a.properties.Test_only_force_compression) |
| 1492 | } |
| 1493 | |
Dennis Shen | af41bc1 | 2022-08-03 16:46:43 +0000 | [diff] [blame] | 1494 | // See the dynamic_common_lib_apex property |
| 1495 | func (a *apexBundle) dynamic_common_lib_apex() bool { |
| 1496 | return proptools.BoolDefault(a.properties.Dynamic_common_lib_apex, false) |
| 1497 | } |
| 1498 | |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 1499 | // See the list of libs to trim |
| 1500 | func (a *apexBundle) libs_to_trim(ctx android.ModuleContext) []string { |
| 1501 | dclaModules := ctx.GetDirectDepsWithTag(dclaTag) |
| 1502 | if len(dclaModules) > 1 { |
| 1503 | panic(fmt.Errorf("expected exactly at most one dcla dependency, got %d", len(dclaModules))) |
| 1504 | } |
| 1505 | if len(dclaModules) > 0 { |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 1506 | DCLAInfo, _ := android.OtherModuleProvider(ctx, dclaModules[0], DCLAInfoProvider) |
Dennis Shen | e2ed70c | 2023-01-11 14:15:43 +0000 | [diff] [blame] | 1507 | return DCLAInfo.ProvidedLibs |
| 1508 | } |
| 1509 | return []string{} |
| 1510 | } |
| 1511 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1512 | // These functions are interfacing with cc/sanitizer.go. The entire APEX (along with all of its |
| 1513 | // members) can be sanitized, either forcibly, or by the global configuration. For some of the |
| 1514 | // sanitizers, extra dependencies can be forcibly added as well. |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1515 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 1516 | func (a *apexBundle) EnableSanitizer(sanitizerName string) { |
| 1517 | if !android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 1518 | a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName) |
| 1519 | } |
| 1520 | } |
| 1521 | |
Lukacs T. Berki | 01a648a | 2022-06-17 08:59:37 +0200 | [diff] [blame] | 1522 | func (a *apexBundle) IsSanitizerEnabled(config android.Config, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 1523 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 1524 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | // Then follow the global setting |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1528 | var globalSanitizerNames []string |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 1529 | arches := config.SanitizeDeviceArch() |
| 1530 | if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { |
| 1531 | globalSanitizerNames = config.SanitizeDevice() |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 1532 | } |
| 1533 | return android.InList(sanitizerName, globalSanitizerNames) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1534 | } |
| 1535 | |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1536 | func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1537 | // TODO(jiyong): move this info (the sanitizer name, the lib name, etc.) to cc/sanitize.go |
| 1538 | // Keep only the mechanism here. |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 1539 | if sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") { |
Kiyoung Kim | 4e765b1 | 2024-04-04 17:33:42 +0900 | [diff] [blame] | 1540 | imageVariation := a.getImageVariation() |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1541 | for _, target := range ctx.MultiTargets() { |
| 1542 | if target.Arch.ArchType.Multilib == "lib64" { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1543 | addDependenciesForNativeModules(ctx, ApexNativeDependencies{ |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1544 | Native_shared_libs: []string{"libclang_rt.hwasan"}, |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1545 | Tests: nil, |
| 1546 | Jni_libs: nil, |
| 1547 | Binaries: nil, |
| 1548 | }, target, imageVariation) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1549 | break |
| 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1555 | // apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The |
| 1556 | // returned apexFile saves information about the Soong module that will be used for creating the |
| 1557 | // build rules. |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1558 | func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1559 | // Decide the APEX-local directory by the multilib of the library In the future, we may |
| 1560 | // query this to the module. |
| 1561 | // TODO(jiyong): use the new PackagingSpec |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1562 | var dirInApex string |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1563 | switch ccMod.Arch().ArchType.Multilib { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1564 | case "lib32": |
| 1565 | dirInApex = "lib" |
| 1566 | case "lib64": |
| 1567 | dirInApex = "lib64" |
| 1568 | } |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1569 | if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1570 | dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1571 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1572 | if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1573 | // Special case for Bionic libs and other libs installed with them. This is to |
| 1574 | // prevent those libs from being included in the search path |
| 1575 | // /apex/com.android.runtime/${LIB}. This exclusion is required because those libs |
| 1576 | // in the Runtime APEX are available via the legacy paths in /system/lib/. By the |
| 1577 | // init process, the libs in the APEX are bind-mounted to the legacy paths and thus |
| 1578 | // will be loaded into the default linker namespace (aka "platform" namespace). If |
| 1579 | // the libs are directly in /apex/com.android.runtime/${LIB} then the same libs will |
| 1580 | // be loaded again into the runtime linker namespace, which will result in double |
| 1581 | // loading of them, which isn't supported. |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1582 | dirInApex = filepath.Join(dirInApex, "bionic") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1583 | } |
Florian Mayer | 95cd6db | 2023-03-23 17:48:07 -0700 | [diff] [blame] | 1584 | // This needs to go after the runtime APEX handling because otherwise we would get |
| 1585 | // weird paths like lib64/rel_install_path/bionic rather than |
| 1586 | // lib64/bionic/rel_install_path. |
| 1587 | dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1588 | |
Colin Cross | 1d48715 | 2022-10-03 19:14:46 -0700 | [diff] [blame] | 1589 | fileToCopy := android.OutputFileForModule(ctx, ccMod, "") |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1590 | androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName |
| 1591 | return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1592 | } |
| 1593 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1594 | func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile { |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 1595 | dirInApex := "bin" |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1596 | if cc.Target().NativeBridge == android.NativeBridgeEnabled { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1597 | dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) |
Jiyong Park | acbf6c7 | 2019-07-09 16:19:16 +0900 | [diff] [blame] | 1598 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 1599 | dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath()) |
Colin Cross | 1d48715 | 2022-10-03 19:14:46 -0700 | [diff] [blame] | 1600 | fileToCopy := android.OutputFileForModule(ctx, cc, "") |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1601 | androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName |
| 1602 | af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1603 | af.symlinks = cc.Symlinks() |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 1604 | af.dataPaths = cc.DataPaths() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1605 | return af |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1606 | } |
| 1607 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1608 | func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module) apexFile { |
| 1609 | dirInApex := "bin" |
| 1610 | if rustm.Target().NativeBridge == android.NativeBridgeEnabled { |
| 1611 | dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath) |
| 1612 | } |
Jooyung Han | 4ed512b | 2023-08-11 16:30:04 +0900 | [diff] [blame] | 1613 | dirInApex = filepath.Join(dirInApex, rustm.RelativeInstallPath()) |
Colin Cross | 1d48715 | 2022-10-03 19:14:46 -0700 | [diff] [blame] | 1614 | fileToCopy := android.OutputFileForModule(ctx, rustm, "") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1615 | androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName |
| 1616 | af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, rustm) |
| 1617 | return af |
| 1618 | } |
| 1619 | |
| 1620 | func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile { |
| 1621 | // Decide the APEX-local directory by the multilib of the library |
| 1622 | // In the future, we may query this to the module. |
| 1623 | var dirInApex string |
| 1624 | switch rustm.Arch().ArchType.Multilib { |
| 1625 | case "lib32": |
| 1626 | dirInApex = "lib" |
| 1627 | case "lib64": |
| 1628 | dirInApex = "lib64" |
| 1629 | } |
| 1630 | if rustm.Target().NativeBridge == android.NativeBridgeEnabled { |
| 1631 | dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath) |
| 1632 | } |
Jooyung Han | 4ed512b | 2023-08-11 16:30:04 +0900 | [diff] [blame] | 1633 | dirInApex = filepath.Join(dirInApex, rustm.RelativeInstallPath()) |
Colin Cross | 1d48715 | 2022-10-03 19:14:46 -0700 | [diff] [blame] | 1634 | fileToCopy := android.OutputFileForModule(ctx, rustm, "") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1635 | androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName |
| 1636 | return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm) |
| 1637 | } |
| 1638 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 1639 | func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1640 | dirInApex := filepath.Join("bin", sh.SubDir()) |
Sundong Ahn | 80c0489 | 2021-11-23 00:57:19 +0000 | [diff] [blame] | 1641 | if sh.Target().NativeBridge == android.NativeBridgeEnabled { |
| 1642 | dirInApex = filepath.Join(dirInApex, sh.Target().NativeBridgeRelativePath) |
| 1643 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1644 | fileToCopy := sh.OutputFile() |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1645 | af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1646 | af.symlinks = sh.Symlinks() |
| 1647 | return af |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1648 | } |
| 1649 | |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 1650 | func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, outputFile android.Path) apexFile { |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 1651 | dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir()) |
Cole Faust | 7c991b4 | 2024-05-15 11:17:55 -0700 | [diff] [blame] | 1652 | makeModuleName := strings.ReplaceAll(filepath.Join(dirInApex, outputFile.Base()), "/", "_") |
| 1653 | return newApexFile(ctx, outputFile, makeModuleName, dirInApex, etc, prebuilt) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1654 | } |
| 1655 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 1656 | func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile { |
| 1657 | dirInApex := filepath.Join("etc", config.SubDir()) |
| 1658 | fileToCopy := config.CompatConfig() |
| 1659 | return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config) |
| 1660 | } |
| 1661 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1662 | // javaModule is an interface to handle all Java modules (java_library, dex_import, etc) in the same |
| 1663 | // way. |
| 1664 | type javaModule interface { |
| 1665 | android.Module |
| 1666 | BaseModuleName() string |
Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 1667 | DexJarBuildPath(ctx android.ModuleErrorfContext) java.OptionalDexJarPath |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1668 | JacocoReportClassesFile() android.Path |
| 1669 | LintDepSets() java.LintDepSets |
| 1670 | Stem() string |
| 1671 | } |
| 1672 | |
| 1673 | var _ javaModule = (*java.Library)(nil) |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 1674 | var _ javaModule = (*java.Import)(nil) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1675 | var _ javaModule = (*java.SdkLibrary)(nil) |
| 1676 | var _ javaModule = (*java.DexImport)(nil) |
| 1677 | var _ javaModule = (*java.SdkLibraryImport)(nil) |
| 1678 | |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 1679 | // apexFileForJavaModule creates an apexFile for a java module's dex implementation jar. |
Justin Yun | 613bdc5 | 2024-06-12 21:32:10 +0900 | [diff] [blame] | 1680 | func apexFileForJavaModule(ctx android.ModuleContext, module javaModule) apexFile { |
Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 1681 | return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath(ctx).PathOrNil()) |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | // apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file. |
Justin Yun | 613bdc5 | 2024-06-12 21:32:10 +0900 | [diff] [blame] | 1685 | func apexFileForJavaModuleWithFile(ctx android.ModuleContext, module javaModule, dexImplementationJar android.Path) apexFile { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1686 | dirInApex := "javalib" |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 1687 | af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1688 | af.jacocoReportClassesFile = module.JacocoReportClassesFile() |
| 1689 | af.lintDepSets = module.LintDepSets() |
| 1690 | af.customStem = module.Stem() + ".jar" |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1691 | // TODO: b/338641779 - Remove special casing of sdkLibrary once bcpf and sscpf depends |
| 1692 | // on the implementation library |
| 1693 | if sdkLib, ok := module.(*java.SdkLibrary); ok { |
| 1694 | for _, install := range sdkLib.BuiltInstalledForApex() { |
| 1695 | af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName()) |
Justin Yun | 613bdc5 | 2024-06-12 21:32:10 +0900 | [diff] [blame] | 1696 | install.PackageFile(ctx) |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1697 | } |
| 1698 | } else if dexpreopter, ok := module.(java.DexpreopterInterface); ok { |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 1699 | for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() { |
| 1700 | af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName()) |
Justin Yun | 613bdc5 | 2024-06-12 21:32:10 +0900 | [diff] [blame] | 1701 | install.PackageFile(ctx) |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 1702 | } |
| 1703 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1704 | return af |
| 1705 | } |
| 1706 | |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 1707 | func apexFileForJavaModuleProfile(ctx android.BaseModuleContext, module javaModule) *apexFile { |
| 1708 | if dexpreopter, ok := module.(java.DexpreopterInterface); ok { |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 1709 | if profilePathOnHost := dexpreopter.OutputProfilePathOnHost(); profilePathOnHost != nil { |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 1710 | dirInApex := "javalib" |
| 1711 | af := newApexFile(ctx, profilePathOnHost, module.BaseModuleName()+"-profile", dirInApex, etc, nil) |
| 1712 | af.customStem = module.Stem() + ".jar.prof" |
| 1713 | return &af |
| 1714 | } |
| 1715 | } |
| 1716 | return nil |
| 1717 | } |
| 1718 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1719 | // androidApp is an interface to handle all app modules (android_app, android_app_import, etc.) in |
| 1720 | // the same way. |
| 1721 | type androidApp interface { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1722 | android.Module |
| 1723 | Privileged() bool |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 1724 | InstallApkName() string |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1725 | OutputFile() android.Path |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1726 | JacocoReportClassesFile() android.Path |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 1727 | Certificate() java.Certificate |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1728 | BaseModuleName() string |
Colin Cross | 8355c15 | 2021-08-10 19:24:07 -0700 | [diff] [blame] | 1729 | LintDepSets() java.LintDepSets |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 1730 | PrivAppAllowlist() android.OptionalPath |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | var _ androidApp = (*java.AndroidApp)(nil) |
| 1734 | var _ androidApp = (*java.AndroidAppImport)(nil) |
| 1735 | |
Oriol Prieto Gasco | 17e2290 | 2022-05-05 13:52:25 +0000 | [diff] [blame] | 1736 | func sanitizedBuildIdForPath(ctx android.BaseModuleContext) string { |
| 1737 | buildId := ctx.Config().BuildId() |
| 1738 | |
| 1739 | // The build ID is used as a suffix for a filename, so ensure that |
| 1740 | // the set of characters being used are sanitized. |
| 1741 | // - any word character: [a-zA-Z0-9_] |
| 1742 | // - dots: . |
| 1743 | // - dashes: - |
| 1744 | validRegex := regexp.MustCompile(`^[\w\.\-\_]+$`) |
| 1745 | if !validRegex.MatchString(buildId) { |
| 1746 | ctx.ModuleErrorf("Unable to use build id %s as filename suffix, valid characters are [a-z A-Z 0-9 _ . -].", buildId) |
| 1747 | } |
| 1748 | return buildId |
| 1749 | } |
Jingwen Chen | 8ce1efc | 2022-04-19 13:57:01 +0000 | [diff] [blame] | 1750 | |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 1751 | func apexFilesForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) []apexFile { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 1752 | appDir := "app" |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1753 | if aapp.Privileged() { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 1754 | appDir = "priv-app" |
| 1755 | } |
Jingwen Chen | 8ce1efc | 2022-04-19 13:57:01 +0000 | [diff] [blame] | 1756 | |
| 1757 | // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed |
| 1758 | // so that PackageManager correctly invalidates the existing installed apk |
| 1759 | // 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] | 1760 | dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+sanitizedBuildIdForPath(ctx)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1761 | fileToCopy := aapp.OutputFile() |
Jingwen Chen | 8ce1efc | 2022-04-19 13:57:01 +0000 | [diff] [blame] | 1762 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 1763 | af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp) |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1764 | af.jacocoReportClassesFile = aapp.JacocoReportClassesFile() |
Colin Cross | 8355c15 | 2021-08-10 19:24:07 -0700 | [diff] [blame] | 1765 | af.lintDepSets = aapp.LintDepSets() |
Colin Cross | 503c1d0 | 2020-01-28 14:00:53 -0800 | [diff] [blame] | 1766 | af.certificate = aapp.Certificate() |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 1767 | |
| 1768 | if app, ok := aapp.(interface { |
| 1769 | OverriddenManifestPackageName() string |
| 1770 | }); ok { |
| 1771 | af.overriddenPackageName = app.OverriddenManifestPackageName() |
| 1772 | } |
Sam Delmerico | b1daccd | 2023-05-25 14:45:30 -0400 | [diff] [blame] | 1773 | |
| 1774 | apexFiles := []apexFile{} |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 1775 | |
| 1776 | if allowlist := aapp.PrivAppAllowlist(); allowlist.Valid() { |
| 1777 | dirInApex := filepath.Join("etc", "permissions") |
Sam Delmerico | b1daccd | 2023-05-25 14:45:30 -0400 | [diff] [blame] | 1778 | privAppAllowlist := newApexFile(ctx, allowlist.Path(), aapp.BaseModuleName()+"_privapp", dirInApex, etc, aapp) |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 1779 | apexFiles = append(apexFiles, privAppAllowlist) |
| 1780 | } |
| 1781 | |
Sam Delmerico | b1daccd | 2023-05-25 14:45:30 -0400 | [diff] [blame] | 1782 | apexFiles = append(apexFiles, af) |
| 1783 | |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 1784 | return apexFiles |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 1785 | } |
| 1786 | |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 1787 | func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile { |
| 1788 | rroDir := "overlay" |
| 1789 | dirInApex := filepath.Join(rroDir, rro.Theme()) |
| 1790 | fileToCopy := rro.OutputFile() |
| 1791 | af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro) |
| 1792 | af.certificate = rro.Certificate() |
| 1793 | |
| 1794 | if a, ok := rro.(interface { |
| 1795 | OverriddenManifestPackageName() string |
| 1796 | }); ok { |
| 1797 | af.overriddenPackageName = a.OverriddenManifestPackageName() |
| 1798 | } |
| 1799 | return af |
| 1800 | } |
| 1801 | |
Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 1802 | func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, apex_sub_dir string, bpfProgram bpf.BpfModule) apexFile { |
| 1803 | dirInApex := filepath.Join("etc", "bpf", apex_sub_dir) |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 1804 | return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram) |
| 1805 | } |
| 1806 | |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 1807 | func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile { |
| 1808 | dirInApex := filepath.Join("etc", "fs") |
| 1809 | return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs) |
| 1810 | } |
| 1811 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1812 | // 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] | 1813 | // visited module, the `do` callback is executed. Returning true in the callback continues the visit |
| 1814 | // to the child modules. Returning false makes the visit to continue in the sibling or the parent |
| 1815 | // modules. This is used in check* functions below. |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1816 | func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) { |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 1817 | ctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1818 | am, ok := child.(android.ApexModule) |
| 1819 | if !ok || !am.CanHaveApexVariants() { |
| 1820 | return false |
| 1821 | } |
| 1822 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1823 | // Filter-out unwanted depedendencies |
| 1824 | depTag := ctx.OtherModuleDependencyTag(child) |
| 1825 | if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok { |
| 1826 | return false |
| 1827 | } |
Paul Duffin | 520917a | 2022-05-13 13:01:59 +0000 | [diff] [blame] | 1828 | if dt, ok := depTag.(*dependencyTag); ok && !dt.payload { |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 1829 | return false |
| 1830 | } |
Jiyong Park | 8bcf3c6 | 2024-03-18 18:37:10 +0900 | [diff] [blame] | 1831 | if depTag == android.RequiredDepTag { |
| 1832 | return false |
| 1833 | } |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 1834 | |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 1835 | ai, _ := android.OtherModuleProvider(ctx, child, android.ApexInfoProvider) |
Jiyong Park | ab50b07 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 1836 | externalDep := !android.InList(ctx.ModuleName(), ai.InApexVariants) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1837 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1838 | // Visit actually |
| 1839 | return do(ctx, parent, am, externalDep) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1840 | }) |
| 1841 | } |
| 1842 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1843 | // filesystem type of the apex_payload.img inside the APEX. Currently, ext4 and f2fs are supported. |
| 1844 | type fsType int |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1845 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1846 | const ( |
| 1847 | ext4 fsType = iota |
| 1848 | f2fs |
Huang Jianan | 13cac63 | 2021-08-02 15:02:17 +0800 | [diff] [blame] | 1849 | erofs |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1850 | ) |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 1851 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1852 | func (f fsType) string() string { |
| 1853 | switch f { |
| 1854 | case ext4: |
| 1855 | return ext4FsType |
| 1856 | case f2fs: |
| 1857 | return f2fsFsType |
Huang Jianan | 13cac63 | 2021-08-02 15:02:17 +0800 | [diff] [blame] | 1858 | case erofs: |
| 1859 | return erofsFsType |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 1860 | default: |
| 1861 | panic(fmt.Errorf("unknown APEX payload type %d", f)) |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
Sasha Smundak | fe9a5b8 | 2022-07-27 14:51:45 -0700 | [diff] [blame] | 1865 | func (a *apexBundle) setCompression(ctx android.ModuleContext) { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 1866 | if a.testOnlyShouldForceCompression() { |
Sasha Smundak | fe9a5b8 | 2022-07-27 14:51:45 -0700 | [diff] [blame] | 1867 | a.isCompressed = true |
| 1868 | } else { |
| 1869 | a.isCompressed = ctx.Config().ApexCompressionEnabled() && a.isCompressable() |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | func (a *apexBundle) setSystemLibLink(ctx android.ModuleContext) { |
| 1874 | // Optimization. If we are building bundled APEX, for the files that are gathered due to the |
| 1875 | // transitive dependencies, don't place them inside the APEX, but place a symlink pointing |
| 1876 | // the same library in the system partition, thus effectively sharing the same libraries |
| 1877 | // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed |
| 1878 | // in the APEX. |
| 1879 | a.linkToSystemLib = !ctx.Config().UnbundledBuild() && a.installable() |
| 1880 | |
| 1881 | // APEXes targeting other than system/system_ext partitions use vendor/product variants. |
| 1882 | // So we can't link them to /system/lib libs which are core variants. |
| 1883 | if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { |
| 1884 | a.linkToSystemLib = false |
| 1885 | } |
| 1886 | |
| 1887 | forced := ctx.Config().ForceApexSymlinkOptimization() |
| 1888 | updatable := a.Updatable() || a.FutureUpdatable() |
| 1889 | |
| 1890 | // We don't need the optimization for updatable APEXes, as it might give false signal |
| 1891 | // to the system health when the APEXes are still bundled (b/149805758). |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 1892 | if !forced && updatable { |
Sasha Smundak | fe9a5b8 | 2022-07-27 14:51:45 -0700 | [diff] [blame] | 1893 | a.linkToSystemLib = false |
| 1894 | } |
Sasha Smundak | fe9a5b8 | 2022-07-27 14:51:45 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | func (a *apexBundle) setPayloadFsType(ctx android.ModuleContext) { |
| 1898 | switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) { |
| 1899 | case ext4FsType: |
| 1900 | a.payloadFsType = ext4 |
| 1901 | case f2fsFsType: |
| 1902 | a.payloadFsType = f2fs |
| 1903 | case erofsFsType: |
| 1904 | a.payloadFsType = erofs |
| 1905 | default: |
| 1906 | ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs, erofs]", *a.properties.Payload_fs_type) |
| 1907 | } |
| 1908 | } |
| 1909 | |
Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 1910 | func (a *apexBundle) isCompressable() bool { |
Sasha Smundak | fe9a5b8 | 2022-07-27 14:51:45 -0700 | [diff] [blame] | 1911 | return proptools.BoolDefault(a.overridableProperties.Compressible, false) && !a.testApex |
| 1912 | } |
| 1913 | |
| 1914 | func (a *apexBundle) commonBuildActions(ctx android.ModuleContext) bool { |
| 1915 | a.checkApexAvailability(ctx) |
| 1916 | a.checkUpdatable(ctx) |
| 1917 | a.CheckMinSdkVersion(ctx) |
| 1918 | a.checkStaticLinkingToStubLibraries(ctx) |
| 1919 | a.checkStaticExecutables(ctx) |
| 1920 | if len(a.properties.Tests) > 0 && !a.testApex { |
| 1921 | ctx.PropertyErrorf("tests", "property allowed only in apex_test module type") |
| 1922 | return false |
| 1923 | } |
| 1924 | return true |
| 1925 | } |
| 1926 | |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1927 | type visitorContext struct { |
| 1928 | // all the files that will be included in this APEX |
| 1929 | filesInfo []apexFile |
| 1930 | |
| 1931 | // native lib dependencies |
| 1932 | provideNativeLibs []string |
| 1933 | requireNativeLibs []string |
| 1934 | |
| 1935 | handleSpecialLibs bool |
Jooyung Han | 862c0d6 | 2022-12-21 10:15:37 +0900 | [diff] [blame] | 1936 | |
| 1937 | // if true, raise error on duplicate apexFile |
| 1938 | checkDuplicate bool |
Jooyung Han | a8bd72a | 2023-11-02 11:56:48 +0900 | [diff] [blame] | 1939 | |
| 1940 | // visitor skips these from this list of module names |
| 1941 | unwantedTransitiveDeps []string |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 1942 | |
| 1943 | aconfigFiles []android.Path |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Jooyung Han | 862c0d6 | 2022-12-21 10:15:37 +0900 | [diff] [blame] | 1946 | func (vctx *visitorContext) normalizeFileInfo(mctx android.ModuleContext) { |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1947 | encountered := make(map[string]apexFile) |
| 1948 | for _, f := range vctx.filesInfo { |
Jooyung Han | a8bd72a | 2023-11-02 11:56:48 +0900 | [diff] [blame] | 1949 | // Skips unwanted transitive deps. This happens, for example, with Rust binaries with prefer_rlib:true. |
| 1950 | // TODO(b/295593640) |
| 1951 | // Needs additional verification for the resulting APEX to ensure that skipped artifacts don't make problems. |
| 1952 | // For example, DT_NEEDED modules should be found within the APEX unless they are marked in `requiredNativeLibs`. |
| 1953 | if f.transitiveDep && f.module != nil && android.InList(mctx.OtherModuleName(f.module), vctx.unwantedTransitiveDeps) { |
| 1954 | continue |
| 1955 | } |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1956 | dest := filepath.Join(f.installDir, f.builtFile.Base()) |
| 1957 | if e, ok := encountered[dest]; !ok { |
| 1958 | encountered[dest] = f |
| 1959 | } else { |
Jooyung Han | 862c0d6 | 2022-12-21 10:15:37 +0900 | [diff] [blame] | 1960 | if vctx.checkDuplicate && f.builtFile.String() != e.builtFile.String() { |
| 1961 | mctx.ModuleErrorf("apex file %v is provided by two different files %v and %v", |
| 1962 | dest, e.builtFile, f.builtFile) |
| 1963 | return |
| 1964 | } |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1965 | // If a module is directly included and also transitively depended on |
| 1966 | // consider it as directly included. |
| 1967 | e.transitiveDep = e.transitiveDep && f.transitiveDep |
Jiakai Zhang | 9c60c17 | 2023-09-05 15:19:21 +0100 | [diff] [blame] | 1968 | // If a module is added as both a JNI library and a regular shared library, consider it as a |
| 1969 | // JNI library. |
| 1970 | e.isJniLib = e.isJniLib || f.isJniLib |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1971 | encountered[dest] = e |
| 1972 | } |
| 1973 | } |
| 1974 | vctx.filesInfo = vctx.filesInfo[:0] |
| 1975 | for _, v := range encountered { |
| 1976 | vctx.filesInfo = append(vctx.filesInfo, v) |
| 1977 | } |
| 1978 | sort.Slice(vctx.filesInfo, func(i, j int) bool { |
| 1979 | // Sort by destination path so as to ensure consistent ordering even if the source of the files |
| 1980 | // changes. |
| 1981 | return vctx.filesInfo[i].path() < vctx.filesInfo[j].path() |
| 1982 | }) |
| 1983 | } |
| 1984 | |
| 1985 | func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext, child, parent blueprint.Module) bool { |
| 1986 | depTag := ctx.OtherModuleDependencyTag(child) |
| 1987 | if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok { |
| 1988 | return false |
| 1989 | } |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 1990 | if mod, ok := child.(android.Module); ok && !mod.Enabled(ctx) { |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 1991 | return false |
| 1992 | } |
| 1993 | depName := ctx.OtherModuleName(child) |
| 1994 | if _, isDirectDep := parent.(*apexBundle); isDirectDep { |
| 1995 | switch depTag { |
| 1996 | case sharedLibTag, jniLibTag: |
| 1997 | isJniLib := depTag == jniLibTag |
Jooyung Han | 2034875 | 2023-12-05 15:23:56 +0900 | [diff] [blame] | 1998 | propertyName := "native_shared_libs" |
| 1999 | if isJniLib { |
| 2000 | propertyName = "jni_libs" |
| 2001 | } |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2002 | switch ch := child.(type) { |
| 2003 | case *cc.Module: |
Jooyung Han | 2034875 | 2023-12-05 15:23:56 +0900 | [diff] [blame] | 2004 | if ch.IsStubs() { |
| 2005 | ctx.PropertyErrorf(propertyName, "%q is a stub. Remove it from the list.", depName) |
| 2006 | } |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2007 | fi := apexFileForNativeLibrary(ctx, ch, vctx.handleSpecialLibs) |
| 2008 | fi.isJniLib = isJniLib |
| 2009 | vctx.filesInfo = append(vctx.filesInfo, fi) |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 2010 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2011 | // Collect the list of stub-providing libs except: |
| 2012 | // - VNDK libs are only for vendors |
| 2013 | // - bootstrap bionic libs are treated as provided by system |
| 2014 | if ch.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(ch.BaseModuleName(), ctx.Config()) { |
| 2015 | vctx.provideNativeLibs = append(vctx.provideNativeLibs, fi.stem()) |
| 2016 | } |
| 2017 | return true // track transitive dependencies |
| 2018 | case *rust.Module: |
| 2019 | fi := apexFileForRustLibrary(ctx, ch) |
| 2020 | fi.isJniLib = isJniLib |
| 2021 | vctx.filesInfo = append(vctx.filesInfo, fi) |
Yu Liu | cec0e41 | 2023-11-30 16:45:50 -0800 | [diff] [blame] | 2022 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2023 | return true // track transitive dependencies |
| 2024 | default: |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2025 | ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName) |
| 2026 | } |
| 2027 | case executableTag: |
| 2028 | switch ch := child.(type) { |
| 2029 | case *cc.Module: |
| 2030 | vctx.filesInfo = append(vctx.filesInfo, apexFileForExecutable(ctx, ch)) |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 2031 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2032 | return true // track transitive dependencies |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2033 | case *rust.Module: |
| 2034 | vctx.filesInfo = append(vctx.filesInfo, apexFileForRustExecutable(ctx, ch)) |
Yu Liu | cec0e41 | 2023-11-30 16:45:50 -0800 | [diff] [blame] | 2035 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2036 | return true // track transitive dependencies |
| 2037 | default: |
| 2038 | ctx.PropertyErrorf("binaries", |
| 2039 | "%q is neither cc_binary, rust_binary, (embedded) py_binary, (host) blueprint_go_binary, nor (host) bootstrap_go_binary", depName) |
| 2040 | } |
| 2041 | case shBinaryTag: |
| 2042 | if csh, ok := child.(*sh.ShBinary); ok { |
| 2043 | vctx.filesInfo = append(vctx.filesInfo, apexFileForShBinary(ctx, csh)) |
| 2044 | } else { |
| 2045 | ctx.PropertyErrorf("sh_binaries", "%q is not a sh_binary module", depName) |
| 2046 | } |
| 2047 | case bcpfTag: |
Jiakai Zhang | b47cacc | 2023-05-10 16:40:18 +0100 | [diff] [blame] | 2048 | _, ok := child.(*java.BootclasspathFragmentModule) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2049 | if !ok { |
| 2050 | ctx.PropertyErrorf("bootclasspath_fragments", "%q is not a bootclasspath_fragment module", depName) |
| 2051 | return false |
| 2052 | } |
| 2053 | |
| 2054 | vctx.filesInfo = append(vctx.filesInfo, apexBootclasspathFragmentFiles(ctx, child)...) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2055 | return true |
| 2056 | case sscpfTag: |
| 2057 | if _, ok := child.(*java.SystemServerClasspathModule); !ok { |
| 2058 | ctx.PropertyErrorf("systemserverclasspath_fragments", |
| 2059 | "%q is not a systemserverclasspath_fragment module", depName) |
| 2060 | return false |
| 2061 | } |
| 2062 | if af := apexClasspathFragmentProtoFile(ctx, child); af != nil { |
| 2063 | vctx.filesInfo = append(vctx.filesInfo, *af) |
| 2064 | } |
| 2065 | return true |
| 2066 | case javaLibTag: |
| 2067 | switch child.(type) { |
| 2068 | case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport, *java.Import: |
| 2069 | af := apexFileForJavaModule(ctx, child.(javaModule)) |
| 2070 | if !af.ok() { |
| 2071 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 2072 | return false |
| 2073 | } |
| 2074 | vctx.filesInfo = append(vctx.filesInfo, af) |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 2075 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2076 | return true // track transitive dependencies |
| 2077 | default: |
| 2078 | ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
| 2079 | } |
| 2080 | case androidAppTag: |
| 2081 | switch ap := child.(type) { |
| 2082 | case *java.AndroidApp: |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 2083 | vctx.filesInfo = append(vctx.filesInfo, apexFilesForAndroidApp(ctx, ap)...) |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 2084 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2085 | return true // track transitive dependencies |
| 2086 | case *java.AndroidAppImport: |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 2087 | vctx.filesInfo = append(vctx.filesInfo, apexFilesForAndroidApp(ctx, ap)...) |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2088 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2089 | case *java.AndroidTestHelperApp: |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 2090 | vctx.filesInfo = append(vctx.filesInfo, apexFilesForAndroidApp(ctx, ap)...) |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2091 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2092 | case *java.AndroidAppSet: |
| 2093 | appDir := "app" |
| 2094 | if ap.Privileged() { |
| 2095 | appDir = "priv-app" |
| 2096 | } |
| 2097 | // TODO(b/224589412, b/226559955): Ensure that the dirname is |
| 2098 | // suffixed so that PackageManager correctly invalidates the |
| 2099 | // existing installed apk in favour of the new APK-in-APEX. |
| 2100 | // See bugs for more information. |
| 2101 | appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+sanitizedBuildIdForPath(ctx)) |
| 2102 | af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap) |
| 2103 | af.certificate = java.PresignedCertificate |
| 2104 | vctx.filesInfo = append(vctx.filesInfo, af) |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2105 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2106 | default: |
| 2107 | ctx.PropertyErrorf("apps", "%q is not an android_app module", depName) |
| 2108 | } |
| 2109 | case rroTag: |
| 2110 | if rro, ok := child.(java.RuntimeResourceOverlayModule); ok { |
| 2111 | vctx.filesInfo = append(vctx.filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro)) |
| 2112 | } else { |
| 2113 | ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName) |
| 2114 | } |
| 2115 | case bpfTag: |
| 2116 | if bpfProgram, ok := child.(bpf.BpfModule); ok { |
mrziwang | e6c8581 | 2024-05-22 14:36:09 -0700 | [diff] [blame] | 2117 | filesToCopy := android.OutputFilesForModule(ctx, bpfProgram, "") |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2118 | apex_sub_dir := bpfProgram.SubDir() |
| 2119 | for _, bpfFile := range filesToCopy { |
| 2120 | vctx.filesInfo = append(vctx.filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram)) |
| 2121 | } |
| 2122 | } else { |
| 2123 | ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName) |
| 2124 | } |
| 2125 | case fsTag: |
| 2126 | if fs, ok := child.(filesystem.Filesystem); ok { |
| 2127 | vctx.filesInfo = append(vctx.filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs)) |
| 2128 | } else { |
| 2129 | ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName) |
| 2130 | } |
| 2131 | case prebuiltTag: |
| 2132 | if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok { |
mrziwang | e2346b8 | 2024-06-10 15:09:45 -0700 | [diff] [blame] | 2133 | filesToCopy := android.OutputFilesForModule(ctx, prebuilt, "") |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 2134 | for _, etcFile := range filesToCopy { |
| 2135 | vctx.filesInfo = append(vctx.filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, etcFile)) |
| 2136 | } |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2137 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2138 | } else { |
| 2139 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
| 2140 | } |
| 2141 | case compatConfigTag: |
| 2142 | if compatConfig, ok := child.(java.PlatformCompatConfigIntf); ok { |
| 2143 | vctx.filesInfo = append(vctx.filesInfo, apexFileForCompatConfig(ctx, compatConfig, depName)) |
| 2144 | } else { |
| 2145 | ctx.PropertyErrorf("compat_configs", "%q is not a platform_compat_config module", depName) |
| 2146 | } |
| 2147 | case testTag: |
| 2148 | if ccTest, ok := child.(*cc.Module); ok { |
| 2149 | if ccTest.IsTestPerSrcAllTestsVariation() { |
| 2150 | // Multiple-output test module (where `test_per_src: true`). |
| 2151 | // |
| 2152 | // `ccTest` is the "" ("all tests") variation of a `test_per_src` module. |
| 2153 | // We do not add this variation to `filesInfo`, as it has no output; |
| 2154 | // however, we do add the other variations of this module as indirect |
| 2155 | // dependencies (see below). |
| 2156 | } else { |
| 2157 | // Single-output test module (where `test_per_src: false`). |
| 2158 | af := apexFileForExecutable(ctx, ccTest) |
| 2159 | af.class = nativeTest |
| 2160 | vctx.filesInfo = append(vctx.filesInfo, af) |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2161 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2162 | } |
| 2163 | return true // track transitive dependencies |
| 2164 | } else { |
| 2165 | ctx.PropertyErrorf("tests", "%q is not a cc module", depName) |
| 2166 | } |
| 2167 | case keyTag: |
| 2168 | if key, ok := child.(*apexKey); ok { |
| 2169 | a.privateKeyFile = key.privateKeyFile |
| 2170 | a.publicKeyFile = key.publicKeyFile |
| 2171 | } else { |
| 2172 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
| 2173 | } |
| 2174 | case certificateTag: |
| 2175 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
| 2176 | a.containerCertificateFile = dep.Certificate.Pem |
| 2177 | a.containerPrivateKeyFile = dep.Certificate.Key |
| 2178 | } else { |
| 2179 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 2180 | } |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2181 | } |
| 2182 | return false |
| 2183 | } |
| 2184 | |
| 2185 | if a.vndkApex { |
| 2186 | return false |
| 2187 | } |
| 2188 | |
| 2189 | // indirect dependencies |
| 2190 | am, ok := child.(android.ApexModule) |
| 2191 | if !ok { |
| 2192 | return false |
| 2193 | } |
| 2194 | // We cannot use a switch statement on `depTag` here as the checked |
| 2195 | // tags used below are private (e.g. `cc.sharedDepTag`). |
| 2196 | if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) { |
| 2197 | if ch, ok := child.(*cc.Module); ok { |
Kiyoung Kim | 8269cee | 2023-07-26 12:39:19 +0900 | [diff] [blame] | 2198 | if ch.UseVndk() && a.useVndkAsStable(ctx) && ch.IsVndk() { |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2199 | vctx.requireNativeLibs = append(vctx.requireNativeLibs, ":vndk") |
| 2200 | return false |
| 2201 | } |
Kiyoung Kim | cbe2ba0 | 2023-09-07 16:00:04 +0900 | [diff] [blame] | 2202 | |
| 2203 | //TODO: b/296491928 Vendor APEX should use libbinder.ndk instead of libbinder once VNDK is fully deprecated. |
Kiyoung Kim | aa39480 | 2024-01-08 12:55:45 +0900 | [diff] [blame] | 2204 | if ch.InVendorOrProduct() && ctx.Config().IsVndkDeprecated() && child.Name() == "libbinder" { |
Kiyoung Kim | cbe2ba0 | 2023-09-07 16:00:04 +0900 | [diff] [blame] | 2205 | return false |
| 2206 | } |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2207 | af := apexFileForNativeLibrary(ctx, ch, vctx.handleSpecialLibs) |
| 2208 | af.transitiveDep = true |
| 2209 | |
Spandan Das | f5e03f1 | 2024-01-25 19:25:42 +0000 | [diff] [blame] | 2210 | abInfo, _ := android.ModuleProvider(ctx, android.ApexBundleInfoProvider) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2211 | if !abInfo.Contents.DirectlyInApex(depName) && (ch.IsStubs() || ch.HasStubsVariants()) { |
| 2212 | // If the dependency is a stubs lib, don't include it in this APEX, |
| 2213 | // but make sure that the lib is installed on the device. |
| 2214 | // In case no APEX is having the lib, the lib is installed to the system |
| 2215 | // partition. |
| 2216 | // |
| 2217 | // Always include if we are a host-apex however since those won't have any |
| 2218 | // system libraries. |
Colin Cross | df2043e | 2023-01-26 15:39:15 -0800 | [diff] [blame] | 2219 | // |
| 2220 | // Skip the dependency in unbundled builds where the device image is not |
| 2221 | // being built. |
| 2222 | if ch.IsStubsImplementationRequired() && !am.DirectlyInAnyApex() && !ctx.Config().UnbundledBuild() { |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2223 | // we need a module name for Make |
| 2224 | name := ch.ImplementationModuleNameForMake(ctx) + ch.Properties.SubName |
Jingwen Chen | 29743c8 | 2023-01-25 17:49:46 +0000 | [diff] [blame] | 2225 | if !android.InList(name, a.makeModulesToInstall) { |
| 2226 | a.makeModulesToInstall = append(a.makeModulesToInstall, name) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | vctx.requireNativeLibs = append(vctx.requireNativeLibs, af.stem()) |
| 2230 | // Don't track further |
| 2231 | return false |
| 2232 | } |
| 2233 | |
| 2234 | // If the dep is not considered to be in the same |
| 2235 | // apex, don't add it to filesInfo so that it is not |
| 2236 | // included in this APEX. |
| 2237 | // TODO(jiyong): move this to at the top of the |
| 2238 | // else-if clause for the indirect dependencies. |
| 2239 | // Currently, that's impossible because we would |
| 2240 | // like to record requiredNativeLibs even when |
| 2241 | // DepIsInSameAPex is false. We also shouldn't do |
| 2242 | // this for host. |
| 2243 | // |
| 2244 | // TODO(jiyong): explain why the same module is passed in twice. |
| 2245 | // Switching the first am to parent breaks lots of tests. |
| 2246 | if !android.IsDepInSameApex(ctx, am, am) { |
| 2247 | return false |
| 2248 | } |
| 2249 | |
| 2250 | vctx.filesInfo = append(vctx.filesInfo, af) |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2251 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2252 | return true // track transitive dependencies |
| 2253 | } else if rm, ok := child.(*rust.Module); ok { |
| 2254 | af := apexFileForRustLibrary(ctx, rm) |
| 2255 | af.transitiveDep = true |
| 2256 | vctx.filesInfo = append(vctx.filesInfo, af) |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2257 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2258 | return true // track transitive dependencies |
| 2259 | } |
| 2260 | } else if cc.IsTestPerSrcDepTag(depTag) { |
| 2261 | if ch, ok := child.(*cc.Module); ok { |
| 2262 | af := apexFileForExecutable(ctx, ch) |
| 2263 | // Handle modules created as `test_per_src` variations of a single test module: |
| 2264 | // use the name of the generated test binary (`fileToCopy`) instead of the name |
| 2265 | // of the original test module (`depName`, shared by all `test_per_src` |
| 2266 | // variations of that module). |
| 2267 | af.androidMkModuleName = filepath.Base(af.builtFile.String()) |
| 2268 | // these are not considered transitive dep |
| 2269 | af.transitiveDep = false |
| 2270 | vctx.filesInfo = append(vctx.filesInfo, af) |
| 2271 | return true // track transitive dependencies |
| 2272 | } |
| 2273 | } else if cc.IsHeaderDepTag(depTag) { |
| 2274 | // nothing |
| 2275 | } else if java.IsJniDepTag(depTag) { |
| 2276 | // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps |
| 2277 | } else if java.IsXmlPermissionsFileDepTag(depTag) { |
| 2278 | if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok { |
mrziwang | e2346b8 | 2024-06-10 15:09:45 -0700 | [diff] [blame] | 2279 | filesToCopy := android.OutputFilesForModule(ctx, prebuilt, "") |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 2280 | for _, etcFile := range filesToCopy { |
| 2281 | vctx.filesInfo = append(vctx.filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, etcFile)) |
| 2282 | } |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2283 | } |
| 2284 | } else if rust.IsDylibDepTag(depTag) { |
| 2285 | if rustm, ok := child.(*rust.Module); ok && rustm.IsInstallableToApex() { |
| 2286 | af := apexFileForRustLibrary(ctx, rustm) |
| 2287 | af.transitiveDep = true |
| 2288 | vctx.filesInfo = append(vctx.filesInfo, af) |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2289 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2290 | return true // track transitive dependencies |
| 2291 | } |
| 2292 | } else if rust.IsRlibDepTag(depTag) { |
| 2293 | // Rlib is statically linked, but it might have shared lib |
| 2294 | // dependencies. Track them. |
| 2295 | return true |
| 2296 | } else if java.IsBootclasspathFragmentContentDepTag(depTag) { |
| 2297 | // Add the contents of the bootclasspath fragment to the apex. |
| 2298 | switch child.(type) { |
| 2299 | case *java.Library, *java.SdkLibrary: |
| 2300 | javaModule := child.(javaModule) |
| 2301 | af := apexFileForBootclasspathFragmentContentModule(ctx, parent, javaModule) |
| 2302 | if !af.ok() { |
| 2303 | ctx.PropertyErrorf("bootclasspath_fragments", |
| 2304 | "bootclasspath_fragment content %q is not configured to be compiled into dex", depName) |
| 2305 | return false |
| 2306 | } |
| 2307 | vctx.filesInfo = append(vctx.filesInfo, af) |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2308 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2309 | return true // track transitive dependencies |
| 2310 | default: |
| 2311 | ctx.PropertyErrorf("bootclasspath_fragments", |
| 2312 | "bootclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
| 2313 | } |
| 2314 | } else if java.IsSystemServerClasspathFragmentContentDepTag(depTag) { |
| 2315 | // Add the contents of the systemserverclasspath fragment to the apex. |
| 2316 | switch child.(type) { |
| 2317 | case *java.Library, *java.SdkLibrary: |
| 2318 | af := apexFileForJavaModule(ctx, child.(javaModule)) |
| 2319 | vctx.filesInfo = append(vctx.filesInfo, af) |
Jiakai Zhang | 3317ce7 | 2023-02-08 01:19:19 +0800 | [diff] [blame] | 2320 | if profileAf := apexFileForJavaModuleProfile(ctx, child.(javaModule)); profileAf != nil { |
| 2321 | vctx.filesInfo = append(vctx.filesInfo, *profileAf) |
| 2322 | } |
Yu Liu | ab31c82 | 2024-02-28 22:21:31 +0000 | [diff] [blame] | 2323 | addAconfigFiles(vctx, ctx, child) |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2324 | return true // track transitive dependencies |
| 2325 | default: |
| 2326 | ctx.PropertyErrorf("systemserverclasspath_fragments", |
| 2327 | "systemserverclasspath_fragment content %q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
| 2328 | } |
| 2329 | } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok { |
| 2330 | // nothing |
| 2331 | } else if depTag == android.DarwinUniversalVariantTag { |
| 2332 | // nothing |
Jiyong Park | 8bcf3c6 | 2024-03-18 18:37:10 +0900 | [diff] [blame] | 2333 | } else if depTag == android.RequiredDepTag { |
| 2334 | // nothing |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2335 | } else if am.CanHaveApexVariants() && am.IsInstallableToApex() { |
| 2336 | ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName) |
| 2337 | } |
| 2338 | return false |
| 2339 | } |
| 2340 | |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 2341 | func addAconfigFiles(vctx *visitorContext, ctx android.ModuleContext, module blueprint.Module) { |
Justin Yun | 40182b6 | 2024-05-07 10:22:19 +0900 | [diff] [blame] | 2342 | if dep, ok := android.OtherModuleProvider(ctx, module, android.AconfigPropagatingProviderKey); ok { |
Yu Liu | 67a2842 | 2024-03-05 00:36:31 +0000 | [diff] [blame] | 2343 | if len(dep.AconfigFiles) > 0 && dep.AconfigFiles[ctx.ModuleName()] != nil { |
| 2344 | vctx.aconfigFiles = append(vctx.aconfigFiles, dep.AconfigFiles[ctx.ModuleName()]...) |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | validationFlag := ctx.DeviceConfig().AconfigContainerValidation() |
| 2349 | if validationFlag == "error" || validationFlag == "warning" { |
| 2350 | android.VerifyAconfigBuildMode(ctx, ctx.ModuleName(), module, validationFlag == "error") |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
Jooyung Han | 862c0d6 | 2022-12-21 10:15:37 +0900 | [diff] [blame] | 2354 | func (a *apexBundle) shouldCheckDuplicate(ctx android.ModuleContext) bool { |
| 2355 | // TODO(b/263308293) remove this |
| 2356 | if a.properties.IsCoverageVariant { |
| 2357 | return false |
| 2358 | } |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 2359 | if ctx.DeviceConfig().DeviceArch() == "" { |
Jooyung Han | 862c0d6 | 2022-12-21 10:15:37 +0900 | [diff] [blame] | 2360 | return false |
| 2361 | } |
| 2362 | return true |
| 2363 | } |
| 2364 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2365 | // Creates build rules for an APEX. It consists of the following major steps: |
| 2366 | // |
| 2367 | // 1) do some validity checks such as apex_available, min_sdk_version, etc. |
| 2368 | // 2) traverse the dependency tree to collect apexFile structs from them. |
| 2369 | // 3) some fields in apexBundle struct are configured |
| 2370 | // 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] | 2371 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2372 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 2373 | // 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] | 2374 | if !a.commonBuildActions(ctx) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2375 | return |
| 2376 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2377 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 2378 | // 2) traverse the dependency tree to collect apexFile structs from them. |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 2379 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2380 | // TODO(jiyong): do this using WalkPayloadDeps |
| 2381 | // TODO(jiyong): make this clean!!! |
Jooyung Han | 862c0d6 | 2022-12-21 10:15:37 +0900 | [diff] [blame] | 2382 | vctx := visitorContext{ |
Jooyung Han | a8bd72a | 2023-11-02 11:56:48 +0900 | [diff] [blame] | 2383 | handleSpecialLibs: !android.Bool(a.properties.Ignore_system_library_special_case), |
| 2384 | checkDuplicate: a.shouldCheckDuplicate(ctx), |
| 2385 | unwantedTransitiveDeps: a.properties.Unwanted_transitive_deps, |
Jooyung Han | 862c0d6 | 2022-12-21 10:15:37 +0900 | [diff] [blame] | 2386 | } |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2387 | 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] | 2388 | vctx.normalizeFileInfo(ctx) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2389 | if a.privateKeyFile == nil { |
Nicolas Geoffray | 036ff9a | 2023-05-15 10:46:38 +0100 | [diff] [blame] | 2390 | if ctx.Config().AllowMissingDependencies() { |
| 2391 | // TODO(b/266099037): a better approach for slim manifests. |
| 2392 | ctx.AddMissingDependencies([]string{String(a.overridableProperties.Key)}) |
| 2393 | // Create placeholder paths for later stages that expect to see those paths, |
| 2394 | // though they won't be used. |
| 2395 | var unusedPath = android.PathForModuleOut(ctx, "nonexistentprivatekey") |
| 2396 | ctx.Build(pctx, android.BuildParams{ |
| 2397 | Rule: android.ErrorRule, |
| 2398 | Output: unusedPath, |
| 2399 | Args: map[string]string{ |
| 2400 | "error": "Private key not available", |
| 2401 | }, |
| 2402 | }) |
| 2403 | a.privateKeyFile = unusedPath |
| 2404 | } else { |
| 2405 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.overridableProperties.Key)) |
| 2406 | return |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | if a.publicKeyFile == nil { |
| 2411 | if ctx.Config().AllowMissingDependencies() { |
| 2412 | // TODO(b/266099037): a better approach for slim manifests. |
| 2413 | ctx.AddMissingDependencies([]string{String(a.overridableProperties.Key)}) |
| 2414 | // Create placeholder paths for later stages that expect to see those paths, |
| 2415 | // though they won't be used. |
| 2416 | var unusedPath = android.PathForModuleOut(ctx, "nonexistentpublickey") |
| 2417 | ctx.Build(pctx, android.BuildParams{ |
| 2418 | Rule: android.ErrorRule, |
| 2419 | Output: unusedPath, |
| 2420 | Args: map[string]string{ |
| 2421 | "error": "Public key not available", |
| 2422 | }, |
| 2423 | }) |
| 2424 | a.publicKeyFile = unusedPath |
| 2425 | } else { |
| 2426 | ctx.PropertyErrorf("key", "public_key for %q could not be found", String(a.overridableProperties.Key)) |
| 2427 | return |
| 2428 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2429 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 2430 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2431 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 2432 | // 3) some fields in apexBundle struct are configured |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 2433 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2434 | a.filesInfo = vctx.filesInfo |
Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 2435 | a.aconfigFiles = android.FirstUniquePaths(vctx.aconfigFiles) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 2436 | |
Sasha Smundak | fe9a5b8 | 2022-07-27 14:51:45 -0700 | [diff] [blame] | 2437 | a.setPayloadFsType(ctx) |
| 2438 | a.setSystemLibLink(ctx) |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 2439 | a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2440 | |
| 2441 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 2442 | // 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] | 2443 | a.buildManifest(ctx, vctx.provideNativeLibs, vctx.requireNativeLibs) |
Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 2444 | a.buildApex(ctx) |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 2445 | a.buildApexDependencyInfo(ctx) |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2446 | a.buildLintReports(ctx) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 2447 | |
| 2448 | // Set a provider for dexpreopt of bootjars |
| 2449 | a.provideApexExportsInfo(ctx) |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 2450 | |
| 2451 | a.providePrebuiltInfo(ctx) |
| 2452 | } |
| 2453 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 2454 | // Set prebuiltInfoProvider. This will be used by `apex_prebuiltinfo_singleton` to print out a metadata file |
| 2455 | // with information about whether source or prebuilt of an apex was used during the build. |
| 2456 | func (a *apexBundle) providePrebuiltInfo(ctx android.ModuleContext) { |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 2457 | info := android.PrebuiltInfo{ |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 2458 | Name: a.Name(), |
| 2459 | Is_prebuilt: false, |
| 2460 | } |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 2461 | android.SetProvider(ctx, android.PrebuiltInfoProvider, info) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | // Set a provider containing information about the jars and .prof provided by the apex |
| 2465 | // Apexes built from source retrieve this information by visiting `bootclasspath_fragments` |
| 2466 | // Used by dex_bootjars to generate the boot image |
| 2467 | func (a *apexBundle) provideApexExportsInfo(ctx android.ModuleContext) { |
| 2468 | ctx.VisitDirectDepsWithTag(bcpfTag, func(child android.Module) { |
| 2469 | if info, ok := android.OtherModuleProvider(ctx, child, java.BootclasspathFragmentApexContentInfoProvider); ok { |
| 2470 | exports := android.ApexExportsInfo{ |
Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 2471 | ApexName: a.ApexVariationName(), |
| 2472 | ProfilePathOnHost: info.ProfilePathOnHost(), |
| 2473 | LibraryNameToDexJarPathOnHost: info.DexBootJarPathMap(), |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 2474 | } |
Spandan Das | a41b8ec | 2023-12-22 00:05:04 +0000 | [diff] [blame] | 2475 | android.SetProvider(ctx, android.ApexExportsInfoProvider, exports) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 2476 | } |
| 2477 | }) |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 2478 | } |
| 2479 | |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2480 | // apexBootclasspathFragmentFiles returns the list of apexFile structures defining the files that |
| 2481 | // the bootclasspath_fragment contributes to the apex. |
| 2482 | func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.Module) []apexFile { |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 2483 | bootclasspathFragmentInfo, _ := android.OtherModuleProvider(ctx, module, java.BootclasspathFragmentApexContentInfoProvider) |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2484 | var filesToAdd []apexFile |
| 2485 | |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 2486 | // Add classpaths.proto config. |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2487 | if af := apexClasspathFragmentProtoFile(ctx, module); af != nil { |
| 2488 | filesToAdd = append(filesToAdd, *af) |
| 2489 | } |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 2490 | |
Ulya Trafimovich | f5c548d | 2022-11-16 14:52:41 +0000 | [diff] [blame] | 2491 | pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex() |
Jiakai Zhang | bc698cd | 2023-05-08 16:28:38 +0000 | [diff] [blame] | 2492 | if pathInApex != "" { |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 2493 | pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost() |
| 2494 | tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex) |
| 2495 | |
| 2496 | if pathOnHost != nil { |
| 2497 | // We need to copy the profile to a temporary path with the right filename because the apexer |
| 2498 | // will take the filename as is. |
| 2499 | ctx.Build(pctx, android.BuildParams{ |
| 2500 | Rule: android.Cp, |
| 2501 | Input: pathOnHost, |
| 2502 | Output: tempPath, |
| 2503 | }) |
| 2504 | } else { |
| 2505 | // At this point, the boot image profile cannot be generated. It is probably because the boot |
| 2506 | // image profile source file does not exist on the branch, or it is not available for the |
| 2507 | // current build target. |
| 2508 | // However, we cannot enforce the boot image profile to be generated because some build |
| 2509 | // targets (such as module SDK) do not need it. It is only needed when the APEX is being |
| 2510 | // built. Therefore, we create an error rule so that an error will occur at the ninja phase |
| 2511 | // only if the APEX is being built. |
| 2512 | ctx.Build(pctx, android.BuildParams{ |
| 2513 | Rule: android.ErrorRule, |
| 2514 | Output: tempPath, |
| 2515 | Args: map[string]string{ |
| 2516 | "error": "Boot image profile cannot be generated", |
| 2517 | }, |
| 2518 | }) |
| 2519 | } |
| 2520 | |
| 2521 | androidMkModuleName := filepath.Base(pathInApex) |
| 2522 | af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil) |
| 2523 | filesToAdd = append(filesToAdd, af) |
| 2524 | } |
| 2525 | |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2526 | return filesToAdd |
| 2527 | } |
| 2528 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2529 | // apexClasspathFragmentProtoFile returns *apexFile structure defining the classpath.proto config that |
| 2530 | // the module contributes to the apex; or nil if the proto config was not generated. |
| 2531 | func apexClasspathFragmentProtoFile(ctx android.ModuleContext, module blueprint.Module) *apexFile { |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 2532 | info, _ := android.OtherModuleProvider(ctx, module, java.ClasspathFragmentProtoContentInfoProvider) |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2533 | if !info.ClasspathFragmentProtoGenerated { |
| 2534 | return nil |
| 2535 | } |
| 2536 | classpathProtoOutput := info.ClasspathFragmentProtoOutput |
| 2537 | af := newApexFile(ctx, classpathProtoOutput, classpathProtoOutput.Base(), info.ClasspathFragmentProtoInstallDir.Rel(), etc, nil) |
| 2538 | return &af |
satayev | 14e4913 | 2021-05-17 21:03:07 +0100 | [diff] [blame] | 2539 | } |
| 2540 | |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2541 | // apexFileForBootclasspathFragmentContentModule creates an apexFile for a bootclasspath_fragment |
| 2542 | // content module, i.e. a library that is part of the bootclasspath. |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 2543 | func apexFileForBootclasspathFragmentContentModule(ctx android.ModuleContext, fragmentModule blueprint.Module, javaModule javaModule) apexFile { |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 2544 | bootclasspathFragmentInfo, _ := android.OtherModuleProvider(ctx, fragmentModule, java.BootclasspathFragmentApexContentInfoProvider) |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 2545 | |
| 2546 | // Get the dexBootJar from the bootclasspath_fragment as that is responsible for performing the |
| 2547 | // hidden API encpding. |
Paul Duffin | 1a8010a | 2021-05-15 12:39:23 +0100 | [diff] [blame] | 2548 | dexBootJar, err := bootclasspathFragmentInfo.DexBootJarPathForContentModule(javaModule) |
| 2549 | if err != nil { |
| 2550 | ctx.ModuleErrorf("%s", err) |
| 2551 | } |
Paul Duffin | 190fdef | 2021-04-26 10:33:59 +0100 | [diff] [blame] | 2552 | |
| 2553 | // Create an apexFile as for a normal java module but with the dex boot jar provided by the |
| 2554 | // bootclasspath_fragment. |
| 2555 | af := apexFileForJavaModuleWithFile(ctx, javaModule, dexBootJar) |
| 2556 | return af |
Paul Duffin | cc33ec8 | 2021-04-25 23:14:55 +0100 | [diff] [blame] | 2557 | } |
| 2558 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2559 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2560 | // Factory functions |
| 2561 | // |
| 2562 | |
| 2563 | func newApexBundle() *apexBundle { |
| 2564 | module := &apexBundle{} |
| 2565 | |
| 2566 | module.AddProperties(&module.properties) |
| 2567 | module.AddProperties(&module.targetProperties) |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 2568 | module.AddProperties(&module.archProperties) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2569 | module.AddProperties(&module.overridableProperties) |
| 2570 | |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 2571 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2572 | android.InitDefaultableModule(module) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2573 | android.InitOverridableModule(module, &module.overridableProperties.Overrides) |
Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 2574 | multitree.InitExportableModule(module) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2575 | return module |
| 2576 | } |
| 2577 | |
Paul Duffin | eb8051d | 2021-10-18 17:49:39 +0100 | [diff] [blame] | 2578 | func ApexBundleFactory(testApex bool) android.Module { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2579 | bundle := newApexBundle() |
| 2580 | bundle.testApex = testApex |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2581 | return bundle |
| 2582 | } |
| 2583 | |
| 2584 | // apex_test is an APEX for testing. The difference from the ordinary apex module type is that |
| 2585 | // 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] | 2586 | func TestApexBundleFactory() android.Module { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2587 | bundle := newApexBundle() |
| 2588 | bundle.testApex = true |
| 2589 | return bundle |
| 2590 | } |
| 2591 | |
| 2592 | // apex packages other modules into an APEX file which is a packaging format for system-level |
| 2593 | // components like binaries, shared libraries, etc. |
| 2594 | func BundleFactory() android.Module { |
| 2595 | return newApexBundle() |
| 2596 | } |
| 2597 | |
| 2598 | type Defaults struct { |
| 2599 | android.ModuleBase |
| 2600 | android.DefaultsModuleBase |
| 2601 | } |
| 2602 | |
| 2603 | // apex_defaults provides defaultable properties to other apex modules. |
Cole Faust | 912bc88 | 2023-03-08 12:29:50 -0800 | [diff] [blame] | 2604 | func DefaultsFactory() android.Module { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2605 | module := &Defaults{} |
| 2606 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2607 | module.AddProperties( |
| 2608 | &apexBundleProperties{}, |
| 2609 | &apexTargetBundleProperties{}, |
Nikita Ioffe | e58f527 | 2022-10-24 17:24:38 +0100 | [diff] [blame] | 2610 | &apexArchBundleProperties{}, |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2611 | &overridableProperties{}, |
| 2612 | ) |
| 2613 | |
| 2614 | android.InitDefaultsModule(module) |
| 2615 | return module |
| 2616 | } |
| 2617 | |
| 2618 | type OverrideApex struct { |
| 2619 | android.ModuleBase |
| 2620 | android.OverrideModuleBase |
| 2621 | } |
| 2622 | |
Sasha Smundak | 6f9e91d | 2022-06-28 22:43:04 -0700 | [diff] [blame] | 2623 | func (o *OverrideApex) GenerateAndroidBuildActions(_ android.ModuleContext) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2624 | // All the overrides happen in the base module. |
| 2625 | } |
| 2626 | |
| 2627 | // override_apex is used to create an apex module based on another apex module by overriding some of |
| 2628 | // its properties. |
Wei Li | 1c66fc7 | 2022-05-09 23:59:14 -0700 | [diff] [blame] | 2629 | func OverrideApexFactory() android.Module { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2630 | m := &OverrideApex{} |
| 2631 | |
| 2632 | m.AddProperties(&overridableProperties{}) |
| 2633 | |
| 2634 | android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 2635 | android.InitOverrideModule(m) |
| 2636 | return m |
| 2637 | } |
| 2638 | |
| 2639 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2640 | // Vality check routines |
| 2641 | // |
| 2642 | // These are called in at the very beginning of GenerateAndroidBuildActions to flag an error when |
| 2643 | // certain conditions are not met. |
| 2644 | // |
| 2645 | // TODO(jiyong): move these checks to a separate go file. |
| 2646 | |
satayev | ad99149 | 2021-12-03 18:58:32 +0000 | [diff] [blame] | 2647 | var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil) |
| 2648 | |
Spandan Das | a5f39a1 | 2022-08-05 02:35:52 +0000 | [diff] [blame] | 2649 | // 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] | 2650 | // of this apexBundle. |
satayev | b3fd411 | 2021-12-02 13:59:35 +0000 | [diff] [blame] | 2651 | func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2652 | if a.testApex || a.vndkApex { |
| 2653 | return |
| 2654 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2655 | // apexBundle::minSdkVersion reports its own errors. |
| 2656 | minSdkVersion := a.minSdkVersion(ctx) |
satayev | b3fd411 | 2021-12-02 13:59:35 +0000 | [diff] [blame] | 2657 | android.CheckMinSdkVersion(ctx, minSdkVersion, a.WalkPayloadDeps) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2658 | } |
| 2659 | |
Albert Martin | eefabcf | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 2660 | // Returns apex's min_sdk_version string value, honoring overrides |
| 2661 | func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string { |
| 2662 | // Only override the minSdkVersion value on Apexes which already specify |
| 2663 | // a min_sdk_version (it's optional for non-updatable apexes), and that its |
| 2664 | // min_sdk_version value is lower than the one to override with. |
Spandan Das | 50801e2 | 2024-05-13 18:29:45 +0000 | [diff] [blame] | 2665 | minApiLevel := android.MinSdkVersionFromValue(ctx, proptools.String(a.overridableProperties.Min_sdk_version)) |
Colin Cross | 56534df | 2022-10-04 09:58:58 -0700 | [diff] [blame] | 2666 | if minApiLevel.IsNone() { |
| 2667 | return "" |
Albert Martin | eefabcf | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
Colin Cross | 56534df | 2022-10-04 09:58:58 -0700 | [diff] [blame] | 2670 | overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride() |
Sam Delmerico | 0e0d96e | 2023-08-18 22:43:28 +0000 | [diff] [blame] | 2671 | overrideApiLevel := android.MinSdkVersionFromValue(ctx, overrideMinSdkValue) |
Colin Cross | 56534df | 2022-10-04 09:58:58 -0700 | [diff] [blame] | 2672 | if !overrideApiLevel.IsNone() && overrideApiLevel.CompareTo(minApiLevel) > 0 { |
| 2673 | minApiLevel = overrideApiLevel |
| 2674 | } |
| 2675 | |
| 2676 | return minApiLevel.String() |
Albert Martin | eefabcf | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | // Returns apex's min_sdk_version SdkSpec, honoring overrides |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2680 | func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 2681 | return a.minSdkVersion(ctx) |
satayev | ad99149 | 2021-12-03 18:58:32 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
Albert Martin | eefabcf | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 2684 | // Returns apex's min_sdk_version ApiLevel, honoring overrides |
satayev | ad99149 | 2021-12-03 18:58:32 +0000 | [diff] [blame] | 2685 | func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
Sam Delmerico | 0e0d96e | 2023-08-18 22:43:28 +0000 | [diff] [blame] | 2686 | return android.MinSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx)) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | // Ensures that a lib providing stub isn't statically linked |
| 2690 | func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) { |
| 2691 | // Practically, we only care about regular APEXes on the device. |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 2692 | if a.testApex || a.vndkApex { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2693 | return |
| 2694 | } |
| 2695 | |
Spandan Das | f5e03f1 | 2024-01-25 19:25:42 +0000 | [diff] [blame] | 2696 | abInfo, _ := android.ModuleProvider(ctx, android.ApexBundleInfoProvider) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2697 | |
| 2698 | a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { |
| 2699 | if ccm, ok := to.(*cc.Module); ok { |
| 2700 | apexName := ctx.ModuleName() |
| 2701 | fromName := ctx.OtherModuleName(from) |
| 2702 | toName := ctx.OtherModuleName(to) |
| 2703 | |
| 2704 | // If `to` is not actually in the same APEX as `from` then it does not need |
| 2705 | // apex_available and neither do any of its dependencies. |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 2706 | // |
| 2707 | // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps(). |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2708 | if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) { |
| 2709 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 2710 | return false |
| 2711 | } |
| 2712 | |
| 2713 | // The dynamic linker and crash_dump tool in the runtime APEX is the only |
| 2714 | // exception to this rule. It can't make the static dependencies dynamic |
| 2715 | // because it can't do the dynamic linking for itself. |
Kiyoung Kim | 4098c7e | 2020-11-30 14:42:14 +0900 | [diff] [blame] | 2716 | // Same rule should be applied to linkerconfig, because it should be executed |
| 2717 | // only with static linked libraries before linker is available with ld.config.txt |
| 2718 | if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump" || fromName == "linkerconfig") { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2719 | return false |
| 2720 | } |
| 2721 | |
| 2722 | isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName) |
| 2723 | if isStubLibraryFromOtherApex && !externalDep { |
| 2724 | ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+ |
| 2725 | "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false)) |
| 2726 | } |
| 2727 | |
| 2728 | } |
| 2729 | return true |
| 2730 | }) |
| 2731 | } |
| 2732 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2733 | // 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] | 2734 | func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) { |
| 2735 | if a.Updatable() { |
Albert Martin | eefabcf | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 2736 | if a.minSdkVersionValue(ctx) == "" { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2737 | ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well") |
| 2738 | } |
Jiyong Park | 1bc8412 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 2739 | if a.UsePlatformApis() { |
| 2740 | ctx.PropertyErrorf("updatable", "updatable APEXes can't use platform APIs") |
| 2741 | } |
Jooyung Han | dfc864c | 2023-03-20 18:19:07 +0900 | [diff] [blame] | 2742 | if proptools.Bool(a.properties.Use_vndk_as_stable) { |
| 2743 | 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] | 2744 | } |
Jiyong Park | f402058 | 2021-11-29 12:37:10 +0900 | [diff] [blame] | 2745 | if a.FutureUpdatable() { |
| 2746 | ctx.PropertyErrorf("future_updatable", "Already updatable. Remove `future_updatable: true:`") |
| 2747 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2748 | a.checkJavaStableSdkVersion(ctx) |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2749 | a.checkClasspathFragments(ctx) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2753 | // checkClasspathFragments enforces that all classpath fragments in deps generate classpaths.proto config. |
| 2754 | func (a *apexBundle) checkClasspathFragments(ctx android.ModuleContext) { |
| 2755 | ctx.VisitDirectDeps(func(module android.Module) { |
| 2756 | if tag := ctx.OtherModuleDependencyTag(module); tag == bcpfTag || tag == sscpfTag { |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 2757 | info, _ := android.OtherModuleProvider(ctx, module, java.ClasspathFragmentProtoContentInfoProvider) |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2758 | if !info.ClasspathFragmentProtoGenerated { |
| 2759 | ctx.OtherModuleErrorf(module, "is included in updatable apex %v, it must not set generate_classpaths_proto to false", ctx.ModuleName()) |
| 2760 | } |
| 2761 | } |
| 2762 | }) |
| 2763 | } |
| 2764 | |
| 2765 | // checkJavaStableSdkVersion enforces that all Java deps are using stable SDKs to compile. |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2766 | func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2767 | // Visit direct deps only. As long as we guarantee top-level deps are using stable SDKs, |
| 2768 | // java's checkLinkType guarantees correct usage for transitive deps |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2769 | ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) { |
| 2770 | tag := ctx.OtherModuleDependencyTag(module) |
| 2771 | switch tag { |
| 2772 | case javaLibTag, androidAppTag: |
Jiyong Park | dbd710c | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2773 | if m, ok := module.(interface { |
| 2774 | CheckStableSdkVersion(ctx android.BaseModuleContext) error |
| 2775 | }); ok { |
| 2776 | if err := m.CheckStableSdkVersion(ctx); err != nil { |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2777 | ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err) |
| 2778 | } |
| 2779 | } |
| 2780 | } |
| 2781 | }) |
| 2782 | } |
| 2783 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 2784 | // 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] | 2785 | func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) { |
| 2786 | // Let's be practical. Availability for test, host, and the VNDK apex isn't important |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 2787 | if a.testApex || a.vndkApex { |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2788 | return |
| 2789 | } |
| 2790 | |
| 2791 | // Because APEXes targeting other than system/system_ext partitions can't set |
| 2792 | // apex_available, we skip checks for these APEXes |
| 2793 | if a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { |
| 2794 | return |
| 2795 | } |
| 2796 | |
| 2797 | // Coverage build adds additional dependencies for the coverage-only runtime libraries. |
| 2798 | // Requiring them and their transitive depencies with apex_available is not right |
| 2799 | // because they just add noise. |
| 2800 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) { |
| 2801 | return |
| 2802 | } |
| 2803 | |
| 2804 | a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { |
| 2805 | // As soon as the dependency graph crosses the APEX boundary, don't go further. |
| 2806 | if externalDep { |
| 2807 | return false |
| 2808 | } |
| 2809 | |
| 2810 | apexName := ctx.ModuleName() |
Sam Delmerico | ca81653 | 2023-06-02 14:09:50 -0400 | [diff] [blame] | 2811 | for _, props := range ctx.Module().GetProperties() { |
| 2812 | if apexProps, ok := props.(*apexBundleProperties); ok { |
| 2813 | if apexProps.Apex_available_name != nil { |
| 2814 | apexName = *apexProps.Apex_available_name |
| 2815 | } |
| 2816 | } |
| 2817 | } |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2818 | fromName := ctx.OtherModuleName(from) |
| 2819 | toName := ctx.OtherModuleName(to) |
| 2820 | |
| 2821 | // If `to` is not actually in the same APEX as `from` then it does not need |
| 2822 | // apex_available and neither do any of its dependencies. |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 2823 | // |
| 2824 | // It is ok to call DepIsInSameApex() directly from within WalkPayloadDeps(). |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2825 | if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) { |
| 2826 | // As soon as the dependency graph crosses the APEX boundary, don't go |
| 2827 | // further. |
| 2828 | return false |
| 2829 | } |
| 2830 | |
| 2831 | if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) { |
| 2832 | return true |
| 2833 | } |
Jiyong Park | 767dbd9 | 2021-03-04 13:03:10 +0900 | [diff] [blame] | 2834 | ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'."+ |
| 2835 | "\n\nDependency path:%s\n\n"+ |
| 2836 | "Consider adding %q to 'apex_available' property of %q", |
| 2837 | fromName, toName, ctx.GetPathString(true), apexName, toName) |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2838 | // Visit this module's dependencies to check and report any issues with their availability. |
| 2839 | return true |
| 2840 | }) |
| 2841 | } |
| 2842 | |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 2843 | // checkStaticExecutable ensures that executables in an APEX are not static. |
| 2844 | func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) { |
| 2845 | ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) { |
| 2846 | if ctx.OtherModuleDependencyTag(module) != executableTag { |
| 2847 | return |
| 2848 | } |
Jiyong Park | d12979d | 2021-08-03 13:36:09 +0900 | [diff] [blame] | 2849 | |
| 2850 | if l, ok := module.(cc.LinkableInterface); ok && l.StaticExecutable() { |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 2851 | apex := a.ApexVariationName() |
| 2852 | exec := ctx.OtherModuleName(module) |
| 2853 | if isStaticExecutableAllowed(apex, exec) { |
| 2854 | return |
| 2855 | } |
| 2856 | ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module)) |
| 2857 | } |
| 2858 | }) |
| 2859 | } |
| 2860 | |
| 2861 | // A small list of exceptions where static executables are allowed in APEXes. |
| 2862 | func isStaticExecutableAllowed(apex string, exec string) bool { |
| 2863 | m := map[string][]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 2864 | "com.android.runtime": { |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 2865 | "linker", |
| 2866 | "linkerconfig", |
| 2867 | }, |
| 2868 | } |
| 2869 | execNames, ok := m[apex] |
| 2870 | return ok && android.InList(exec, execNames) |
| 2871 | } |
| 2872 | |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 2873 | // Collect information for opening IDE project files in java/jdeps.go. |
| 2874 | func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) { |
Anton Hansson | e754585 | 2023-02-24 11:06:07 +0000 | [diff] [blame] | 2875 | dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...) |
| 2876 | dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...) |
| 2877 | dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...) |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 2878 | } |
| 2879 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2880 | var ( |
| 2881 | apexAvailBaseline = makeApexAvailableBaseline() |
| 2882 | inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline) |
| 2883 | ) |
| 2884 | |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2885 | func baselineApexAvailable(apex, moduleName string) bool { |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2886 | key := apex |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 2887 | moduleName = normalizeModuleName(moduleName) |
| 2888 | |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2889 | if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) { |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 2890 | return true |
| 2891 | } |
| 2892 | |
| 2893 | key = android.AvailableToAnyApex |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2894 | if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) { |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 2895 | return true |
| 2896 | } |
| 2897 | |
| 2898 | return false |
| 2899 | } |
| 2900 | |
| 2901 | func normalizeModuleName(moduleName string) string { |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2902 | // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build |
| 2903 | // system. Trim the prefix for the check since they are confusing |
Paul Duffin | d23c726 | 2020-12-11 18:13:08 +0000 | [diff] [blame] | 2904 | moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2905 | if strings.HasPrefix(moduleName, "libclang_rt.") { |
| 2906 | // This module has many arch variants that depend on the product being built. |
| 2907 | // We don't want to list them all |
| 2908 | moduleName = "libclang_rt" |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2909 | } |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 2910 | if strings.HasPrefix(moduleName, "androidx.") { |
| 2911 | // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries |
| 2912 | moduleName = "androidx" |
| 2913 | } |
Paul Duffin | 7d74e7b | 2020-03-06 12:30:13 +0000 | [diff] [blame] | 2914 | return moduleName |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2917 | // Transform the map of apex -> modules to module -> apexes. |
| 2918 | func invertApexBaseline(m map[string][]string) map[string][]string { |
| 2919 | r := make(map[string][]string) |
| 2920 | for apex, modules := range m { |
| 2921 | for _, module := range modules { |
| 2922 | r[module] = append(r[module], apex) |
| 2923 | } |
| 2924 | } |
| 2925 | return r |
| 2926 | } |
| 2927 | |
| 2928 | // Retrieve the baseline of apexes to which the supplied module belongs. |
| 2929 | func BaselineApexAvailable(moduleName string) []string { |
| 2930 | return inverseApexAvailBaseline[normalizeModuleName(moduleName)] |
| 2931 | } |
| 2932 | |
Jiyong Park | c0ec6f9 | 2020-11-19 23:00:52 +0900 | [diff] [blame] | 2933 | // This is a map from apex to modules, which overrides the apex_available setting for that |
| 2934 | // 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] | 2935 | // TODO(b/147364041): remove this |
| 2936 | func makeApexAvailableBaseline() map[string][]string { |
| 2937 | // The "Module separator"s below are employed to minimize merge conflicts. |
| 2938 | m := make(map[string][]string) |
| 2939 | // |
| 2940 | // Module separator |
| 2941 | // |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2942 | m["com.android.runtime"] = []string{ |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2943 | "libz", |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2944 | } |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2945 | return m |
| 2946 | } |
| 2947 | |
| 2948 | func init() { |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 2949 | android.AddNeverAllowRules(createBcpPermittedPackagesRules(qBcpPackages())...) |
| 2950 | android.AddNeverAllowRules(createBcpPermittedPackagesRules(rBcpPackages())...) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2951 | } |
| 2952 | |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 2953 | func createBcpPermittedPackagesRules(bcpPermittedPackages map[string][]string) []android.Rule { |
| 2954 | rules := make([]android.Rule, 0, len(bcpPermittedPackages)) |
| 2955 | for jar, permittedPackages := range bcpPermittedPackages { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2956 | permittedPackagesRule := android.NeverAllow(). |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 2957 | With("name", jar). |
| 2958 | WithMatcher("permitted_packages", android.NotInList(permittedPackages)). |
| 2959 | Because(jar + |
| 2960 | " bootjar may only use these package prefixes: " + strings.Join(permittedPackages, ",") + |
Anton Hansson | e1b1836 | 2021-12-23 15:05:38 +0000 | [diff] [blame] | 2961 | ". Please consider the following alternatives:\n" + |
Andrei Onea | d967aee | 2022-01-19 15:36:40 +0000 | [diff] [blame] | 2962 | " 1. If the offending code is from a statically linked library, consider " + |
| 2963 | "removing that dependency and using an alternative already in the " + |
| 2964 | "bootclasspath, or perhaps a shared library." + |
| 2965 | " 2. Move the offending code into an allowed package.\n" + |
| 2966 | " 3. Jarjar the offending code. Please be mindful of the potential system " + |
| 2967 | "health implications of bundling that code, particularly if the offending jar " + |
| 2968 | "is part of the bootclasspath.") |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 2969 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2970 | rules = append(rules, permittedPackagesRule) |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2971 | } |
| 2972 | return rules |
| 2973 | } |
| 2974 | |
Anton Hansson | e1b1836 | 2021-12-23 15:05:38 +0000 | [diff] [blame] | 2975 | // 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] | 2976 | // 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] | 2977 | func qBcpPackages() map[string][]string { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2978 | return map[string][]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 2979 | "conscrypt": { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2980 | "android.net.ssl", |
| 2981 | "com.android.org.conscrypt", |
| 2982 | }, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 2983 | "updatable-media": { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2984 | "android.media", |
| 2985 | }, |
| 2986 | } |
| 2987 | } |
| 2988 | |
Anton Hansson | e1b1836 | 2021-12-23 15:05:38 +0000 | [diff] [blame] | 2989 | // 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] | 2990 | // 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] | 2991 | func rBcpPackages() map[string][]string { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2992 | return map[string][]string{ |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 2993 | "framework-mediaprovider": { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2994 | "android.provider", |
| 2995 | }, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 2996 | "framework-permission": { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 2997 | "android.permission", |
| 2998 | "android.app.role", |
| 2999 | "com.android.permission", |
| 3000 | "com.android.role", |
| 3001 | }, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 3002 | "framework-sdkextensions": { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3003 | "android.os.ext", |
| 3004 | }, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 3005 | "framework-statsd": { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3006 | "android.app", |
| 3007 | "android.os", |
| 3008 | "android.util", |
| 3009 | "com.android.internal.statsd", |
| 3010 | "com.android.server.stats", |
| 3011 | }, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 3012 | "framework-wifi": { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3013 | "com.android.server.wifi", |
| 3014 | "com.android.wifi.x", |
| 3015 | "android.hardware.wifi", |
| 3016 | "android.net.wifi", |
| 3017 | }, |
Wei Li | 40f9873 | 2022-05-20 22:08:11 -0700 | [diff] [blame] | 3018 | "framework-tethering": { |
Jiyong Park | 8e6d52f | 2020-11-19 14:37:47 +0900 | [diff] [blame] | 3019 | "android.net", |
| 3020 | }, |
| 3021 | } |
| 3022 | } |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 3023 | |
Spandan Das | f57a966 | 2023-04-12 19:05:49 +0000 | [diff] [blame] | 3024 | func (a *apexBundle) IsTestApex() bool { |
| 3025 | return a.testApex |
| 3026 | } |
Kiyoung Kim | 8269cee | 2023-07-26 12:39:19 +0900 | [diff] [blame] | 3027 | |
| 3028 | func (a *apexBundle) useVndkAsStable(ctx android.BaseModuleContext) bool { |
| 3029 | // VNDK cannot be linked if it is deprecated |
| 3030 | if ctx.Config().IsVndkDeprecated() { |
| 3031 | return false |
| 3032 | } |
| 3033 | |
| 3034 | return proptools.Bool(a.properties.Use_vndk_as_stable) |
| 3035 | } |