Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 1 | // Copyright (C) 2024 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 fsgen |
| 16 | |
| 17 | import ( |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 18 | "crypto/sha256" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 19 | "fmt" |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 20 | "path/filepath" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 21 | "strconv" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 22 | "strings" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 23 | |
| 24 | "android/soong/android" |
| 25 | "android/soong/filesystem" |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 26 | "android/soong/kernel" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 27 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint/parser" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" |
| 31 | ) |
| 32 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 33 | var pctx = android.NewPackageContext("android/soong/fsgen") |
| 34 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 35 | func init() { |
| 36 | registerBuildComponents(android.InitRegistrationContext) |
| 37 | } |
| 38 | |
| 39 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 40 | ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 41 | ctx.PreDepsMutators(RegisterCollectFileSystemDepsMutators) |
| 42 | } |
| 43 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 44 | type filesystemCreatorProps struct { |
| 45 | Generated_partition_types []string `blueprint:"mutated"` |
| 46 | Unsupported_partition_types []string `blueprint:"mutated"` |
| 47 | } |
| 48 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 49 | type filesystemCreator struct { |
| 50 | android.ModuleBase |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 51 | |
| 52 | properties filesystemCreatorProps |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | func filesystemCreatorFactory() android.Module { |
| 56 | module := &filesystemCreator{} |
| 57 | |
Cole Faust | 6978879 | 2024-10-10 11:00:36 -0700 | [diff] [blame] | 58 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 59 | module.AddProperties(&module.properties) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 60 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
Jihoon Kang | 675d468 | 2024-10-24 23:45:11 +0000 | [diff] [blame] | 61 | generatedPrebuiltEtcModuleNames := createPrebuiltEtcModules(ctx) |
| 62 | createFsGenState(ctx, generatedPrebuiltEtcModuleNames) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 63 | module.createInternalModules(ctx) |
| 64 | }) |
| 65 | |
| 66 | return module |
| 67 | } |
| 68 | |
| 69 | func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) { |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 70 | soongGeneratedPartitions := &ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions |
| 71 | for _, partitionType := range *soongGeneratedPartitions { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 72 | if f.createPartition(ctx, partitionType) { |
| 73 | f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType) |
| 74 | } else { |
| 75 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType) |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 76 | _, *soongGeneratedPartitions = android.RemoveFromList(partitionType, *soongGeneratedPartitions) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 77 | } |
| 78 | } |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 79 | f.createDeviceModule(ctx) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 82 | func generatedModuleName(cfg android.Config, suffix string) string { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 83 | prefix := "soong" |
| 84 | if cfg.HasDeviceProduct() { |
| 85 | prefix = cfg.DeviceProduct() |
| 86 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 87 | return fmt.Sprintf("%s_generated_%s", prefix, suffix) |
| 88 | } |
| 89 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 90 | func generatedModuleNameForPartition(cfg android.Config, partitionType string) string { |
| 91 | return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType)) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 94 | func (f *filesystemCreator) createDeviceModule(ctx android.LoadHookContext) { |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 95 | baseProps := &struct { |
| 96 | Name *string |
| 97 | }{ |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 98 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")), |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Priyanka Advani (xWF) | dafaa7f | 2024-10-21 22:55:13 +0000 | [diff] [blame] | 101 | // Currently, only the system and system_ext partition module is created. |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 102 | partitionProps := &filesystem.PartitionNameProperties{} |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 103 | if android.InList("system", f.properties.Generated_partition_types) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 104 | partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system")) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 105 | } |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 106 | if android.InList("system_ext", f.properties.Generated_partition_types) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 107 | partitionProps.System_ext_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext")) |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 108 | } |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 109 | if android.InList("vendor", f.properties.Generated_partition_types) { |
Spandan Das | e3b6531 | 2024-10-22 00:27:27 +0000 | [diff] [blame] | 110 | partitionProps.Vendor_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor")) |
| 111 | } |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 112 | if android.InList("product", f.properties.Generated_partition_types) { |
Jihoon Kang | 6dd13b6 | 2024-10-22 23:21:02 +0000 | [diff] [blame] | 113 | partitionProps.Product_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product")) |
| 114 | } |
Liana Kazanova | 50cb131 | 2024-11-07 20:47:49 +0000 | [diff] [blame] | 115 | if android.InList("odm", f.properties.Generated_partition_types) { |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 116 | partitionProps.Odm_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm")) |
| 117 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 118 | |
| 119 | ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 122 | func partitionSpecificFsProps(fsProps *filesystem.FilesystemProperties, partitionType string) { |
| 123 | switch partitionType { |
| 124 | case "system": |
| 125 | fsProps.Build_logtags = proptools.BoolPtr(true) |
| 126 | // https://source.corp.google.com/h/googleplex-android/platform/build//639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0 |
| 127 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
Spandan Das | a8fa6b4 | 2024-10-23 00:45:29 +0000 | [diff] [blame] | 128 | // Identical to that of the generic_system_image |
| 129 | fsProps.Fsverity.Inputs = []string{ |
| 130 | "etc/boot-image.prof", |
| 131 | "etc/dirty-image-objects", |
| 132 | "etc/preloaded-classes", |
| 133 | "etc/classpaths/*.pb", |
| 134 | "framework/*", |
| 135 | "framework/*/*", // framework/{arch} |
| 136 | "framework/oat/*/*", // framework/oat/{arch} |
| 137 | } |
| 138 | fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"} |
mrziwang | 9afc298 | 2024-11-05 14:29:48 -0800 | [diff] [blame] | 139 | // TODO(b/377734331): only generate the symlinks if the relevant partitions exist |
| 140 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 141 | filesystem.SymlinkDefinition{ |
| 142 | Target: proptools.StringPtr("/product"), |
| 143 | Name: proptools.StringPtr("system/product"), |
| 144 | }, |
| 145 | filesystem.SymlinkDefinition{ |
| 146 | Target: proptools.StringPtr("/system_ext"), |
| 147 | Name: proptools.StringPtr("system/system_ext"), |
| 148 | }, |
| 149 | filesystem.SymlinkDefinition{ |
| 150 | Target: proptools.StringPtr("/vendor"), |
| 151 | Name: proptools.StringPtr("system/vendor"), |
| 152 | }, |
| 153 | filesystem.SymlinkDefinition{ |
| 154 | Target: proptools.StringPtr("/system_dlkm/lib/modules"), |
| 155 | Name: proptools.StringPtr("system/lib/modules"), |
| 156 | }, |
| 157 | } |
| 158 | fsProps.Base_dir = proptools.StringPtr("system") |
Spandan Das | a8fa6b4 | 2024-10-23 00:45:29 +0000 | [diff] [blame] | 159 | case "system_ext": |
| 160 | fsProps.Fsverity.Inputs = []string{ |
| 161 | "framework/*", |
| 162 | "framework/*/*", // framework/{arch} |
| 163 | "framework/oat/*/*", // framework/oat/{arch} |
| 164 | } |
| 165 | fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"} |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 166 | case "product": |
| 167 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
| 168 | case "vendor": |
| 169 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 170 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 171 | filesystem.SymlinkDefinition{ |
| 172 | Target: proptools.StringPtr("/odm"), |
| 173 | Name: proptools.StringPtr("vendor/odm"), |
| 174 | }, |
| 175 | filesystem.SymlinkDefinition{ |
| 176 | Target: proptools.StringPtr("/vendor_dlkm/lib/modules"), |
| 177 | Name: proptools.StringPtr("vendor/lib/modules"), |
| 178 | }, |
| 179 | } |
| 180 | fsProps.Base_dir = proptools.StringPtr("vendor") |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 181 | case "odm": |
| 182 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 183 | filesystem.SymlinkDefinition{ |
| 184 | Target: proptools.StringPtr("/odm_dlkm/lib/modules"), |
| 185 | Name: proptools.StringPtr("odm/lib/modules"), |
| 186 | }, |
| 187 | } |
| 188 | fsProps.Base_dir = proptools.StringPtr("odm") |
| 189 | |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 190 | } |
| 191 | } |
Spandan Das | cbe641a | 2024-10-14 21:07:34 +0000 | [diff] [blame] | 192 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 193 | // Creates a soong module to build the given partition. Returns false if we can't support building |
| 194 | // it. |
| 195 | func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool { |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 196 | baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType))) |
| 197 | |
| 198 | fsProps, supported := generateFsProps(ctx, partitionType) |
| 199 | if !supported { |
| 200 | return false |
mrziwang | a077b94 | 2024-10-16 16:00:06 -0700 | [diff] [blame] | 201 | } |
mrziwang | a077b94 | 2024-10-16 16:00:06 -0700 | [diff] [blame] | 202 | |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 203 | if partitionType == "vendor" || partitionType == "product" { |
Spandan Das | 173256b | 2024-10-31 19:59:30 +0000 | [diff] [blame] | 204 | fsProps.Linkerconfig.Gen_linker_config = proptools.BoolPtr(true) |
| 205 | fsProps.Linkerconfig.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType) |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 208 | if partitionType == "system_dlkm" { |
| 209 | kernelModules := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules |
| 210 | f.createPrebuiltKernelModules(ctx, partitionType, kernelModules) |
| 211 | } |
| 212 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 213 | var module android.Module |
| 214 | if partitionType == "system" { |
| 215 | module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps) |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 216 | } else if partitionType == "system_dlkm" { |
| 217 | // Do not set partition_type. build/soong/android/paths#modulePartition currently does not support dlkm |
| 218 | // partitions. Since `android_filesystem` uses a partition based filter, setting the partition here |
| 219 | // would result in missing in entries. |
| 220 | module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps) |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 221 | } else { |
| 222 | // Explicitly set the partition. |
| 223 | fsProps.Partition_type = proptools.StringPtr(partitionType) |
| 224 | module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps) |
| 225 | } |
| 226 | module.HideFromMake() |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 227 | if partitionType == "vendor" { |
Spandan Das | 4cd93b5 | 2024-11-05 23:27:03 +0000 | [diff] [blame] | 228 | f.createVendorBuildProp(ctx) |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 229 | } |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 230 | return true |
| 231 | } |
| 232 | |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 233 | // createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the |
Spandan Das | 7b25a51 | 2024-11-06 20:41:26 +0000 | [diff] [blame] | 234 | // autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency. |
| 235 | // This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view. |
| 236 | |
| 237 | // The input `kernelModules` is a space separated list of .ko files in the workspace. |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 238 | func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string, kernelModules []string) { |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 239 | fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
Spandan Das | 7b25a51 | 2024-11-06 20:41:26 +0000 | [diff] [blame] | 240 | name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType)) |
| 241 | props := &struct { |
| 242 | Name *string |
| 243 | Srcs []string |
| 244 | }{ |
| 245 | Name: proptools.StringPtr(name), |
| 246 | Srcs: kernelModules, |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 247 | } |
Spandan Das | 7b25a51 | 2024-11-06 20:41:26 +0000 | [diff] [blame] | 248 | kernelModule := ctx.CreateModuleInDirectory( |
| 249 | kernel.PrebuiltKernelModulesFactory, |
| 250 | ".", // create in root directory for now |
| 251 | props, |
| 252 | ) |
| 253 | kernelModule.HideFromMake() |
| 254 | // Add to deps |
| 255 | (*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config()) |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Spandan Das | 4cd93b5 | 2024-11-05 23:27:03 +0000 | [diff] [blame] | 258 | // Create a build_prop and android_info module. This will be used to create /vendor/build.prop |
| 259 | func (f *filesystemCreator) createVendorBuildProp(ctx android.LoadHookContext) { |
| 260 | // Create a android_info for vendor |
| 261 | // The board info files might be in a directory outside the root soong namespace, so create |
| 262 | // the module in "." |
| 263 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 264 | androidInfoProps := &struct { |
| 265 | Name *string |
| 266 | Board_info_files []string |
| 267 | Bootloader_board_name *string |
| 268 | }{ |
| 269 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "android-info.prop")), |
| 270 | Board_info_files: partitionVars.BoardInfoFiles, |
| 271 | } |
| 272 | if len(androidInfoProps.Board_info_files) == 0 { |
| 273 | androidInfoProps.Bootloader_board_name = proptools.StringPtr(partitionVars.BootLoaderBoardName) |
| 274 | } |
| 275 | androidInfoProp := ctx.CreateModuleInDirectory( |
| 276 | android.AndroidInfoFactory, |
| 277 | ".", |
| 278 | androidInfoProps, |
| 279 | ) |
| 280 | androidInfoProp.HideFromMake() |
| 281 | // Create a build prop for vendor |
| 282 | vendorBuildProps := &struct { |
| 283 | Name *string |
| 284 | Vendor *bool |
| 285 | Stem *string |
| 286 | Product_config *string |
| 287 | Android_info *string |
| 288 | }{ |
| 289 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")), |
| 290 | Vendor: proptools.BoolPtr(true), |
| 291 | Stem: proptools.StringPtr("build.prop"), |
| 292 | Product_config: proptools.StringPtr(":product_config"), |
| 293 | Android_info: proptools.StringPtr(":" + androidInfoProp.Name()), |
| 294 | } |
| 295 | vendorBuildProp := ctx.CreateModule( |
| 296 | android.BuildPropFactory, |
| 297 | vendorBuildProps, |
| 298 | ) |
| 299 | vendorBuildProp.HideFromMake() |
| 300 | } |
| 301 | |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 302 | // createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions |
| 303 | // 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list) |
| 304 | // 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list) |
| 305 | // It creates a filegroup for each file in the fragment list |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 306 | // The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`. |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 307 | func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string { |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 308 | ret := []string{} |
| 309 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 310 | var linkerConfigSrcs []string |
| 311 | if partitionType == "vendor" { |
| 312 | linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs) |
| 313 | } else if partitionType == "product" { |
| 314 | linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs) |
| 315 | } else { |
| 316 | ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`") |
| 317 | } |
| 318 | |
| 319 | if len(linkerConfigSrcs) > 0 { |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 320 | // Create a filegroup, and add `:<filegroup_name>` to ret. |
| 321 | for index, linkerConfigSrc := range linkerConfigSrcs { |
| 322 | dir := filepath.Dir(linkerConfigSrc) |
| 323 | base := filepath.Base(linkerConfigSrc) |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 324 | fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index))) |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 325 | srcs := []string{base} |
| 326 | fgProps := &struct { |
| 327 | Name *string |
| 328 | Srcs proptools.Configurable[[]string] |
| 329 | }{ |
| 330 | Name: proptools.StringPtr(fgName), |
| 331 | Srcs: proptools.NewSimpleConfigurable(srcs), |
| 332 | } |
| 333 | ctx.CreateModuleInDirectory( |
| 334 | android.FileGroupFactory, |
| 335 | dir, |
| 336 | fgProps, |
| 337 | ) |
| 338 | ret = append(ret, ":"+fgName) |
| 339 | } |
| 340 | } |
| 341 | return ret |
| 342 | } |
| 343 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 344 | type filesystemBaseProperty struct { |
| 345 | Name *string |
| 346 | Compile_multilib *string |
| 347 | } |
| 348 | |
| 349 | func generateBaseProps(namePtr *string) *filesystemBaseProperty { |
| 350 | return &filesystemBaseProperty{ |
| 351 | Name: namePtr, |
| 352 | Compile_multilib: proptools.StringPtr("both"), |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 357 | fsProps := &filesystem.FilesystemProperties{} |
| 358 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 359 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 360 | specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType] |
| 361 | |
| 362 | // BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE |
| 363 | fsType := specificPartitionVars.BoardFileSystemType |
| 364 | if fsType == "" { |
| 365 | fsType = "ext4" //default |
| 366 | } |
| 367 | fsProps.Type = proptools.StringPtr(fsType) |
| 368 | if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() { |
| 369 | // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs |
| 370 | return nil, false |
| 371 | } |
| 372 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 373 | // Don't build this module on checkbuilds, the soong-built partitions are still in-progress |
| 374 | // and sometimes don't build. |
| 375 | fsProps.Unchecked_module = proptools.BoolPtr(true) |
| 376 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 377 | // BOARD_AVB_ENABLE |
| 378 | fsProps.Use_avb = proptools.BoolPtr(partitionVars.BoardAvbEnable) |
| 379 | // BOARD_AVB_KEY_PATH |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 380 | fsProps.Avb_private_key = proptools.StringPtr(specificPartitionVars.BoardAvbKeyPath) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 381 | // BOARD_AVB_ALGORITHM |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 382 | fsProps.Avb_algorithm = proptools.StringPtr(specificPartitionVars.BoardAvbAlgorithm) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 383 | // BOARD_AVB_SYSTEM_ROLLBACK_INDEX |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 384 | if rollbackIndex, err := strconv.ParseInt(specificPartitionVars.BoardAvbRollbackIndex, 10, 64); err == nil { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 385 | fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex) |
| 386 | } |
| 387 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 388 | fsProps.Partition_name = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 389 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 390 | fsProps.Base_dir = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 391 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 392 | fsProps.Is_auto_generated = proptools.BoolPtr(true) |
| 393 | |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 394 | partitionSpecificFsProps(fsProps, partitionType) |
| 395 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 396 | // system_image properties that are not set: |
| 397 | // - filesystemProperties.Avb_hash_algorithm |
| 398 | // - filesystemProperties.File_contexts |
| 399 | // - filesystemProperties.Dirs |
| 400 | // - filesystemProperties.Symlinks |
| 401 | // - filesystemProperties.Fake_timestamp |
| 402 | // - filesystemProperties.Uuid |
| 403 | // - filesystemProperties.Mount_point |
| 404 | // - filesystemProperties.Include_make_built_files |
| 405 | // - filesystemProperties.Build_logtags |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 406 | // - systemImageProperties.Linker_config_src |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 407 | |
| 408 | return fsProps, true |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | func (f *filesystemCreator) createDiffTest(ctx android.ModuleContext, partitionType string) android.Path { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 412 | partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 413 | systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag) |
| 414 | filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider) |
| 415 | if !ok { |
| 416 | ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName) |
| 417 | } |
| 418 | makeFileList := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partitionType)) |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 419 | diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 420 | |
| 421 | builder := android.NewRuleBuilder(pctx, ctx) |
| 422 | builder.Command().BuiltTool("file_list_diff"). |
| 423 | Input(makeFileList). |
| 424 | Input(filesystemInfo.FileListFile). |
Cole Faust | 5630157 | 2024-11-07 15:22:42 -0800 | [diff] [blame^] | 425 | Text(partitionModuleName) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 426 | builder.Command().Text("touch").Output(diffTestResultFile) |
| 427 | builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test") |
| 428 | return diffTestResultFile |
| 429 | } |
| 430 | |
| 431 | func createFailingCommand(ctx android.ModuleContext, message string) android.Path { |
| 432 | hasher := sha256.New() |
| 433 | hasher.Write([]byte(message)) |
| 434 | filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil)) |
| 435 | file := android.PathForModuleOut(ctx, filename) |
| 436 | builder := android.NewRuleBuilder(pctx, ctx) |
| 437 | builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message)) |
| 438 | builder.Command().Text("exit 1 #").Output(file) |
| 439 | builder.Build("failing command "+filename, "failing command "+filename) |
| 440 | return file |
| 441 | } |
| 442 | |
| 443 | type systemImageDepTagType struct { |
| 444 | blueprint.BaseDependencyTag |
| 445 | } |
| 446 | |
| 447 | var generatedFilesystemDepTag systemImageDepTagType |
| 448 | |
| 449 | func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 450 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 451 | ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 452 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 456 | if ctx.ModuleDir() != "build/soong/fsgen" { |
| 457 | ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen") |
| 458 | } |
| 459 | f.HideFromMake() |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 460 | |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 461 | var content strings.Builder |
| 462 | generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp") |
| 463 | for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions { |
| 464 | content.WriteString(generateBpContent(ctx, partition)) |
| 465 | content.WriteString("\n") |
| 466 | } |
| 467 | android.WriteFileRule(ctx, generatedBp, content.String()) |
| 468 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 469 | ctx.Phony("product_config_to_bp", generatedBp) |
| 470 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 471 | var diffTestFiles []android.Path |
| 472 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | 72f812f | 2024-10-17 18:46:24 +0000 | [diff] [blame] | 473 | diffTestFile := f.createDiffTest(ctx, partitionType) |
| 474 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 475 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 476 | } |
| 477 | for _, partitionType := range f.properties.Unsupported_partition_types { |
Jihoon Kang | 72f812f | 2024-10-17 18:46:24 +0000 | [diff] [blame] | 478 | diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType)) |
| 479 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 480 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 481 | } |
| 482 | ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 483 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 484 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 485 | func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string { |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 486 | fsProps, fsTypeSupported := generateFsProps(ctx, partitionType) |
| 487 | if !fsTypeSupported { |
| 488 | return "" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 489 | } |
| 490 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 491 | baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType))) |
mrziwang | 2a506cf | 2024-10-17 15:38:37 -0700 | [diff] [blame] | 492 | deps := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).fsDeps[partitionType] |
| 493 | depProps := generateDepStruct(*deps) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 494 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 495 | result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps}) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 496 | if err != nil { |
Cole Faust | ae3e1d3 | 2024-11-05 13:22:50 -0800 | [diff] [blame] | 497 | ctx.ModuleErrorf("%s", err.Error()) |
| 498 | return "" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 501 | moduleType := "android_filesystem" |
| 502 | if partitionType == "system" { |
| 503 | moduleType = "android_system_image" |
| 504 | } |
| 505 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 506 | file := &parser.File{ |
| 507 | Defs: []parser.Definition{ |
| 508 | &parser.Module{ |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 509 | Type: moduleType, |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 510 | Map: *result, |
| 511 | }, |
| 512 | }, |
| 513 | } |
| 514 | bytes, err := parser.Print(file) |
| 515 | if err != nil { |
| 516 | ctx.ModuleErrorf(err.Error()) |
| 517 | } |
| 518 | return strings.TrimSpace(string(bytes)) |
| 519 | } |