blob: 672353919670eab09c794bf5ef0ec6d3f8156ee0 [file] [log] [blame]
Jihoon Kang98047cf2024-10-02 17:13:54 +00001// 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
15package fsgen
16
17import (
Cole Faust92ccbe22024-10-03 14:38:37 -070018 "crypto/sha256"
Jihoon Kang98047cf2024-10-02 17:13:54 +000019 "fmt"
Spandan Das312cc412024-10-29 18:20:11 +000020 "path/filepath"
Jihoon Kang98047cf2024-10-02 17:13:54 +000021 "strconv"
mrziwang8f86c882024-10-03 12:34:33 -070022 "strings"
mrziwang8f86c882024-10-03 12:34:33 -070023
24 "android/soong/android"
25 "android/soong/filesystem"
Spandan Das5e336422024-11-01 22:31:20 +000026 "android/soong/kernel"
Jihoon Kang98047cf2024-10-02 17:13:54 +000027
Cole Faust92ccbe22024-10-03 14:38:37 -070028 "github.com/google/blueprint"
mrziwang8f86c882024-10-03 12:34:33 -070029 "github.com/google/blueprint/parser"
Jihoon Kang98047cf2024-10-02 17:13:54 +000030 "github.com/google/blueprint/proptools"
31)
32
Cole Faust92ccbe22024-10-03 14:38:37 -070033var pctx = android.NewPackageContext("android/soong/fsgen")
34
Jihoon Kang98047cf2024-10-02 17:13:54 +000035func init() {
36 registerBuildComponents(android.InitRegistrationContext)
37}
38
39func registerBuildComponents(ctx android.RegistrationContext) {
40 ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory)
mrziwang8f86c882024-10-03 12:34:33 -070041 ctx.PreDepsMutators(RegisterCollectFileSystemDepsMutators)
42}
43
Cole Faust92ccbe22024-10-03 14:38:37 -070044type filesystemCreatorProps struct {
45 Generated_partition_types []string `blueprint:"mutated"`
46 Unsupported_partition_types []string `blueprint:"mutated"`
Cole Faust3552eb62024-11-06 18:07:26 -080047
48 Vbmeta_module_names []string `blueprint:"mutated"`
49 Vbmeta_partition_names []string `blueprint:"mutated"`
Cole Faustf2a6e8b2024-11-14 10:54:48 -080050
Cole Faust24938e22024-11-18 14:01:58 -080051 Boot_image string `blueprint:"mutated" android:"path_device_first"`
52 Vendor_boot_image string `blueprint:"mutated" android:"path_device_first"`
Cole Faust92ccbe22024-10-03 14:38:37 -070053}
54
Jihoon Kang98047cf2024-10-02 17:13:54 +000055type filesystemCreator struct {
56 android.ModuleBase
Cole Faust92ccbe22024-10-03 14:38:37 -070057
58 properties filesystemCreatorProps
Jihoon Kang98047cf2024-10-02 17:13:54 +000059}
60
61func filesystemCreatorFactory() android.Module {
62 module := &filesystemCreator{}
63
Cole Faust69788792024-10-10 11:00:36 -070064 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
Cole Faust92ccbe22024-10-03 14:38:37 -070065 module.AddProperties(&module.properties)
Jihoon Kang98047cf2024-10-02 17:13:54 +000066 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
Jihoon Kang675d4682024-10-24 23:45:11 +000067 generatedPrebuiltEtcModuleNames := createPrebuiltEtcModules(ctx)
Jihoon Kang04f12c92024-11-12 23:03:08 +000068 avbpubkeyGenerated := createAvbpubkeyModule(ctx)
69 createFsGenState(ctx, generatedPrebuiltEtcModuleNames, avbpubkeyGenerated)
Cole Faust953476f2024-11-14 14:11:29 -080070 module.createAvbKeyFilegroups(ctx)
Jihoon Kang98047cf2024-10-02 17:13:54 +000071 module.createInternalModules(ctx)
72 })
73
74 return module
75}
76
Cole Faustf2a6e8b2024-11-14 10:54:48 -080077func generatedPartitions(ctx android.LoadHookContext) []string {
Cole Faust24938e22024-11-18 14:01:58 -080078 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Cole Faustf2a6e8b2024-11-14 10:54:48 -080079 generatedPartitions := []string{"system"}
80 if ctx.DeviceConfig().SystemExtPath() == "system_ext" {
81 generatedPartitions = append(generatedPartitions, "system_ext")
82 }
83 if ctx.DeviceConfig().BuildingVendorImage() && ctx.DeviceConfig().VendorPath() == "vendor" {
84 generatedPartitions = append(generatedPartitions, "vendor")
85 }
86 if ctx.DeviceConfig().BuildingProductImage() && ctx.DeviceConfig().ProductPath() == "product" {
87 generatedPartitions = append(generatedPartitions, "product")
88 }
89 if ctx.DeviceConfig().BuildingOdmImage() && ctx.DeviceConfig().OdmPath() == "odm" {
90 generatedPartitions = append(generatedPartitions, "odm")
91 }
92 if ctx.DeviceConfig().BuildingUserdataImage() && ctx.DeviceConfig().UserdataPath() == "data" {
93 generatedPartitions = append(generatedPartitions, "userdata")
94 }
Cole Faust24938e22024-11-18 14:01:58 -080095 if partitionVars.BuildingSystemDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -080096 generatedPartitions = append(generatedPartitions, "system_dlkm")
97 }
Cole Faust24938e22024-11-18 14:01:58 -080098 if partitionVars.BuildingVendorDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -080099 generatedPartitions = append(generatedPartitions, "vendor_dlkm")
100 }
Cole Faust24938e22024-11-18 14:01:58 -0800101 if partitionVars.BuildingOdmDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800102 generatedPartitions = append(generatedPartitions, "odm_dlkm")
103 }
Cole Faust24938e22024-11-18 14:01:58 -0800104 if partitionVars.BuildingRamdiskImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800105 generatedPartitions = append(generatedPartitions, "ramdisk")
106 }
Cole Faust24938e22024-11-18 14:01:58 -0800107 if buildingVendorBootImage(partitionVars) {
108 generatedPartitions = append(generatedPartitions, "vendor_ramdisk")
109 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800110 return generatedPartitions
111}
112
Jihoon Kang98047cf2024-10-02 17:13:54 +0000113func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) {
Cole Faust3552eb62024-11-06 18:07:26 -0800114 soongGeneratedPartitions := generatedPartitions(ctx)
115 finalSoongGeneratedPartitions := make([]string, 0, len(soongGeneratedPartitions))
116 for _, partitionType := range soongGeneratedPartitions {
Cole Faust92ccbe22024-10-03 14:38:37 -0700117 if f.createPartition(ctx, partitionType) {
118 f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType)
Cole Faust3552eb62024-11-06 18:07:26 -0800119 finalSoongGeneratedPartitions = append(finalSoongGeneratedPartitions, partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700120 } else {
121 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType)
122 }
123 }
Cole Faust3552eb62024-11-06 18:07:26 -0800124
Cole Faust24938e22024-11-18 14:01:58 -0800125 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
126 if buildingBootImage(partitionVars) {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800127 if createBootImage(ctx) {
128 f.properties.Boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "boot")
129 } else {
130 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "boot")
131 }
132 }
Cole Faust24938e22024-11-18 14:01:58 -0800133 if buildingVendorBootImage(partitionVars) {
134 if createVendorBootImage(ctx) {
135 f.properties.Vendor_boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "vendor_boot")
136 } else {
137 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "vendor_boot")
138 }
139 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800140
Cole Faust3552eb62024-11-06 18:07:26 -0800141 for _, x := range createVbmetaPartitions(ctx, finalSoongGeneratedPartitions) {
142 f.properties.Vbmeta_module_names = append(f.properties.Vbmeta_module_names, x.moduleName)
143 f.properties.Vbmeta_partition_names = append(f.properties.Vbmeta_partition_names, x.partitionName)
144 }
145
146 ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions = finalSoongGeneratedPartitions
147 f.createDeviceModule(ctx, finalSoongGeneratedPartitions, f.properties.Vbmeta_module_names)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000148}
149
Jihoon Kang0d545b82024-10-11 00:21:57 +0000150func generatedModuleName(cfg android.Config, suffix string) string {
Cole Faust92ccbe22024-10-03 14:38:37 -0700151 prefix := "soong"
152 if cfg.HasDeviceProduct() {
153 prefix = cfg.DeviceProduct()
154 }
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000155 return fmt.Sprintf("%s_generated_%s", prefix, suffix)
156}
157
Jihoon Kang0d545b82024-10-11 00:21:57 +0000158func generatedModuleNameForPartition(cfg android.Config, partitionType string) string {
159 return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType))
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000160}
161
Cole Faust3552eb62024-11-06 18:07:26 -0800162func (f *filesystemCreator) createDeviceModule(
163 ctx android.LoadHookContext,
164 generatedPartitionTypes []string,
165 vbmetaPartitions []string,
166) {
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000167 baseProps := &struct {
168 Name *string
169 }{
Jihoon Kang0d545b82024-10-11 00:21:57 +0000170 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")),
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000171 }
172
Priyanka Advani (xWF)dafaa7f2024-10-21 22:55:13 +0000173 // Currently, only the system and system_ext partition module is created.
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000174 partitionProps := &filesystem.PartitionNameProperties{}
Cole Faust3552eb62024-11-06 18:07:26 -0800175 if android.InList("system", generatedPartitionTypes) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000176 partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system"))
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000177 }
Cole Faust3552eb62024-11-06 18:07:26 -0800178 if android.InList("system_ext", generatedPartitionTypes) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000179 partitionProps.System_ext_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext"))
Spandan Das7a46f6c2024-10-14 18:41:18 +0000180 }
Cole Faust3552eb62024-11-06 18:07:26 -0800181 if android.InList("vendor", generatedPartitionTypes) {
Spandan Dase3b65312024-10-22 00:27:27 +0000182 partitionProps.Vendor_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor"))
183 }
Cole Faust3552eb62024-11-06 18:07:26 -0800184 if android.InList("product", generatedPartitionTypes) {
Jihoon Kang6dd13b62024-10-22 23:21:02 +0000185 partitionProps.Product_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product"))
186 }
Cole Faust3552eb62024-11-06 18:07:26 -0800187 if android.InList("odm", generatedPartitionTypes) {
Spandan Dasc5717162024-11-01 18:33:57 +0000188 partitionProps.Odm_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm"))
189 }
mrziwang23ba8762024-11-07 16:21:53 -0800190 if android.InList("userdata", f.properties.Generated_partition_types) {
191 partitionProps.Userdata_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "userdata"))
192 }
Cole Faust3552eb62024-11-06 18:07:26 -0800193 partitionProps.Vbmeta_partitions = vbmetaPartitions
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000194
195 ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps)
Cole Faust92ccbe22024-10-03 14:38:37 -0700196}
197
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000198func partitionSpecificFsProps(fsProps *filesystem.FilesystemProperties, partitionType string) {
199 switch partitionType {
200 case "system":
201 fsProps.Build_logtags = proptools.BoolPtr(true)
202 // https://source.corp.google.com/h/googleplex-android/platform/build//639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0
203 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000204 // Identical to that of the generic_system_image
205 fsProps.Fsverity.Inputs = []string{
206 "etc/boot-image.prof",
207 "etc/dirty-image-objects",
208 "etc/preloaded-classes",
209 "etc/classpaths/*.pb",
210 "framework/*",
211 "framework/*/*", // framework/{arch}
212 "framework/oat/*/*", // framework/oat/{arch}
213 }
214 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
mrziwang9afc2982024-11-05 14:29:48 -0800215 // TODO(b/377734331): only generate the symlinks if the relevant partitions exist
216 fsProps.Symlinks = []filesystem.SymlinkDefinition{
217 filesystem.SymlinkDefinition{
218 Target: proptools.StringPtr("/product"),
219 Name: proptools.StringPtr("system/product"),
220 },
221 filesystem.SymlinkDefinition{
222 Target: proptools.StringPtr("/system_ext"),
223 Name: proptools.StringPtr("system/system_ext"),
224 },
225 filesystem.SymlinkDefinition{
226 Target: proptools.StringPtr("/vendor"),
227 Name: proptools.StringPtr("system/vendor"),
228 },
229 filesystem.SymlinkDefinition{
230 Target: proptools.StringPtr("/system_dlkm/lib/modules"),
231 Name: proptools.StringPtr("system/lib/modules"),
232 },
233 }
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000234 case "system_ext":
235 fsProps.Fsverity.Inputs = []string{
236 "framework/*",
237 "framework/*/*", // framework/{arch}
238 "framework/oat/*/*", // framework/oat/{arch}
239 }
240 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000241 case "product":
242 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
243 case "vendor":
244 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Spandan Das69464c32024-10-25 20:08:06 +0000245 fsProps.Symlinks = []filesystem.SymlinkDefinition{
246 filesystem.SymlinkDefinition{
247 Target: proptools.StringPtr("/odm"),
248 Name: proptools.StringPtr("vendor/odm"),
249 },
250 filesystem.SymlinkDefinition{
251 Target: proptools.StringPtr("/vendor_dlkm/lib/modules"),
252 Name: proptools.StringPtr("vendor/lib/modules"),
253 },
254 }
Spandan Dasc5717162024-11-01 18:33:57 +0000255 case "odm":
256 fsProps.Symlinks = []filesystem.SymlinkDefinition{
257 filesystem.SymlinkDefinition{
258 Target: proptools.StringPtr("/odm_dlkm/lib/modules"),
259 Name: proptools.StringPtr("odm/lib/modules"),
260 },
261 }
mrziwang23ba8762024-11-07 16:21:53 -0800262 case "userdata":
263 fsProps.Base_dir = proptools.StringPtr("data")
Spandan Dasc5717162024-11-01 18:33:57 +0000264
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000265 }
266}
Spandan Dascbe641a2024-10-14 21:07:34 +0000267
Spandan Das5b493cd2024-11-07 20:55:56 +0000268var (
269 dlkmPartitions = []string{
270 "system_dlkm",
271 "vendor_dlkm",
272 "odm_dlkm",
273 }
274)
275
Cole Faust92ccbe22024-10-03 14:38:37 -0700276// Creates a soong module to build the given partition. Returns false if we can't support building
277// it.
278func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool {
mrziwang4b0ca972024-10-17 14:56:19 -0700279 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
280
281 fsProps, supported := generateFsProps(ctx, partitionType)
282 if !supported {
283 return false
mrziwanga077b942024-10-16 16:00:06 -0700284 }
mrziwanga077b942024-10-16 16:00:06 -0700285
Spandan Das8fe68dc2024-10-29 18:20:11 +0000286 if partitionType == "vendor" || partitionType == "product" {
Spandan Das2047a4c2024-11-11 21:24:58 +0000287 fsProps.Linker_config.Gen_linker_config = proptools.BoolPtr(true)
288 fsProps.Linker_config.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType)
Spandan Das312cc412024-10-29 18:20:11 +0000289 }
290
Spandan Das5b493cd2024-11-07 20:55:56 +0000291 if android.InList(partitionType, dlkmPartitions) {
292 f.createPrebuiltKernelModules(ctx, partitionType)
Spandan Das5e336422024-11-01 22:31:20 +0000293 }
294
mrziwang4b0ca972024-10-17 14:56:19 -0700295 var module android.Module
296 if partitionType == "system" {
297 module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps)
298 } else {
299 // Explicitly set the partition.
300 fsProps.Partition_type = proptools.StringPtr(partitionType)
301 module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps)
302 }
303 module.HideFromMake()
Spandan Das168098c2024-10-28 19:44:34 +0000304 if partitionType == "vendor" {
Spandan Das4cd93b52024-11-05 23:27:03 +0000305 f.createVendorBuildProp(ctx)
Spandan Das168098c2024-10-28 19:44:34 +0000306 }
mrziwang4b0ca972024-10-17 14:56:19 -0700307 return true
308}
309
Cole Faust953476f2024-11-14 14:11:29 -0800310// Creates filegroups for the files specified in BOARD_(partition_)AVB_KEY_PATH
311func (f *filesystemCreator) createAvbKeyFilegroups(ctx android.LoadHookContext) {
312 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
313 var files []string
314
315 if len(partitionVars.BoardAvbKeyPath) > 0 {
316 files = append(files, partitionVars.BoardAvbKeyPath)
317 }
318 for _, partition := range android.SortedKeys(partitionVars.PartitionQualifiedVariables) {
319 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partition]
320 if len(specificPartitionVars.BoardAvbKeyPath) > 0 {
321 files = append(files, specificPartitionVars.BoardAvbKeyPath)
322 }
323 }
324
325 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
326 for _, file := range files {
327 if _, ok := fsGenState.avbKeyFilegroups[file]; ok {
328 continue
329 }
330 if file == "external/avb/test/data/testkey_rsa4096.pem" {
331 // There already exists a checked-in filegroup for this commonly-used key, just use that
332 fsGenState.avbKeyFilegroups[file] = "avb_testkey_rsa4096"
333 continue
334 }
335 dir := filepath.Dir(file)
336 base := filepath.Base(file)
337 name := fmt.Sprintf("avb_key_%x", strings.ReplaceAll(file, "/", "_"))
338 ctx.CreateModuleInDirectory(
339 android.FileGroupFactory,
340 dir,
341 &struct {
342 Name *string
343 Srcs []string
344 Visibility []string
345 }{
346 Name: proptools.StringPtr(name),
347 Srcs: []string{base},
348 Visibility: []string{"//visibility:public"},
349 },
350 )
351 fsGenState.avbKeyFilegroups[file] = name
352 }
353}
354
Spandan Das5e336422024-11-01 22:31:20 +0000355// createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the
Spandan Das7b25a512024-11-06 20:41:26 +0000356// autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency.
357// This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view.
Spandan Das5b493cd2024-11-07 20:55:56 +0000358func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string) {
Spandan Das5e336422024-11-01 22:31:20 +0000359 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Spandan Das7b25a512024-11-06 20:41:26 +0000360 name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType))
361 props := &struct {
Spandan Das912d26b2024-11-06 19:35:17 +0000362 Name *string
363 Srcs []string
Spandan Das5b493cd2024-11-07 20:55:56 +0000364 System_deps []string
Spandan Das912d26b2024-11-06 19:35:17 +0000365 System_dlkm_specific *bool
Spandan Das5b493cd2024-11-07 20:55:56 +0000366 Vendor_dlkm_specific *bool
367 Odm_dlkm_specific *bool
368 Load_by_default *bool
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000369 Blocklist_file *string
Spandan Das7b25a512024-11-06 20:41:26 +0000370 }{
371 Name: proptools.StringPtr(name),
Spandan Das5e336422024-11-01 22:31:20 +0000372 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000373 switch partitionType {
374 case "system_dlkm":
375 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules
Spandan Das912d26b2024-11-06 19:35:17 +0000376 props.System_dlkm_specific = proptools.BoolPtr(true)
Spandan Das5b493cd2024-11-07 20:55:56 +0000377 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelLoadModules) == 0 {
378 // Create empty modules.load file for system
379 // https://source.corp.google.com/h/googleplex-android/platform/build/+/ef55daac9954896161b26db4f3ef1781b5a5694c:core/Makefile;l=695-700;drc=549fe2a5162548bd8b47867d35f907eb22332023;bpv=1;bpt=0
380 props.Load_by_default = proptools.BoolPtr(false)
381 }
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000382 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelBlocklistFile; blocklistFile != "" {
383 props.Blocklist_file = proptools.StringPtr(blocklistFile)
384 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000385 case "vendor_dlkm":
386 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelModules
387 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules) > 0 {
388 props.System_deps = []string{":" + generatedModuleName(ctx.Config(), "system_dlkm-kernel-modules") + "{.modules}"}
389 }
390 props.Vendor_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000391 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelBlocklistFile; blocklistFile != "" {
392 props.Blocklist_file = proptools.StringPtr(blocklistFile)
393 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000394 case "odm_dlkm":
395 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelModules
396 props.Odm_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000397 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelBlocklistFile; blocklistFile != "" {
398 props.Blocklist_file = proptools.StringPtr(blocklistFile)
399 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000400 default:
401 ctx.ModuleErrorf("DLKM is not supported for %s\n", partitionType)
Spandan Das912d26b2024-11-06 19:35:17 +0000402 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000403
404 if len(props.Srcs) == 0 {
405 return // do not generate `prebuilt_kernel_modules` if there are no sources
406 }
407
Spandan Das7b25a512024-11-06 20:41:26 +0000408 kernelModule := ctx.CreateModuleInDirectory(
409 kernel.PrebuiltKernelModulesFactory,
410 ".", // create in root directory for now
411 props,
412 )
413 kernelModule.HideFromMake()
414 // Add to deps
415 (*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config())
Spandan Das5e336422024-11-01 22:31:20 +0000416}
417
Spandan Das4cd93b52024-11-05 23:27:03 +0000418// Create a build_prop and android_info module. This will be used to create /vendor/build.prop
419func (f *filesystemCreator) createVendorBuildProp(ctx android.LoadHookContext) {
420 // Create a android_info for vendor
421 // The board info files might be in a directory outside the root soong namespace, so create
422 // the module in "."
423 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
424 androidInfoProps := &struct {
425 Name *string
426 Board_info_files []string
427 Bootloader_board_name *string
428 }{
429 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "android-info.prop")),
430 Board_info_files: partitionVars.BoardInfoFiles,
431 }
432 if len(androidInfoProps.Board_info_files) == 0 {
433 androidInfoProps.Bootloader_board_name = proptools.StringPtr(partitionVars.BootLoaderBoardName)
434 }
435 androidInfoProp := ctx.CreateModuleInDirectory(
436 android.AndroidInfoFactory,
437 ".",
438 androidInfoProps,
439 )
440 androidInfoProp.HideFromMake()
441 // Create a build prop for vendor
442 vendorBuildProps := &struct {
443 Name *string
444 Vendor *bool
445 Stem *string
446 Product_config *string
447 Android_info *string
448 }{
449 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")),
450 Vendor: proptools.BoolPtr(true),
451 Stem: proptools.StringPtr("build.prop"),
452 Product_config: proptools.StringPtr(":product_config"),
453 Android_info: proptools.StringPtr(":" + androidInfoProp.Name()),
454 }
455 vendorBuildProp := ctx.CreateModule(
456 android.BuildPropFactory,
457 vendorBuildProps,
458 )
459 vendorBuildProp.HideFromMake()
460}
461
Spandan Das8fe68dc2024-10-29 18:20:11 +0000462// createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions
463// 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list)
464// 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list)
465// It creates a filegroup for each file in the fragment list
Spandan Das312cc412024-10-29 18:20:11 +0000466// The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`.
Spandan Das8fe68dc2024-10-29 18:20:11 +0000467func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string {
Spandan Das312cc412024-10-29 18:20:11 +0000468 ret := []string{}
469 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Spandan Das8fe68dc2024-10-29 18:20:11 +0000470 var linkerConfigSrcs []string
471 if partitionType == "vendor" {
472 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs)
473 } else if partitionType == "product" {
474 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs)
475 } else {
476 ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`")
477 }
478
479 if len(linkerConfigSrcs) > 0 {
Spandan Das312cc412024-10-29 18:20:11 +0000480 // Create a filegroup, and add `:<filegroup_name>` to ret.
481 for index, linkerConfigSrc := range linkerConfigSrcs {
482 dir := filepath.Dir(linkerConfigSrc)
483 base := filepath.Base(linkerConfigSrc)
Spandan Das8fe68dc2024-10-29 18:20:11 +0000484 fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index)))
Spandan Das312cc412024-10-29 18:20:11 +0000485 srcs := []string{base}
486 fgProps := &struct {
487 Name *string
488 Srcs proptools.Configurable[[]string]
489 }{
490 Name: proptools.StringPtr(fgName),
491 Srcs: proptools.NewSimpleConfigurable(srcs),
492 }
493 ctx.CreateModuleInDirectory(
494 android.FileGroupFactory,
495 dir,
496 fgProps,
497 )
498 ret = append(ret, ":"+fgName)
499 }
500 }
501 return ret
502}
503
mrziwang4b0ca972024-10-17 14:56:19 -0700504type filesystemBaseProperty struct {
505 Name *string
506 Compile_multilib *string
Cole Faust3552eb62024-11-06 18:07:26 -0800507 Visibility []string
mrziwang4b0ca972024-10-17 14:56:19 -0700508}
509
510func generateBaseProps(namePtr *string) *filesystemBaseProperty {
511 return &filesystemBaseProperty{
512 Name: namePtr,
513 Compile_multilib: proptools.StringPtr("both"),
Cole Faust3552eb62024-11-06 18:07:26 -0800514 // The vbmeta modules are currently in the root directory and depend on the partitions
515 Visibility: []string{"//.", "//build/soong:__subpackages__"},
mrziwang4b0ca972024-10-17 14:56:19 -0700516 }
517}
518
519func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) {
Cole Faust953476f2024-11-14 14:11:29 -0800520 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Cole Faust92ccbe22024-10-03 14:38:37 -0700521 fsProps := &filesystem.FilesystemProperties{}
522
mrziwang4b0ca972024-10-17 14:56:19 -0700523 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Cole Faust76a6e952024-11-07 16:56:45 -0800524 var boardAvbEnable bool
Cole Faust953476f2024-11-14 14:11:29 -0800525 var boardAvbKeyPath string
526 var boardAvbAlgorithm string
527 var boardAvbRollbackIndex string
Cole Faust76a6e952024-11-07 16:56:45 -0800528 var fsType string
529 if strings.Contains(partitionType, "ramdisk") {
530 fsType = "compressed_cpio"
531 } else {
Cole Faust953476f2024-11-14 14:11:29 -0800532 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType]
Cole Faust76a6e952024-11-07 16:56:45 -0800533 fsType = specificPartitionVars.BoardFileSystemType
Cole Faust953476f2024-11-14 14:11:29 -0800534 boardAvbEnable = partitionVars.BoardAvbEnable
535 boardAvbKeyPath = specificPartitionVars.BoardAvbKeyPath
536 boardAvbAlgorithm = specificPartitionVars.BoardAvbAlgorithm
537 boardAvbRollbackIndex = specificPartitionVars.BoardAvbRollbackIndex
538 if boardAvbEnable {
539 if boardAvbKeyPath == "" {
540 boardAvbKeyPath = partitionVars.BoardAvbKeyPath
541 }
542 if boardAvbAlgorithm == "" {
543 boardAvbAlgorithm = partitionVars.BoardAvbAlgorithm
544 }
545 if boardAvbRollbackIndex == "" {
546 boardAvbRollbackIndex = partitionVars.BoardAvbRollbackIndex
547 }
548 }
549 if fsType == "" {
550 fsType = "ext4" //default
551 }
Cole Faust76a6e952024-11-07 16:56:45 -0800552 }
Cole Faust953476f2024-11-14 14:11:29 -0800553 if boardAvbKeyPath != "" {
554 boardAvbKeyPath = ":" + fsGenState.avbKeyFilegroups[boardAvbKeyPath]
mrziwang4b0ca972024-10-17 14:56:19 -0700555 }
Cole Faust76a6e952024-11-07 16:56:45 -0800556
mrziwang4b0ca972024-10-17 14:56:19 -0700557 fsProps.Type = proptools.StringPtr(fsType)
558 if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() {
559 // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs
560 return nil, false
561 }
562
Cole Faust92ccbe22024-10-03 14:38:37 -0700563 // Don't build this module on checkbuilds, the soong-built partitions are still in-progress
564 // and sometimes don't build.
565 fsProps.Unchecked_module = proptools.BoolPtr(true)
566
Jihoon Kang98047cf2024-10-02 17:13:54 +0000567 // BOARD_AVB_ENABLE
Cole Faust76a6e952024-11-07 16:56:45 -0800568 fsProps.Use_avb = proptools.BoolPtr(boardAvbEnable)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000569 // BOARD_AVB_KEY_PATH
Cole Faust953476f2024-11-14 14:11:29 -0800570 fsProps.Avb_private_key = proptools.StringPtr(boardAvbKeyPath)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000571 // BOARD_AVB_ALGORITHM
Cole Faust953476f2024-11-14 14:11:29 -0800572 fsProps.Avb_algorithm = proptools.StringPtr(boardAvbAlgorithm)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000573 // BOARD_AVB_SYSTEM_ROLLBACK_INDEX
Cole Faust953476f2024-11-14 14:11:29 -0800574 if rollbackIndex, err := strconv.ParseInt(boardAvbRollbackIndex, 10, 64); err == nil {
Jihoon Kang98047cf2024-10-02 17:13:54 +0000575 fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex)
576 }
577
Cole Faust92ccbe22024-10-03 14:38:37 -0700578 fsProps.Partition_name = proptools.StringPtr(partitionType)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000579
Cole Faust92ccbe22024-10-03 14:38:37 -0700580 fsProps.Base_dir = proptools.StringPtr(partitionType)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000581
Jihoon Kang0d545b82024-10-11 00:21:57 +0000582 fsProps.Is_auto_generated = proptools.BoolPtr(true)
583
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000584 partitionSpecificFsProps(fsProps, partitionType)
585
Jihoon Kang98047cf2024-10-02 17:13:54 +0000586 // system_image properties that are not set:
587 // - filesystemProperties.Avb_hash_algorithm
588 // - filesystemProperties.File_contexts
589 // - filesystemProperties.Dirs
590 // - filesystemProperties.Symlinks
591 // - filesystemProperties.Fake_timestamp
592 // - filesystemProperties.Uuid
593 // - filesystemProperties.Mount_point
594 // - filesystemProperties.Include_make_built_files
595 // - filesystemProperties.Build_logtags
Jihoon Kang98047cf2024-10-02 17:13:54 +0000596 // - systemImageProperties.Linker_config_src
mrziwang4b0ca972024-10-17 14:56:19 -0700597
598 return fsProps, true
Cole Faust92ccbe22024-10-03 14:38:37 -0700599}
600
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800601func (f *filesystemCreator) createFileListDiffTest(ctx android.ModuleContext, partitionType string) android.Path {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000602 partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700603 systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag)
604 filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider)
605 if !ok {
606 ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName)
607 }
608 makeFileList := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partitionType))
Jihoon Kang9e866c82024-10-07 22:39:18 +0000609 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName))
Cole Faust92ccbe22024-10-03 14:38:37 -0700610
611 builder := android.NewRuleBuilder(pctx, ctx)
612 builder.Command().BuiltTool("file_list_diff").
613 Input(makeFileList).
614 Input(filesystemInfo.FileListFile).
Cole Faust56301572024-11-07 15:22:42 -0800615 Text(partitionModuleName)
Cole Faust92ccbe22024-10-03 14:38:37 -0700616 builder.Command().Text("touch").Output(diffTestResultFile)
617 builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test")
618 return diffTestResultFile
619}
620
621func createFailingCommand(ctx android.ModuleContext, message string) android.Path {
622 hasher := sha256.New()
623 hasher.Write([]byte(message))
624 filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil))
625 file := android.PathForModuleOut(ctx, filename)
626 builder := android.NewRuleBuilder(pctx, ctx)
627 builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message))
628 builder.Command().Text("exit 1 #").Output(file)
629 builder.Build("failing command "+filename, "failing command "+filename)
630 return file
631}
632
Cole Faust3552eb62024-11-06 18:07:26 -0800633func createVbmetaDiff(ctx android.ModuleContext, vbmetaModuleName string, vbmetaPartitionName string) android.Path {
634 vbmetaModule := ctx.GetDirectDepWithTag(vbmetaModuleName, generatedVbmetaPartitionDepTag)
635 outputFilesProvider, ok := android.OtherModuleProvider(ctx, vbmetaModule, android.OutputFilesProvider)
636 if !ok {
637 ctx.ModuleErrorf("Expected module %s to provide OutputFiles", vbmetaModule)
638 }
639 if len(outputFilesProvider.DefaultOutputFiles) != 1 {
640 ctx.ModuleErrorf("Expected 1 output file from module %s", vbmetaModule)
641 }
642 soongVbMetaFile := outputFilesProvider.DefaultOutputFiles[0]
643 makeVbmetaFile := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/%s.img", ctx.Config().DeviceName(), vbmetaPartitionName))
644
645 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", vbmetaModuleName))
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800646 createDiffTest(ctx, diffTestResultFile, soongVbMetaFile, makeVbmetaFile)
647 return diffTestResultFile
648}
649
650func createDiffTest(ctx android.ModuleContext, diffTestResultFile android.WritablePath, file1 android.Path, file2 android.Path) {
Cole Faust3552eb62024-11-06 18:07:26 -0800651 builder := android.NewRuleBuilder(pctx, ctx)
652 builder.Command().Text("diff").
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800653 Input(file1).
654 Input(file2)
Cole Faust3552eb62024-11-06 18:07:26 -0800655 builder.Command().Text("touch").Output(diffTestResultFile)
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800656 builder.Build("diff test "+diffTestResultFile.String(), "diff test")
Cole Faust3552eb62024-11-06 18:07:26 -0800657}
658
Cole Faust92ccbe22024-10-03 14:38:37 -0700659type systemImageDepTagType struct {
660 blueprint.BaseDependencyTag
661}
662
663var generatedFilesystemDepTag systemImageDepTagType
Cole Faust3552eb62024-11-06 18:07:26 -0800664var generatedVbmetaPartitionDepTag systemImageDepTagType
Cole Faust92ccbe22024-10-03 14:38:37 -0700665
666func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) {
667 for _, partitionType := range f.properties.Generated_partition_types {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000668 ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType))
Cole Faust92ccbe22024-10-03 14:38:37 -0700669 }
Cole Faust3552eb62024-11-06 18:07:26 -0800670 for _, vbmetaModule := range f.properties.Vbmeta_module_names {
671 ctx.AddDependency(ctx.Module(), generatedVbmetaPartitionDepTag, vbmetaModule)
672 }
Jihoon Kang98047cf2024-10-02 17:13:54 +0000673}
674
675func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Cole Faust92ccbe22024-10-03 14:38:37 -0700676 if ctx.ModuleDir() != "build/soong/fsgen" {
677 ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen")
678 }
679 f.HideFromMake()
Jihoon Kang98047cf2024-10-02 17:13:54 +0000680
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000681 var content strings.Builder
682 generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp")
683 for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions {
684 content.WriteString(generateBpContent(ctx, partition))
685 content.WriteString("\n")
686 }
687 android.WriteFileRule(ctx, generatedBp, content.String())
688
mrziwang8f86c882024-10-03 12:34:33 -0700689 ctx.Phony("product_config_to_bp", generatedBp)
690
Cole Faust92ccbe22024-10-03 14:38:37 -0700691 var diffTestFiles []android.Path
692 for _, partitionType := range f.properties.Generated_partition_types {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800693 diffTestFile := f.createFileListDiffTest(ctx, partitionType)
Jihoon Kang72f812f2024-10-17 18:46:24 +0000694 diffTestFiles = append(diffTestFiles, diffTestFile)
695 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700696 }
697 for _, partitionType := range f.properties.Unsupported_partition_types {
Jihoon Kang72f812f2024-10-17 18:46:24 +0000698 diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType))
699 diffTestFiles = append(diffTestFiles, diffTestFile)
700 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700701 }
Cole Faust3552eb62024-11-06 18:07:26 -0800702 for i, vbmetaModule := range f.properties.Vbmeta_module_names {
703 diffTestFile := createVbmetaDiff(ctx, vbmetaModule, f.properties.Vbmeta_partition_names[i])
704 diffTestFiles = append(diffTestFiles, diffTestFile)
705 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", f.properties.Vbmeta_partition_names[i]), diffTestFile)
706 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800707 if f.properties.Boot_image != "" {
708 diffTestFile := android.PathForModuleOut(ctx, "boot_diff_test.txt")
709 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image)
710 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/boot.img", ctx.Config().DeviceName()))
711 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
712 diffTestFiles = append(diffTestFiles, diffTestFile)
713 ctx.Phony("soong_generated_boot_filesystem_test", diffTestFile)
714 }
Cole Faust24938e22024-11-18 14:01:58 -0800715 if f.properties.Vendor_boot_image != "" {
716 diffTestFile := android.PathForModuleOut(ctx, "vendor_boot_diff_test.txt")
717 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image)
718 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/vendor_boot.img", ctx.Config().DeviceName()))
719 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
720 diffTestFiles = append(diffTestFiles, diffTestFile)
721 ctx.Phony("soong_generated_vendor_boot_filesystem_test", diffTestFile)
722 }
Cole Faust92ccbe22024-10-03 14:38:37 -0700723 ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000724}
mrziwang8f86c882024-10-03 12:34:33 -0700725
mrziwang8f86c882024-10-03 12:34:33 -0700726func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string {
mrziwang4b0ca972024-10-17 14:56:19 -0700727 fsProps, fsTypeSupported := generateFsProps(ctx, partitionType)
728 if !fsTypeSupported {
729 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700730 }
731
mrziwang4b0ca972024-10-17 14:56:19 -0700732 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
Jihoon Kang0d7b0112024-11-13 20:44:05 +0000733 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
734 deps := fsGenState.fsDeps[partitionType]
735 highPriorityDeps := fsGenState.generatedPrebuiltEtcModuleNames
736 depProps := generateDepStruct(*deps, highPriorityDeps)
mrziwang8f86c882024-10-03 12:34:33 -0700737
mrziwang4b0ca972024-10-17 14:56:19 -0700738 result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps})
mrziwang8f86c882024-10-03 12:34:33 -0700739 if err != nil {
Cole Faustae3e1d32024-11-05 13:22:50 -0800740 ctx.ModuleErrorf("%s", err.Error())
741 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700742 }
743
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000744 moduleType := "android_filesystem"
745 if partitionType == "system" {
746 moduleType = "android_system_image"
747 }
748
mrziwang8f86c882024-10-03 12:34:33 -0700749 file := &parser.File{
750 Defs: []parser.Definition{
751 &parser.Module{
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000752 Type: moduleType,
mrziwang8f86c882024-10-03 12:34:33 -0700753 Map: *result,
754 },
755 },
756 }
757 bytes, err := parser.Print(file)
758 if err != nil {
759 ctx.ModuleErrorf(err.Error())
760 }
761 return strings.TrimSpace(string(bytes))
762}