blob: d178710cf8190d94dc831fbd3dd25f1ba30a47c1 [file] [log] [blame]
Jiyong Park6f0f6882020-11-12 13:14:30 +09001// Copyright (C) 2020 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 filesystem
16
17import (
Jooyung Han65f402b2022-04-21 14:24:04 +090018 "crypto/sha256"
Jiyong Park6f0f6882020-11-12 13:14:30 +090019 "fmt"
Jooyung Han65f402b2022-04-21 14:24:04 +090020 "io"
Inseob Kim14199b02021-02-09 21:18:31 +090021 "path/filepath"
Cole Faust4a2a7c92024-03-12 12:44:40 -070022 "slices"
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +000023 "strconv"
Inseob Kim14199b02021-02-09 21:18:31 +090024 "strings"
Jiyong Park6f0f6882020-11-12 13:14:30 +090025
26 "android/soong/android"
Jooyung Hane6067592023-03-16 13:11:17 +090027 "android/soong/cc"
Spandan Das92631882024-10-28 22:49:38 +000028 "android/soong/linkerconfig"
Jiyong Park65b62242020-11-25 12:44:59 +090029
30 "github.com/google/blueprint"
Jiyong Park71baa762021-01-18 21:11:03 +090031 "github.com/google/blueprint/proptools"
Jiyong Park6f0f6882020-11-12 13:14:30 +090032)
33
34func init() {
Jooyung Han9706cbc2021-04-15 22:43:48 +090035 registerBuildComponents(android.InitRegistrationContext)
36}
37
38func registerBuildComponents(ctx android.RegistrationContext) {
Cole Faust92ccbe22024-10-03 14:38:37 -070039 ctx.RegisterModuleType("android_filesystem", FilesystemFactory)
Jiyong Parkf46b1af2024-04-05 18:13:33 +090040 ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory)
Jihoon Kang98047cf2024-10-02 17:13:54 +000041 ctx.RegisterModuleType("android_system_image", SystemImageFactory)
Jiyong Parkbc485482022-11-15 22:31:49 +090042 ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090043 ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory)
Alice Wang000e3a32023-01-03 16:11:20 +000044 ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090045 ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090046}
47
48type filesystem struct {
49 android.ModuleBase
50 android.PackagingBase
Jiyong Parkf46b1af2024-04-05 18:13:33 +090051 android.DefaultableModuleBase
Jiyong Park65c49f52020-11-24 14:23:26 +090052
Jihoon Kang98047cf2024-10-02 17:13:54 +000053 properties FilesystemProperties
Jiyong Park71baa762021-01-18 21:11:03 +090054
Jiyong Parkfa616132021-04-20 11:36:40 +090055 // Function that builds extra files under the root directory and returns the files
56 buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
57
Jeongik Cha54bf8752024-02-08 10:44:37 +090058 // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs()
59 filterPackagingSpec func(spec android.PackagingSpec) bool
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090060
Jiyong Park65c49f52020-11-24 14:23:26 +090061 output android.OutputPath
62 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090063
Kiyoung Kim99a954d2024-06-21 14:22:20 +090064 fileListFile android.OutputPath
65
66 // Keeps the entries installed from this filesystem
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090067 entries []string
Jiyong Park6f0f6882020-11-12 13:14:30 +090068}
69
Spandan Das69464c32024-10-25 20:08:06 +000070type SymlinkDefinition struct {
Inseob Kim14199b02021-02-09 21:18:31 +090071 Target *string
72 Name *string
73}
74
Jihoon Kang98047cf2024-10-02 17:13:54 +000075type FilesystemProperties struct {
Jiyong Park71baa762021-01-18 21:11:03 +090076 // When set to true, sign the image with avbtool. Default is false.
77 Use_avb *bool
78
79 // Path to the private key that avbtool will use to sign this filesystem image.
80 // TODO(jiyong): allow apex_key to be specified here
81 Avb_private_key *string `android:"path"`
82
Shikha Panwar01403bb2022-12-22 12:22:57 +000083 // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Jiyong Park71baa762021-01-18 21:11:03 +090084 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090085
Shikha Panwar01403bb2022-12-22 12:22:57 +000086 // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
87 // avbtool. Default used by avbtool is sha1.
Shikha Panware6f30632022-12-21 12:54:45 +000088 Avb_hash_algorithm *string
89
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +000090 // The index used to prevent rollback of the image. Only used if use_avb is true.
91 Rollback_index *int64
92
Jiyong Parkac4076d2021-03-15 23:21:30 +090093 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
94 Partition_name *string
95
Spandan Dasc35d6fb2024-10-10 17:51:14 +000096 // Type of the filesystem. Currently, ext4, erofs, cpio, and compressed_cpio are supported. Default
Jiyong Park837cdb22021-02-05 00:17:14 +090097 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090098 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090099
Cole Faust9a24d902024-03-18 15:38:12 -0700100 // Identifies which partition this is for //visibility:any_system_image (and others) visibility
101 // checks, and will be used in the future for API surface checks.
102 Partition_type *string
103
Inseob Kimcc8e5362021-02-03 14:05:24 +0900104 // file_contexts file to make image. Currently, only ext4 is supported.
105 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900106
107 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
108 // (root).
109 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +0900110
111 // Directories to be created under root. e.g. /dev, /proc, etc.
Cole Faustd9c6a5b2024-05-21 14:54:00 -0700112 Dirs proptools.Configurable[[]string]
Inseob Kim14199b02021-02-09 21:18:31 +0900113
114 // Symbolic links to be created under root with "ln -sf <target> <name>".
Spandan Das69464c32024-10-25 20:08:06 +0000115 Symlinks []SymlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +0900116
117 // Seconds since unix epoch to override timestamps of file entries
118 Fake_timestamp *string
119
120 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
121 // Otherwise, they'll be set as random which might cause indeterministic build output.
122 Uuid *string
Inseob Kim376d72f2023-11-01 15:40:25 +0900123
124 // Mount point for this image. Default is "/"
125 Mount_point *string
Cole Faust4a2a7c92024-03-12 12:44:40 -0700126
127 // If set to the name of a partition ("system", "vendor", etc), this filesystem module
128 // will also include the contents of the make-built staging directories. If any soong
129 // modules would be installed to the same location as a make module, they will overwrite
130 // the make version.
131 Include_make_built_files string
Inseob Kim53391842024-03-29 17:44:07 +0900132
Inseob Kimb7b84572024-04-30 10:51:47 +0900133 // When set, builds etc/event-log-tags file by merging logtags from all dependencies.
134 // Default is false
135 Build_logtags *bool
136
Justin Yun74f3f302024-05-07 14:32:14 +0900137 // Install aconfig_flags.pb file for the modules installed in this partition.
138 Gen_aconfig_flags_pb *bool
139
Inseob Kim53391842024-03-29 17:44:07 +0900140 Fsverity fsverityProperties
Cole Faust92ccbe22024-10-03 14:38:37 -0700141
142 // If this property is set to true, the filesystem will call ctx.UncheckedModule(), causing
143 // it to not be built on checkbuilds. Used for the automatic migration from make to soong
144 // build modules, where we want to emit some not-yet-working filesystems and we don't want them
145 // to be built.
146 Unchecked_module *bool `blueprint:"mutated"`
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000147
148 Erofs ErofsProperties
Jihoon Kang0d545b82024-10-11 00:21:57 +0000149
Spandan Das92631882024-10-28 22:49:38 +0000150 // List of files (in .json format) that will be converted to a linker config file (in .pb format).
151 // The linker config file be installed in the filesystem at /etc/linker.config.pb
152 Linker_config_srcs []string `android:"path"`
153
Jihoon Kang0d545b82024-10-11 00:21:57 +0000154 // Determines if the module is auto-generated from Soong or not. If the module is
155 // auto-generated, its deps are exempted from visibility enforcement.
156 Is_auto_generated *bool
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000157}
158
159// Additional properties required to generate erofs FS partitions.
160type ErofsProperties struct {
161 // Compressor and Compression level passed to mkfs.erofs. e.g. (lz4hc,9)
162 // Please see external/erofs-utils/README for complete documentation.
163 Compressor *string
164
165 // Used as --compress-hints for mkfs.erofs
166 Compress_hints *string `android:"path"`
167
168 Sparse *bool
Jiyong Park71baa762021-01-18 21:11:03 +0900169}
170
Jiyong Park65c49f52020-11-24 14:23:26 +0900171// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
172// image. The filesystem images are expected to be mounted in the target device, which means the
173// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
174// The modules are placed in the filesystem image just like they are installed to the ordinary
175// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Cole Faust92ccbe22024-10-03 14:38:37 -0700176func FilesystemFactory() android.Module {
Jiyong Park6f0f6882020-11-12 13:14:30 +0900177 module := &filesystem{}
Jiyong Park7e7d4af2024-05-01 12:36:10 +0000178 module.filterPackagingSpec = module.filterInstallablePackagingSpec
Cole Faust2cfe6962024-09-17 11:31:14 -0700179 initFilesystemModule(module, module)
Jiyong Parkfa616132021-04-20 11:36:40 +0900180 return module
181}
182
Cole Faust2cfe6962024-09-17 11:31:14 -0700183func initFilesystemModule(module android.DefaultableModule, filesystemModule *filesystem) {
184 module.AddProperties(&filesystemModule.properties)
185 android.InitPackageModule(filesystemModule)
186 filesystemModule.PackagingBase.DepsCollectFirstTargetOnly = true
Jiyong Park6f0f6882020-11-12 13:14:30 +0900187 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900188 android.InitDefaultableModule(module)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900189}
190
Jihoon Kang0d545b82024-10-11 00:21:57 +0000191type depTag struct {
Jiyong Park12a719c2021-01-07 15:31:24 +0900192 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900193 android.PackagingItemAlwaysDepTag
Jihoon Kang0d545b82024-10-11 00:21:57 +0000194}
195
196var dependencyTag = depTag{}
197
198type depTagWithVisibilityEnforcementBypass struct {
199 depTag
200}
201
202var _ android.ExcludeFromVisibilityEnforcementTag = (*depTagWithVisibilityEnforcementBypass)(nil)
203
204func (t depTagWithVisibilityEnforcementBypass) ExcludeFromVisibilityEnforcement() {}
205
206var dependencyTagWithVisibilityEnforcementBypass = depTagWithVisibilityEnforcementBypass{}
Jiyong Park65b62242020-11-25 12:44:59 +0900207
Jiyong Park6f0f6882020-11-12 13:14:30 +0900208func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000209 if proptools.Bool(f.properties.Is_auto_generated) {
210 f.AddDeps(ctx, dependencyTagWithVisibilityEnforcementBypass)
211 } else {
212 f.AddDeps(ctx, dependencyTag)
213 }
Jiyong Park6f0f6882020-11-12 13:14:30 +0900214}
215
Jiyong Park11a65972021-02-01 21:09:38 +0900216type fsType int
217
218const (
219 ext4Type fsType = iota
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000220 erofsType
Jiyong Park11a65972021-02-01 21:09:38 +0900221 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900222 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900223 unknown
224)
225
Spandan Das7a46f6c2024-10-14 18:41:18 +0000226func (fs fsType) IsUnknown() bool {
227 return fs == unknown
228}
229
Cole Faust92ccbe22024-10-03 14:38:37 -0700230type FilesystemInfo struct {
231 // A text file containing the list of paths installed on the partition.
232 FileListFile android.Path
233}
234
235var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]()
236
Spandan Das7a46f6c2024-10-14 18:41:18 +0000237func GetFsTypeFromString(ctx android.EarlyModuleContext, typeStr string) fsType {
Jiyong Park11a65972021-02-01 21:09:38 +0900238 switch typeStr {
239 case "ext4":
240 return ext4Type
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000241 case "erofs":
242 return erofsType
Jiyong Park11a65972021-02-01 21:09:38 +0900243 case "compressed_cpio":
244 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900245 case "cpio":
246 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900247 default:
Jiyong Park11a65972021-02-01 21:09:38 +0900248 return unknown
249 }
250}
251
Spandan Das7a46f6c2024-10-14 18:41:18 +0000252func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
253 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
254 fsType := GetFsTypeFromString(ctx, typeStr)
255 if fsType == unknown {
256 ctx.PropertyErrorf("type", "%q not supported", typeStr)
257 }
258 return fsType
259}
260
Jiyong Park65c49f52020-11-24 14:23:26 +0900261func (f *filesystem) installFileName() string {
262 return f.BaseModuleName() + ".img"
263}
264
Inseob Kim53391842024-03-29 17:44:07 +0900265func (f *filesystem) partitionName() string {
266 return proptools.StringDefault(f.properties.Partition_name, f.Name())
267}
268
Jiyong Park7e7d4af2024-05-01 12:36:10 +0000269func (f *filesystem) filterInstallablePackagingSpec(ps android.PackagingSpec) bool {
270 // Filesystem module respects the installation semantic. A PackagingSpec from a module with
271 // IsSkipInstall() is skipped.
Spandan Das6d056502024-10-21 15:40:32 +0000272 if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this.
273 return !ps.SkipInstall() && (ps.Partition() == f.PartitionType())
274 }
275 return !ps.SkipInstall()
Jiyong Park7e7d4af2024-05-01 12:36:10 +0000276}
277
Jiyong Park6f0f6882020-11-12 13:14:30 +0900278var pctx = android.NewPackageContext("android/soong/filesystem")
279
280func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900281 validatePartitionType(ctx, f)
Jiyong Park11a65972021-02-01 21:09:38 +0900282 switch f.fsType(ctx) {
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000283 case ext4Type, erofsType:
Jiyong Park11a65972021-02-01 21:09:38 +0900284 f.output = f.buildImageUsingBuildImage(ctx)
285 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900286 f.output = f.buildCpioImage(ctx, true)
287 case cpioType:
288 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900289 default:
290 return
291 }
292
293 f.installDir = android.PathForModuleInstall(ctx, "etc")
294 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
mrziwang555d1332024-06-07 11:15:33 -0700295 ctx.SetOutputFiles([]android.Path{f.output}, "")
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900296
297 f.fileListFile = android.PathForModuleOut(ctx, "fileList").OutputPath
298 android.WriteFileRule(ctx, f.fileListFile, f.installedFilesList())
Cole Faust92ccbe22024-10-03 14:38:37 -0700299
300 android.SetProvider(ctx, FilesystemProvider, FilesystemInfo{
301 FileListFile: f.fileListFile,
302 })
303
304 if proptools.Bool(f.properties.Unchecked_module) {
305 ctx.UncheckedModule()
306 }
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900307}
308
309func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.OutputPath) {
310 partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/"
311
312 relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir)
313 if inTargetPartition {
314 f.entries = append(f.entries, relPath)
315 }
316}
317
318func (f *filesystem) installedFilesList() string {
319 installedFilePaths := android.FirstUniqueStrings(f.entries)
320 slices.Sort(installedFilePaths)
321
322 return strings.Join(installedFilePaths, "\n")
Jiyong Park11a65972021-02-01 21:09:38 +0900323}
324
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900325func validatePartitionType(ctx android.ModuleContext, p partition) {
326 if !android.InList(p.PartitionType(), validPartitions) {
327 ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType())
328 }
329
330 ctx.VisitDirectDepsWithTag(android.DefaultsDepTag, func(m android.Module) {
331 if fdm, ok := m.(*filesystemDefaults); ok {
332 if p.PartitionType() != fdm.PartitionType() {
333 ctx.PropertyErrorf("partition_type",
334 "%s doesn't match with the partition type %s of the filesystem default module %s",
335 p.PartitionType(), fdm.PartitionType(), m.Name())
336 }
337 }
338 })
339}
340
Cole Faust3b806d32024-03-11 15:15:03 -0700341// Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files
342// already in `rootDir`.
343func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) {
Inseob Kim14199b02021-02-09 21:18:31 +0900344 // create dirs and symlinks
Cole Faustd9c6a5b2024-05-21 14:54:00 -0700345 for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) {
Inseob Kim14199b02021-02-09 21:18:31 +0900346 // OutputPath.Join verifies dir
347 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
348 }
349
350 for _, symlink := range f.properties.Symlinks {
351 name := strings.TrimSpace(proptools.String(symlink.Name))
352 target := strings.TrimSpace(proptools.String(symlink.Target))
353
354 if name == "" {
355 ctx.PropertyErrorf("symlinks", "Name can't be empty")
356 continue
357 }
358
359 if target == "" {
360 ctx.PropertyErrorf("symlinks", "Target can't be empty")
361 continue
362 }
363
364 // OutputPath.Join verifies name. don't need to verify target.
365 dst := rootDir.Join(ctx, name)
Cole Faust3b806d32024-03-11 15:15:03 -0700366 builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst)
Inseob Kim14199b02021-02-09 21:18:31 +0900367 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
368 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900369 f.appendToEntry(ctx, dst)
Inseob Kim14199b02021-02-09 21:18:31 +0900370 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900371
Jiyong Parkfa616132021-04-20 11:36:40 +0900372 // create extra files if there's any
Jiyong Parkfa616132021-04-20 11:36:40 +0900373 if f.buildExtraFiles != nil {
Cole Faust4a2a7c92024-03-12 12:44:40 -0700374 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
375 extraFiles := f.buildExtraFiles(ctx, rootForExtraFiles)
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900376 for _, extraFile := range extraFiles {
377 rel, err := filepath.Rel(rootForExtraFiles.String(), extraFile.String())
Cole Faust4a2a7c92024-03-12 12:44:40 -0700378 if err != nil || strings.HasPrefix(rel, "..") {
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900379 ctx.ModuleErrorf("can't make %q relative to %q", extraFile, rootForExtraFiles)
Cole Faust4a2a7c92024-03-12 12:44:40 -0700380 }
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900381 f.appendToEntry(ctx, rootDir.Join(ctx, rel))
Jiyong Parkfa616132021-04-20 11:36:40 +0900382 }
Cole Faust4a2a7c92024-03-12 12:44:40 -0700383 if len(extraFiles) > 0 {
384 builder.Command().BuiltTool("merge_directories").
385 Implicits(extraFiles.Paths()).
386 Text(rootDir.String()).
387 Text(rootForExtraFiles.String())
388 }
Jiyong Parkfa616132021-04-20 11:36:40 +0900389 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900390}
391
Inseob Kim33f95a92024-07-11 15:44:49 +0900392func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string {
393 rootDirSpecs := make(map[string]android.PackagingSpec)
394 rebasedDirSpecs := make(map[string]android.PackagingSpec)
395
396 for rel, spec := range specs {
397 if spec.Partition() == "root" {
398 rootDirSpecs[rel] = spec
399 } else {
400 rebasedDirSpecs[rel] = spec
401 }
402 }
403
404 dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec)
405 dirsToSpecs[rootDir] = rootDirSpecs
406 dirsToSpecs[rebasedDir] = rebasedDirSpecs
407
408 return f.CopySpecsToDirs(ctx, builder, dirsToSpecs)
409}
410
Justin Yun34baa2e2024-08-30 21:11:33 +0900411func (f *filesystem) copyFilesToProductOut(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
Justin Yun2cc42502024-09-11 14:10:20 +0900412 if f.Name() != ctx.Config().SoongDefinedSystemImage() {
Justin Yun34baa2e2024-08-30 21:11:33 +0900413 return
414 }
415 installPath := android.PathForModuleInPartitionInstall(ctx, f.partitionName())
416 builder.Command().Textf("cp -prf %s/* %s", rebasedDir, installPath)
417}
418
Jiyong Park11a65972021-02-01 21:09:38 +0900419func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Jiyong Park6f0f6882020-11-12 13:14:30 +0900420 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Cole Faust3b806d32024-03-11 15:15:03 -0700421 rebasedDir := rootDir
422 if f.properties.Base_dir != nil {
423 rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
424 }
425 builder := android.NewRuleBuilder(pctx, ctx)
426 // Wipe the root dir to get rid of leftover files from prior builds
427 builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900428 specs := f.gatherFilteredPackagingSpecs(ctx)
Inseob Kim33f95a92024-07-11 15:44:49 +0900429 f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir)
Cole Faust3b806d32024-03-11 15:15:03 -0700430
431 f.buildNonDepsFiles(ctx, builder, rootDir)
Cole Faust4a2a7c92024-03-12 12:44:40 -0700432 f.addMakeBuiltFiles(ctx, builder, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900433 f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
Inseob Kimb7b84572024-04-30 10:51:47 +0900434 f.buildEventLogtagsFile(ctx, builder, rebasedDir)
Justin Yun74f3f302024-05-07 14:32:14 +0900435 f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir)
Spandan Das92631882024-10-28 22:49:38 +0000436 f.buildLinkerConfigFile(ctx, builder, rebasedDir)
Justin Yun34baa2e2024-08-30 21:11:33 +0900437 f.copyFilesToProductOut(ctx, builder, rebasedDir)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900438
Nikita Ioffe519015f2022-12-23 15:36:29 +0000439 // run host_init_verifier
440 // Ideally we should have a concept of pluggable linters that verify the generated image.
441 // While such concept is not implement this will do.
442 // TODO(b/263574231): substitute with pluggable linter.
443 builder.Command().
444 BuiltTool("host_init_verifier").
445 FlagWithArg("--out_system=", rootDir.String()+"/system")
446
Jiyong Park72678312021-01-18 17:29:49 +0900447 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900448 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800449 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900450 Text(rootDir.String()). // input directory
451 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900452 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900453 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900454 Text(rootDir.String()) // directory where to find fs_config_files|dirs
455
456 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800457 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900458
Jiyong Park11a65972021-02-01 21:09:38 +0900459 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900460}
461
Inseob Kimcc8e5362021-02-03 14:05:24 +0900462func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
463 builder := android.NewRuleBuilder(pctx, ctx)
464 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
465 builder.Command().BuiltTool("sefcontext_compile").
466 FlagWithOutput("-o ", fcBin).
467 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
468 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
469 return fcBin.OutputPath
470}
471
Jooyung Han65f402b2022-04-21 14:24:04 +0900472// Calculates avb_salt from entry list (sorted) for deterministic output.
473func (f *filesystem) salt() string {
474 return sha1sum(f.entries)
475}
476
Jiyong Park72678312021-01-18 17:29:49 +0900477func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
Jiyong Park72678312021-01-18 17:29:49 +0900478 var deps android.Paths
Cole Faustcec230a2024-03-07 15:51:12 -0800479 var propFileString strings.Builder
Jiyong Park72678312021-01-18 17:29:49 +0900480 addStr := func(name string, value string) {
Cole Faustcec230a2024-03-07 15:51:12 -0800481 propFileString.WriteString(name)
482 propFileString.WriteRune('=')
483 propFileString.WriteString(value)
484 propFileString.WriteRune('\n')
Jiyong Park72678312021-01-18 17:29:49 +0900485 }
486 addPath := func(name string, path android.Path) {
Cole Faustcec230a2024-03-07 15:51:12 -0800487 addStr(name, path.String())
Jiyong Park72678312021-01-18 17:29:49 +0900488 deps = append(deps, path)
489 }
490
Jiyong Park11a65972021-02-01 21:09:38 +0900491 // Type string that build_image.py accepts.
492 fsTypeStr := func(t fsType) string {
493 switch t {
Spandan Das94668822024-10-09 20:51:33 +0000494 // TODO(372522486): add more types like f2fs, erofs, etc.
Jiyong Park11a65972021-02-01 21:09:38 +0900495 case ext4Type:
496 return "ext4"
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000497 case erofsType:
498 return "erofs"
Jiyong Park11a65972021-02-01 21:09:38 +0900499 }
500 panic(fmt.Errorf("unsupported fs type %v", t))
501 }
502
503 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim376d72f2023-11-01 15:40:25 +0900504 addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/"))
Jiyong Park72678312021-01-18 17:29:49 +0900505 addStr("use_dynamic_partition_size", "true")
506 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
507 // b/177813163 deps of the host tools have to be added. Remove this.
508 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
509 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
510 }
511
Jiyong Park71baa762021-01-18 21:11:03 +0900512 if proptools.Bool(f.properties.Use_avb) {
513 addStr("avb_hashtree_enable", "true")
514 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
515 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
516 addStr("avb_algorithm", algorithm)
517 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
518 addPath("avb_key_path", key)
Inseob Kim53391842024-03-29 17:44:07 +0900519 addStr("partition_name", f.partitionName())
Shikha Panware6f30632022-12-21 12:54:45 +0000520 avb_add_hashtree_footer_args := "--do_not_generate_fec"
521 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
522 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
523 }
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +0000524 if f.properties.Rollback_index != nil {
525 rollbackIndex := proptools.Int(f.properties.Rollback_index)
526 if rollbackIndex < 0 {
527 ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative")
528 }
529 avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex)
530 }
Inseob Kim53391842024-03-29 17:44:07 +0900531 securityPatchKey := "com.android.build." + f.partitionName() + ".security_patch"
Seungjae Yooa30e4502023-11-09 14:55:44 +0900532 securityPatchValue := ctx.Config().PlatformSecurityPatch()
533 avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue
Shikha Panware6f30632022-12-21 12:54:45 +0000534 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jooyung Han65f402b2022-04-21 14:24:04 +0900535 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900536 }
537
Inseob Kimcc8e5362021-02-03 14:05:24 +0900538 if proptools.String(f.properties.File_contexts) != "" {
539 addPath("selinux_fc", f.buildFileContexts(ctx))
540 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900541 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
542 addStr("timestamp", timestamp)
543 }
544 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
545 addStr("uuid", uuid)
546 addStr("hash_seed", uuid)
547 }
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000548 // Add erofs properties
549 if f.fsType(ctx) == erofsType {
550 if compressor := f.properties.Erofs.Compressor; compressor != nil {
551 addStr("erofs_default_compressor", proptools.String(compressor))
552 }
553 if compressHints := f.properties.Erofs.Compress_hints; compressHints != nil {
Cole Faust7cd4bad2024-10-11 10:31:12 -0700554 addPath("erofs_default_compress_hints", android.PathForModuleSrc(ctx, *compressHints))
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000555 }
556 if proptools.BoolDefault(f.properties.Erofs.Sparse, true) {
557 // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b
558 addStr("erofs_sparse_flag", "-s")
559 }
Cole Faust7cd4bad2024-10-11 10:31:12 -0700560 } else if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil {
561 // Raise an exception if the propfile contains erofs properties, but the fstype is not erofs
562 fs := fsTypeStr(f.fsType(ctx))
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000563 ctx.PropertyErrorf("erofs", "erofs is non-empty, but FS type is %s\n. Please delete erofs properties if this partition should use %s\n", fs, fs)
564 }
565
Jiyong Park72678312021-01-18 17:29:49 +0900566 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
Cole Faustcec230a2024-03-07 15:51:12 -0800567 android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String())
Jiyong Park72678312021-01-18 17:29:49 +0900568 return propFile, deps
569}
570
Jiyong Park837cdb22021-02-05 00:17:14 +0900571func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900572 if proptools.Bool(f.properties.Use_avb) {
573 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
574 "Consider adding this to bootimg module and signing the entire boot image.")
575 }
576
Inseob Kimcc8e5362021-02-03 14:05:24 +0900577 if proptools.String(f.properties.File_contexts) != "" {
578 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
579 }
580
Cole Faust4a2a7c92024-03-12 12:44:40 -0700581 if f.properties.Include_make_built_files != "" {
582 ctx.PropertyErrorf("include_make_built_files", "include_make_built_files is not supported for compressed cpio image.")
583 }
584
Jiyong Park11a65972021-02-01 21:09:38 +0900585 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Cole Faust3b806d32024-03-11 15:15:03 -0700586 rebasedDir := rootDir
587 if f.properties.Base_dir != nil {
588 rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
589 }
590 builder := android.NewRuleBuilder(pctx, ctx)
591 // Wipe the root dir to get rid of leftover files from prior builds
592 builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900593 specs := f.gatherFilteredPackagingSpecs(ctx)
Inseob Kim33f95a92024-07-11 15:44:49 +0900594 f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir)
Cole Faust3b806d32024-03-11 15:15:03 -0700595
596 f.buildNonDepsFiles(ctx, builder, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900597 f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
Inseob Kimb7b84572024-04-30 10:51:47 +0900598 f.buildEventLogtagsFile(ctx, builder, rebasedDir)
Justin Yun74f3f302024-05-07 14:32:14 +0900599 f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir)
Spandan Das92631882024-10-28 22:49:38 +0000600 f.buildLinkerConfigFile(ctx, builder, rebasedDir)
Justin Yun34baa2e2024-08-30 21:11:33 +0900601 f.copyFilesToProductOut(ctx, builder, rebasedDir)
Jiyong Park11a65972021-02-01 21:09:38 +0900602
603 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900604 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900605 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900606 Text(rootDir.String()) // input directory
607 if compressed {
608 cmd.Text("|").
609 BuiltTool("lz4").
610 Flag("--favor-decSpeed"). // for faster boot
611 Flag("-12"). // maximum compression level
612 Flag("-l"). // legacy format for kernel
613 Text(">").Output(output)
614 } else {
615 cmd.Text(">").Output(output)
616 }
Jiyong Park11a65972021-02-01 21:09:38 +0900617
618 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900619 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900620
621 return output
622}
623
Cole Faust4a2a7c92024-03-12 12:44:40 -0700624var validPartitions = []string{
625 "system",
626 "userdata",
627 "cache",
628 "system_other",
629 "vendor",
630 "product",
631 "system_ext",
632 "odm",
633 "vendor_dlkm",
634 "odm_dlkm",
635 "system_dlkm",
636}
637
638func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) {
639 partition := f.properties.Include_make_built_files
640 if partition == "" {
641 return
642 }
643 if !slices.Contains(validPartitions, partition) {
644 ctx.PropertyErrorf("include_make_built_files", "Expected one of %#v, found %q", validPartitions, partition)
645 return
646 }
647 stampFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/staging_dir.stamp", ctx.Config().DeviceName(), partition)
648 fileListFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partition)
649 stagingDir := fmt.Sprintf("target/product/%s/%s", ctx.Config().DeviceName(), partition)
650
651 builder.Command().BuiltTool("merge_directories").
652 Implicit(android.PathForArbitraryOutput(ctx, stampFile)).
653 Text("--ignore-duplicates").
654 FlagWithInput("--file-list", android.PathForArbitraryOutput(ctx, fileListFile)).
655 Text(rootDir.String()).
656 Text(android.PathForArbitraryOutput(ctx, stagingDir).String())
657}
658
Inseob Kimb7b84572024-04-30 10:51:47 +0900659func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
660 if !proptools.Bool(f.properties.Build_logtags) {
661 return
662 }
663
664 logtagsFilePaths := make(map[string]bool)
665 ctx.WalkDeps(func(child, parent android.Module) bool {
666 if logtagsInfo, ok := android.OtherModuleProvider(ctx, child, android.LogtagsProviderKey); ok {
667 for _, path := range logtagsInfo.Logtags {
668 logtagsFilePaths[path.String()] = true
669 }
670 }
671 return true
672 })
673
674 if len(logtagsFilePaths) == 0 {
675 return
676 }
677
678 etcPath := rebasedDir.Join(ctx, "etc")
679 eventLogtagsPath := etcPath.Join(ctx, "event-log-tags")
680 builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String())
681 cmd := builder.Command().BuiltTool("merge-event-log-tags").
682 FlagWithArg("-o ", eventLogtagsPath.String()).
683 FlagWithInput("-m ", android.MergedLogtagsPath(ctx))
684
685 for _, path := range android.SortedKeys(logtagsFilePaths) {
686 cmd.Text(path)
687 }
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900688
689 f.appendToEntry(ctx, eventLogtagsPath)
Inseob Kimb7b84572024-04-30 10:51:47 +0900690}
691
Spandan Das92631882024-10-28 22:49:38 +0000692func (f *filesystem) buildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
693 getCStubLibs := func() []android.Module {
694 // Determine the list of C stub libraries that are part of this filesystem.
695 // These will be added to `provideLibs`.
696 // The current implementation assumes that stub libraries are listed explicitly in `deps`
697 // (direct deps). If this is not true, ctx.VisitDeps will need to be replaced by ctx.WalkDeps.
698 ret := []android.Module{}
699 ctx.VisitDirectDeps(func(child android.Module) {
700 if c, ok := child.(*cc.Module); ok && c.HasStubsVariants() {
701 ret = append(ret, c)
702 }
703 })
704 return ret
705 }
706
707 if len(f.properties.Linker_config_srcs) == 0 {
708 return
709 }
710
711 // cp to the final output
712 output := rebasedDir.Join(ctx, "etc", "linker.config.pb")
713 linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, f.properties.Linker_config_srcs), getCStubLibs(), nil, output)
714
715 f.appendToEntry(ctx, output)
716}
717
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900718type partition interface {
719 PartitionType() string
720}
721
Cole Faust9a24d902024-03-18 15:38:12 -0700722func (f *filesystem) PartitionType() string {
723 return proptools.StringDefault(f.properties.Partition_type, "system")
724}
725
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900726var _ partition = (*filesystem)(nil)
727
Jiyong Park65c49f52020-11-24 14:23:26 +0900728var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
729
730// Implements android.AndroidMkEntriesProvider
731func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
732 return []android.AndroidMkEntries{android.AndroidMkEntries{
733 Class: "ETC",
734 OutputFile: android.OptionalPathForPath(f.output),
735 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700736 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800737 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900738 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900739 entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900740 },
741 },
742 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900743}
Jiyong Park12a719c2021-01-07 15:31:24 +0900744
745// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
746// package to have access to the output file.
747type Filesystem interface {
748 android.Module
749 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900750
751 // Returns the output file that is signed by avbtool. If this module is not signed, returns
752 // nil.
753 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900754}
755
756var _ Filesystem = (*filesystem)(nil)
757
758func (f *filesystem) OutputPath() android.Path {
759 return f.output
760}
Jiyong Park972e06c2021-03-15 23:32:49 +0900761
762func (f *filesystem) SignedOutputPath() android.Path {
763 if proptools.Bool(f.properties.Use_avb) {
764 return f.OutputPath()
765 }
766 return nil
767}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900768
769// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
770// Note that "apex" module installs its contents to "apex"(fake partition) as well
771// for symbol lookup by imitating "activated" paths.
772func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
Jeongik Cha54bf8752024-02-08 10:44:37 +0900773 specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec)
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900774 return specs
775}
Jooyung Han65f402b2022-04-21 14:24:04 +0900776
777func sha1sum(values []string) string {
778 h := sha256.New()
779 for _, value := range values {
780 io.WriteString(h, value)
781 }
782 return fmt.Sprintf("%x", h.Sum(nil))
783}
Jooyung Hane6067592023-03-16 13:11:17 +0900784
785// Base cc.UseCoverage
786
787var _ cc.UseCoverage = (*filesystem)(nil)
788
Colin Crosse1a85552024-06-14 12:17:37 -0700789func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
Jooyung Hane6067592023-03-16 13:11:17 +0900790 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
791}
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900792
793// android_filesystem_defaults
794
795type filesystemDefaults struct {
796 android.ModuleBase
797 android.DefaultsModuleBase
798
799 properties filesystemDefaultsProperties
800}
801
802type filesystemDefaultsProperties struct {
803 // Identifies which partition this is for //visibility:any_system_image (and others) visibility
804 // checks, and will be used in the future for API surface checks.
805 Partition_type *string
806}
807
808// android_filesystem_defaults is a default module for android_filesystem and android_system_image
809func filesystemDefaultsFactory() android.Module {
810 module := &filesystemDefaults{}
811 module.AddProperties(&module.properties)
812 module.AddProperties(&android.PackagingProperties{})
813 android.InitDefaultsModule(module)
814 return module
815}
816
817func (f *filesystemDefaults) PartitionType() string {
818 return proptools.StringDefault(f.properties.Partition_type, "system")
819}
820
821var _ partition = (*filesystemDefaults)(nil)
822
823func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
824 validatePartitionType(ctx, f)
825}