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