Add GatherPackagingSpecsWithFilter

android_system_image used GatherPackagingSpecs and then filter only
system modules. But some modules were omitted in this logic because
there are modules which has the same relative path, so the later one is
ignored even though its partition info is what we're looking for. So add
filter logic in GatherPackagingSpecs to avoid this problem

Bug: 323793487
Test: build android_system_image, and then check if it contains every
module we want

Change-Id: Iec8ae920736d3d1920eecad71ba0f8f2fe848e6c
This commit is contained in:
Jeongik Cha 2024-02-08 10:44:37 +09:00
parent c21f548fd4
commit 54bf875c97
3 changed files with 18 additions and 15 deletions

View file

@ -85,6 +85,7 @@ type PackageModule interface {
// GatherPackagingSpecs gathers PackagingSpecs of transitive dependencies. // GatherPackagingSpecs gathers PackagingSpecs of transitive dependencies.
GatherPackagingSpecs(ctx ModuleContext) map[string]PackagingSpec GatherPackagingSpecs(ctx ModuleContext) map[string]PackagingSpec
GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec
// CopyDepsToZip zips the built artifacts of the dependencies into the given zip file and // CopyDepsToZip zips the built artifacts of the dependencies into the given zip file and
// returns zip entries in it. This is expected to be called in GenerateAndroidBuildActions, // returns zip entries in it. This is expected to be called in GenerateAndroidBuildActions,
@ -221,14 +222,18 @@ func (p *PackagingBase) AddDeps(ctx BottomUpMutatorContext, depTag blueprint.Dep
} }
} }
// See PackageModule.GatherPackagingSpecs func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec {
func (p *PackagingBase) GatherPackagingSpecs(ctx ModuleContext) map[string]PackagingSpec {
m := make(map[string]PackagingSpec) m := make(map[string]PackagingSpec)
ctx.VisitDirectDeps(func(child Module) { ctx.VisitDirectDeps(func(child Module) {
if pi, ok := ctx.OtherModuleDependencyTag(child).(PackagingItem); !ok || !pi.IsPackagingItem() { if pi, ok := ctx.OtherModuleDependencyTag(child).(PackagingItem); !ok || !pi.IsPackagingItem() {
return return
} }
for _, ps := range child.TransitivePackagingSpecs() { for _, ps := range child.TransitivePackagingSpecs() {
if filter != nil {
if !filter(ps) {
continue
}
}
if _, ok := m[ps.relPathInPackage]; !ok { if _, ok := m[ps.relPathInPackage]; !ok {
m[ps.relPathInPackage] = ps m[ps.relPathInPackage] = ps
} }
@ -237,6 +242,11 @@ func (p *PackagingBase) GatherPackagingSpecs(ctx ModuleContext) map[string]Packa
return m return m
} }
// See PackageModule.GatherPackagingSpecs
func (p *PackagingBase) GatherPackagingSpecs(ctx ModuleContext) map[string]PackagingSpec {
return p.GatherPackagingSpecsWithFilter(ctx, nil)
}
// CopySpecsToDir is a helper that will add commands to the rule builder to copy the PackagingSpec // CopySpecsToDir is a helper that will add commands to the rule builder to copy the PackagingSpec
// entries into the specified directory. // entries into the specified directory.
func (p *PackagingBase) CopySpecsToDir(ctx ModuleContext, builder *RuleBuilder, specs map[string]PackagingSpec, dir WritablePath) (entries []string) { func (p *PackagingBase) CopySpecsToDir(ctx ModuleContext, builder *RuleBuilder, specs map[string]PackagingSpec, dir WritablePath) (entries []string) {

View file

@ -50,8 +50,8 @@ type filesystem struct {
// Function that builds extra files under the root directory and returns the files // Function that builds extra files under the root directory and returns the files
buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
// Function that filters PackagingSpecs returned by PackagingBase.GatherPackagingSpecs() // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs()
filterPackagingSpecs func(specs map[string]android.PackagingSpec) filterPackagingSpec func(spec android.PackagingSpec) bool
output android.OutputPath output android.OutputPath
installDir android.InstallPath installDir android.InstallPath
@ -493,10 +493,7 @@ func (f *filesystem) SignedOutputPath() android.Path {
// Note that "apex" module installs its contents to "apex"(fake partition) as well // Note that "apex" module installs its contents to "apex"(fake partition) as well
// for symbol lookup by imitating "activated" paths. // for symbol lookup by imitating "activated" paths.
func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
specs := f.PackagingBase.GatherPackagingSpecs(ctx) specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec)
if f.filterPackagingSpecs != nil {
f.filterPackagingSpecs(specs)
}
return specs return specs
} }

View file

@ -37,7 +37,7 @@ func systemImageFactory() android.Module {
module := &systemImage{} module := &systemImage{}
module.AddProperties(&module.properties) module.AddProperties(&module.properties)
module.filesystem.buildExtraFiles = module.buildExtraFiles module.filesystem.buildExtraFiles = module.buildExtraFiles
module.filesystem.filterPackagingSpecs = module.filterPackagingSpecs module.filesystem.filterPackagingSpec = module.filterPackagingSpec
initFilesystemModule(&module.filesystem) initFilesystemModule(&module.filesystem)
return module return module
} }
@ -73,10 +73,6 @@ func (s *systemImage) buildLinkerConfigFile(ctx android.ModuleContext, root andr
// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition. // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
// Note that "apex" module installs its contents to "apex"(fake partition) as well // Note that "apex" module installs its contents to "apex"(fake partition) as well
// for symbol lookup by imitating "activated" paths. // for symbol lookup by imitating "activated" paths.
func (s *systemImage) filterPackagingSpecs(specs map[string]android.PackagingSpec) { func (s *systemImage) filterPackagingSpec(ps android.PackagingSpec) bool {
for k, ps := range specs { return ps.Partition() == "system"
if ps.Partition() != "system" {
delete(specs, k)
}
}
} }