Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 1 | // Copyright (C) 2020 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 | |
| 15 | package filesystem |
| 16 | |
| 17 | import ( |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 18 | "crypto/sha256" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 19 | "fmt" |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 20 | "io" |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 21 | "path/filepath" |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 22 | "slices" |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 23 | "sort" |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 24 | "strconv" |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 25 | "strings" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 26 | |
| 27 | "android/soong/android" |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 28 | "android/soong/cc" |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 29 | "android/soong/java" |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 30 | "android/soong/linkerconfig" |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 31 | |
| 32 | "github.com/google/blueprint" |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 33 | "github.com/google/blueprint/proptools" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | func init() { |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 37 | registerBuildComponents(android.InitRegistrationContext) |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 38 | registerMutators(android.InitRegistrationContext) |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 39 | pctx.HostBinToolVariable("fileslist", "fileslist") |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 40 | pctx.HostBinToolVariable("fs_config", "fs_config") |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | func registerBuildComponents(ctx android.RegistrationContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 44 | ctx.RegisterModuleType("android_filesystem", FilesystemFactory) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 45 | ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 46 | ctx.RegisterModuleType("android_system_image", SystemImageFactory) |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 47 | ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 48 | ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory) |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 49 | ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 50 | ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 51 | } |
| 52 | |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 53 | func registerMutators(ctx android.RegistrationContext) { |
| 54 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 55 | ctx.BottomUp("add_autogenerated_rro_deps", addAutogeneratedRroDeps) |
| 56 | }) |
| 57 | } |
| 58 | |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 59 | var ( |
| 60 | // Remember to add referenced files to implicits! |
| 61 | textFileProcessorRule = pctx.AndroidStaticRule("text_file_processing", blueprint.RuleParams{ |
| 62 | Command: "build/soong/scripts/text_file_processor.py $in $out", |
| 63 | CommandDeps: []string{"build/soong/scripts/text_file_processor.py"}, |
| 64 | }) |
| 65 | |
| 66 | // Remember to add the output image file as an implicit dependency! |
| 67 | installedFilesJsonRule = pctx.AndroidStaticRule("installed_files_json", blueprint.RuleParams{ |
| 68 | Command: `${fileslist} ${rootDir} > ${out}`, |
| 69 | CommandDeps: []string{"${fileslist}"}, |
| 70 | }, "rootDir") |
| 71 | |
| 72 | installedFilesTxtRule = pctx.AndroidStaticRule("installed_files_txt", blueprint.RuleParams{ |
| 73 | Command: `build/make/tools/fileslist_util.py -c ${in} > ${out}`, |
| 74 | CommandDeps: []string{"build/make/tools/fileslist_util.py"}, |
| 75 | }) |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 76 | fsConfigRule = pctx.AndroidStaticRule("fs_config_rule", blueprint.RuleParams{ |
| 77 | Command: `(cd ${rootDir}; find . -type d | sed 's,$$,/,'; find . \! -type d) | cut -c 3- | sort | sed 's,^,${prefix},' | ${fs_config} -C -D ${rootDir} -R "${prefix}" > ${out}`, |
| 78 | CommandDeps: []string{"${fs_config}"}, |
| 79 | }, "rootDir", "prefix") |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 80 | ) |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 81 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 82 | type filesystem struct { |
| 83 | android.ModuleBase |
| 84 | android.PackagingBase |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 85 | android.DefaultableModuleBase |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 86 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 87 | properties FilesystemProperties |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 88 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 89 | output android.Path |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 90 | installDir android.InstallPath |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 91 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 92 | fileListFile android.Path |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 93 | |
| 94 | // Keeps the entries installed from this filesystem |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 95 | entries []string |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 96 | |
| 97 | filesystemBuilder filesystemBuilder |
Spandan Das | f12ff9b | 2025-02-12 22:27:43 +0000 | [diff] [blame] | 98 | |
| 99 | selinuxFc android.Path |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 100 | } |
| 101 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 102 | type filesystemBuilder interface { |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 103 | BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath, fullInstallPaths *[]FullInstallPathInfo) |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 104 | // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs() |
| 105 | FilterPackagingSpec(spec android.PackagingSpec) bool |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 106 | // Function that modifies PackagingSpec in PackagingBase.GatherPackagingSpecs() to customize. |
| 107 | // For example, GSI system.img contains system_ext and product artifacts and their |
| 108 | // relPathInPackage need to be rebased to system/system_ext and system/system_product. |
| 109 | ModifyPackagingSpec(spec *android.PackagingSpec) |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 110 | |
| 111 | // Function to check if the filesystem should not use `vintf_fragments` property, |
| 112 | // but use `vintf_fragment` module type instead |
| 113 | ShouldUseVintfFragmentModuleOnly() bool |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | var _ filesystemBuilder = (*filesystem)(nil) |
| 117 | |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 118 | type SymlinkDefinition struct { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 119 | Target *string |
| 120 | Name *string |
| 121 | } |
| 122 | |
Jihoon Kang | 0a45389 | 2024-12-09 22:16:26 +0000 | [diff] [blame] | 123 | // CopyWithNamePrefix returns a new [SymlinkDefinition] with prefix added to Name. |
| 124 | func (s *SymlinkDefinition) CopyWithNamePrefix(prefix string) SymlinkDefinition { |
| 125 | return SymlinkDefinition{ |
| 126 | Target: s.Target, |
| 127 | Name: proptools.StringPtr(filepath.Join(prefix, proptools.String(s.Name))), |
| 128 | } |
| 129 | } |
| 130 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 131 | type FilesystemProperties struct { |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 132 | // When set to true, sign the image with avbtool. Default is false. |
| 133 | Use_avb *bool |
| 134 | |
| 135 | // Path to the private key that avbtool will use to sign this filesystem image. |
| 136 | // TODO(jiyong): allow apex_key to be specified here |
| 137 | Avb_private_key *string `android:"path"` |
| 138 | |
Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 139 | // Signing algorithm for avbtool. Default is SHA256_RSA4096. |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 140 | Avb_algorithm *string |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 141 | |
Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 142 | // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to |
Nikita Ioffe | 50fb49c | 2025-01-24 13:49:00 +0000 | [diff] [blame] | 143 | // avbtool. Default is sha256. |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 144 | Avb_hash_algorithm *string |
| 145 | |
Spandan Das | e5c393c | 2024-12-12 19:25:07 +0000 | [diff] [blame] | 146 | // The security patch passed to as the com.android.build.<type>.security_patch avb property. |
| 147 | Security_patch *string |
| 148 | |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 149 | // Whether or not to use forward-error-correction codes when signing with AVB. Defaults to true. |
| 150 | Use_fec *bool |
| 151 | |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 152 | // The index used to prevent rollback of the image. Only used if use_avb is true. |
| 153 | Rollback_index *int64 |
| 154 | |
Luca Stefani | 9235f4c | 2025-02-08 12:09:34 +0100 | [diff] [blame] | 155 | // Rollback index location of this image. Must be 1, 2, 3, etc. |
Jihoon Kang | 2f0d193 | 2025-01-17 19:22:44 +0000 | [diff] [blame] | 156 | Rollback_index_location *int64 |
| 157 | |
Jiyong Park | ac4076d | 2021-03-15 23:21:30 +0900 | [diff] [blame] | 158 | // Name of the partition stored in vbmeta desc. Defaults to the name of this module. |
| 159 | Partition_name *string |
| 160 | |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 161 | // Type of the filesystem. Currently, ext4, erofs, cpio, and compressed_cpio are supported. Default |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 162 | // is ext4. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 163 | Type *string |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 164 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 165 | // Identifies which partition this is for //visibility:any_system_image (and others) visibility |
| 166 | // checks, and will be used in the future for API surface checks. |
| 167 | Partition_type *string |
| 168 | |
Cole Faust | 0d46705 | 2024-12-04 17:19:19 -0800 | [diff] [blame] | 169 | // file_contexts file to make image. Currently, only ext4 is supported. These file contexts |
| 170 | // will be compiled with sefcontext_compile |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 171 | File_contexts *string `android:"path"` |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 172 | |
Cole Faust | 0d46705 | 2024-12-04 17:19:19 -0800 | [diff] [blame] | 173 | // The selinux file contexts, after having already run them through sefcontext_compile |
| 174 | Precompiled_file_contexts *string `android:"path"` |
| 175 | |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 176 | // Base directory relative to root, to which deps are installed, e.g. "system". Default is "." |
| 177 | // (root). |
| 178 | Base_dir *string |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 179 | |
| 180 | // Directories to be created under root. e.g. /dev, /proc, etc. |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 181 | Dirs proptools.Configurable[[]string] |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 182 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 183 | // List of filesystem modules to include in creating the partition. The root directory of |
| 184 | // the provided filesystem modules are included in creating the partition. |
| 185 | // This is only supported for cpio and compressed cpio filesystem types. |
| 186 | Include_files_of []string |
| 187 | |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 188 | // Symbolic links to be created under root with "ln -sf <target> <name>". |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 189 | Symlinks []SymlinkDefinition |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 190 | |
| 191 | // Seconds since unix epoch to override timestamps of file entries |
| 192 | Fake_timestamp *string |
| 193 | |
| 194 | // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed. |
| 195 | // Otherwise, they'll be set as random which might cause indeterministic build output. |
| 196 | Uuid *string |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 197 | |
| 198 | // Mount point for this image. Default is "/" |
| 199 | Mount_point *string |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 200 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 201 | // When set, builds etc/event-log-tags file by merging logtags from all dependencies. |
| 202 | // Default is false |
| 203 | Build_logtags *bool |
| 204 | |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 205 | // Install aconfig_flags.pb file for the modules installed in this partition. |
| 206 | Gen_aconfig_flags_pb *bool |
| 207 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 208 | // List of names of other filesystem partitions to import their aconfig flags from. |
| 209 | // This is used for the system partition to import system_ext's aconfig flags, as currently |
| 210 | // those are considered one "container": aosp/3261300 |
| 211 | Import_aconfig_flags_from []string |
| 212 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 213 | Fsverity fsverityProperties |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 214 | |
| 215 | // If this property is set to true, the filesystem will call ctx.UncheckedModule(), causing |
| 216 | // it to not be built on checkbuilds. Used for the automatic migration from make to soong |
| 217 | // build modules, where we want to emit some not-yet-working filesystems and we don't want them |
| 218 | // to be built. |
| 219 | Unchecked_module *bool `blueprint:"mutated"` |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 220 | |
| 221 | Erofs ErofsProperties |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 222 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 223 | F2fs F2fsProperties |
| 224 | |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 225 | Linker_config LinkerConfigProperties |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 226 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 227 | // Determines if the module is auto-generated from Soong or not. If the module is |
| 228 | // auto-generated, its deps are exempted from visibility enforcement. |
| 229 | Is_auto_generated *bool |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 230 | |
| 231 | // Path to the dev nodes description file. This is only needed for building the ramdisk |
| 232 | // partition and should not be explicitly specified. |
| 233 | Dev_nodes_description_file *string `android:"path" blueprint:"mutated"` |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 234 | |
| 235 | // Additional dependencies used for building android products |
| 236 | Android_filesystem_deps AndroidFilesystemDeps |
Spandan Das | c49b85e | 2025-01-10 00:51:25 +0000 | [diff] [blame] | 237 | |
| 238 | // Name of the output. Default is $(module_name).img |
| 239 | Stem *string |
Jihoon Kang | 983dd88 | 2025-01-13 23:14:11 +0000 | [diff] [blame] | 240 | |
| 241 | // The size of the partition on the device. It will be a build error if this built partition |
| 242 | // image exceeds this size. |
| 243 | Partition_size *int64 |
Jihoon Kang | 6d08d92 | 2025-01-14 18:31:57 +0000 | [diff] [blame] | 244 | |
| 245 | // Whether to format f2fs and ext4 in a way that supports casefolding |
| 246 | Support_casefolding *bool |
| 247 | |
| 248 | // Whether to format f2fs and ext4 in a way that supports project quotas |
| 249 | Support_project_quota *bool |
| 250 | |
| 251 | // Whether to enable per-file compression in f2fs |
| 252 | Enable_compression *bool |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | type AndroidFilesystemDeps struct { |
| 256 | System *string |
| 257 | System_ext *string |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Additional properties required to generate erofs FS partitions. |
| 261 | type ErofsProperties struct { |
| 262 | // Compressor and Compression level passed to mkfs.erofs. e.g. (lz4hc,9) |
| 263 | // Please see external/erofs-utils/README for complete documentation. |
| 264 | Compressor *string |
| 265 | |
| 266 | // Used as --compress-hints for mkfs.erofs |
| 267 | Compress_hints *string `android:"path"` |
| 268 | |
| 269 | Sparse *bool |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 270 | } |
| 271 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 272 | // Additional properties required to generate f2fs FS partitions. |
| 273 | type F2fsProperties struct { |
| 274 | Sparse *bool |
| 275 | } |
| 276 | |
Spandan Das | 173256b | 2024-10-31 19:59:30 +0000 | [diff] [blame] | 277 | type LinkerConfigProperties struct { |
| 278 | |
| 279 | // Build a linker.config.pb file |
| 280 | Gen_linker_config *bool |
| 281 | |
| 282 | // List of files (in .json format) that will be converted to a linker config file (in .pb format). |
| 283 | // The linker config file be installed in the filesystem at /etc/linker.config.pb |
| 284 | Linker_config_srcs []string `android:"path"` |
| 285 | } |
| 286 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 287 | // android_filesystem packages a set of modules and their transitive dependencies into a filesystem |
| 288 | // image. The filesystem images are expected to be mounted in the target device, which means the |
| 289 | // modules in the filesystem image are built for the target device (i.e. Android, not Linux host). |
| 290 | // The modules are placed in the filesystem image just like they are installed to the ordinary |
| 291 | // partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory. |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 292 | func FilesystemFactory() android.Module { |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 293 | module := &filesystem{} |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 294 | module.filesystemBuilder = module |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 295 | initFilesystemModule(module, module) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 296 | return module |
| 297 | } |
| 298 | |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 299 | func initFilesystemModule(module android.DefaultableModule, filesystemModule *filesystem) { |
| 300 | module.AddProperties(&filesystemModule.properties) |
| 301 | android.InitPackageModule(filesystemModule) |
| 302 | filesystemModule.PackagingBase.DepsCollectFirstTargetOnly = true |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 303 | filesystemModule.PackagingBase.AllowHighPriorityDeps = true |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 304 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 305 | android.InitDefaultableModule(module) |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 306 | |
| 307 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 308 | filesystemModule.setDevNodesDescriptionProp() |
| 309 | }) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 310 | } |
| 311 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 312 | type depTag struct { |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 313 | blueprint.BaseDependencyTag |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 314 | android.PackagingItemAlwaysDepTag |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | var dependencyTag = depTag{} |
| 318 | |
| 319 | type depTagWithVisibilityEnforcementBypass struct { |
| 320 | depTag |
| 321 | } |
| 322 | |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 323 | type interPartitionDepTag struct { |
| 324 | blueprint.BaseDependencyTag |
| 325 | } |
| 326 | |
| 327 | var interPartitionDependencyTag = interPartitionDepTag{} |
| 328 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 329 | var interPartitionInstallDependencyTag = interPartitionDepTag{} |
| 330 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 331 | var _ android.ExcludeFromVisibilityEnforcementTag = (*depTagWithVisibilityEnforcementBypass)(nil) |
| 332 | |
| 333 | func (t depTagWithVisibilityEnforcementBypass) ExcludeFromVisibilityEnforcement() {} |
| 334 | |
| 335 | var dependencyTagWithVisibilityEnforcementBypass = depTagWithVisibilityEnforcementBypass{} |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 336 | |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 337 | // ramdiskDevNodesDescription is the name of the filegroup module that provides the file that |
| 338 | // contains the description of dev nodes added to the CPIO archive for the ramdisk partition. |
| 339 | const ramdiskDevNodesDescription = "ramdisk_node_list" |
| 340 | |
| 341 | func (f *filesystem) setDevNodesDescriptionProp() { |
| 342 | if proptools.String(f.properties.Partition_name) == "ramdisk" { |
| 343 | f.properties.Dev_nodes_description_file = proptools.StringPtr(":" + ramdiskDevNodesDescription) |
| 344 | } |
| 345 | } |
| 346 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 347 | func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 348 | if proptools.Bool(f.properties.Is_auto_generated) { |
| 349 | f.AddDeps(ctx, dependencyTagWithVisibilityEnforcementBypass) |
| 350 | } else { |
| 351 | f.AddDeps(ctx, dependencyTag) |
| 352 | } |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 353 | if f.properties.Android_filesystem_deps.System != nil { |
| 354 | ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System)) |
| 355 | } |
| 356 | if f.properties.Android_filesystem_deps.System_ext != nil { |
| 357 | ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System_ext)) |
| 358 | } |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 359 | for _, partition := range f.properties.Import_aconfig_flags_from { |
| 360 | ctx.AddDependency(ctx.Module(), importAconfigDependencyTag, partition) |
| 361 | } |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 362 | for _, partition := range f.properties.Include_files_of { |
| 363 | ctx.AddDependency(ctx.Module(), interPartitionInstallDependencyTag, partition) |
| 364 | } |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 365 | } |
| 366 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 367 | type fsType int |
| 368 | |
| 369 | const ( |
| 370 | ext4Type fsType = iota |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 371 | erofsType |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 372 | f2fsType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 373 | compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 374 | cpioType // uncompressed |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 375 | unknown |
| 376 | ) |
| 377 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 378 | func (fs fsType) IsUnknown() bool { |
| 379 | return fs == unknown |
| 380 | } |
| 381 | |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 382 | type InstalledFilesStruct struct { |
| 383 | Txt android.Path |
| 384 | Json android.Path |
| 385 | } |
| 386 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 387 | type FilesystemInfo struct { |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 388 | // The built filesystem image |
| 389 | Output android.Path |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 390 | // An additional hermetic filesystem image. |
| 391 | // e.g. this will contain inodes with pinned timestamps. |
| 392 | // This will be copied to target_files.zip |
| 393 | OutputHermetic android.Path |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 394 | // A text file containing the list of paths installed on the partition. |
| 395 | FileListFile android.Path |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 396 | // The root staging directory used to build the output filesystem. If consuming this, make sure |
| 397 | // to add a dependency on the Output file, as you cannot add dependencies on directories |
| 398 | // in ninja. |
| 399 | RootDir android.Path |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 400 | // The rebased staging directory used to build the output filesystem. If consuming this, make |
| 401 | // sure to add a dependency on the Output file, as you cannot add dependencies on directories |
| 402 | // in ninja. In many cases this is the same as RootDir, only in the system partition is it |
| 403 | // different. There, it points to the "system" sub-directory of RootDir. |
| 404 | RebasedDir android.Path |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 405 | // A text file with block data of the .img file |
| 406 | // This is an implicit output of `build_image` |
| 407 | MapFile android.Path |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 408 | // Name of the module that produced this FilesystemInfo origionally. (though it may be |
| 409 | // re-exported by super images or boot images) |
| 410 | ModuleName string |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 411 | // The property file generated by this module and passed to build_image. |
| 412 | // It's exported here so that system_other can reuse system's property file. |
| 413 | BuildImagePropFile android.Path |
| 414 | // Paths to all the tools referenced inside of the build image property file. |
| 415 | BuildImagePropFileDeps android.Paths |
Cole Faust | b8e280f | 2025-01-16 16:33:26 -0800 | [diff] [blame] | 416 | // Packaging specs to be installed on the system_other image, for the initial boot's dexpreopt. |
| 417 | SpecsForSystemOther map[string]android.PackagingSpec |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 418 | |
| 419 | FullInstallPaths []FullInstallPathInfo |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 420 | |
| 421 | // Installed files list |
| 422 | InstalledFiles InstalledFilesStruct |
Spandan Das | d71af18 | 2025-02-12 18:03:29 +0000 | [diff] [blame] | 423 | |
| 424 | // Path to compress hints file for erofs filesystems |
| 425 | // This will be nil for other fileystems like ext4 |
| 426 | ErofsCompressHints android.Path |
Spandan Das | f12ff9b | 2025-02-12 22:27:43 +0000 | [diff] [blame] | 427 | |
| 428 | SelinuxFc android.Path |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 429 | |
| 430 | FilesystemConfig android.Path |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | // FullInstallPathInfo contains information about the "full install" paths of all the files |
| 434 | // inside this partition. The full install paths are the files installed in |
| 435 | // out/target/product/<device>/<partition>. This is essentially legacy behavior, maintained for |
| 436 | // tools like adb sync and adevice, but we should update them to query the build system for the |
| 437 | // installed files no matter where they are. |
| 438 | type FullInstallPathInfo struct { |
| 439 | // RequiresFullInstall tells us if the origional module did the install to FullInstallPath |
| 440 | // already. If it's false, the android_device module needs to emit the install rule. |
| 441 | RequiresFullInstall bool |
| 442 | // The "full install" paths for the files in this filesystem. This is the paths in the |
| 443 | // out/target/product/<device>/<partition> folder. They're not used by this filesystem, |
| 444 | // but can be depended on by the top-level android_device module to cause the staging |
| 445 | // directories to be built. |
| 446 | FullInstallPath android.InstallPath |
| 447 | |
| 448 | // The file that's copied to FullInstallPath. May be nil if SymlinkTarget is set or IsDir is |
| 449 | // true. |
| 450 | SourcePath android.Path |
| 451 | |
| 452 | // The target of the symlink, if this file is a symlink. |
| 453 | SymlinkTarget string |
| 454 | |
| 455 | // If this file is a directory. Only used for empty directories, which are mostly mount points. |
| 456 | IsDir bool |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]() |
| 460 | |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame] | 461 | type FilesystemDefaultsInfo struct { |
| 462 | // Identifies which partition this is for //visibility:any_system_image (and others) visibility |
| 463 | // checks, and will be used in the future for API surface checks. |
| 464 | PartitionType string |
| 465 | } |
| 466 | |
| 467 | var FilesystemDefaultsInfoProvider = blueprint.NewProvider[FilesystemDefaultsInfo]() |
| 468 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 469 | func GetFsTypeFromString(ctx android.EarlyModuleContext, typeStr string) fsType { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 470 | switch typeStr { |
| 471 | case "ext4": |
| 472 | return ext4Type |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 473 | case "erofs": |
| 474 | return erofsType |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 475 | case "f2fs": |
| 476 | return f2fsType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 477 | case "compressed_cpio": |
| 478 | return compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 479 | case "cpio": |
| 480 | return cpioType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 481 | default: |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 482 | return unknown |
| 483 | } |
| 484 | } |
| 485 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 486 | func (f *filesystem) fsType(ctx android.ModuleContext) fsType { |
| 487 | typeStr := proptools.StringDefault(f.properties.Type, "ext4") |
| 488 | fsType := GetFsTypeFromString(ctx, typeStr) |
| 489 | if fsType == unknown { |
| 490 | ctx.PropertyErrorf("type", "%q not supported", typeStr) |
| 491 | } |
| 492 | return fsType |
| 493 | } |
| 494 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 495 | func (f *filesystem) installFileName() string { |
Spandan Das | c49b85e | 2025-01-10 00:51:25 +0000 | [diff] [blame] | 496 | return proptools.StringDefault(f.properties.Stem, f.BaseModuleName()+".img") |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 497 | } |
| 498 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 499 | func (f *filesystem) partitionName() string { |
| 500 | return proptools.StringDefault(f.properties.Partition_name, f.Name()) |
| 501 | } |
| 502 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 503 | func (f *filesystem) FilterPackagingSpec(ps android.PackagingSpec) bool { |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 504 | // Filesystem module respects the installation semantic. A PackagingSpec from a module with |
| 505 | // IsSkipInstall() is skipped. |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 506 | if ps.SkipInstall() { |
| 507 | return false |
Spandan Das | 6d05650 | 2024-10-21 15:40:32 +0000 | [diff] [blame] | 508 | } |
Cole Faust | 0d3fd56 | 2025-01-31 13:17:58 -0800 | [diff] [blame] | 509 | // "apex" is a fake partition used to install files in out/target/product/<device>/apex/. |
| 510 | // Don't include these files in the partition. We should also look into removing the following |
| 511 | // TODO to check the PackagingSpec's partition against this filesystem's partition for all |
| 512 | // modules, not just autogenerated ones, which will fix this as well. |
| 513 | if ps.Partition() == "apex" { |
| 514 | return false |
| 515 | } |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 516 | if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this. |
| 517 | pt := f.PartitionType() |
Cole Faust | c88cff1 | 2024-11-12 13:24:05 -0800 | [diff] [blame] | 518 | return ps.Partition() == pt || strings.HasPrefix(ps.Partition(), pt+"/") |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 519 | } |
| 520 | return true |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 523 | func (f *filesystem) ModifyPackagingSpec(ps *android.PackagingSpec) { |
Cole Faust | c88cff1 | 2024-11-12 13:24:05 -0800 | [diff] [blame] | 524 | // Sometimes, android.modulePartition() returns a path with >1 path components. |
| 525 | // This makes the partition field of packagingSpecs have multiple components, like |
| 526 | // "system/product". Right now, the filesystem module doesn't look at the partition field |
| 527 | // when deciding what path to install the file under, only the RelPathInPackage field, so |
| 528 | // we move the later path components from partition to relPathInPackage. This should probably |
| 529 | // be revisited in the future. |
| 530 | prefix := f.PartitionType() + "/" |
| 531 | if strings.HasPrefix(ps.Partition(), prefix) { |
| 532 | subPartition := strings.TrimPrefix(ps.Partition(), prefix) |
| 533 | ps.SetPartition(f.PartitionType()) |
| 534 | ps.SetRelPathInPackage(filepath.Join(subPartition, ps.RelPathInPackage())) |
| 535 | } |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 536 | } |
| 537 | |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 538 | func buildInstalledFiles(ctx android.ModuleContext, partition string, rootDir android.Path, image android.Path) (txt android.ModuleOutPath, json android.ModuleOutPath) { |
| 539 | fileName := "installed-files" |
| 540 | if len(partition) > 0 { |
| 541 | fileName += fmt.Sprintf("-%s", partition) |
| 542 | } |
| 543 | txt = android.PathForModuleOut(ctx, fmt.Sprintf("%s.txt", fileName)) |
| 544 | json = android.PathForModuleOut(ctx, fmt.Sprintf("%s.json", fileName)) |
| 545 | |
| 546 | ctx.Build(pctx, android.BuildParams{ |
| 547 | Rule: installedFilesJsonRule, |
| 548 | Implicit: image, |
| 549 | Output: json, |
| 550 | Description: "Installed file list json", |
| 551 | Args: map[string]string{ |
| 552 | "rootDir": rootDir.String(), |
| 553 | }, |
| 554 | }) |
| 555 | |
| 556 | ctx.Build(pctx, android.BuildParams{ |
| 557 | Rule: installedFilesTxtRule, |
| 558 | Input: json, |
| 559 | Output: txt, |
| 560 | Description: "Installed file list txt", |
| 561 | }) |
| 562 | |
| 563 | return txt, json |
| 564 | } |
| 565 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 566 | var pctx = android.NewPackageContext("android/soong/filesystem") |
| 567 | |
| 568 | func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 569 | validatePartitionType(ctx, f) |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 570 | if f.filesystemBuilder.ShouldUseVintfFragmentModuleOnly() { |
| 571 | f.validateVintfFragments(ctx) |
| 572 | } |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 573 | |
| 574 | if len(f.properties.Include_files_of) > 0 && !android.InList(f.fsType(ctx), []fsType{compressedCpioType, cpioType}) { |
| 575 | ctx.PropertyErrorf("include_files_of", "include_files_of is only supported for cpio and compressed cpio filesystem types.") |
| 576 | } |
| 577 | |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 578 | rootDir := android.PathForModuleOut(ctx, f.rootDirString()).OutputPath |
| 579 | rebasedDir := rootDir |
| 580 | if f.properties.Base_dir != nil { |
| 581 | rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) |
| 582 | } |
| 583 | builder := android.NewRuleBuilder(pctx, ctx) |
| 584 | |
| 585 | // Wipe the root dir to get rid of leftover files from prior builds |
| 586 | builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) |
| 587 | specs := f.gatherFilteredPackagingSpecs(ctx) |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 588 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 589 | var fullInstallPaths []FullInstallPathInfo |
| 590 | for _, spec := range specs { |
| 591 | fullInstallPaths = append(fullInstallPaths, FullInstallPathInfo{ |
| 592 | FullInstallPath: spec.FullInstallPath(), |
| 593 | RequiresFullInstall: spec.RequiresFullInstall(), |
| 594 | SourcePath: spec.SrcPath(), |
| 595 | SymlinkTarget: spec.ToGob().SymlinkTarget, |
| 596 | }) |
| 597 | } |
| 598 | |
| 599 | f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) |
| 600 | f.buildNonDepsFiles(ctx, builder, rootDir, rebasedDir, &fullInstallPaths) |
| 601 | f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir, &fullInstallPaths) |
| 602 | f.buildEventLogtagsFile(ctx, builder, rebasedDir, &fullInstallPaths) |
| 603 | f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir, &fullInstallPaths) |
| 604 | f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir, &fullInstallPaths) |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 605 | // Assemeble the staging dir and output a timestamp |
| 606 | builder.Command().Text("touch").Output(f.fileystemStagingDirTimestamp(ctx)) |
| 607 | builder.Build("assemble_filesystem_staging_dir", fmt.Sprintf("Assemble filesystem staging dir %s", f.BaseModuleName())) |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 608 | |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 609 | // Create a new rule builder for build_image |
| 610 | builder = android.NewRuleBuilder(pctx, ctx) |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 611 | var mapFile android.Path |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 612 | var outputHermetic android.WritablePath |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 613 | var buildImagePropFile android.Path |
| 614 | var buildImagePropFileDeps android.Paths |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 615 | switch f.fsType(ctx) { |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 616 | case ext4Type, erofsType, f2fsType: |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 617 | buildImagePropFile, buildImagePropFileDeps = f.buildPropFile(ctx) |
| 618 | output := android.PathForModuleOut(ctx, f.installFileName()) |
| 619 | f.buildImageUsingBuildImage(ctx, builder, buildImageParams{rootDir, buildImagePropFile, buildImagePropFileDeps, output}) |
| 620 | f.output = output |
| 621 | // Create the hermetic img file using a separate rule builder so that it can be built independently |
| 622 | hermeticBuilder := android.NewRuleBuilder(pctx, ctx) |
| 623 | outputHermetic = android.PathForModuleOut(ctx, "for_target_files", f.installFileName()) |
| 624 | propFileHermetic := f.propFileForHermeticImg(ctx, hermeticBuilder, buildImagePropFile) |
| 625 | f.buildImageUsingBuildImage(ctx, hermeticBuilder, buildImageParams{rootDir, propFileHermetic, buildImagePropFileDeps, outputHermetic}) |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 626 | mapFile = f.getMapFile(ctx) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 627 | case compressedCpioType: |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 628 | f.output = f.buildCpioImage(ctx, builder, rootDir, true) |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 629 | case cpioType: |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 630 | f.output = f.buildCpioImage(ctx, builder, rootDir, false) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 631 | default: |
| 632 | return |
| 633 | } |
| 634 | |
| 635 | f.installDir = android.PathForModuleInstall(ctx, "etc") |
| 636 | ctx.InstallFile(f.installDir, f.installFileName(), f.output) |
mrziwang | 555d133 | 2024-06-07 11:15:33 -0700 | [diff] [blame] | 637 | ctx.SetOutputFiles([]android.Path{f.output}, "") |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 638 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 639 | if f.partitionName() == "recovery" { |
| 640 | rootDir = rootDir.Join(ctx, "root") |
| 641 | } |
| 642 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 643 | fileListFile := android.PathForModuleOut(ctx, "fileList") |
| 644 | android.WriteFileRule(ctx, fileListFile, f.installedFilesList()) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 645 | |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 646 | partitionName := f.partitionName() |
| 647 | if partitionName == "system" { |
| 648 | partitionName = "" |
| 649 | } |
| 650 | installedFileTxt, installedFileJson := buildInstalledFiles(ctx, partitionName, rootDir, f.output) |
| 651 | |
Spandan Das | d71af18 | 2025-02-12 18:03:29 +0000 | [diff] [blame] | 652 | var erofsCompressHints android.Path |
| 653 | if f.properties.Erofs.Compress_hints != nil { |
| 654 | erofsCompressHints = android.PathForModuleSrc(ctx, *f.properties.Erofs.Compress_hints) |
| 655 | } |
| 656 | |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 657 | fsInfo := FilesystemInfo{ |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 658 | Output: f.output, |
| 659 | OutputHermetic: outputHermetic, |
| 660 | FileListFile: fileListFile, |
| 661 | RootDir: rootDir, |
| 662 | RebasedDir: rebasedDir, |
| 663 | MapFile: mapFile, |
| 664 | ModuleName: ctx.ModuleName(), |
| 665 | BuildImagePropFile: buildImagePropFile, |
| 666 | BuildImagePropFileDeps: buildImagePropFileDeps, |
Cole Faust | b8e280f | 2025-01-16 16:33:26 -0800 | [diff] [blame] | 667 | SpecsForSystemOther: f.systemOtherFiles(ctx), |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 668 | FullInstallPaths: fullInstallPaths, |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 669 | InstalledFiles: InstalledFilesStruct{ |
| 670 | Txt: installedFileTxt, |
| 671 | Json: installedFileJson, |
| 672 | }, |
Spandan Das | d71af18 | 2025-02-12 18:03:29 +0000 | [diff] [blame] | 673 | ErofsCompressHints: erofsCompressHints, |
Spandan Das | f12ff9b | 2025-02-12 22:27:43 +0000 | [diff] [blame] | 674 | SelinuxFc: f.selinuxFc, |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 675 | FilesystemConfig: f.generateFilesystemConfig(ctx, rootDir, rebasedDir), |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 676 | } |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 677 | |
| 678 | android.SetProvider(ctx, FilesystemProvider, fsInfo) |
Spandan Das | 3ec6d06 | 2025-01-09 19:37:47 +0000 | [diff] [blame] | 679 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 680 | f.fileListFile = fileListFile |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 681 | |
| 682 | if proptools.Bool(f.properties.Unchecked_module) { |
| 683 | ctx.UncheckedModule() |
| 684 | } |
Jihoon Kang | 2f0d193 | 2025-01-17 19:22:44 +0000 | [diff] [blame] | 685 | |
| 686 | f.setVbmetaPartitionProvider(ctx) |
| 687 | } |
| 688 | |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 689 | func (f *filesystem) fileystemStagingDirTimestamp(ctx android.ModuleContext) android.WritablePath { |
| 690 | return android.PathForModuleOut(ctx, "staging_dir.timestamp") |
| 691 | } |
| 692 | |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 693 | func (f *filesystem) generateFilesystemConfig(ctx android.ModuleContext, rootDir android.Path, rebasedDir android.Path) android.Path { |
| 694 | rootDirString := rootDir.String() |
| 695 | prefix := f.partitionName() + "/" |
| 696 | if f.partitionName() == "system" { |
| 697 | rootDirString = rebasedDir.String() |
| 698 | } |
| 699 | if f.partitionName() == "ramdisk" || f.partitionName() == "recovery" { |
| 700 | // Hardcoded to match make behavior. |
| 701 | // https://cs.android.com/android/_/android/platform/build/+/2a0ef42a432d4da00201e8eb7697dcaa68fd2389:core/Makefile;l=6957-6962;drc=9ea8ad9232cef4d0a24d70133b1b9d2ce2defe5f;bpv=1;bpt=0 |
| 702 | prefix = "" |
| 703 | } |
| 704 | out := android.PathForModuleOut(ctx, "filesystem_config.txt") |
| 705 | ctx.Build(pctx, android.BuildParams{ |
| 706 | Rule: fsConfigRule, |
| 707 | Input: f.fileystemStagingDirTimestamp(ctx), // assemble the staging directory |
| 708 | Output: out, |
| 709 | Args: map[string]string{ |
| 710 | "rootDir": rootDirString, |
| 711 | "prefix": prefix, |
| 712 | }, |
| 713 | }) |
| 714 | return out |
| 715 | } |
| 716 | |
Jihoon Kang | 2f0d193 | 2025-01-17 19:22:44 +0000 | [diff] [blame] | 717 | func (f *filesystem) setVbmetaPartitionProvider(ctx android.ModuleContext) { |
| 718 | var extractedPublicKey android.ModuleOutPath |
| 719 | if f.properties.Avb_private_key != nil { |
| 720 | key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) |
| 721 | extractedPublicKey = android.PathForModuleOut(ctx, f.partitionName()+".avbpubkey") |
| 722 | ctx.Build(pctx, android.BuildParams{ |
| 723 | Rule: extractPublicKeyRule, |
| 724 | Input: key, |
| 725 | Output: extractedPublicKey, |
| 726 | }) |
| 727 | } |
| 728 | |
| 729 | var ril int |
| 730 | if f.properties.Rollback_index_location != nil { |
| 731 | ril = proptools.Int(f.properties.Rollback_index_location) |
| 732 | } |
| 733 | |
| 734 | android.SetProvider(ctx, vbmetaPartitionProvider, vbmetaPartitionInfo{ |
| 735 | Name: f.partitionName(), |
| 736 | RollbackIndexLocation: ril, |
| 737 | PublicKey: extractedPublicKey, |
| 738 | Output: f.output, |
| 739 | }) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 740 | } |
| 741 | |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 742 | func (f *filesystem) getMapFile(ctx android.ModuleContext) android.WritablePath { |
| 743 | // create the filepath by replacing the extension of the corresponding img file |
| 744 | return android.PathForModuleOut(ctx, f.installFileName()).ReplaceExtension(ctx, "map") |
| 745 | } |
| 746 | |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 747 | func (f *filesystem) validateVintfFragments(ctx android.ModuleContext) { |
| 748 | visitedModule := map[string]bool{} |
| 749 | packagingSpecs := f.gatherFilteredPackagingSpecs(ctx) |
| 750 | |
| 751 | moduleInFileSystem := func(mod android.Module) bool { |
| 752 | for _, ps := range android.OtherModuleProviderOrDefault( |
| 753 | ctx, mod, android.InstallFilesProvider).PackagingSpecs { |
| 754 | if _, ok := packagingSpecs[ps.RelPathInPackage()]; ok { |
| 755 | return true |
| 756 | } |
| 757 | } |
| 758 | return false |
| 759 | } |
| 760 | |
| 761 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 762 | if visitedModule[child.Name()] { |
| 763 | return false |
| 764 | } |
| 765 | if !moduleInFileSystem(child) { |
| 766 | visitedModule[child.Name()] = true |
| 767 | return true |
| 768 | } |
| 769 | if vintfFragments := child.VintfFragments(ctx); vintfFragments != nil { |
| 770 | ctx.PropertyErrorf( |
| 771 | "vintf_fragments", |
| 772 | "Module %s is referenced by soong-defined filesystem %s with property vintf_fragments(%s) in use."+ |
| 773 | " Use vintf_fragment_modules property instead.", |
| 774 | child.Name(), |
| 775 | f.BaseModuleName(), |
| 776 | strings.Join(vintfFragments, ", "), |
| 777 | ) |
| 778 | } |
| 779 | visitedModule[child.Name()] = true |
| 780 | return true |
| 781 | }) |
| 782 | } |
| 783 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 784 | func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.Path) { |
Spandan Das | 420e16a | 2024-12-11 18:10:52 +0000 | [diff] [blame] | 785 | partitionBaseDir := android.PathForModuleOut(ctx, f.rootDirString(), proptools.String(f.properties.Base_dir)).String() + "/" |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 786 | |
| 787 | relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir) |
| 788 | if inTargetPartition { |
| 789 | f.entries = append(f.entries, relPath) |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | func (f *filesystem) installedFilesList() string { |
| 794 | installedFilePaths := android.FirstUniqueStrings(f.entries) |
| 795 | slices.Sort(installedFilePaths) |
| 796 | |
| 797 | return strings.Join(installedFilePaths, "\n") |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 798 | } |
| 799 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 800 | func validatePartitionType(ctx android.ModuleContext, p partition) { |
| 801 | if !android.InList(p.PartitionType(), validPartitions) { |
| 802 | ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType()) |
| 803 | } |
| 804 | |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame] | 805 | ctx.VisitDirectDepsProxyWithTag(android.DefaultsDepTag, func(m android.ModuleProxy) { |
| 806 | if fdm, ok := android.OtherModuleProvider(ctx, m, FilesystemDefaultsInfoProvider); ok { |
| 807 | if p.PartitionType() != fdm.PartitionType { |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 808 | ctx.PropertyErrorf("partition_type", |
| 809 | "%s doesn't match with the partition type %s of the filesystem default module %s", |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame] | 810 | p.PartitionType(), fdm.PartitionType, m.Name()) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | }) |
| 814 | } |
| 815 | |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 816 | // Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files |
| 817 | // already in `rootDir`. |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 818 | func (f *filesystem) buildNonDepsFiles( |
| 819 | ctx android.ModuleContext, |
| 820 | builder *android.RuleBuilder, |
| 821 | rootDir android.OutputPath, |
| 822 | rebasedDir android.OutputPath, |
| 823 | fullInstallPaths *[]FullInstallPathInfo, |
| 824 | ) { |
| 825 | rebasedPrefix, err := filepath.Rel(rootDir.String(), rebasedDir.String()) |
| 826 | if err != nil || strings.HasPrefix(rebasedPrefix, "../") { |
| 827 | panic("rebasedDir could not be made relative to rootDir") |
| 828 | } |
| 829 | if !strings.HasSuffix(rebasedPrefix, "/") { |
| 830 | rebasedPrefix += "/" |
| 831 | } |
| 832 | if rebasedPrefix == "./" { |
| 833 | rebasedPrefix = "" |
| 834 | } |
| 835 | |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 836 | // create dirs and symlinks |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 837 | for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 838 | // OutputPath.Join verifies dir |
| 839 | builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String()) |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 840 | // Only add the fullInstallPath logic for files in the rebased dir. The root dir |
| 841 | // is harder to install to. |
| 842 | if strings.HasPrefix(dir, rebasedPrefix) { |
| 843 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 844 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), strings.TrimPrefix(dir, rebasedPrefix)), |
| 845 | IsDir: true, |
| 846 | }) |
| 847 | } |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | for _, symlink := range f.properties.Symlinks { |
| 851 | name := strings.TrimSpace(proptools.String(symlink.Name)) |
| 852 | target := strings.TrimSpace(proptools.String(symlink.Target)) |
| 853 | |
| 854 | if name == "" { |
| 855 | ctx.PropertyErrorf("symlinks", "Name can't be empty") |
| 856 | continue |
| 857 | } |
| 858 | |
| 859 | if target == "" { |
| 860 | ctx.PropertyErrorf("symlinks", "Target can't be empty") |
| 861 | continue |
| 862 | } |
| 863 | |
| 864 | // OutputPath.Join verifies name. don't need to verify target. |
| 865 | dst := rootDir.Join(ctx, name) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 866 | builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst) |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 867 | builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) |
| 868 | builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 869 | f.appendToEntry(ctx, dst) |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 870 | // Only add the fullInstallPath logic for files in the rebased dir. The root dir |
| 871 | // is harder to install to. |
| 872 | if strings.HasPrefix(name, rebasedPrefix) { |
| 873 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 874 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), strings.TrimPrefix(name, rebasedPrefix)), |
| 875 | SymlinkTarget: target, |
| 876 | }) |
| 877 | } |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 878 | } |
Jihoon Kang | 89e8a69 | 2024-12-18 19:28:33 +0000 | [diff] [blame] | 879 | |
| 880 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2835;drc=b186569ef00ff2f2a1fab28aedc75ebc32bcd67b |
| 881 | if f.partitionName() == "recovery" { |
| 882 | builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, "root/linkerconfig").String()) |
| 883 | builder.Command().Text("touch").Text(rootDir.Join(ctx, "root/linkerconfig/ld.config.txt").String()) |
| 884 | } |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 885 | } |
| 886 | |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 887 | func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string { |
| 888 | rootDirSpecs := make(map[string]android.PackagingSpec) |
| 889 | rebasedDirSpecs := make(map[string]android.PackagingSpec) |
| 890 | |
| 891 | for rel, spec := range specs { |
| 892 | if spec.Partition() == "root" { |
| 893 | rootDirSpecs[rel] = spec |
| 894 | } else { |
| 895 | rebasedDirSpecs[rel] = spec |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec) |
| 900 | dirsToSpecs[rootDir] = rootDirSpecs |
| 901 | dirsToSpecs[rebasedDir] = rebasedDirSpecs |
| 902 | |
Cole Faust | e384505 | 2025-02-13 12:45:35 -0800 | [diff] [blame] | 903 | // Preserve timestamps for adb sync, so that this staging dir file matches the timestamp in the |
| 904 | // out/target/product staging directory. |
| 905 | return f.CopySpecsToDirs(ctx, builder, dirsToSpecs, true) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 906 | } |
| 907 | |
Spandan Das | 420e16a | 2024-12-11 18:10:52 +0000 | [diff] [blame] | 908 | func (f *filesystem) rootDirString() string { |
| 909 | return f.partitionName() |
| 910 | } |
| 911 | |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 912 | type buildImageParams struct { |
| 913 | // inputs |
| 914 | rootDir android.OutputPath |
| 915 | propFile android.Path |
| 916 | toolDeps android.Paths |
| 917 | // outputs |
| 918 | output android.WritablePath |
| 919 | } |
| 920 | |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 921 | func (f *filesystem) buildImageUsingBuildImage( |
| 922 | ctx android.ModuleContext, |
| 923 | builder *android.RuleBuilder, |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 924 | params buildImageParams) { |
Nikita Ioffe | 519015f | 2022-12-23 15:36:29 +0000 | [diff] [blame] | 925 | // run host_init_verifier |
| 926 | // Ideally we should have a concept of pluggable linters that verify the generated image. |
| 927 | // While such concept is not implement this will do. |
| 928 | // TODO(b/263574231): substitute with pluggable linter. |
| 929 | builder.Command(). |
| 930 | BuiltTool("host_init_verifier"). |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 931 | FlagWithArg("--out_system=", params.rootDir.String()+"/system") |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 932 | |
| 933 | // Most of the time, if build_image were to call a host tool, it accepts the path to the |
| 934 | // host tool in a field in the prop file. However, it doesn't have that option for fec, which |
| 935 | // it expects to just be on the PATH. Add fec to the PATH. |
| 936 | fec := ctx.Config().HostToolPath(ctx, "fec") |
| 937 | pathToolDirs := []string{filepath.Dir(fec.String())} |
| 938 | |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 939 | builder.Command(). |
| 940 | Textf("PATH=%s:$PATH", strings.Join(pathToolDirs, ":")). |
| 941 | BuiltTool("build_image"). |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 942 | Text(params.rootDir.String()). // input directory |
| 943 | Input(params.propFile). |
| 944 | Implicits(params.toolDeps). |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 945 | Implicit(fec). |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 946 | Implicit(f.fileystemStagingDirTimestamp(ctx)). // assemble the staging directory |
| 947 | Output(params.output). |
| 948 | Text(params.rootDir.String()) // directory where to find fs_config_files|dirs |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 949 | |
Jihoon Kang | 983dd88 | 2025-01-13 23:14:11 +0000 | [diff] [blame] | 950 | if f.properties.Partition_size != nil { |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 951 | assertMaxImageSize(builder, params.output, *f.properties.Partition_size, false) |
Jihoon Kang | 983dd88 | 2025-01-13 23:14:11 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 954 | // rootDir is not deleted. Might be useful for quick inspection. |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 955 | builder.Build("build_"+params.output.String(), fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
| 956 | } |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 957 | |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 958 | func (f *filesystem) propFileForHermeticImg(ctx android.ModuleContext, builder *android.RuleBuilder, inputPropFile android.Path) android.Path { |
| 959 | propFilePinnedTimestamp := android.PathForModuleOut(ctx, "for_target_files", "prop") |
| 960 | builder.Command().Textf("cat").Input(inputPropFile).Flag(">").Output(propFilePinnedTimestamp). |
| 961 | Textf(" && echo use_fixed_timestamp=true >> %s", propFilePinnedTimestamp). |
| 962 | Textf(" && echo block_list=%s >> %s", f.getMapFile(ctx).String(), propFilePinnedTimestamp) // mapfile will be an implicit output |
| 963 | builder.Command().Text("touch").Output(f.getMapFile(ctx)) |
| 964 | return propFilePinnedTimestamp |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 965 | } |
| 966 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 967 | func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.Path { |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 968 | builder := android.NewRuleBuilder(pctx, ctx) |
| 969 | fcBin := android.PathForModuleOut(ctx, "file_contexts.bin") |
| 970 | builder.Command().BuiltTool("sefcontext_compile"). |
| 971 | FlagWithOutput("-o ", fcBin). |
| 972 | Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts))) |
| 973 | builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName())) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 974 | return fcBin |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 975 | } |
| 976 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 977 | func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, android.Paths) { |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 978 | var deps android.Paths |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 979 | var lines []string |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 980 | addStr := func(name string, value string) { |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 981 | lines = append(lines, fmt.Sprintf("%s=%s", name, value)) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 982 | } |
| 983 | addPath := func(name string, path android.Path) { |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 984 | addStr(name, path.String()) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 985 | deps = append(deps, path) |
| 986 | } |
| 987 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 988 | // Type string that build_image.py accepts. |
| 989 | fsTypeStr := func(t fsType) string { |
| 990 | switch t { |
Spandan Das | 9466882 | 2024-10-09 20:51:33 +0000 | [diff] [blame] | 991 | // TODO(372522486): add more types like f2fs, erofs, etc. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 992 | case ext4Type: |
| 993 | return "ext4" |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 994 | case erofsType: |
| 995 | return "erofs" |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 996 | case f2fsType: |
| 997 | return "f2fs" |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 998 | } |
| 999 | panic(fmt.Errorf("unsupported fs type %v", t)) |
| 1000 | } |
| 1001 | |
| 1002 | addStr("fs_type", fsTypeStr(f.fsType(ctx))) |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 1003 | addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/")) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 1004 | addStr("use_dynamic_partition_size", "true") |
| 1005 | addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) |
| 1006 | // b/177813163 deps of the host tools have to be added. Remove this. |
| 1007 | for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} { |
| 1008 | deps = append(deps, ctx.Config().HostToolPath(ctx, t)) |
| 1009 | } |
| 1010 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 1011 | if proptools.Bool(f.properties.Use_avb) { |
| 1012 | addStr("avb_hashtree_enable", "true") |
| 1013 | addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool")) |
| 1014 | algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") |
| 1015 | addStr("avb_algorithm", algorithm) |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 1016 | if f.properties.Avb_private_key != nil { |
| 1017 | key := android.PathForModuleSrc(ctx, *f.properties.Avb_private_key) |
| 1018 | addPath("avb_key_path", key) |
| 1019 | } |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 1020 | addStr("partition_name", f.partitionName()) |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 1021 | avb_add_hashtree_footer_args := "" |
| 1022 | if !proptools.BoolDefault(f.properties.Use_fec, true) { |
| 1023 | avb_add_hashtree_footer_args += " --do_not_generate_fec" |
| 1024 | } |
Nikita Ioffe | 50fb49c | 2025-01-24 13:49:00 +0000 | [diff] [blame] | 1025 | hashAlgorithm := proptools.StringDefault(f.properties.Avb_hash_algorithm, "sha256") |
| 1026 | avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 1027 | if f.properties.Rollback_index != nil { |
| 1028 | rollbackIndex := proptools.Int(f.properties.Rollback_index) |
| 1029 | if rollbackIndex < 0 { |
| 1030 | ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") |
| 1031 | } |
| 1032 | avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex) |
| 1033 | } |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 1034 | avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.os_version:%s", f.partitionName(), ctx.Config().PlatformVersionLastStable()) |
Cole Faust | efeb5c4 | 2024-12-16 10:47:26 -0800 | [diff] [blame] | 1035 | // We're not going to add BuildFingerPrintFile as a dep. If it changed, it's likely because |
| 1036 | // the build number changed, and we don't want to trigger rebuilds solely based on the build |
| 1037 | // number. |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 1038 | avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.fingerprint:{CONTENTS_OF:%s}", f.partitionName(), ctx.Config().BuildFingerprintFile(ctx)) |
Spandan Das | e5c393c | 2024-12-12 19:25:07 +0000 | [diff] [blame] | 1039 | if f.properties.Security_patch != nil && proptools.String(f.properties.Security_patch) != "" { |
| 1040 | avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.security_patch:%s", f.partitionName(), proptools.String(f.properties.Security_patch)) |
| 1041 | } |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 1042 | addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 1043 | } |
| 1044 | |
Cole Faust | 0d46705 | 2024-12-04 17:19:19 -0800 | [diff] [blame] | 1045 | if f.properties.File_contexts != nil && f.properties.Precompiled_file_contexts != nil { |
| 1046 | ctx.ModuleErrorf("file_contexts and precompiled_file_contexts cannot both be set") |
| 1047 | } else if f.properties.File_contexts != nil { |
Spandan Das | f12ff9b | 2025-02-12 22:27:43 +0000 | [diff] [blame] | 1048 | f.selinuxFc = f.buildFileContexts(ctx) |
Cole Faust | 0d46705 | 2024-12-04 17:19:19 -0800 | [diff] [blame] | 1049 | } else if f.properties.Precompiled_file_contexts != nil { |
Spandan Das | f12ff9b | 2025-02-12 22:27:43 +0000 | [diff] [blame] | 1050 | f.selinuxFc = android.PathForModuleSrc(ctx, *f.properties.Precompiled_file_contexts) |
| 1051 | } |
| 1052 | if f.selinuxFc != nil { |
| 1053 | addPath("selinux_fc", f.selinuxFc) |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 1054 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 1055 | if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" { |
| 1056 | addStr("timestamp", timestamp) |
Spandan Das | a0ddc51 | 2025-01-06 20:23:55 +0000 | [diff] [blame] | 1057 | } else if ctx.Config().Getenv("USE_FIXED_TIMESTAMP_IMG_FILES") == "true" { |
| 1058 | addStr("use_fixed_timestamp", "true") |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 1059 | } |
Spandan Das | a0ddc51 | 2025-01-06 20:23:55 +0000 | [diff] [blame] | 1060 | |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 1061 | if uuid := proptools.String(f.properties.Uuid); uuid != "" { |
| 1062 | addStr("uuid", uuid) |
| 1063 | addStr("hash_seed", uuid) |
| 1064 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 1065 | |
Jihoon Kang | 40551e6 | 2025-01-14 21:55:08 +0000 | [diff] [blame] | 1066 | // Disable sparse only when partition size is not defined. disable_sparse has the same |
| 1067 | // effect as <partition name>_disable_sparse. |
| 1068 | if f.properties.Partition_size == nil { |
| 1069 | addStr("disable_sparse", "true") |
| 1070 | } |
Cole Faust | 43a52c7 | 2024-11-26 12:46:08 -0800 | [diff] [blame] | 1071 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 1072 | fst := f.fsType(ctx) |
| 1073 | switch fst { |
| 1074 | case erofsType: |
| 1075 | // Add erofs properties |
Cole Faust | 3e73097 | 2024-12-03 13:12:08 -0800 | [diff] [blame] | 1076 | addStr("erofs_default_compressor", proptools.StringDefault(f.properties.Erofs.Compressor, "lz4hc,9")) |
| 1077 | if f.properties.Erofs.Compress_hints != nil { |
| 1078 | src := android.PathForModuleSrc(ctx, *f.properties.Erofs.Compress_hints) |
| 1079 | addPath("erofs_default_compress_hints", src) |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 1080 | } |
| 1081 | if proptools.BoolDefault(f.properties.Erofs.Sparse, true) { |
| 1082 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b |
| 1083 | addStr("erofs_sparse_flag", "-s") |
| 1084 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 1085 | case f2fsType: |
| 1086 | if proptools.BoolDefault(f.properties.F2fs.Sparse, true) { |
| 1087 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2294;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b;bpv=1;bpt=0 |
| 1088 | addStr("f2fs_sparse_flag", "-S") |
| 1089 | } |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 1090 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 1091 | f.checkFsTypePropertyError(ctx, fst, fsTypeStr(fst)) |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 1092 | |
Jihoon Kang | 983dd88 | 2025-01-13 23:14:11 +0000 | [diff] [blame] | 1093 | if f.properties.Partition_size != nil { |
| 1094 | addStr("partition_size", strconv.FormatInt(*f.properties.Partition_size, 10)) |
| 1095 | } |
| 1096 | |
Jihoon Kang | 6d08d92 | 2025-01-14 18:31:57 +0000 | [diff] [blame] | 1097 | if proptools.BoolDefault(f.properties.Support_casefolding, false) { |
| 1098 | addStr("needs_casefold", "1") |
| 1099 | } |
| 1100 | |
| 1101 | if proptools.BoolDefault(f.properties.Support_project_quota, false) { |
| 1102 | addStr("needs_projid", "1") |
| 1103 | } |
| 1104 | |
| 1105 | if proptools.BoolDefault(f.properties.Enable_compression, false) { |
| 1106 | addStr("needs_compress", "1") |
| 1107 | } |
| 1108 | |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 1109 | sort.Strings(lines) |
| 1110 | |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 1111 | propFilePreProcessing := android.PathForModuleOut(ctx, "prop_pre_processing") |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 1112 | android.WriteFileRule(ctx, propFilePreProcessing, strings.Join(lines, "\n")) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 1113 | propFile := android.PathForModuleOut(ctx, "prop") |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 1114 | ctx.Build(pctx, android.BuildParams{ |
Cole Faust | efeb5c4 | 2024-12-16 10:47:26 -0800 | [diff] [blame] | 1115 | Rule: textFileProcessorRule, |
| 1116 | Input: propFilePreProcessing, |
| 1117 | Output: propFile, |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 1118 | }) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 1119 | return propFile, deps |
| 1120 | } |
| 1121 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 1122 | // This method checks if there is any property set for the fstype(s) other than |
| 1123 | // the current fstype. |
| 1124 | func (f *filesystem) checkFsTypePropertyError(ctx android.ModuleContext, t fsType, fs string) { |
| 1125 | raiseError := func(otherFsType, currentFsType string) { |
| 1126 | errMsg := fmt.Sprintf("%s is non-empty, but FS type is %s\n. Please delete %s properties if this partition should use %s\n", otherFsType, currentFsType, otherFsType, currentFsType) |
| 1127 | ctx.PropertyErrorf(otherFsType, errMsg) |
| 1128 | } |
| 1129 | |
| 1130 | if t != erofsType { |
| 1131 | if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil { |
| 1132 | raiseError("erofs", fs) |
| 1133 | } |
| 1134 | } |
| 1135 | if t != f2fsType { |
| 1136 | if f.properties.F2fs.Sparse != nil { |
| 1137 | raiseError("f2fs", fs) |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 1142 | func includeFilesRootDir(ctx android.ModuleContext) (rootDirs android.Paths, partitions android.Paths) { |
| 1143 | ctx.VisitDirectDepsWithTag(interPartitionInstallDependencyTag, func(m android.Module) { |
| 1144 | if fsProvider, ok := android.OtherModuleProvider(ctx, m, FilesystemProvider); ok { |
| 1145 | rootDirs = append(rootDirs, fsProvider.RootDir) |
| 1146 | partitions = append(partitions, fsProvider.Output) |
| 1147 | } else { |
| 1148 | ctx.PropertyErrorf("include_files_of", "only filesystem modules can be listed in "+ |
| 1149 | "include_files_of but %s is not a filesystem module", m.Name()) |
| 1150 | } |
| 1151 | }) |
| 1152 | return rootDirs, partitions |
| 1153 | } |
| 1154 | |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 1155 | func (f *filesystem) buildCpioImage( |
| 1156 | ctx android.ModuleContext, |
| 1157 | builder *android.RuleBuilder, |
| 1158 | rootDir android.OutputPath, |
| 1159 | compressed bool, |
| 1160 | ) android.Path { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1161 | if proptools.Bool(f.properties.Use_avb) { |
| 1162 | ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+ |
| 1163 | "Consider adding this to bootimg module and signing the entire boot image.") |
| 1164 | } |
| 1165 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 1166 | if proptools.String(f.properties.File_contexts) != "" { |
| 1167 | ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.") |
| 1168 | } |
| 1169 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 1170 | rootDirs, partitions := includeFilesRootDir(ctx) |
| 1171 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 1172 | output := android.PathForModuleOut(ctx, f.installFileName()) |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 1173 | cmd := builder.Command(). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1174 | BuiltTool("mkbootfs"). |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 1175 | Implicit(f.fileystemStagingDirTimestamp(ctx)). |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 1176 | Text(rootDir.String()) // input directory |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 1177 | |
| 1178 | for i := range len(rootDirs) { |
| 1179 | cmd.Text(rootDirs[i].String()) |
| 1180 | } |
| 1181 | cmd.Implicits(partitions) |
| 1182 | |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 1183 | if nodeList := f.properties.Dev_nodes_description_file; nodeList != nil { |
| 1184 | cmd.FlagWithInput("-n ", android.PathForModuleSrc(ctx, proptools.String(nodeList))) |
| 1185 | } |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 1186 | if compressed { |
| 1187 | cmd.Text("|"). |
| 1188 | BuiltTool("lz4"). |
| 1189 | Flag("--favor-decSpeed"). // for faster boot |
| 1190 | Flag("-12"). // maximum compression level |
| 1191 | Flag("-l"). // legacy format for kernel |
| 1192 | Text(">").Output(output) |
| 1193 | } else { |
| 1194 | cmd.Text(">").Output(output) |
| 1195 | } |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1196 | |
| 1197 | // rootDir is not deleted. Might be useful for quick inspection. |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 1198 | builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1199 | |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 1200 | return output |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1201 | } |
| 1202 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 1203 | var validPartitions = []string{ |
| 1204 | "system", |
| 1205 | "userdata", |
| 1206 | "cache", |
| 1207 | "system_other", |
| 1208 | "vendor", |
| 1209 | "product", |
| 1210 | "system_ext", |
| 1211 | "odm", |
| 1212 | "vendor_dlkm", |
| 1213 | "odm_dlkm", |
| 1214 | "system_dlkm", |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 1215 | "ramdisk", |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 1216 | "vendor_ramdisk", |
Jihoon Kang | 3216c98 | 2024-12-02 19:42:20 +0000 | [diff] [blame] | 1217 | "recovery", |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 1220 | func (f *filesystem) buildEventLogtagsFile( |
| 1221 | ctx android.ModuleContext, |
| 1222 | builder *android.RuleBuilder, |
| 1223 | rebasedDir android.OutputPath, |
| 1224 | fullInstallPaths *[]FullInstallPathInfo, |
| 1225 | ) { |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 1226 | if !proptools.Bool(f.properties.Build_logtags) { |
| 1227 | return |
| 1228 | } |
| 1229 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 1230 | etcPath := rebasedDir.Join(ctx, "etc") |
| 1231 | eventLogtagsPath := etcPath.Join(ctx, "event-log-tags") |
| 1232 | builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String()) |
Cole Faust | e4506af | 2024-12-11 14:14:50 -0800 | [diff] [blame] | 1233 | builder.Command().Text("cp").Input(android.MergedLogtagsPath(ctx)).Text(eventLogtagsPath.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 1234 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 1235 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 1236 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc", "event-log-tags"), |
| 1237 | SourcePath: android.MergedLogtagsPath(ctx), |
| 1238 | }) |
| 1239 | |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 1240 | f.appendToEntry(ctx, eventLogtagsPath) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 1241 | } |
| 1242 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 1243 | func (f *filesystem) BuildLinkerConfigFile( |
| 1244 | ctx android.ModuleContext, |
| 1245 | builder *android.RuleBuilder, |
| 1246 | rebasedDir android.OutputPath, |
| 1247 | fullInstallPaths *[]FullInstallPathInfo, |
| 1248 | ) { |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 1249 | if !proptools.Bool(f.properties.Linker_config.Gen_linker_config) { |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 1250 | return |
| 1251 | } |
| 1252 | |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1253 | provideModules, _ := f.getLibsForLinkerConfig(ctx) |
Cole Faust | fee2701 | 2024-12-13 14:10:31 -0800 | [diff] [blame] | 1254 | intermediateOutput := android.PathForModuleOut(ctx, "linker.config.pb") |
| 1255 | linkerconfig.BuildLinkerConfig(ctx, android.PathsForModuleSrc(ctx, f.properties.Linker_config.Linker_config_srcs), provideModules, nil, intermediateOutput) |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 1256 | output := rebasedDir.Join(ctx, "etc", "linker.config.pb") |
Cole Faust | fee2701 | 2024-12-13 14:10:31 -0800 | [diff] [blame] | 1257 | builder.Command().Text("cp").Input(intermediateOutput).Output(output) |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 1258 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 1259 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 1260 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc", "linker.config.pb"), |
| 1261 | SourcePath: intermediateOutput, |
| 1262 | }) |
| 1263 | |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 1264 | f.appendToEntry(ctx, output) |
| 1265 | } |
| 1266 | |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 1267 | func (f *filesystem) ShouldUseVintfFragmentModuleOnly() bool { |
| 1268 | return false |
| 1269 | } |
| 1270 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1271 | type partition interface { |
| 1272 | PartitionType() string |
| 1273 | } |
| 1274 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 1275 | func (f *filesystem) PartitionType() string { |
| 1276 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 1277 | } |
| 1278 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1279 | var _ partition = (*filesystem)(nil) |
| 1280 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 1281 | var _ android.AndroidMkEntriesProvider = (*filesystem)(nil) |
| 1282 | |
| 1283 | // Implements android.AndroidMkEntriesProvider |
| 1284 | func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { |
| 1285 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 1286 | Class: "ETC", |
| 1287 | OutputFile: android.OptionalPathForPath(f.output), |
| 1288 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 1289 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 1290 | entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 1291 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 1292 | entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 1293 | }, |
| 1294 | }, |
| 1295 | }} |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 1296 | } |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 1297 | |
| 1298 | // Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex |
| 1299 | // package to have access to the output file. |
| 1300 | type Filesystem interface { |
| 1301 | android.Module |
| 1302 | OutputPath() android.Path |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 1303 | |
| 1304 | // Returns the output file that is signed by avbtool. If this module is not signed, returns |
| 1305 | // nil. |
| 1306 | SignedOutputPath() android.Path |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | var _ Filesystem = (*filesystem)(nil) |
| 1310 | |
| 1311 | func (f *filesystem) OutputPath() android.Path { |
| 1312 | return f.output |
| 1313 | } |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 1314 | |
| 1315 | func (f *filesystem) SignedOutputPath() android.Path { |
| 1316 | if proptools.Bool(f.properties.Use_avb) { |
| 1317 | return f.OutputPath() |
| 1318 | } |
| 1319 | return nil |
| 1320 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 1321 | |
| 1322 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition. |
| 1323 | // Note that "apex" module installs its contents to "apex"(fake partition) as well |
| 1324 | // for symbol lookup by imitating "activated" paths. |
| 1325 | func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { |
Cole Faust | b8e280f | 2025-01-16 16:33:26 -0800 | [diff] [blame] | 1326 | return f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, f.filesystemBuilder.FilterPackagingSpec, f.filesystemBuilder.ModifyPackagingSpec) |
| 1327 | } |
| 1328 | |
| 1329 | // Dexpreopt files are installed to system_other. Collect the packaingSpecs for the dexpreopt files |
| 1330 | // from this partition to export to the system_other partition later. |
| 1331 | func (f *filesystem) systemOtherFiles(ctx android.ModuleContext) map[string]android.PackagingSpec { |
| 1332 | filter := func(spec android.PackagingSpec) bool { |
| 1333 | // For some reason system_other packaging specs don't set the partition field. |
| 1334 | return strings.HasPrefix(spec.RelPathInPackage(), "system_other/") |
| 1335 | } |
| 1336 | modifier := func(spec *android.PackagingSpec) { |
| 1337 | spec.SetRelPathInPackage(strings.TrimPrefix(spec.RelPathInPackage(), "system_other/")) |
| 1338 | spec.SetPartition("system_other") |
| 1339 | } |
| 1340 | return f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, filter, modifier) |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 1341 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 1342 | |
| 1343 | func sha1sum(values []string) string { |
| 1344 | h := sha256.New() |
| 1345 | for _, value := range values { |
| 1346 | io.WriteString(h, value) |
| 1347 | } |
| 1348 | return fmt.Sprintf("%x", h.Sum(nil)) |
| 1349 | } |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 1350 | |
| 1351 | // Base cc.UseCoverage |
| 1352 | |
| 1353 | var _ cc.UseCoverage = (*filesystem)(nil) |
| 1354 | |
Colin Cross | e1a8555 | 2024-06-14 12:17:37 -0700 | [diff] [blame] | 1355 | func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 1356 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 1357 | } |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1358 | |
| 1359 | // android_filesystem_defaults |
| 1360 | |
| 1361 | type filesystemDefaults struct { |
| 1362 | android.ModuleBase |
| 1363 | android.DefaultsModuleBase |
| 1364 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 1365 | properties FilesystemProperties |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | // android_filesystem_defaults is a default module for android_filesystem and android_system_image |
| 1369 | func filesystemDefaultsFactory() android.Module { |
| 1370 | module := &filesystemDefaults{} |
| 1371 | module.AddProperties(&module.properties) |
| 1372 | module.AddProperties(&android.PackagingProperties{}) |
| 1373 | android.InitDefaultsModule(module) |
| 1374 | return module |
| 1375 | } |
| 1376 | |
| 1377 | func (f *filesystemDefaults) PartitionType() string { |
| 1378 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 1379 | } |
| 1380 | |
| 1381 | var _ partition = (*filesystemDefaults)(nil) |
| 1382 | |
| 1383 | func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1384 | validatePartitionType(ctx, f) |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame] | 1385 | android.SetProvider(ctx, FilesystemDefaultsInfoProvider, FilesystemDefaultsInfo{ |
| 1386 | PartitionType: f.PartitionType(), |
| 1387 | }) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1388 | } |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1389 | |
| 1390 | // getLibsForLinkerConfig returns |
| 1391 | // 1. A list of libraries installed in this filesystem |
| 1392 | // 2. A list of dep libraries _not_ installed in this filesystem |
| 1393 | // |
| 1394 | // `linkerconfig.BuildLinkerConfig` will convert these two to a linker.config.pb for the filesystem |
| 1395 | // (1) will be added to --provideLibs if they are C libraries with a stable interface (has stubs) |
| 1396 | // (2) will be added to --requireLibs if they are C libraries with a stable interface (has stubs) |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1397 | func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]android.ModuleProxy, []android.ModuleProxy) { |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1398 | // we need "Module"s for packaging items |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1399 | modulesInPackageByModule := make(map[android.ModuleProxy]bool) |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1400 | modulesInPackageByName := make(map[string]bool) |
| 1401 | |
| 1402 | deps := f.gatherFilteredPackagingSpecs(ctx) |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1403 | ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool { |
| 1404 | if !android.OtherModuleProviderOrDefault(ctx, child, android.CommonModuleInfoKey).Enabled { |
Yu Liu | 9c6b676 | 2025-01-08 22:04:35 +0000 | [diff] [blame] | 1405 | return false |
| 1406 | } |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1407 | for _, ps := range android.OtherModuleProviderOrDefault( |
| 1408 | ctx, child, android.InstallFilesProvider).PackagingSpecs { |
Spandan Das | ecf667f | 2024-12-05 00:58:56 +0000 | [diff] [blame] | 1409 | if _, ok := deps[ps.RelPathInPackage()]; ok && ps.Partition() == f.PartitionType() { |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1410 | modulesInPackageByModule[child] = true |
| 1411 | modulesInPackageByName[child.Name()] = true |
| 1412 | return true |
| 1413 | } |
| 1414 | } |
| 1415 | return true |
| 1416 | }) |
| 1417 | |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1418 | provideModules := make([]android.ModuleProxy, 0, len(modulesInPackageByModule)) |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1419 | for mod := range modulesInPackageByModule { |
| 1420 | provideModules = append(provideModules, mod) |
| 1421 | } |
| 1422 | |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1423 | var requireModules []android.ModuleProxy |
| 1424 | ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool { |
| 1425 | if !android.OtherModuleProviderOrDefault(ctx, child, android.CommonModuleInfoKey).Enabled { |
Yu Liu | 9c6b676 | 2025-01-08 22:04:35 +0000 | [diff] [blame] | 1426 | return false |
| 1427 | } |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1428 | _, parentInPackage := modulesInPackageByModule[parent] |
| 1429 | _, childInPackageName := modulesInPackageByName[child.Name()] |
| 1430 | |
| 1431 | // When parent is in the package, and child (or its variant) is not, this can be from an interface. |
| 1432 | if parentInPackage && !childInPackageName { |
| 1433 | requireModules = append(requireModules, child) |
| 1434 | } |
| 1435 | return true |
| 1436 | }) |
| 1437 | |
| 1438 | return provideModules, requireModules |
| 1439 | } |
Cole Faust | 26bdac5 | 2024-11-19 13:37:53 -0800 | [diff] [blame] | 1440 | |
| 1441 | // Checks that the given file doesn't exceed the given size, and will also print a warning |
| 1442 | // if it's nearing the maximum size. Equivalent to assert-max-image-size in make: |
| 1443 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/definitions.mk;l=3455;drc=993c4de29a02a6accd60ceaaee153307e1a18d10 |
| 1444 | func assertMaxImageSize(builder *android.RuleBuilder, image android.Path, maxSize int64, addAvbLater bool) { |
| 1445 | if addAvbLater { |
| 1446 | // The value 69632 is derived from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in avbtool. |
| 1447 | // Logic copied from make: |
| 1448 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=228;drc=a6a0007ef24e16c0b79f439beac4a118416717e6 |
| 1449 | maxSize -= 69632 |
| 1450 | } |
| 1451 | cmd := builder.Command() |
| 1452 | cmd.Textf(`file="%s"; maxsize="%d";`+ |
| 1453 | `total=$(stat -c "%%s" "$file" | tr -d '\n');`+ |
| 1454 | `if [ "$total" -gt "$maxsize" ]; then `+ |
| 1455 | ` echo "error: $file too large ($total > $maxsize)";`+ |
| 1456 | ` false;`+ |
| 1457 | `elif [ "$total" -gt $((maxsize - 32768)) ]; then `+ |
| 1458 | ` echo "WARNING: $file approaching size limit ($total now; limit $maxsize)";`+ |
| 1459 | `fi`, |
| 1460 | image, maxSize) |
| 1461 | cmd.Implicit(image) |
| 1462 | } |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 1463 | |
| 1464 | // addAutogeneratedRroDeps walks the transitive closure of vendor and product partitions. |
| 1465 | // It visits apps installed in system and system_ext partitions, and adds the autogenerated |
| 1466 | // RRO modules to its own deps. |
| 1467 | func addAutogeneratedRroDeps(ctx android.BottomUpMutatorContext) { |
| 1468 | f, ok := ctx.Module().(*filesystem) |
| 1469 | if !ok { |
| 1470 | return |
| 1471 | } |
| 1472 | thisPartition := f.PartitionType() |
| 1473 | if thisPartition != "vendor" && thisPartition != "product" { |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 1474 | if f.properties.Android_filesystem_deps.System != nil { |
| 1475 | ctx.PropertyErrorf("android_filesystem_deps.system", "only vendor or product partitions can use android_filesystem_deps") |
| 1476 | } |
| 1477 | if f.properties.Android_filesystem_deps.System_ext != nil { |
| 1478 | ctx.PropertyErrorf("android_filesystem_deps.system_ext", "only vendor or product partitions can use android_filesystem_deps") |
| 1479 | } |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 1480 | return |
| 1481 | } |
| 1482 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 1483 | depTag := ctx.OtherModuleDependencyTag(child) |
| 1484 | if parent.Name() == f.Name() && depTag != interPartitionDependencyTag { |
| 1485 | return false // This is a module listed in deps of vendor/product filesystem |
| 1486 | } |
| 1487 | if vendorOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "vendor"); ctx.OtherModuleExists(vendorOverlay) && thisPartition == "vendor" { |
| 1488 | ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, vendorOverlay) |
| 1489 | } |
| 1490 | if productOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "product"); ctx.OtherModuleExists(productOverlay) && thisPartition == "product" { |
| 1491 | ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, productOverlay) |
| 1492 | } |
| 1493 | return true |
| 1494 | }) |
| 1495 | } |
Spandan Das | 6ec1fcf | 2025-02-11 22:51:51 +0000 | [diff] [blame] | 1496 | |
| 1497 | func (f *filesystem) MakeVars(ctx android.MakeVarsModuleContext) { |
| 1498 | if f.Name() == ctx.Config().SoongDefinedSystemImage() { |
| 1499 | ctx.StrictRaw("SOONG_DEFINED_SYSTEM_IMAGE_PATH", f.output.String()) |
| 1500 | } |
| 1501 | } |