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