Use generics for DepSets
Use Go's generics for DepSets so they don't require a type-specific
wrapper and reflection.
Test: depsets_test.go
Change-Id: I22ba0b7d680d37d2cd05230b0f560d166c4dd20b
diff --git a/android/module.go b/android/module.go
index ba32710..c1ba67a 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1517,10 +1517,10 @@
noAddressSanitizer bool
installFiles InstallPaths
- installFilesDepSet *installPathsDepSet
+ installFilesDepSet *DepSet[InstallPath]
checkbuildFiles Paths
packagingSpecs []PackagingSpec
- packagingSpecsDepSet *packagingSpecsDepSet
+ packagingSpecsDepSet *DepSet[PackagingSpec]
// katiInstalls tracks the install rules that were created by Soong but are being exported
// to Make to convert to ninja rules so that Make can add additional dependencies.
katiInstalls katiInstalls
@@ -2083,9 +2083,9 @@
// computeInstallDeps finds the installed paths of all dependencies that have a dependency
// tag that is annotated as needing installation via the isInstallDepNeeded method.
-func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*installPathsDepSet, []*packagingSpecsDepSet) {
- var installDeps []*installPathsDepSet
- var packagingSpecs []*packagingSpecsDepSet
+func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*DepSet[InstallPath], []*DepSet[PackagingSpec]) {
+ var installDeps []*DepSet[InstallPath]
+ var packagingSpecs []*DepSet[PackagingSpec]
ctx.VisitDirectDeps(func(dep Module) {
if isInstallDepNeeded(dep, ctx.OtherModuleDependencyTag(dep)) {
// Installation is still handled by Make, so anything hidden from Make is not
@@ -2380,7 +2380,7 @@
// set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies
// of installed files of this module. It will be replaced by a depset including the installed
// files of this module at the end for use by modules that depend on this one.
- m.installFilesDepSet = newInstallPathsDepSet(nil, dependencyInstallFiles)
+ m.installFilesDepSet = NewDepSet[InstallPath](TOPOLOGICAL, nil, dependencyInstallFiles)
// Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
// reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
@@ -2487,8 +2487,8 @@
}
}
- m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles)
- m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs)
+ m.installFilesDepSet = NewDepSet[InstallPath](TOPOLOGICAL, m.installFiles, dependencyInstallFiles)
+ m.packagingSpecsDepSet = NewDepSet[PackagingSpec](TOPOLOGICAL, m.packagingSpecs, dependencyPackagingSpecs)
buildLicenseMetadata(ctx, m.licenseMetadataFile)
@@ -3369,7 +3369,7 @@
m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
if !m.skipInstall() {
- deps = append(deps, m.module.base().installFilesDepSet.ToList().Paths()...)
+ deps = append(deps, InstallPaths(m.module.base().installFilesDepSet.ToList()).Paths()...)
var implicitDeps, orderOnlyDeps Paths
@@ -3944,26 +3944,6 @@
return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
}
-// installPathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
-// topological order.
-type installPathsDepSet struct {
- depSet
-}
-
-// newInstallPathsDepSet returns an immutable packagingSpecsDepSet with the given direct and
-// transitive contents.
-func newInstallPathsDepSet(direct InstallPaths, transitive []*installPathsDepSet) *installPathsDepSet {
- return &installPathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
-}
-
-// ToList returns the installPathsDepSet flattened to a list in topological order.
-func (d *installPathsDepSet) ToList() InstallPaths {
- if d == nil {
- return nil
- }
- return d.depSet.ToList().(InstallPaths)
-}
-
func registerSoongConfigTraceMutator(ctx RegisterMutatorsContext) {
ctx.BottomUp("soongconfigtrace", soongConfigTraceMutator).Parallel()
}