Dedupe logic to generate linker.config.pb
Between android_filesystem and generic_system_image.
`getLibsForLinkerConfig` will return a list of provideLibs and
requireLibs for the fileystem. `linkerConfig.BuildLinkerConfig` will
then filer out the non-stub libraries.
For `android_filesystem`, requireLibs is ignored for now to match the
logic in the kati built vendor.img
Test: m nothing --no-skip-soong-tests
Test: no diff in out/soong/.intermediates/build/make/target/product/generic/generic_system_image/android_common/gen/root-extra/system/etc/linker.config.pb
paste of cmd: https://diff.googleplex.com/#key=KAqqP9bhKZMD
Change-Id: I1f1d626a3a161fb2e12597909fd287533cbb8482
diff --git a/filesystem/system_image.go b/filesystem/system_image.go
index 6200df4..898987d 100644
--- a/filesystem/system_image.go
+++ b/filesystem/system_image.go
@@ -59,40 +59,7 @@
input := android.PathForModuleSrc(ctx, android.String(s.properties.Linker_config_src))
output := root.Join(ctx, "system", "etc", "linker.config.pb")
- // we need "Module"s for packaging items
- modulesInPackageByModule := make(map[android.Module]bool)
- modulesInPackageByName := make(map[string]bool)
-
- deps := s.gatherFilteredPackagingSpecs(ctx)
- ctx.WalkDeps(func(child, parent android.Module) bool {
- for _, ps := range android.OtherModuleProviderOrDefault(
- ctx, child, android.InstallFilesProvider).PackagingSpecs {
- if _, ok := deps[ps.RelPathInPackage()]; ok {
- modulesInPackageByModule[child] = true
- modulesInPackageByName[child.Name()] = true
- return true
- }
- }
- return true
- })
-
- provideModules := make([]android.Module, 0, len(modulesInPackageByModule))
- for mod := range modulesInPackageByModule {
- provideModules = append(provideModules, mod)
- }
-
- var requireModules []android.Module
- ctx.WalkDeps(func(child, parent android.Module) bool {
- _, parentInPackage := modulesInPackageByModule[parent]
- _, childInPackageName := modulesInPackageByName[child.Name()]
-
- // When parent is in the package, and child (or its variant) is not, this can be from an interface.
- if parentInPackage && !childInPackageName {
- requireModules = append(requireModules, child)
- }
- return true
- })
-
+ provideModules, requireModules := s.getLibsForLinkerConfig(ctx)
builder := android.NewRuleBuilder(pctx, ctx)
linkerconfig.BuildLinkerConfig(ctx, builder, android.Paths{input}, provideModules, requireModules, output)
builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String())