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
This commit is contained in:
Colin Cross
2022-04-21 12:50:51 -07:00
parent abcfc77717
commit c85750bfe3
26 changed files with 262 additions and 627 deletions

View File

@@ -1747,24 +1747,24 @@ func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
type providesTransitiveHeaderJars struct {
// set of header jars for all transitive libs deps
transitiveLibsHeaderJars *android.DepSet
transitiveLibsHeaderJars *android.DepSet[android.Path]
// set of header jars for all transitive static libs deps
transitiveStaticLibsHeaderJars *android.DepSet
transitiveStaticLibsHeaderJars *android.DepSet[android.Path]
}
func (j *providesTransitiveHeaderJars) TransitiveLibsHeaderJars() *android.DepSet {
func (j *providesTransitiveHeaderJars) TransitiveLibsHeaderJars() *android.DepSet[android.Path] {
return j.transitiveLibsHeaderJars
}
func (j *providesTransitiveHeaderJars) TransitiveStaticLibsHeaderJars() *android.DepSet {
func (j *providesTransitiveHeaderJars) TransitiveStaticLibsHeaderJars() *android.DepSet[android.Path] {
return j.transitiveStaticLibsHeaderJars
}
func (j *providesTransitiveHeaderJars) collectTransitiveHeaderJars(ctx android.ModuleContext) {
directLibs := android.Paths{}
directStaticLibs := android.Paths{}
transitiveLibs := []*android.DepSet{}
transitiveStaticLibs := []*android.DepSet{}
transitiveLibs := []*android.DepSet[android.Path]{}
transitiveStaticLibs := []*android.DepSet[android.Path]{}
ctx.VisitDirectDeps(func(module android.Module) {
// don't add deps of the prebuilt version of the same library
if ctx.ModuleName() == android.RemoveOptionalPrebuiltPrefix(module.Name()) {

View File

@@ -231,10 +231,10 @@ type JavaInfo struct {
HeaderJars android.Paths
// set of header jars for all transitive libs deps
TransitiveLibsHeaderJars *android.DepSet
TransitiveLibsHeaderJars *android.DepSet[android.Path]
// set of header jars for all transitive static libs deps
TransitiveStaticLibsHeaderJars *android.DepSet
TransitiveStaticLibsHeaderJars *android.DepSet[android.Path]
// ImplementationAndResourceJars is a list of jars that contain the implementations of classes
// in the module as well as any resources included in the module.

View File

@@ -117,18 +117,18 @@ type LintDepSetsIntf interface {
}
type LintDepSets struct {
HTML, Text, XML *android.DepSet
HTML, Text, XML *android.DepSet[android.Path]
}
type LintDepSetsBuilder struct {
HTML, Text, XML *android.DepSetBuilder
HTML, Text, XML *android.DepSetBuilder[android.Path]
}
func NewLintDepSetBuilder() LintDepSetsBuilder {
return LintDepSetsBuilder{
HTML: android.NewDepSetBuilder(android.POSTORDER),
Text: android.NewDepSetBuilder(android.POSTORDER),
XML: android.NewDepSetBuilder(android.POSTORDER),
HTML: android.NewDepSetBuilder[android.Path](android.POSTORDER),
Text: android.NewDepSetBuilder[android.Path](android.POSTORDER),
XML: android.NewDepSetBuilder[android.Path](android.POSTORDER),
}
}
@@ -553,9 +553,9 @@ func (l *linter) lint(ctx android.ModuleContext) {
}
func BuildModuleLintReportZips(ctx android.ModuleContext, depSets LintDepSets) android.Paths {
htmlList := depSets.HTML.ToSortedList()
textList := depSets.Text.ToSortedList()
xmlList := depSets.XML.ToSortedList()
htmlList := android.SortedUniquePaths(depSets.HTML.ToList())
textList := android.SortedUniquePaths(depSets.Text.ToList())
xmlList := android.SortedUniquePaths(depSets.XML.ToList())
if len(htmlList) == 0 && len(textList) == 0 && len(xmlList) == 0 {
return nil