blob: 7daefcb6deffc4168afa55a9dfe68ef03298c053 [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
51 Boot_image string `blueprint:"mutated" android:"path_device_first"`
Cole Faust92ccbe22024-10-03 14:38:37 -070052}
53
Jihoon Kang98047cf2024-10-02 17:13:54 +000054type filesystemCreator struct {
55 android.ModuleBase
Cole Faust92ccbe22024-10-03 14:38:37 -070056
57 properties filesystemCreatorProps
Jihoon Kang98047cf2024-10-02 17:13:54 +000058}
59
60func filesystemCreatorFactory() android.Module {
61 module := &filesystemCreator{}
62
Cole Faust69788792024-10-10 11:00:36 -070063 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
Cole Faust92ccbe22024-10-03 14:38:37 -070064 module.AddProperties(&module.properties)
Jihoon Kang98047cf2024-10-02 17:13:54 +000065 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
Jihoon Kang675d4682024-10-24 23:45:11 +000066 generatedPrebuiltEtcModuleNames := createPrebuiltEtcModules(ctx)
Jihoon Kang04f12c92024-11-12 23:03:08 +000067 avbpubkeyGenerated := createAvbpubkeyModule(ctx)
68 createFsGenState(ctx, generatedPrebuiltEtcModuleNames, avbpubkeyGenerated)
Cole Faust953476f2024-11-14 14:11:29 -080069 module.createAvbKeyFilegroups(ctx)
Jihoon Kang98047cf2024-10-02 17:13:54 +000070 module.createInternalModules(ctx)
71 })
72
73 return module
74}
75
Cole Faustf2a6e8b2024-11-14 10:54:48 -080076func generatedPartitions(ctx android.LoadHookContext) []string {
77 generatedPartitions := []string{"system"}
78 if ctx.DeviceConfig().SystemExtPath() == "system_ext" {
79 generatedPartitions = append(generatedPartitions, "system_ext")
80 }
81 if ctx.DeviceConfig().BuildingVendorImage() && ctx.DeviceConfig().VendorPath() == "vendor" {
82 generatedPartitions = append(generatedPartitions, "vendor")
83 }
84 if ctx.DeviceConfig().BuildingProductImage() && ctx.DeviceConfig().ProductPath() == "product" {
85 generatedPartitions = append(generatedPartitions, "product")
86 }
87 if ctx.DeviceConfig().BuildingOdmImage() && ctx.DeviceConfig().OdmPath() == "odm" {
88 generatedPartitions = append(generatedPartitions, "odm")
89 }
90 if ctx.DeviceConfig().BuildingUserdataImage() && ctx.DeviceConfig().UserdataPath() == "data" {
91 generatedPartitions = append(generatedPartitions, "userdata")
92 }
93 if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingSystemDlkmImage {
94 generatedPartitions = append(generatedPartitions, "system_dlkm")
95 }
96 if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingVendorDlkmImage {
97 generatedPartitions = append(generatedPartitions, "vendor_dlkm")
98 }
99 if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingOdmDlkmImage {
100 generatedPartitions = append(generatedPartitions, "odm_dlkm")
101 }
102 if ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.BuildingRamdiskImage {
103 generatedPartitions = append(generatedPartitions, "ramdisk")
104 }
105 return generatedPartitions
106}
107
Jihoon Kang98047cf2024-10-02 17:13:54 +0000108func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) {
Cole Faust3552eb62024-11-06 18:07:26 -0800109 soongGeneratedPartitions := generatedPartitions(ctx)
110 finalSoongGeneratedPartitions := make([]string, 0, len(soongGeneratedPartitions))
111 for _, partitionType := range soongGeneratedPartitions {
Cole Faust92ccbe22024-10-03 14:38:37 -0700112 if f.createPartition(ctx, partitionType) {
113 f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType)
Cole Faust3552eb62024-11-06 18:07:26 -0800114 finalSoongGeneratedPartitions = append(finalSoongGeneratedPartitions, partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700115 } else {
116 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType)
117 }
118 }
Cole Faust3552eb62024-11-06 18:07:26 -0800119
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800120 if buildingBootImage(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse) {
121 if createBootImage(ctx) {
122 f.properties.Boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "boot")
123 } else {
124 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "boot")
125 }
126 }
127
Cole Faust3552eb62024-11-06 18:07:26 -0800128 for _, x := range createVbmetaPartitions(ctx, finalSoongGeneratedPartitions) {
129 f.properties.Vbmeta_module_names = append(f.properties.Vbmeta_module_names, x.moduleName)
130 f.properties.Vbmeta_partition_names = append(f.properties.Vbmeta_partition_names, x.partitionName)
131 }
132
133 ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions = finalSoongGeneratedPartitions
134 f.createDeviceModule(ctx, finalSoongGeneratedPartitions, f.properties.Vbmeta_module_names)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000135}
136
Jihoon Kang0d545b82024-10-11 00:21:57 +0000137func generatedModuleName(cfg android.Config, suffix string) string {
Cole Faust92ccbe22024-10-03 14:38:37 -0700138 prefix := "soong"
139 if cfg.HasDeviceProduct() {
140 prefix = cfg.DeviceProduct()
141 }
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000142 return fmt.Sprintf("%s_generated_%s", prefix, suffix)
143}
144
Jihoon Kang0d545b82024-10-11 00:21:57 +0000145func generatedModuleNameForPartition(cfg android.Config, partitionType string) string {
146 return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType))
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000147}
148
Cole Faust3552eb62024-11-06 18:07:26 -0800149func (f *filesystemCreator) createDeviceModule(
150 ctx android.LoadHookContext,
151 generatedPartitionTypes []string,
152 vbmetaPartitions []string,
153) {
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000154 baseProps := &struct {
155 Name *string
156 }{
Jihoon Kang0d545b82024-10-11 00:21:57 +0000157 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")),
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000158 }
159
Priyanka Advani (xWF)dafaa7f2024-10-21 22:55:13 +0000160 // Currently, only the system and system_ext partition module is created.
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000161 partitionProps := &filesystem.PartitionNameProperties{}
Cole Faust3552eb62024-11-06 18:07:26 -0800162 if android.InList("system", generatedPartitionTypes) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000163 partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system"))
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000164 }
Cole Faust3552eb62024-11-06 18:07:26 -0800165 if android.InList("system_ext", generatedPartitionTypes) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000166 partitionProps.System_ext_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext"))
Spandan Das7a46f6c2024-10-14 18:41:18 +0000167 }
Cole Faust3552eb62024-11-06 18:07:26 -0800168 if android.InList("vendor", generatedPartitionTypes) {
Spandan Dase3b65312024-10-22 00:27:27 +0000169 partitionProps.Vendor_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor"))
170 }
Cole Faust3552eb62024-11-06 18:07:26 -0800171 if android.InList("product", generatedPartitionTypes) {
Jihoon Kang6dd13b62024-10-22 23:21:02 +0000172 partitionProps.Product_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product"))
173 }
Cole Faust3552eb62024-11-06 18:07:26 -0800174 if android.InList("odm", generatedPartitionTypes) {
Spandan Dasc5717162024-11-01 18:33:57 +0000175 partitionProps.Odm_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm"))
176 }
mrziwang23ba8762024-11-07 16:21:53 -0800177 if android.InList("userdata", f.properties.Generated_partition_types) {
178 partitionProps.Userdata_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "userdata"))
179 }
Cole Faust3552eb62024-11-06 18:07:26 -0800180 partitionProps.Vbmeta_partitions = vbmetaPartitions
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000181
182 ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps)
Cole Faust92ccbe22024-10-03 14:38:37 -0700183}
184
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000185func partitionSpecificFsProps(fsProps *filesystem.FilesystemProperties, partitionType string) {
186 switch partitionType {
187 case "system":
188 fsProps.Build_logtags = proptools.BoolPtr(true)
189 // https://source.corp.google.com/h/googleplex-android/platform/build//639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0
190 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000191 // Identical to that of the generic_system_image
192 fsProps.Fsverity.Inputs = []string{
193 "etc/boot-image.prof",
194 "etc/dirty-image-objects",
195 "etc/preloaded-classes",
196 "etc/classpaths/*.pb",
197 "framework/*",
198 "framework/*/*", // framework/{arch}
199 "framework/oat/*/*", // framework/oat/{arch}
200 }
201 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
mrziwang9afc2982024-11-05 14:29:48 -0800202 // TODO(b/377734331): only generate the symlinks if the relevant partitions exist
203 fsProps.Symlinks = []filesystem.SymlinkDefinition{
204 filesystem.SymlinkDefinition{
205 Target: proptools.StringPtr("/product"),
206 Name: proptools.StringPtr("system/product"),
207 },
208 filesystem.SymlinkDefinition{
209 Target: proptools.StringPtr("/system_ext"),
210 Name: proptools.StringPtr("system/system_ext"),
211 },
212 filesystem.SymlinkDefinition{
213 Target: proptools.StringPtr("/vendor"),
214 Name: proptools.StringPtr("system/vendor"),
215 },
216 filesystem.SymlinkDefinition{
217 Target: proptools.StringPtr("/system_dlkm/lib/modules"),
218 Name: proptools.StringPtr("system/lib/modules"),
219 },
220 }
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000221 case "system_ext":
222 fsProps.Fsverity.Inputs = []string{
223 "framework/*",
224 "framework/*/*", // framework/{arch}
225 "framework/oat/*/*", // framework/oat/{arch}
226 }
227 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000228 case "product":
229 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
230 case "vendor":
231 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Spandan Das69464c32024-10-25 20:08:06 +0000232 fsProps.Symlinks = []filesystem.SymlinkDefinition{
233 filesystem.SymlinkDefinition{
234 Target: proptools.StringPtr("/odm"),
235 Name: proptools.StringPtr("vendor/odm"),
236 },
237 filesystem.SymlinkDefinition{
238 Target: proptools.StringPtr("/vendor_dlkm/lib/modules"),
239 Name: proptools.StringPtr("vendor/lib/modules"),
240 },
241 }
Spandan Dasc5717162024-11-01 18:33:57 +0000242 case "odm":
243 fsProps.Symlinks = []filesystem.SymlinkDefinition{
244 filesystem.SymlinkDefinition{
245 Target: proptools.StringPtr("/odm_dlkm/lib/modules"),
246 Name: proptools.StringPtr("odm/lib/modules"),
247 },
248 }
mrziwang23ba8762024-11-07 16:21:53 -0800249 case "userdata":
250 fsProps.Base_dir = proptools.StringPtr("data")
Spandan Dasc5717162024-11-01 18:33:57 +0000251
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000252 }
253}
Spandan Dascbe641a2024-10-14 21:07:34 +0000254
Spandan Das5b493cd2024-11-07 20:55:56 +0000255var (
256 dlkmPartitions = []string{
257 "system_dlkm",
258 "vendor_dlkm",
259 "odm_dlkm",
260 }
261)
262
Cole Faust92ccbe22024-10-03 14:38:37 -0700263// Creates a soong module to build the given partition. Returns false if we can't support building
264// it.
265func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool {
mrziwang4b0ca972024-10-17 14:56:19 -0700266 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
267
268 fsProps, supported := generateFsProps(ctx, partitionType)
269 if !supported {
270 return false
mrziwanga077b942024-10-16 16:00:06 -0700271 }
mrziwanga077b942024-10-16 16:00:06 -0700272
Spandan Das8fe68dc2024-10-29 18:20:11 +0000273 if partitionType == "vendor" || partitionType == "product" {
Spandan Das2047a4c2024-11-11 21:24:58 +0000274 fsProps.Linker_config.Gen_linker_config = proptools.BoolPtr(true)
275 fsProps.Linker_config.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType)
Spandan Das312cc412024-10-29 18:20:11 +0000276 }
277
Spandan Das5b493cd2024-11-07 20:55:56 +0000278 if android.InList(partitionType, dlkmPartitions) {
279 f.createPrebuiltKernelModules(ctx, partitionType)
Spandan Das5e336422024-11-01 22:31:20 +0000280 }
281
mrziwang4b0ca972024-10-17 14:56:19 -0700282 var module android.Module
283 if partitionType == "system" {
284 module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps)
285 } else {
286 // Explicitly set the partition.
287 fsProps.Partition_type = proptools.StringPtr(partitionType)
288 module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps)
289 }
290 module.HideFromMake()
Spandan Das168098c2024-10-28 19:44:34 +0000291 if partitionType == "vendor" {
Spandan Das4cd93b52024-11-05 23:27:03 +0000292 f.createVendorBuildProp(ctx)
Spandan Das168098c2024-10-28 19:44:34 +0000293 }
mrziwang4b0ca972024-10-17 14:56:19 -0700294 return true
295}
296
Cole Faust953476f2024-11-14 14:11:29 -0800297// Creates filegroups for the files specified in BOARD_(partition_)AVB_KEY_PATH
298func (f *filesystemCreator) createAvbKeyFilegroups(ctx android.LoadHookContext) {
299 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
300 var files []string
301
302 if len(partitionVars.BoardAvbKeyPath) > 0 {
303 files = append(files, partitionVars.BoardAvbKeyPath)
304 }
305 for _, partition := range android.SortedKeys(partitionVars.PartitionQualifiedVariables) {
306 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partition]
307 if len(specificPartitionVars.BoardAvbKeyPath) > 0 {
308 files = append(files, specificPartitionVars.BoardAvbKeyPath)
309 }
310 }
311
312 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
313 for _, file := range files {
314 if _, ok := fsGenState.avbKeyFilegroups[file]; ok {
315 continue
316 }
317 if file == "external/avb/test/data/testkey_rsa4096.pem" {
318 // There already exists a checked-in filegroup for this commonly-used key, just use that
319 fsGenState.avbKeyFilegroups[file] = "avb_testkey_rsa4096"
320 continue
321 }
322 dir := filepath.Dir(file)
323 base := filepath.Base(file)
324 name := fmt.Sprintf("avb_key_%x", strings.ReplaceAll(file, "/", "_"))
325 ctx.CreateModuleInDirectory(
326 android.FileGroupFactory,
327 dir,
328 &struct {
329 Name *string
330 Srcs []string
331 Visibility []string
332 }{
333 Name: proptools.StringPtr(name),
334 Srcs: []string{base},
335 Visibility: []string{"//visibility:public"},
336 },
337 )
338 fsGenState.avbKeyFilegroups[file] = name
339 }
340}
341
Spandan Das5e336422024-11-01 22:31:20 +0000342// createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the
Spandan Das7b25a512024-11-06 20:41:26 +0000343// autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency.
344// This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view.
Spandan Das5b493cd2024-11-07 20:55:56 +0000345func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string) {
Spandan Das5e336422024-11-01 22:31:20 +0000346 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Spandan Das7b25a512024-11-06 20:41:26 +0000347 name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType))
348 props := &struct {
Spandan Das912d26b2024-11-06 19:35:17 +0000349 Name *string
350 Srcs []string
Spandan Das5b493cd2024-11-07 20:55:56 +0000351 System_deps []string
Spandan Das912d26b2024-11-06 19:35:17 +0000352 System_dlkm_specific *bool
Spandan Das5b493cd2024-11-07 20:55:56 +0000353 Vendor_dlkm_specific *bool
354 Odm_dlkm_specific *bool
355 Load_by_default *bool
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000356 Blocklist_file *string
Spandan Das7b25a512024-11-06 20:41:26 +0000357 }{
358 Name: proptools.StringPtr(name),
Spandan Das5e336422024-11-01 22:31:20 +0000359 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000360 switch partitionType {
361 case "system_dlkm":
362 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules
Spandan Das912d26b2024-11-06 19:35:17 +0000363 props.System_dlkm_specific = proptools.BoolPtr(true)
Spandan Das5b493cd2024-11-07 20:55:56 +0000364 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelLoadModules) == 0 {
365 // Create empty modules.load file for system
366 // https://source.corp.google.com/h/googleplex-android/platform/build/+/ef55daac9954896161b26db4f3ef1781b5a5694c:core/Makefile;l=695-700;drc=549fe2a5162548bd8b47867d35f907eb22332023;bpv=1;bpt=0
367 props.Load_by_default = proptools.BoolPtr(false)
368 }
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000369 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelBlocklistFile; blocklistFile != "" {
370 props.Blocklist_file = proptools.StringPtr(blocklistFile)
371 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000372 case "vendor_dlkm":
373 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelModules
374 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules) > 0 {
375 props.System_deps = []string{":" + generatedModuleName(ctx.Config(), "system_dlkm-kernel-modules") + "{.modules}"}
376 }
377 props.Vendor_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000378 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelBlocklistFile; blocklistFile != "" {
379 props.Blocklist_file = proptools.StringPtr(blocklistFile)
380 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000381 case "odm_dlkm":
382 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelModules
383 props.Odm_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000384 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelBlocklistFile; blocklistFile != "" {
385 props.Blocklist_file = proptools.StringPtr(blocklistFile)
386 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000387 default:
388 ctx.ModuleErrorf("DLKM is not supported for %s\n", partitionType)
Spandan Das912d26b2024-11-06 19:35:17 +0000389 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000390
391 if len(props.Srcs) == 0 {
392 return // do not generate `prebuilt_kernel_modules` if there are no sources
393 }
394
Spandan Das7b25a512024-11-06 20:41:26 +0000395 kernelModule := ctx.CreateModuleInDirectory(
396 kernel.PrebuiltKernelModulesFactory,
397 ".", // create in root directory for now
398 props,
399 )
400 kernelModule.HideFromMake()
401 // Add to deps
402 (*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config())
Spandan Das5e336422024-11-01 22:31:20 +0000403}
404
Spandan Das4cd93b52024-11-05 23:27:03 +0000405// Create a build_prop and android_info module. This will be used to create /vendor/build.prop
406func (f *filesystemCreator) createVendorBuildProp(ctx android.LoadHookContext) {
407 // Create a android_info for vendor
408 // The board info files might be in a directory outside the root soong namespace, so create
409 // the module in "."
410 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
411 androidInfoProps := &struct {
412 Name *string
413 Board_info_files []string
414 Bootloader_board_name *string
415 }{
416 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "android-info.prop")),
417 Board_info_files: partitionVars.BoardInfoFiles,
418 }
419 if len(androidInfoProps.Board_info_files) == 0 {
420 androidInfoProps.Bootloader_board_name = proptools.StringPtr(partitionVars.BootLoaderBoardName)
421 }
422 androidInfoProp := ctx.CreateModuleInDirectory(
423 android.AndroidInfoFactory,
424 ".",
425 androidInfoProps,
426 )
427 androidInfoProp.HideFromMake()
428 // Create a build prop for vendor
429 vendorBuildProps := &struct {
430 Name *string
431 Vendor *bool
432 Stem *string
433 Product_config *string
434 Android_info *string
435 }{
436 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")),
437 Vendor: proptools.BoolPtr(true),
438 Stem: proptools.StringPtr("build.prop"),
439 Product_config: proptools.StringPtr(":product_config"),
440 Android_info: proptools.StringPtr(":" + androidInfoProp.Name()),
441 }
442 vendorBuildProp := ctx.CreateModule(
443 android.BuildPropFactory,
444 vendorBuildProps,
445 )
446 vendorBuildProp.HideFromMake()
447}
448
Spandan Das8fe68dc2024-10-29 18:20:11 +0000449// createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions
450// 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list)
451// 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list)
452// It creates a filegroup for each file in the fragment list
Spandan Das312cc412024-10-29 18:20:11 +0000453// The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`.
Spandan Das8fe68dc2024-10-29 18:20:11 +0000454func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string {
Spandan Das312cc412024-10-29 18:20:11 +0000455 ret := []string{}
456 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Spandan Das8fe68dc2024-10-29 18:20:11 +0000457 var linkerConfigSrcs []string
458 if partitionType == "vendor" {
459 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs)
460 } else if partitionType == "product" {
461 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs)
462 } else {
463 ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`")
464 }
465
466 if len(linkerConfigSrcs) > 0 {
Spandan Das312cc412024-10-29 18:20:11 +0000467 // Create a filegroup, and add `:<filegroup_name>` to ret.
468 for index, linkerConfigSrc := range linkerConfigSrcs {
469 dir := filepath.Dir(linkerConfigSrc)
470 base := filepath.Base(linkerConfigSrc)
Spandan Das8fe68dc2024-10-29 18:20:11 +0000471 fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index)))
Spandan Das312cc412024-10-29 18:20:11 +0000472 srcs := []string{base}
473 fgProps := &struct {
474 Name *string
475 Srcs proptools.Configurable[[]string]
476 }{
477 Name: proptools.StringPtr(fgName),
478 Srcs: proptools.NewSimpleConfigurable(srcs),
479 }
480 ctx.CreateModuleInDirectory(
481 android.FileGroupFactory,
482 dir,
483 fgProps,
484 )
485 ret = append(ret, ":"+fgName)
486 }
487 }
488 return ret
489}
490
mrziwang4b0ca972024-10-17 14:56:19 -0700491type filesystemBaseProperty struct {
492 Name *string
493 Compile_multilib *string
Cole Faust3552eb62024-11-06 18:07:26 -0800494 Visibility []string
mrziwang4b0ca972024-10-17 14:56:19 -0700495}
496
497func generateBaseProps(namePtr *string) *filesystemBaseProperty {
498 return &filesystemBaseProperty{
499 Name: namePtr,
500 Compile_multilib: proptools.StringPtr("both"),
Cole Faust3552eb62024-11-06 18:07:26 -0800501 // The vbmeta modules are currently in the root directory and depend on the partitions
502 Visibility: []string{"//.", "//build/soong:__subpackages__"},
mrziwang4b0ca972024-10-17 14:56:19 -0700503 }
504}
505
506func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) {
Cole Faust953476f2024-11-14 14:11:29 -0800507 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Cole Faust92ccbe22024-10-03 14:38:37 -0700508 fsProps := &filesystem.FilesystemProperties{}
509
mrziwang4b0ca972024-10-17 14:56:19 -0700510 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Cole Faust76a6e952024-11-07 16:56:45 -0800511 var boardAvbEnable bool
Cole Faust953476f2024-11-14 14:11:29 -0800512 var boardAvbKeyPath string
513 var boardAvbAlgorithm string
514 var boardAvbRollbackIndex string
Cole Faust76a6e952024-11-07 16:56:45 -0800515 var fsType string
516 if strings.Contains(partitionType, "ramdisk") {
517 fsType = "compressed_cpio"
518 } else {
Cole Faust953476f2024-11-14 14:11:29 -0800519 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType]
Cole Faust76a6e952024-11-07 16:56:45 -0800520 fsType = specificPartitionVars.BoardFileSystemType
Cole Faust953476f2024-11-14 14:11:29 -0800521 boardAvbEnable = partitionVars.BoardAvbEnable
522 boardAvbKeyPath = specificPartitionVars.BoardAvbKeyPath
523 boardAvbAlgorithm = specificPartitionVars.BoardAvbAlgorithm
524 boardAvbRollbackIndex = specificPartitionVars.BoardAvbRollbackIndex
525 if boardAvbEnable {
526 if boardAvbKeyPath == "" {
527 boardAvbKeyPath = partitionVars.BoardAvbKeyPath
528 }
529 if boardAvbAlgorithm == "" {
530 boardAvbAlgorithm = partitionVars.BoardAvbAlgorithm
531 }
532 if boardAvbRollbackIndex == "" {
533 boardAvbRollbackIndex = partitionVars.BoardAvbRollbackIndex
534 }
535 }
536 if fsType == "" {
537 fsType = "ext4" //default
538 }
Cole Faust76a6e952024-11-07 16:56:45 -0800539 }
Cole Faust953476f2024-11-14 14:11:29 -0800540 if boardAvbKeyPath != "" {
541 boardAvbKeyPath = ":" + fsGenState.avbKeyFilegroups[boardAvbKeyPath]
mrziwang4b0ca972024-10-17 14:56:19 -0700542 }
Cole Faust76a6e952024-11-07 16:56:45 -0800543
mrziwang4b0ca972024-10-17 14:56:19 -0700544 fsProps.Type = proptools.StringPtr(fsType)
545 if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() {
546 // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs
547 return nil, false
548 }
549
Cole Faust92ccbe22024-10-03 14:38:37 -0700550 // Don't build this module on checkbuilds, the soong-built partitions are still in-progress
551 // and sometimes don't build.
552 fsProps.Unchecked_module = proptools.BoolPtr(true)
553
Jihoon Kang98047cf2024-10-02 17:13:54 +0000554 // BOARD_AVB_ENABLE
Cole Faust76a6e952024-11-07 16:56:45 -0800555 fsProps.Use_avb = proptools.BoolPtr(boardAvbEnable)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000556 // BOARD_AVB_KEY_PATH
Cole Faust953476f2024-11-14 14:11:29 -0800557 fsProps.Avb_private_key = proptools.StringPtr(boardAvbKeyPath)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000558 // BOARD_AVB_ALGORITHM
Cole Faust953476f2024-11-14 14:11:29 -0800559 fsProps.Avb_algorithm = proptools.StringPtr(boardAvbAlgorithm)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000560 // BOARD_AVB_SYSTEM_ROLLBACK_INDEX
Cole Faust953476f2024-11-14 14:11:29 -0800561 if rollbackIndex, err := strconv.ParseInt(boardAvbRollbackIndex, 10, 64); err == nil {
Jihoon Kang98047cf2024-10-02 17:13:54 +0000562 fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex)
563 }
564
Cole Faust92ccbe22024-10-03 14:38:37 -0700565 fsProps.Partition_name = proptools.StringPtr(partitionType)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000566
Cole Faust92ccbe22024-10-03 14:38:37 -0700567 fsProps.Base_dir = proptools.StringPtr(partitionType)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000568
Jihoon Kang0d545b82024-10-11 00:21:57 +0000569 fsProps.Is_auto_generated = proptools.BoolPtr(true)
570
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000571 partitionSpecificFsProps(fsProps, partitionType)
572
Jihoon Kang98047cf2024-10-02 17:13:54 +0000573 // system_image properties that are not set:
574 // - filesystemProperties.Avb_hash_algorithm
575 // - filesystemProperties.File_contexts
576 // - filesystemProperties.Dirs
577 // - filesystemProperties.Symlinks
578 // - filesystemProperties.Fake_timestamp
579 // - filesystemProperties.Uuid
580 // - filesystemProperties.Mount_point
581 // - filesystemProperties.Include_make_built_files
582 // - filesystemProperties.Build_logtags
Jihoon Kang98047cf2024-10-02 17:13:54 +0000583 // - systemImageProperties.Linker_config_src
mrziwang4b0ca972024-10-17 14:56:19 -0700584
585 return fsProps, true
Cole Faust92ccbe22024-10-03 14:38:37 -0700586}
587
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800588func (f *filesystemCreator) createFileListDiffTest(ctx android.ModuleContext, partitionType string) android.Path {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000589 partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700590 systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag)
591 filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider)
592 if !ok {
593 ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName)
594 }
595 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 +0000596 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName))
Cole Faust92ccbe22024-10-03 14:38:37 -0700597
598 builder := android.NewRuleBuilder(pctx, ctx)
599 builder.Command().BuiltTool("file_list_diff").
600 Input(makeFileList).
601 Input(filesystemInfo.FileListFile).
Cole Faust56301572024-11-07 15:22:42 -0800602 Text(partitionModuleName)
Cole Faust92ccbe22024-10-03 14:38:37 -0700603 builder.Command().Text("touch").Output(diffTestResultFile)
604 builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test")
605 return diffTestResultFile
606}
607
608func createFailingCommand(ctx android.ModuleContext, message string) android.Path {
609 hasher := sha256.New()
610 hasher.Write([]byte(message))
611 filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil))
612 file := android.PathForModuleOut(ctx, filename)
613 builder := android.NewRuleBuilder(pctx, ctx)
614 builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message))
615 builder.Command().Text("exit 1 #").Output(file)
616 builder.Build("failing command "+filename, "failing command "+filename)
617 return file
618}
619
Cole Faust3552eb62024-11-06 18:07:26 -0800620func createVbmetaDiff(ctx android.ModuleContext, vbmetaModuleName string, vbmetaPartitionName string) android.Path {
621 vbmetaModule := ctx.GetDirectDepWithTag(vbmetaModuleName, generatedVbmetaPartitionDepTag)
622 outputFilesProvider, ok := android.OtherModuleProvider(ctx, vbmetaModule, android.OutputFilesProvider)
623 if !ok {
624 ctx.ModuleErrorf("Expected module %s to provide OutputFiles", vbmetaModule)
625 }
626 if len(outputFilesProvider.DefaultOutputFiles) != 1 {
627 ctx.ModuleErrorf("Expected 1 output file from module %s", vbmetaModule)
628 }
629 soongVbMetaFile := outputFilesProvider.DefaultOutputFiles[0]
630 makeVbmetaFile := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/%s.img", ctx.Config().DeviceName(), vbmetaPartitionName))
631
632 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", vbmetaModuleName))
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800633 createDiffTest(ctx, diffTestResultFile, soongVbMetaFile, makeVbmetaFile)
634 return diffTestResultFile
635}
636
637func createDiffTest(ctx android.ModuleContext, diffTestResultFile android.WritablePath, file1 android.Path, file2 android.Path) {
Cole Faust3552eb62024-11-06 18:07:26 -0800638 builder := android.NewRuleBuilder(pctx, ctx)
639 builder.Command().Text("diff").
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800640 Input(file1).
641 Input(file2)
Cole Faust3552eb62024-11-06 18:07:26 -0800642 builder.Command().Text("touch").Output(diffTestResultFile)
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800643 builder.Build("diff test "+diffTestResultFile.String(), "diff test")
Cole Faust3552eb62024-11-06 18:07:26 -0800644}
645
Cole Faust92ccbe22024-10-03 14:38:37 -0700646type systemImageDepTagType struct {
647 blueprint.BaseDependencyTag
648}
649
650var generatedFilesystemDepTag systemImageDepTagType
Cole Faust3552eb62024-11-06 18:07:26 -0800651var generatedVbmetaPartitionDepTag systemImageDepTagType
Cole Faust92ccbe22024-10-03 14:38:37 -0700652
653func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) {
654 for _, partitionType := range f.properties.Generated_partition_types {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000655 ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType))
Cole Faust92ccbe22024-10-03 14:38:37 -0700656 }
Cole Faust3552eb62024-11-06 18:07:26 -0800657 for _, vbmetaModule := range f.properties.Vbmeta_module_names {
658 ctx.AddDependency(ctx.Module(), generatedVbmetaPartitionDepTag, vbmetaModule)
659 }
Jihoon Kang98047cf2024-10-02 17:13:54 +0000660}
661
662func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Cole Faust92ccbe22024-10-03 14:38:37 -0700663 if ctx.ModuleDir() != "build/soong/fsgen" {
664 ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen")
665 }
666 f.HideFromMake()
Jihoon Kang98047cf2024-10-02 17:13:54 +0000667
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000668 var content strings.Builder
669 generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp")
670 for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions {
671 content.WriteString(generateBpContent(ctx, partition))
672 content.WriteString("\n")
673 }
674 android.WriteFileRule(ctx, generatedBp, content.String())
675
mrziwang8f86c882024-10-03 12:34:33 -0700676 ctx.Phony("product_config_to_bp", generatedBp)
677
Cole Faust92ccbe22024-10-03 14:38:37 -0700678 var diffTestFiles []android.Path
679 for _, partitionType := range f.properties.Generated_partition_types {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800680 diffTestFile := f.createFileListDiffTest(ctx, partitionType)
Jihoon Kang72f812f2024-10-17 18:46:24 +0000681 diffTestFiles = append(diffTestFiles, diffTestFile)
682 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700683 }
684 for _, partitionType := range f.properties.Unsupported_partition_types {
Jihoon Kang72f812f2024-10-17 18:46:24 +0000685 diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType))
686 diffTestFiles = append(diffTestFiles, diffTestFile)
687 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700688 }
Cole Faust3552eb62024-11-06 18:07:26 -0800689 for i, vbmetaModule := range f.properties.Vbmeta_module_names {
690 diffTestFile := createVbmetaDiff(ctx, vbmetaModule, f.properties.Vbmeta_partition_names[i])
691 diffTestFiles = append(diffTestFiles, diffTestFile)
692 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", f.properties.Vbmeta_partition_names[i]), diffTestFile)
693 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800694 if f.properties.Boot_image != "" {
695 diffTestFile := android.PathForModuleOut(ctx, "boot_diff_test.txt")
696 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image)
697 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/boot.img", ctx.Config().DeviceName()))
698 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
699 diffTestFiles = append(diffTestFiles, diffTestFile)
700 ctx.Phony("soong_generated_boot_filesystem_test", diffTestFile)
701 }
Cole Faust92ccbe22024-10-03 14:38:37 -0700702 ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000703}
mrziwang8f86c882024-10-03 12:34:33 -0700704
mrziwang8f86c882024-10-03 12:34:33 -0700705func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string {
mrziwang4b0ca972024-10-17 14:56:19 -0700706 fsProps, fsTypeSupported := generateFsProps(ctx, partitionType)
707 if !fsTypeSupported {
708 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700709 }
710
mrziwang4b0ca972024-10-17 14:56:19 -0700711 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
Jihoon Kang0d7b0112024-11-13 20:44:05 +0000712 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
713 deps := fsGenState.fsDeps[partitionType]
714 highPriorityDeps := fsGenState.generatedPrebuiltEtcModuleNames
715 depProps := generateDepStruct(*deps, highPriorityDeps)
mrziwang8f86c882024-10-03 12:34:33 -0700716
mrziwang4b0ca972024-10-17 14:56:19 -0700717 result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps})
mrziwang8f86c882024-10-03 12:34:33 -0700718 if err != nil {
Cole Faustae3e1d32024-11-05 13:22:50 -0800719 ctx.ModuleErrorf("%s", err.Error())
720 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700721 }
722
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000723 moduleType := "android_filesystem"
724 if partitionType == "system" {
725 moduleType = "android_system_image"
726 }
727
mrziwang8f86c882024-10-03 12:34:33 -0700728 file := &parser.File{
729 Defs: []parser.Definition{
730 &parser.Module{
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000731 Type: moduleType,
mrziwang8f86c882024-10-03 12:34:33 -0700732 Map: *result,
733 },
734 },
735 }
736 bytes, err := parser.Print(file)
737 if err != nil {
738 ctx.ModuleErrorf(err.Error())
739 }
740 return strings.TrimSpace(string(bytes))
741}