diff options
Diffstat (limited to 'filesystem/filesystem.go')
-rw-r--r-- | filesystem/filesystem.go | 118 |
1 files changed, 61 insertions, 57 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index e84139b9a..c34677060 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -52,21 +52,29 @@ type filesystem struct { properties FilesystemProperties - // Function that builds extra files under the root directory and returns the files - buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths - - // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs() - filterPackagingSpec func(spec android.PackagingSpec) bool - - output android.OutputPath + output android.Path installDir android.InstallPath - fileListFile android.OutputPath + fileListFile android.Path // Keeps the entries installed from this filesystem entries []string + + filesystemBuilder filesystemBuilder +} + +type filesystemBuilder interface { + BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) + // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs() + FilterPackagingSpec(spec android.PackagingSpec) bool + // Function that modifies PackagingSpec in PackagingBase.GatherPackagingSpecs() to customize. + // For example, GSI system.img contains system_ext and product artifacts and their + // relPathInPackage need to be rebased to system/system_ext and system/system_product. + ModifyPackagingSpec(spec *android.PackagingSpec) } +var _ filesystemBuilder = (*filesystem)(nil) + type SymlinkDefinition struct { Target *string Name *string @@ -149,7 +157,7 @@ type FilesystemProperties struct { F2fs F2fsProperties - Linkerconfig LinkerConfigProperties + Linker_config LinkerConfigProperties // Determines if the module is auto-generated from Soong or not. If the module is // auto-generated, its deps are exempted from visibility enforcement. @@ -190,7 +198,7 @@ type LinkerConfigProperties 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 + module.filesystemBuilder = module initFilesystemModule(module, module) return module } @@ -285,13 +293,32 @@ func (f *filesystem) partitionName() string { return proptools.StringDefault(f.properties.Partition_name, f.Name()) } -func (f *filesystem) filterInstallablePackagingSpec(ps android.PackagingSpec) bool { +func (f *filesystem) FilterPackagingSpec(ps android.PackagingSpec) bool { // Filesystem module respects the installation semantic. A PackagingSpec from a module with // IsSkipInstall() is skipped. + if ps.SkipInstall() { + return false + } if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this. - return !ps.SkipInstall() && (ps.Partition() == f.PartitionType()) + pt := f.PartitionType() + return ps.Partition() == pt || strings.HasPrefix(ps.Partition(), pt+"/") + } + return true +} + +func (f *filesystem) ModifyPackagingSpec(ps *android.PackagingSpec) { + // Sometimes, android.modulePartition() returns a path with >1 path components. + // This makes the partition field of packagingSpecs have multiple components, like + // "system/product". Right now, the filesystem module doesn't look at the partition field + // when deciding what path to install the file under, only the RelPathInPackage field, so + // we move the later path components from partition to relPathInPackage. This should probably + // be revisited in the future. + prefix := f.PartitionType() + "/" + if strings.HasPrefix(ps.Partition(), prefix) { + subPartition := strings.TrimPrefix(ps.Partition(), prefix) + ps.SetPartition(f.PartitionType()) + ps.SetRelPathInPackage(filepath.Join(subPartition, ps.RelPathInPackage())) } - return !ps.SkipInstall() } var pctx = android.NewPackageContext("android/soong/filesystem") @@ -313,19 +340,20 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { 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()) + fileListFile := android.PathForModuleOut(ctx, "fileList") + android.WriteFileRule(ctx, fileListFile, f.installedFilesList()) android.SetProvider(ctx, FilesystemProvider, FilesystemInfo{ - FileListFile: f.fileListFile, + FileListFile: fileListFile, }) + f.fileListFile = fileListFile if proptools.Bool(f.properties.Unchecked_module) { ctx.UncheckedModule() } } -func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.OutputPath) { +func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.Path) { partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/" relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir) @@ -387,25 +415,6 @@ func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *andro 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 _, 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", extraFile, rootForExtraFiles) - } - f.appendToEntry(ctx, rootDir.Join(ctx, rel)) - } - if len(extraFiles) > 0 { - builder.Command().BuiltTool("merge_directories"). - Implicits(extraFiles.Paths()). - Text(rootDir.String()). - Text(rootForExtraFiles.String()) - } - } } func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string { @@ -435,7 +444,7 @@ func (f *filesystem) copyFilesToProductOut(ctx android.ModuleContext, builder *a builder.Command().Textf("cp -prf %s/* %s", rebasedDir, installPath) } -func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath { +func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.Path { rootDir := android.PathForModuleOut(ctx, "root").OutputPath rebasedDir := rootDir if f.properties.Base_dir != nil { @@ -452,7 +461,7 @@ func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) androi f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) f.buildEventLogtagsFile(ctx, builder, rebasedDir) f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) - f.buildLinkerConfigFile(ctx, builder, rebasedDir) + f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir) f.copyFilesToProductOut(ctx, builder, rebasedDir) // run host_init_verifier @@ -464,7 +473,7 @@ func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) androi FlagWithArg("--out_system=", rootDir.String()+"/system") propFile, toolDeps := f.buildPropFile(ctx) - output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath + output := android.PathForModuleOut(ctx, f.installFileName()) builder.Command().BuiltTool("build_image"). Text(rootDir.String()). // input directory Input(propFile). @@ -478,14 +487,14 @@ func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) androi return output } -func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath { +func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.Path { builder := android.NewRuleBuilder(pctx, ctx) fcBin := android.PathForModuleOut(ctx, "file_contexts.bin") builder.Command().BuiltTool("sefcontext_compile"). FlagWithOutput("-o ", fcBin). Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts))) builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName())) - return fcBin.OutputPath + return fcBin } // Calculates avb_salt from entry list (sorted) for deterministic output. @@ -493,7 +502,7 @@ func (f *filesystem) salt() string { return sha1sum(f.entries) } -func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) { +func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, android.Paths) { var deps android.Paths var propFileString strings.Builder addStr := func(name string, value string) { @@ -589,7 +598,7 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android. } f.checkFsTypePropertyError(ctx, fst, fsTypeStr(fst)) - propFile = android.PathForModuleOut(ctx, "prop").OutputPath + propFile := android.PathForModuleOut(ctx, "prop") android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String()) return propFile, deps } @@ -614,7 +623,7 @@ func (f *filesystem) checkFsTypePropertyError(ctx android.ModuleContext, t fsTyp } } -func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath { +func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.Path { if proptools.Bool(f.properties.Use_avb) { ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+ "Consider adding this to bootimg module and signing the entire boot image.") @@ -643,10 +652,10 @@ func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) f.buildEventLogtagsFile(ctx, builder, rebasedDir) f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) - f.buildLinkerConfigFile(ctx, builder, rebasedDir) + f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir) f.copyFilesToProductOut(ctx, builder, rebasedDir) - output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath + output := android.PathForModuleOut(ctx, f.installFileName()) cmd := builder.Command(). BuiltTool("mkbootfs"). Text(rootDir.String()) // input directory @@ -679,6 +688,7 @@ var validPartitions = []string{ "vendor_dlkm", "odm_dlkm", "system_dlkm", + "ramdisk", } func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) { @@ -735,14 +745,14 @@ func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *a f.appendToEntry(ctx, eventLogtagsPath) } -func (f *filesystem) buildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { - if !proptools.Bool(f.properties.Linkerconfig.Gen_linker_config) { +func (f *filesystem) BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { + if !proptools.Bool(f.properties.Linker_config.Gen_linker_config) { return } provideModules, _ := f.getLibsForLinkerConfig(ctx) output := rebasedDir.Join(ctx, "etc", "linker.config.pb") - linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, f.properties.Linkerconfig.Linker_config_srcs), provideModules, nil, output) + linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, f.properties.Linker_config.Linker_config_srcs), provideModules, nil, output) f.appendToEntry(ctx, output) } @@ -802,7 +812,7 @@ func (f *filesystem) SignedOutputPath() android.Path { // Note that "apex" module installs its contents to "apex"(fake partition) as well // for symbol lookup by imitating "activated" paths. func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { - specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec) + specs := f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, f.filesystemBuilder.FilterPackagingSpec, f.filesystemBuilder.ModifyPackagingSpec) return specs } @@ -828,13 +838,7 @@ type filesystemDefaults struct { android.ModuleBase android.DefaultsModuleBase - properties filesystemDefaultsProperties -} - -type filesystemDefaultsProperties struct { - // Identifies which partition this is for //visibility:any_system_image (and others) visibility - // checks, and will be used in the future for API surface checks. - Partition_type *string + properties FilesystemProperties } // android_filesystem_defaults is a default module for android_filesystem and android_system_image |