blob: 4d15b4b888995b20c27455310a76c7b9882757d0 [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 }
221 fsProps.Base_dir = proptools.StringPtr("system")
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000222 case "system_ext":
223 fsProps.Fsverity.Inputs = []string{
224 "framework/*",
225 "framework/*/*", // framework/{arch}
226 "framework/oat/*/*", // framework/oat/{arch}
227 }
228 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000229 case "product":
230 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
231 case "vendor":
232 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Spandan Das69464c32024-10-25 20:08:06 +0000233 fsProps.Symlinks = []filesystem.SymlinkDefinition{
234 filesystem.SymlinkDefinition{
235 Target: proptools.StringPtr("/odm"),
236 Name: proptools.StringPtr("vendor/odm"),
237 },
238 filesystem.SymlinkDefinition{
239 Target: proptools.StringPtr("/vendor_dlkm/lib/modules"),
240 Name: proptools.StringPtr("vendor/lib/modules"),
241 },
242 }
243 fsProps.Base_dir = proptools.StringPtr("vendor")
Spandan Dasc5717162024-11-01 18:33:57 +0000244 case "odm":
245 fsProps.Symlinks = []filesystem.SymlinkDefinition{
246 filesystem.SymlinkDefinition{
247 Target: proptools.StringPtr("/odm_dlkm/lib/modules"),
248 Name: proptools.StringPtr("odm/lib/modules"),
249 },
250 }
251 fsProps.Base_dir = proptools.StringPtr("odm")
mrziwang23ba8762024-11-07 16:21:53 -0800252 case "userdata":
253 fsProps.Base_dir = proptools.StringPtr("data")
Spandan Dasc5717162024-11-01 18:33:57 +0000254
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000255 }
256}
Spandan Dascbe641a2024-10-14 21:07:34 +0000257
Spandan Das5b493cd2024-11-07 20:55:56 +0000258var (
259 dlkmPartitions = []string{
260 "system_dlkm",
261 "vendor_dlkm",
262 "odm_dlkm",
263 }
264)
265
Cole Faust92ccbe22024-10-03 14:38:37 -0700266// Creates a soong module to build the given partition. Returns false if we can't support building
267// it.
268func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool {
mrziwang4b0ca972024-10-17 14:56:19 -0700269 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
270
271 fsProps, supported := generateFsProps(ctx, partitionType)
272 if !supported {
273 return false
mrziwanga077b942024-10-16 16:00:06 -0700274 }
mrziwanga077b942024-10-16 16:00:06 -0700275
Spandan Das8fe68dc2024-10-29 18:20:11 +0000276 if partitionType == "vendor" || partitionType == "product" {
Spandan Das2047a4c2024-11-11 21:24:58 +0000277 fsProps.Linker_config.Gen_linker_config = proptools.BoolPtr(true)
278 fsProps.Linker_config.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType)
Spandan Das312cc412024-10-29 18:20:11 +0000279 }
280
Spandan Das5b493cd2024-11-07 20:55:56 +0000281 if android.InList(partitionType, dlkmPartitions) {
282 f.createPrebuiltKernelModules(ctx, partitionType)
Spandan Das5e336422024-11-01 22:31:20 +0000283 }
284
mrziwang4b0ca972024-10-17 14:56:19 -0700285 var module android.Module
286 if partitionType == "system" {
287 module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps)
288 } else {
289 // Explicitly set the partition.
290 fsProps.Partition_type = proptools.StringPtr(partitionType)
291 module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps)
292 }
293 module.HideFromMake()
Spandan Das168098c2024-10-28 19:44:34 +0000294 if partitionType == "vendor" {
Spandan Das4cd93b52024-11-05 23:27:03 +0000295 f.createVendorBuildProp(ctx)
Spandan Das168098c2024-10-28 19:44:34 +0000296 }
mrziwang4b0ca972024-10-17 14:56:19 -0700297 return true
298}
299
Cole Faust953476f2024-11-14 14:11:29 -0800300// Creates filegroups for the files specified in BOARD_(partition_)AVB_KEY_PATH
301func (f *filesystemCreator) createAvbKeyFilegroups(ctx android.LoadHookContext) {
302 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
303 var files []string
304
305 if len(partitionVars.BoardAvbKeyPath) > 0 {
306 files = append(files, partitionVars.BoardAvbKeyPath)
307 }
308 for _, partition := range android.SortedKeys(partitionVars.PartitionQualifiedVariables) {
309 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partition]
310 if len(specificPartitionVars.BoardAvbKeyPath) > 0 {
311 files = append(files, specificPartitionVars.BoardAvbKeyPath)
312 }
313 }
314
315 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
316 for _, file := range files {
317 if _, ok := fsGenState.avbKeyFilegroups[file]; ok {
318 continue
319 }
320 if file == "external/avb/test/data/testkey_rsa4096.pem" {
321 // There already exists a checked-in filegroup for this commonly-used key, just use that
322 fsGenState.avbKeyFilegroups[file] = "avb_testkey_rsa4096"
323 continue
324 }
325 dir := filepath.Dir(file)
326 base := filepath.Base(file)
327 name := fmt.Sprintf("avb_key_%x", strings.ReplaceAll(file, "/", "_"))
328 ctx.CreateModuleInDirectory(
329 android.FileGroupFactory,
330 dir,
331 &struct {
332 Name *string
333 Srcs []string
334 Visibility []string
335 }{
336 Name: proptools.StringPtr(name),
337 Srcs: []string{base},
338 Visibility: []string{"//visibility:public"},
339 },
340 )
341 fsGenState.avbKeyFilegroups[file] = name
342 }
343}
344
Spandan Das5e336422024-11-01 22:31:20 +0000345// createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the
Spandan Das7b25a512024-11-06 20:41:26 +0000346// autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency.
347// This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view.
Spandan Das5b493cd2024-11-07 20:55:56 +0000348func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string) {
Spandan Das5e336422024-11-01 22:31:20 +0000349 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Spandan Das7b25a512024-11-06 20:41:26 +0000350 name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType))
351 props := &struct {
Spandan Das912d26b2024-11-06 19:35:17 +0000352 Name *string
353 Srcs []string
Spandan Das5b493cd2024-11-07 20:55:56 +0000354 System_deps []string
Spandan Das912d26b2024-11-06 19:35:17 +0000355 System_dlkm_specific *bool
Spandan Das5b493cd2024-11-07 20:55:56 +0000356 Vendor_dlkm_specific *bool
357 Odm_dlkm_specific *bool
358 Load_by_default *bool
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000359 Blocklist_file *string
Spandan Das7b25a512024-11-06 20:41:26 +0000360 }{
361 Name: proptools.StringPtr(name),
Spandan Das5e336422024-11-01 22:31:20 +0000362 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000363 switch partitionType {
364 case "system_dlkm":
365 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules
Spandan Das912d26b2024-11-06 19:35:17 +0000366 props.System_dlkm_specific = proptools.BoolPtr(true)
Spandan Das5b493cd2024-11-07 20:55:56 +0000367 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelLoadModules) == 0 {
368 // Create empty modules.load file for system
369 // https://source.corp.google.com/h/googleplex-android/platform/build/+/ef55daac9954896161b26db4f3ef1781b5a5694c:core/Makefile;l=695-700;drc=549fe2a5162548bd8b47867d35f907eb22332023;bpv=1;bpt=0
370 props.Load_by_default = proptools.BoolPtr(false)
371 }
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000372 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelBlocklistFile; blocklistFile != "" {
373 props.Blocklist_file = proptools.StringPtr(blocklistFile)
374 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000375 case "vendor_dlkm":
376 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelModules
377 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules) > 0 {
378 props.System_deps = []string{":" + generatedModuleName(ctx.Config(), "system_dlkm-kernel-modules") + "{.modules}"}
379 }
380 props.Vendor_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000381 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelBlocklistFile; blocklistFile != "" {
382 props.Blocklist_file = proptools.StringPtr(blocklistFile)
383 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000384 case "odm_dlkm":
385 props.Srcs = ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelModules
386 props.Odm_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000387 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelBlocklistFile; blocklistFile != "" {
388 props.Blocklist_file = proptools.StringPtr(blocklistFile)
389 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000390 default:
391 ctx.ModuleErrorf("DLKM is not supported for %s\n", partitionType)
Spandan Das912d26b2024-11-06 19:35:17 +0000392 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000393
394 if len(props.Srcs) == 0 {
395 return // do not generate `prebuilt_kernel_modules` if there are no sources
396 }
397
Spandan Das7b25a512024-11-06 20:41:26 +0000398 kernelModule := ctx.CreateModuleInDirectory(
399 kernel.PrebuiltKernelModulesFactory,
400 ".", // create in root directory for now
401 props,
402 )
403 kernelModule.HideFromMake()
404 // Add to deps
405 (*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config())
Spandan Das5e336422024-11-01 22:31:20 +0000406}
407
Spandan Das4cd93b52024-11-05 23:27:03 +0000408// Create a build_prop and android_info module. This will be used to create /vendor/build.prop
409func (f *filesystemCreator) createVendorBuildProp(ctx android.LoadHookContext) {
410 // Create a android_info for vendor
411 // The board info files might be in a directory outside the root soong namespace, so create
412 // the module in "."
413 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
414 androidInfoProps := &struct {
415 Name *string
416 Board_info_files []string
417 Bootloader_board_name *string
418 }{
419 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "android-info.prop")),
420 Board_info_files: partitionVars.BoardInfoFiles,
421 }
422 if len(androidInfoProps.Board_info_files) == 0 {
423 androidInfoProps.Bootloader_board_name = proptools.StringPtr(partitionVars.BootLoaderBoardName)
424 }
425 androidInfoProp := ctx.CreateModuleInDirectory(
426 android.AndroidInfoFactory,
427 ".",
428 androidInfoProps,
429 )
430 androidInfoProp.HideFromMake()
431 // Create a build prop for vendor
432 vendorBuildProps := &struct {
433 Name *string
434 Vendor *bool
435 Stem *string
436 Product_config *string
437 Android_info *string
438 }{
439 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")),
440 Vendor: proptools.BoolPtr(true),
441 Stem: proptools.StringPtr("build.prop"),
442 Product_config: proptools.StringPtr(":product_config"),
443 Android_info: proptools.StringPtr(":" + androidInfoProp.Name()),
444 }
445 vendorBuildProp := ctx.CreateModule(
446 android.BuildPropFactory,
447 vendorBuildProps,
448 )
449 vendorBuildProp.HideFromMake()
450}
451
Spandan Das8fe68dc2024-10-29 18:20:11 +0000452// createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions
453// 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list)
454// 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list)
455// It creates a filegroup for each file in the fragment list
Spandan Das312cc412024-10-29 18:20:11 +0000456// The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`.
Spandan Das8fe68dc2024-10-29 18:20:11 +0000457func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string {
Spandan Das312cc412024-10-29 18:20:11 +0000458 ret := []string{}
459 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Spandan Das8fe68dc2024-10-29 18:20:11 +0000460 var linkerConfigSrcs []string
461 if partitionType == "vendor" {
462 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs)
463 } else if partitionType == "product" {
464 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs)
465 } else {
466 ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`")
467 }
468
469 if len(linkerConfigSrcs) > 0 {
Spandan Das312cc412024-10-29 18:20:11 +0000470 // Create a filegroup, and add `:<filegroup_name>` to ret.
471 for index, linkerConfigSrc := range linkerConfigSrcs {
472 dir := filepath.Dir(linkerConfigSrc)
473 base := filepath.Base(linkerConfigSrc)
Spandan Das8fe68dc2024-10-29 18:20:11 +0000474 fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index)))
Spandan Das312cc412024-10-29 18:20:11 +0000475 srcs := []string{base}
476 fgProps := &struct {
477 Name *string
478 Srcs proptools.Configurable[[]string]
479 }{
480 Name: proptools.StringPtr(fgName),
481 Srcs: proptools.NewSimpleConfigurable(srcs),
482 }
483 ctx.CreateModuleInDirectory(
484 android.FileGroupFactory,
485 dir,
486 fgProps,
487 )
488 ret = append(ret, ":"+fgName)
489 }
490 }
491 return ret
492}
493
mrziwang4b0ca972024-10-17 14:56:19 -0700494type filesystemBaseProperty struct {
495 Name *string
496 Compile_multilib *string
Cole Faust3552eb62024-11-06 18:07:26 -0800497 Visibility []string
mrziwang4b0ca972024-10-17 14:56:19 -0700498}
499
500func generateBaseProps(namePtr *string) *filesystemBaseProperty {
501 return &filesystemBaseProperty{
502 Name: namePtr,
503 Compile_multilib: proptools.StringPtr("both"),
Cole Faust3552eb62024-11-06 18:07:26 -0800504 // The vbmeta modules are currently in the root directory and depend on the partitions
505 Visibility: []string{"//.", "//build/soong:__subpackages__"},
mrziwang4b0ca972024-10-17 14:56:19 -0700506 }
507}
508
509func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) {
Cole Faust953476f2024-11-14 14:11:29 -0800510 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Cole Faust92ccbe22024-10-03 14:38:37 -0700511 fsProps := &filesystem.FilesystemProperties{}
512
mrziwang4b0ca972024-10-17 14:56:19 -0700513 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Cole Faust76a6e952024-11-07 16:56:45 -0800514 var boardAvbEnable bool
Cole Faust953476f2024-11-14 14:11:29 -0800515 var boardAvbKeyPath string
516 var boardAvbAlgorithm string
517 var boardAvbRollbackIndex string
Cole Faust76a6e952024-11-07 16:56:45 -0800518 var fsType string
519 if strings.Contains(partitionType, "ramdisk") {
520 fsType = "compressed_cpio"
521 } else {
Cole Faust953476f2024-11-14 14:11:29 -0800522 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType]
Cole Faust76a6e952024-11-07 16:56:45 -0800523 fsType = specificPartitionVars.BoardFileSystemType
Cole Faust953476f2024-11-14 14:11:29 -0800524 boardAvbEnable = partitionVars.BoardAvbEnable
525 boardAvbKeyPath = specificPartitionVars.BoardAvbKeyPath
526 boardAvbAlgorithm = specificPartitionVars.BoardAvbAlgorithm
527 boardAvbRollbackIndex = specificPartitionVars.BoardAvbRollbackIndex
528 if boardAvbEnable {
529 if boardAvbKeyPath == "" {
530 boardAvbKeyPath = partitionVars.BoardAvbKeyPath
531 }
532 if boardAvbAlgorithm == "" {
533 boardAvbAlgorithm = partitionVars.BoardAvbAlgorithm
534 }
535 if boardAvbRollbackIndex == "" {
536 boardAvbRollbackIndex = partitionVars.BoardAvbRollbackIndex
537 }
538 }
539 if fsType == "" {
540 fsType = "ext4" //default
541 }
Cole Faust76a6e952024-11-07 16:56:45 -0800542 }
Cole Faust953476f2024-11-14 14:11:29 -0800543 if boardAvbKeyPath != "" {
544 boardAvbKeyPath = ":" + fsGenState.avbKeyFilegroups[boardAvbKeyPath]
mrziwang4b0ca972024-10-17 14:56:19 -0700545 }
Cole Faust76a6e952024-11-07 16:56:45 -0800546
mrziwang4b0ca972024-10-17 14:56:19 -0700547 fsProps.Type = proptools.StringPtr(fsType)
548 if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() {
549 // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs
550 return nil, false
551 }
552
Cole Faust92ccbe22024-10-03 14:38:37 -0700553 // Don't build this module on checkbuilds, the soong-built partitions are still in-progress
554 // and sometimes don't build.
555 fsProps.Unchecked_module = proptools.BoolPtr(true)
556
Jihoon Kang98047cf2024-10-02 17:13:54 +0000557 // BOARD_AVB_ENABLE
Cole Faust76a6e952024-11-07 16:56:45 -0800558 fsProps.Use_avb = proptools.BoolPtr(boardAvbEnable)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000559 // BOARD_AVB_KEY_PATH
Cole Faust953476f2024-11-14 14:11:29 -0800560 fsProps.Avb_private_key = proptools.StringPtr(boardAvbKeyPath)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000561 // BOARD_AVB_ALGORITHM
Cole Faust953476f2024-11-14 14:11:29 -0800562 fsProps.Avb_algorithm = proptools.StringPtr(boardAvbAlgorithm)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000563 // BOARD_AVB_SYSTEM_ROLLBACK_INDEX
Cole Faust953476f2024-11-14 14:11:29 -0800564 if rollbackIndex, err := strconv.ParseInt(boardAvbRollbackIndex, 10, 64); err == nil {
Jihoon Kang98047cf2024-10-02 17:13:54 +0000565 fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex)
566 }
567
Cole Faust92ccbe22024-10-03 14:38:37 -0700568 fsProps.Partition_name = proptools.StringPtr(partitionType)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000569
Cole Faust92ccbe22024-10-03 14:38:37 -0700570 fsProps.Base_dir = proptools.StringPtr(partitionType)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000571
Jihoon Kang0d545b82024-10-11 00:21:57 +0000572 fsProps.Is_auto_generated = proptools.BoolPtr(true)
573
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000574 partitionSpecificFsProps(fsProps, partitionType)
575
Jihoon Kang98047cf2024-10-02 17:13:54 +0000576 // system_image properties that are not set:
577 // - filesystemProperties.Avb_hash_algorithm
578 // - filesystemProperties.File_contexts
579 // - filesystemProperties.Dirs
580 // - filesystemProperties.Symlinks
581 // - filesystemProperties.Fake_timestamp
582 // - filesystemProperties.Uuid
583 // - filesystemProperties.Mount_point
584 // - filesystemProperties.Include_make_built_files
585 // - filesystemProperties.Build_logtags
Jihoon Kang98047cf2024-10-02 17:13:54 +0000586 // - systemImageProperties.Linker_config_src
mrziwang4b0ca972024-10-17 14:56:19 -0700587
588 return fsProps, true
Cole Faust92ccbe22024-10-03 14:38:37 -0700589}
590
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800591func (f *filesystemCreator) createFileListDiffTest(ctx android.ModuleContext, partitionType string) android.Path {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000592 partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700593 systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag)
594 filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider)
595 if !ok {
596 ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName)
597 }
598 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 +0000599 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName))
Cole Faust92ccbe22024-10-03 14:38:37 -0700600
601 builder := android.NewRuleBuilder(pctx, ctx)
602 builder.Command().BuiltTool("file_list_diff").
603 Input(makeFileList).
604 Input(filesystemInfo.FileListFile).
Cole Faust56301572024-11-07 15:22:42 -0800605 Text(partitionModuleName)
Cole Faust92ccbe22024-10-03 14:38:37 -0700606 builder.Command().Text("touch").Output(diffTestResultFile)
607 builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test")
608 return diffTestResultFile
609}
610
611func createFailingCommand(ctx android.ModuleContext, message string) android.Path {
612 hasher := sha256.New()
613 hasher.Write([]byte(message))
614 filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil))
615 file := android.PathForModuleOut(ctx, filename)
616 builder := android.NewRuleBuilder(pctx, ctx)
617 builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message))
618 builder.Command().Text("exit 1 #").Output(file)
619 builder.Build("failing command "+filename, "failing command "+filename)
620 return file
621}
622
Cole Faust3552eb62024-11-06 18:07:26 -0800623func createVbmetaDiff(ctx android.ModuleContext, vbmetaModuleName string, vbmetaPartitionName string) android.Path {
624 vbmetaModule := ctx.GetDirectDepWithTag(vbmetaModuleName, generatedVbmetaPartitionDepTag)
625 outputFilesProvider, ok := android.OtherModuleProvider(ctx, vbmetaModule, android.OutputFilesProvider)
626 if !ok {
627 ctx.ModuleErrorf("Expected module %s to provide OutputFiles", vbmetaModule)
628 }
629 if len(outputFilesProvider.DefaultOutputFiles) != 1 {
630 ctx.ModuleErrorf("Expected 1 output file from module %s", vbmetaModule)
631 }
632 soongVbMetaFile := outputFilesProvider.DefaultOutputFiles[0]
633 makeVbmetaFile := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/%s.img", ctx.Config().DeviceName(), vbmetaPartitionName))
634
635 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", vbmetaModuleName))
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800636 createDiffTest(ctx, diffTestResultFile, soongVbMetaFile, makeVbmetaFile)
637 return diffTestResultFile
638}
639
640func createDiffTest(ctx android.ModuleContext, diffTestResultFile android.WritablePath, file1 android.Path, file2 android.Path) {
Cole Faust3552eb62024-11-06 18:07:26 -0800641 builder := android.NewRuleBuilder(pctx, ctx)
642 builder.Command().Text("diff").
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800643 Input(file1).
644 Input(file2)
Cole Faust3552eb62024-11-06 18:07:26 -0800645 builder.Command().Text("touch").Output(diffTestResultFile)
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800646 builder.Build("diff test "+diffTestResultFile.String(), "diff test")
Cole Faust3552eb62024-11-06 18:07:26 -0800647}
648
Cole Faust92ccbe22024-10-03 14:38:37 -0700649type systemImageDepTagType struct {
650 blueprint.BaseDependencyTag
651}
652
653var generatedFilesystemDepTag systemImageDepTagType
Cole Faust3552eb62024-11-06 18:07:26 -0800654var generatedVbmetaPartitionDepTag systemImageDepTagType
Cole Faust92ccbe22024-10-03 14:38:37 -0700655
656func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) {
657 for _, partitionType := range f.properties.Generated_partition_types {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000658 ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType))
Cole Faust92ccbe22024-10-03 14:38:37 -0700659 }
Cole Faust3552eb62024-11-06 18:07:26 -0800660 for _, vbmetaModule := range f.properties.Vbmeta_module_names {
661 ctx.AddDependency(ctx.Module(), generatedVbmetaPartitionDepTag, vbmetaModule)
662 }
Jihoon Kang98047cf2024-10-02 17:13:54 +0000663}
664
665func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Cole Faust92ccbe22024-10-03 14:38:37 -0700666 if ctx.ModuleDir() != "build/soong/fsgen" {
667 ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen")
668 }
669 f.HideFromMake()
Jihoon Kang98047cf2024-10-02 17:13:54 +0000670
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000671 var content strings.Builder
672 generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp")
673 for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions {
674 content.WriteString(generateBpContent(ctx, partition))
675 content.WriteString("\n")
676 }
677 android.WriteFileRule(ctx, generatedBp, content.String())
678
mrziwang8f86c882024-10-03 12:34:33 -0700679 ctx.Phony("product_config_to_bp", generatedBp)
680
Cole Faust92ccbe22024-10-03 14:38:37 -0700681 var diffTestFiles []android.Path
682 for _, partitionType := range f.properties.Generated_partition_types {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800683 diffTestFile := f.createFileListDiffTest(ctx, partitionType)
Jihoon Kang72f812f2024-10-17 18:46:24 +0000684 diffTestFiles = append(diffTestFiles, diffTestFile)
685 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700686 }
687 for _, partitionType := range f.properties.Unsupported_partition_types {
Jihoon Kang72f812f2024-10-17 18:46:24 +0000688 diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType))
689 diffTestFiles = append(diffTestFiles, diffTestFile)
690 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700691 }
Cole Faust3552eb62024-11-06 18:07:26 -0800692 for i, vbmetaModule := range f.properties.Vbmeta_module_names {
693 diffTestFile := createVbmetaDiff(ctx, vbmetaModule, f.properties.Vbmeta_partition_names[i])
694 diffTestFiles = append(diffTestFiles, diffTestFile)
695 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", f.properties.Vbmeta_partition_names[i]), diffTestFile)
696 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800697 if f.properties.Boot_image != "" {
698 diffTestFile := android.PathForModuleOut(ctx, "boot_diff_test.txt")
699 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image)
700 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/boot.img", ctx.Config().DeviceName()))
701 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
702 diffTestFiles = append(diffTestFiles, diffTestFile)
703 ctx.Phony("soong_generated_boot_filesystem_test", diffTestFile)
704 }
Cole Faust92ccbe22024-10-03 14:38:37 -0700705 ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000706}
mrziwang8f86c882024-10-03 12:34:33 -0700707
mrziwang8f86c882024-10-03 12:34:33 -0700708func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string {
mrziwang4b0ca972024-10-17 14:56:19 -0700709 fsProps, fsTypeSupported := generateFsProps(ctx, partitionType)
710 if !fsTypeSupported {
711 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700712 }
713
mrziwang4b0ca972024-10-17 14:56:19 -0700714 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
Jihoon Kang0d7b0112024-11-13 20:44:05 +0000715 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
716 deps := fsGenState.fsDeps[partitionType]
717 highPriorityDeps := fsGenState.generatedPrebuiltEtcModuleNames
718 depProps := generateDepStruct(*deps, highPriorityDeps)
mrziwang8f86c882024-10-03 12:34:33 -0700719
mrziwang4b0ca972024-10-17 14:56:19 -0700720 result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps})
mrziwang8f86c882024-10-03 12:34:33 -0700721 if err != nil {
Cole Faustae3e1d32024-11-05 13:22:50 -0800722 ctx.ModuleErrorf("%s", err.Error())
723 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700724 }
725
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000726 moduleType := "android_filesystem"
727 if partitionType == "system" {
728 moduleType = "android_system_image"
729 }
730
mrziwang8f86c882024-10-03 12:34:33 -0700731 file := &parser.File{
732 Defs: []parser.Definition{
733 &parser.Module{
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000734 Type: moduleType,
mrziwang8f86c882024-10-03 12:34:33 -0700735 Map: *result,
736 },
737 },
738 }
739 bytes, err := parser.Print(file)
740 if err != nil {
741 ctx.ModuleErrorf(err.Error())
742 }
743 return strings.TrimSpace(string(bytes))
744}