diff options
Diffstat (limited to 'filesystem/filesystem.go')
| -rw-r--r-- | filesystem/filesystem.go | 124 |
1 files changed, 105 insertions, 19 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index cadf9c246..5c7ef434f 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -60,7 +60,9 @@ type filesystem struct { output android.OutputPath installDir android.InstallPath - // For testing. Keeps the result of CopySpecsToDir() + fileListFile android.OutputPath + + // Keeps the entries installed from this filesystem entries []string } @@ -106,7 +108,7 @@ type filesystemProperties struct { Base_dir *string // Directories to be created under root. e.g. /dev, /proc, etc. - Dirs []string + Dirs proptools.Configurable[[]string] // Symbolic links to be created under root with "ln -sf <target> <name>". Symlinks []symlinkDefinition @@ -127,6 +129,13 @@ type filesystemProperties struct { // the make version. Include_make_built_files string + // When set, builds etc/event-log-tags file by merging logtags from all dependencies. + // Default is false + Build_logtags *bool + + // Install aconfig_flags.pb file for the modules installed in this partition. + Gen_aconfig_flags_pb *bool + Fsverity fsverityProperties } @@ -137,6 +146,7 @@ type filesystemProperties struct { // partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory. func filesystemFactory() android.Module { module := &filesystem{} + module.filterPackagingSpec = module.filterInstallablePackagingSpec initFilesystemModule(module) return module } @@ -144,6 +154,7 @@ func filesystemFactory() android.Module { func initFilesystemModule(module *filesystem) { module.AddProperties(&module.properties) android.InitPackageModule(module) + module.PackagingBase.DepsCollectFirstTargetOnly = true android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) } @@ -189,6 +200,12 @@ func (f *filesystem) partitionName() string { return proptools.StringDefault(f.properties.Partition_name, f.Name()) } +func (f *filesystem) filterInstallablePackagingSpec(ps android.PackagingSpec) bool { + // Filesystem module respects the installation semantic. A PackagingSpec from a module with + // IsSkipInstall() is skipped. + return !ps.SkipInstall() +} + var pctx = android.NewPackageContext("android/soong/filesystem") func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -206,6 +223,26 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { f.installDir = android.PathForModuleInstall(ctx, "etc") ctx.InstallFile(f.installDir, f.installFileName(), f.output) + ctx.SetOutputFiles([]android.Path{f.output}, "") + + f.fileListFile = android.PathForModuleOut(ctx, "fileList").OutputPath + android.WriteFileRule(ctx, f.fileListFile, f.installedFilesList()) +} + +func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.OutputPath) { + partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/" + + relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir) + if inTargetPartition { + f.entries = append(f.entries, relPath) + } +} + +func (f *filesystem) installedFilesList() string { + installedFilePaths := android.FirstUniqueStrings(f.entries) + slices.Sort(installedFilePaths) + + return strings.Join(installedFilePaths, "\n") } func validatePartitionType(ctx android.ModuleContext, p partition) { @@ -228,7 +265,7 @@ func validatePartitionType(ctx android.ModuleContext, p partition) { // already in `rootDir`. func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) { // create dirs and symlinks - for _, dir := range f.properties.Dirs { + for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) { // OutputPath.Join verifies dir builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String()) } @@ -252,17 +289,19 @@ func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *andro builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst) builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) + f.appendToEntry(ctx, dst) } // create extra files if there's any if f.buildExtraFiles != nil { rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath extraFiles := f.buildExtraFiles(ctx, rootForExtraFiles) - for _, f := range extraFiles { - rel, err := filepath.Rel(rootForExtraFiles.String(), f.String()) + for _, extraFile := range extraFiles { + rel, err := filepath.Rel(rootForExtraFiles.String(), extraFile.String()) if err != nil || strings.HasPrefix(rel, "..") { - ctx.ModuleErrorf("can't make %q relative to %q", f, rootForExtraFiles) + ctx.ModuleErrorf("can't make %q relative to %q", extraFile, rootForExtraFiles) } + f.appendToEntry(ctx, rootDir.Join(ctx, rel)) } if len(extraFiles) > 0 { builder.Command().BuiltTool("merge_directories"). @@ -273,6 +312,25 @@ func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *andro } } +func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string { + rootDirSpecs := make(map[string]android.PackagingSpec) + rebasedDirSpecs := make(map[string]android.PackagingSpec) + + for rel, spec := range specs { + if spec.Partition() == "root" { + rootDirSpecs[rel] = spec + } else { + rebasedDirSpecs[rel] = spec + } + } + + dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec) + dirsToSpecs[rootDir] = rootDirSpecs + dirsToSpecs[rebasedDir] = rebasedDirSpecs + + return f.CopySpecsToDirs(ctx, builder, dirsToSpecs) +} + func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath { rootDir := android.PathForModuleOut(ctx, "root").OutputPath rebasedDir := rootDir @@ -283,11 +341,13 @@ func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) androi // Wipe the root dir to get rid of leftover files from prior builds builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) specs := f.gatherFilteredPackagingSpecs(ctx) - f.entries = f.CopySpecsToDir(ctx, builder, specs, rebasedDir) + f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) f.buildNonDepsFiles(ctx, builder, rootDir) f.addMakeBuiltFiles(ctx, builder, rootDir) f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) + f.buildEventLogtagsFile(ctx, builder, rebasedDir) + f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) // run host_init_verifier // Ideally we should have a concept of pluggable linters that verify the generated image. @@ -424,10 +484,12 @@ func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) // Wipe the root dir to get rid of leftover files from prior builds builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) specs := f.gatherFilteredPackagingSpecs(ctx) - f.entries = f.CopySpecsToDir(ctx, builder, specs, rebasedDir) + f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) f.buildNonDepsFiles(ctx, builder, rootDir) f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) + f.buildEventLogtagsFile(ctx, builder, rebasedDir) + f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath cmd := builder.Command(). @@ -485,6 +547,39 @@ func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *andro Text(android.PathForArbitraryOutput(ctx, stagingDir).String()) } +func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { + if !proptools.Bool(f.properties.Build_logtags) { + return + } + + logtagsFilePaths := make(map[string]bool) + ctx.WalkDeps(func(child, parent android.Module) bool { + if logtagsInfo, ok := android.OtherModuleProvider(ctx, child, android.LogtagsProviderKey); ok { + for _, path := range logtagsInfo.Logtags { + logtagsFilePaths[path.String()] = true + } + } + return true + }) + + if len(logtagsFilePaths) == 0 { + return + } + + etcPath := rebasedDir.Join(ctx, "etc") + eventLogtagsPath := etcPath.Join(ctx, "event-log-tags") + builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String()) + cmd := builder.Command().BuiltTool("merge-event-log-tags"). + FlagWithArg("-o ", eventLogtagsPath.String()). + FlagWithInput("-m ", android.MergedLogtagsPath(ctx)) + + for _, path := range android.SortedKeys(logtagsFilePaths) { + cmd.Text(path) + } + + f.appendToEntry(ctx, eventLogtagsPath) +} + type partition interface { PartitionType() string } @@ -506,21 +601,12 @@ func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) + entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String()) }, }, }} } -var _ android.OutputFileProducer = (*filesystem)(nil) - -// Implements android.OutputFileProducer -func (f *filesystem) OutputFiles(tag string) (android.Paths, error) { - if tag == "" { - return []android.Path{f.output}, nil - } - return nil, fmt.Errorf("unsupported module reference tag %q", tag) -} - // Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex // package to have access to the output file. type Filesystem interface { @@ -565,7 +651,7 @@ func sha1sum(values []string) string { var _ cc.UseCoverage = (*filesystem)(nil) -func (*filesystem) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { +func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() } |