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:
@@ -108,17 +108,17 @@ type AidlLibraryInfo struct {
|
|||||||
// The direct aidl files of the module
|
// The direct aidl files of the module
|
||||||
Srcs android.Paths
|
Srcs android.Paths
|
||||||
// The include dirs to the direct aidl files and those provided from transitive aidl_library deps
|
// The include dirs to the direct aidl files and those provided from transitive aidl_library deps
|
||||||
IncludeDirs android.DepSet
|
IncludeDirs android.DepSet[android.Path]
|
||||||
// The direct hdrs and hdrs from transitive deps
|
// The direct hdrs and hdrs from transitive deps
|
||||||
Hdrs android.DepSet
|
Hdrs android.DepSet[android.Path]
|
||||||
}
|
}
|
||||||
|
|
||||||
// AidlLibraryProvider provides the srcs and the transitive include dirs
|
// AidlLibraryProvider provides the srcs and the transitive include dirs
|
||||||
var AidlLibraryProvider = blueprint.NewProvider(AidlLibraryInfo{})
|
var AidlLibraryProvider = blueprint.NewProvider(AidlLibraryInfo{})
|
||||||
|
|
||||||
func (lib *AidlLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (lib *AidlLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
includeDirsDepSetBuilder := android.NewDepSetBuilder(android.PREORDER)
|
includeDirsDepSetBuilder := android.NewDepSetBuilder[android.Path](android.PREORDER)
|
||||||
hdrsDepSetBuilder := android.NewDepSetBuilder(android.PREORDER)
|
hdrsDepSetBuilder := android.NewDepSetBuilder[android.Path](android.PREORDER)
|
||||||
|
|
||||||
if len(lib.properties.Srcs) == 0 && len(lib.properties.Hdrs) == 0 {
|
if len(lib.properties.Srcs) == 0 && len(lib.properties.Hdrs) == 0 {
|
||||||
ctx.ModuleErrorf("at least srcs or hdrs prop must be non-empty")
|
ctx.ModuleErrorf("at least srcs or hdrs prop must be non-empty")
|
||||||
|
@@ -52,7 +52,7 @@ func TestAidlLibrary(t *testing.T) {
|
|||||||
t,
|
t,
|
||||||
"aidl include dirs",
|
"aidl include dirs",
|
||||||
[]string{"package_foo/a", "package_bar/x"},
|
[]string{"package_foo/a", "package_bar/x"},
|
||||||
actualInfo.IncludeDirs.ToList().Strings(),
|
android.Paths(actualInfo.IncludeDirs.ToList()).Strings(),
|
||||||
)
|
)
|
||||||
|
|
||||||
android.AssertPathsRelativeToTopEquals(
|
android.AssertPathsRelativeToTopEquals(
|
||||||
@@ -101,7 +101,7 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) {
|
|||||||
t,
|
t,
|
||||||
"aidl include dirs",
|
"aidl include dirs",
|
||||||
[]string{"package_foo", "package_bar"},
|
[]string{"package_foo", "package_bar"},
|
||||||
actualInfo.IncludeDirs.ToList().Strings(),
|
android.Paths(actualInfo.IncludeDirs.ToList()).Strings(),
|
||||||
)
|
)
|
||||||
|
|
||||||
android.AssertPathsRelativeToTopEquals(
|
android.AssertPathsRelativeToTopEquals(
|
||||||
|
@@ -48,7 +48,6 @@ bootstrap_go_package {
|
|||||||
"defaults.go",
|
"defaults.go",
|
||||||
"defs.go",
|
"defs.go",
|
||||||
"depset_generic.go",
|
"depset_generic.go",
|
||||||
"depset_paths.go",
|
|
||||||
"deptag.go",
|
"deptag.go",
|
||||||
"expand.go",
|
"expand.go",
|
||||||
"filegroup.go",
|
"filegroup.go",
|
||||||
|
@@ -16,10 +16,9 @@ package android
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// depSet is designed to be conceptually compatible with Bazel's depsets:
|
// DepSet is designed to be conceptually compatible with Bazel's depsets:
|
||||||
// https://docs.bazel.build/versions/master/skylark/depsets.html
|
// https://docs.bazel.build/versions/master/skylark/depsets.html
|
||||||
|
|
||||||
type DepSetOrder int
|
type DepSetOrder int
|
||||||
@@ -43,142 +42,114 @@ func (o DepSetOrder) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A depSet efficiently stores a slice of an arbitrary type from transitive dependencies without
|
type depSettableType comparable
|
||||||
// copying. It is stored as a DAG of depSet nodes, each of which has some direct contents and a list
|
|
||||||
// of dependency depSet nodes.
|
// A DepSet efficiently stores a slice of an arbitrary type from transitive dependencies without
|
||||||
|
// copying. It is stored as a DAG of DepSet nodes, each of which has some direct contents and a list
|
||||||
|
// of dependency DepSet nodes.
|
||||||
//
|
//
|
||||||
// A depSet has an order that will be used to walk the DAG when ToList() is called. The order
|
// A DepSet has an order that will be used to walk the DAG when ToList() is called. The order
|
||||||
// can be POSTORDER, PREORDER, or TOPOLOGICAL. POSTORDER and PREORDER orders return a postordered
|
// can be POSTORDER, PREORDER, or TOPOLOGICAL. POSTORDER and PREORDER orders return a postordered
|
||||||
// or preordered left to right flattened list. TOPOLOGICAL returns a list that guarantees that
|
// or preordered left to right flattened list. TOPOLOGICAL returns a list that guarantees that
|
||||||
// elements of children are listed after all of their parents (unless there are duplicate direct
|
// elements of children are listed after all of their parents (unless there are duplicate direct
|
||||||
// elements in the depSet or any of its transitive dependencies, in which case the ordering of the
|
// elements in the DepSet or any of its transitive dependencies, in which case the ordering of the
|
||||||
// duplicated element is not guaranteed).
|
// duplicated element is not guaranteed).
|
||||||
//
|
//
|
||||||
// A depSet is created by newDepSet or newDepSetBuilder.Build from the slice for direct contents
|
// A DepSet is created by NewDepSet or NewDepSetBuilder.Build from the slice for direct contents
|
||||||
// and the *depSets of dependencies. A depSet is immutable once created.
|
// and the *DepSets of dependencies. A DepSet is immutable once created.
|
||||||
//
|
type DepSet[T depSettableType] struct {
|
||||||
// This object uses reflection to remain agnostic to the type it contains. It should be replaced
|
|
||||||
// with generics once those exist in Go. Callers should generally use a thin wrapper around depSet
|
|
||||||
// that provides type-safe methods like DepSet for Paths.
|
|
||||||
type depSet struct {
|
|
||||||
preorder bool
|
preorder bool
|
||||||
reverse bool
|
reverse bool
|
||||||
order DepSetOrder
|
order DepSetOrder
|
||||||
direct interface{}
|
direct []T
|
||||||
transitive []*depSet
|
transitive []*DepSet[T]
|
||||||
}
|
}
|
||||||
|
|
||||||
type depSetInterface interface {
|
// NewDepSet returns an immutable DepSet with the given order, direct and transitive contents.
|
||||||
embeddedDepSet() *depSet
|
func NewDepSet[T depSettableType](order DepSetOrder, direct []T, transitive []*DepSet[T]) *DepSet[T] {
|
||||||
}
|
var directCopy []T
|
||||||
|
var transitiveCopy []*DepSet[T]
|
||||||
func (d *depSet) embeddedDepSet() *depSet {
|
for _, t := range transitive {
|
||||||
return d
|
if t.order != order {
|
||||||
}
|
panic(fmt.Errorf("incompatible order, new DepSet is %s but transitive DepSet is %s",
|
||||||
|
order, t.order))
|
||||||
var _ depSetInterface = (*depSet)(nil)
|
}
|
||||||
|
|
||||||
// newDepSet returns an immutable depSet with the given order, direct and transitive contents.
|
|
||||||
// direct must be a slice, but is not type-safe due to the lack of generics in Go. It can be a
|
|
||||||
// nil slice, but not a nil interface{}, i.e. []string(nil) but not nil.
|
|
||||||
func newDepSet(order DepSetOrder, direct interface{}, transitive interface{}) *depSet {
|
|
||||||
var directCopy interface{}
|
|
||||||
transitiveDepSet := sliceToDepSets(transitive, order)
|
|
||||||
|
|
||||||
if order == TOPOLOGICAL {
|
|
||||||
directCopy = reverseSlice(direct)
|
|
||||||
reverseSliceInPlace(transitiveDepSet)
|
|
||||||
} else {
|
|
||||||
directCopy = copySlice(direct)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &depSet{
|
if order == TOPOLOGICAL {
|
||||||
|
// TOPOLOGICAL is implemented as a postorder traversal followed by reversing the output.
|
||||||
|
// Pre-reverse the inputs here so their order is maintained in the output.
|
||||||
|
directCopy = reverseSlice(direct)
|
||||||
|
transitiveCopy = reverseSlice(transitive)
|
||||||
|
} else {
|
||||||
|
directCopy = append([]T(nil), direct...)
|
||||||
|
transitiveCopy = append([]*DepSet[T](nil), transitive...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &DepSet[T]{
|
||||||
preorder: order == PREORDER,
|
preorder: order == PREORDER,
|
||||||
reverse: order == TOPOLOGICAL,
|
reverse: order == TOPOLOGICAL,
|
||||||
order: order,
|
order: order,
|
||||||
direct: directCopy,
|
direct: directCopy,
|
||||||
transitive: transitiveDepSet,
|
transitive: transitiveCopy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// depSetBuilder is used to create an immutable depSet.
|
// DepSetBuilder is used to create an immutable DepSet.
|
||||||
type depSetBuilder struct {
|
type DepSetBuilder[T depSettableType] struct {
|
||||||
order DepSetOrder
|
order DepSetOrder
|
||||||
direct reflect.Value
|
direct []T
|
||||||
transitive []*depSet
|
transitive []*DepSet[T]
|
||||||
}
|
}
|
||||||
|
|
||||||
// newDepSetBuilder returns a depSetBuilder to create an immutable depSet with the given order and
|
// NewDepSetBuilder returns a DepSetBuilder to create an immutable DepSet with the given order and
|
||||||
// type, represented by a slice of type that will be in the depSet.
|
// type, represented by a slice of type that will be in the DepSet.
|
||||||
func newDepSetBuilder(order DepSetOrder, typ interface{}) *depSetBuilder {
|
func NewDepSetBuilder[T depSettableType](order DepSetOrder) *DepSetBuilder[T] {
|
||||||
empty := reflect.Zero(reflect.TypeOf(typ))
|
return &DepSetBuilder[T]{
|
||||||
return &depSetBuilder{
|
|
||||||
order: order,
|
order: order,
|
||||||
direct: empty,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sliceToDepSets converts a slice of any type that implements depSetInterface (by having a depSet
|
// DirectSlice adds direct contents to the DepSet being built by a DepSetBuilder. Newly added direct
|
||||||
// embedded in it) into a []*depSet.
|
// contents are to the right of any existing direct contents.
|
||||||
func sliceToDepSets(in interface{}, order DepSetOrder) []*depSet {
|
func (b *DepSetBuilder[T]) DirectSlice(direct []T) *DepSetBuilder[T] {
|
||||||
slice := reflect.ValueOf(in)
|
b.direct = append(b.direct, direct...)
|
||||||
length := slice.Len()
|
|
||||||
out := make([]*depSet, length)
|
|
||||||
for i := 0; i < length; i++ {
|
|
||||||
vi := slice.Index(i)
|
|
||||||
depSetIntf, ok := vi.Interface().(depSetInterface)
|
|
||||||
if !ok {
|
|
||||||
panic(fmt.Errorf("element %d is a %s, not a depSetInterface", i, vi.Type()))
|
|
||||||
}
|
|
||||||
depSet := depSetIntf.embeddedDepSet()
|
|
||||||
if depSet.order != order {
|
|
||||||
panic(fmt.Errorf("incompatible order, new depSet is %s but transitive depSet is %s",
|
|
||||||
order, depSet.order))
|
|
||||||
}
|
|
||||||
out[i] = depSet
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DirectSlice adds direct contents to the depSet being built by a depSetBuilder. Newly added direct
|
|
||||||
// contents are to the right of any existing direct contents. The argument must be a slice, but
|
|
||||||
// is not type-safe due to the lack of generics in Go.
|
|
||||||
func (b *depSetBuilder) DirectSlice(direct interface{}) *depSetBuilder {
|
|
||||||
b.direct = reflect.AppendSlice(b.direct, reflect.ValueOf(direct))
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direct adds direct contents to the depSet being built by a depSetBuilder. Newly added direct
|
// Direct adds direct contents to the DepSet being built by a DepSetBuilder. Newly added direct
|
||||||
// contents are to the right of any existing direct contents. The argument must be the same type
|
// contents are to the right of any existing direct contents.
|
||||||
// as the element of the slice passed to newDepSetBuilder, but is not type-safe due to the lack of
|
func (b *DepSetBuilder[T]) Direct(direct ...T) *DepSetBuilder[T] {
|
||||||
// generics in Go.
|
b.direct = append(b.direct, direct...)
|
||||||
func (b *depSetBuilder) Direct(direct interface{}) *depSetBuilder {
|
|
||||||
b.direct = reflect.Append(b.direct, reflect.ValueOf(direct))
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transitive adds transitive contents to the DepSet being built by a DepSetBuilder. Newly added
|
// Transitive adds transitive contents to the DepSet being built by a DepSetBuilder. Newly added
|
||||||
// transitive contents are to the right of any existing transitive contents. The argument can
|
// transitive contents are to the right of any existing transitive contents.
|
||||||
// be any slice of type that has depSet embedded in it.
|
func (b *DepSetBuilder[T]) Transitive(transitive ...*DepSet[T]) *DepSetBuilder[T] {
|
||||||
func (b *depSetBuilder) Transitive(transitive interface{}) *depSetBuilder {
|
for _, t := range transitive {
|
||||||
depSets := sliceToDepSets(transitive, b.order)
|
if t.order != b.order {
|
||||||
b.transitive = append(b.transitive, depSets...)
|
panic(fmt.Errorf("incompatible order, new DepSet is %s but transitive DepSet is %s",
|
||||||
|
b.order, t.order))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.transitive = append(b.transitive, transitive...)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the depSet being built by this depSetBuilder. The depSetBuilder retains its contents
|
// Returns the DepSet being built by this DepSetBuilder. The DepSetBuilder retains its contents
|
||||||
// for creating more depSets.
|
// for creating more depSets.
|
||||||
func (b *depSetBuilder) Build() *depSet {
|
func (b *DepSetBuilder[T]) Build() *DepSet[T] {
|
||||||
return newDepSet(b.order, b.direct.Interface(), b.transitive)
|
return NewDepSet(b.order, b.direct, b.transitive)
|
||||||
}
|
}
|
||||||
|
|
||||||
// walk calls the visit method in depth-first order on a DepSet, preordered if d.preorder is set,
|
// walk calls the visit method in depth-first order on a DepSet, preordered if d.preorder is set,
|
||||||
// otherwise postordered.
|
// otherwise postordered.
|
||||||
func (d *depSet) walk(visit func(interface{})) {
|
func (d *DepSet[T]) walk(visit func([]T)) {
|
||||||
visited := make(map[*depSet]bool)
|
visited := make(map[*DepSet[T]]bool)
|
||||||
|
|
||||||
var dfs func(d *depSet)
|
var dfs func(d *DepSet[T])
|
||||||
dfs = func(d *depSet) {
|
dfs = func(d *DepSet[T]) {
|
||||||
visited[d] = true
|
visited[d] = true
|
||||||
if d.preorder {
|
if d.preorder {
|
||||||
visit(d.direct)
|
visit(d.direct)
|
||||||
@@ -197,155 +168,33 @@ func (d *depSet) walk(visit func(interface{})) {
|
|||||||
dfs(d)
|
dfs(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToList returns the depSet flattened to a list. The order in the list is based on the order
|
// ToList returns the DepSet flattened to a list. The order in the list is based on the order
|
||||||
// of the depSet. POSTORDER and PREORDER orders return a postordered or preordered left to right
|
// of the DepSet. POSTORDER and PREORDER orders return a postordered or preordered left to right
|
||||||
// flattened list. TOPOLOGICAL returns a list that guarantees that elements of children are listed
|
// flattened list. TOPOLOGICAL returns a list that guarantees that elements of children are listed
|
||||||
// after all of their parents (unless there are duplicate direct elements in the DepSet or any of
|
// after all of their parents (unless there are duplicate direct elements in the DepSet or any of
|
||||||
// its transitive dependencies, in which case the ordering of the duplicated element is not
|
// its transitive dependencies, in which case the ordering of the duplicated element is not
|
||||||
// guaranteed).
|
// guaranteed).
|
||||||
//
|
func (d *DepSet[T]) ToList() []T {
|
||||||
// This method uses a reflection-based implementation to find the unique elements in slice, which
|
return d.toList(firstUnique[T])
|
||||||
// is around 3x slower than a concrete implementation. Type-safe wrappers around depSet can
|
|
||||||
// provide their own implementation of ToList that calls depSet.toList with a method that
|
|
||||||
// uses a concrete implementation.
|
|
||||||
func (d *depSet) ToList() interface{} {
|
|
||||||
return d.toList(firstUnique)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// toList returns the depSet flattened to a list. The order in the list is based on the order
|
// toList returns the DepSet flattened to a list. The order in the list is based on the order
|
||||||
// of the depSet. POSTORDER and PREORDER orders return a postordered or preordered left to right
|
// of the DepSet. POSTORDER and PREORDER orders return a postordered or preordered left to right
|
||||||
// flattened list. TOPOLOGICAL returns a list that guarantees that elements of children are listed
|
// flattened list. TOPOLOGICAL returns a list that guarantees that elements of children are listed
|
||||||
// after all of their parents (unless there are duplicate direct elements in the DepSet or any of
|
// after all of their parents (unless there are duplicate direct elements in the DepSet or any of
|
||||||
// its transitive dependencies, in which case the ordering of the duplicated element is not
|
// its transitive dependencies, in which case the ordering of the duplicated element is not
|
||||||
// guaranteed). The firstUniqueFunc is used to remove duplicates from the list.
|
// guaranteed). The firstUniqueFunc is used to remove duplicates from the list.
|
||||||
func (d *depSet) toList(firstUniqueFunc func(interface{}) interface{}) interface{} {
|
func (d *DepSet[T]) toList(firstUniqueFunc func([]T) []T) []T {
|
||||||
if d == nil {
|
if d == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
slice := reflect.Zero(reflect.TypeOf(d.direct))
|
var list []T
|
||||||
d.walk(func(paths interface{}) {
|
d.walk(func(paths []T) {
|
||||||
slice = reflect.AppendSlice(slice, reflect.ValueOf(paths))
|
list = append(list, paths...)
|
||||||
})
|
})
|
||||||
list := slice.Interface()
|
|
||||||
list = firstUniqueFunc(list)
|
list = firstUniqueFunc(list)
|
||||||
if d.reverse {
|
if d.reverse {
|
||||||
reverseSliceInPlace(list)
|
reverseSliceInPlace(list)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
// firstUnique returns all unique elements of a slice, keeping the first copy of each. It
|
|
||||||
// modifies the slice contents in place, and returns a subslice of the original slice. The
|
|
||||||
// argument must be a slice, but is not type-safe due to the lack of reflection in Go.
|
|
||||||
//
|
|
||||||
// Performance of the reflection-based firstUnique is up to 3x slower than a concrete type
|
|
||||||
// version such as FirstUniqueStrings.
|
|
||||||
func firstUnique(slice interface{}) interface{} {
|
|
||||||
// 4 was chosen based on Benchmark_firstUnique results.
|
|
||||||
if reflect.ValueOf(slice).Len() > 4 {
|
|
||||||
return firstUniqueMap(slice)
|
|
||||||
}
|
|
||||||
return firstUniqueList(slice)
|
|
||||||
}
|
|
||||||
|
|
||||||
// firstUniqueList is an implementation of firstUnique using an O(N^2) list comparison to look for
|
|
||||||
// duplicates.
|
|
||||||
func firstUniqueList(in interface{}) interface{} {
|
|
||||||
writeIndex := 0
|
|
||||||
slice := reflect.ValueOf(in)
|
|
||||||
length := slice.Len()
|
|
||||||
outer:
|
|
||||||
for readIndex := 0; readIndex < length; readIndex++ {
|
|
||||||
readValue := slice.Index(readIndex)
|
|
||||||
for compareIndex := 0; compareIndex < writeIndex; compareIndex++ {
|
|
||||||
compareValue := slice.Index(compareIndex)
|
|
||||||
// These two Interface() calls seem to cause an allocation and significantly
|
|
||||||
// slow down this list-based implementation. The map implementation below doesn't
|
|
||||||
// have this issue because reflect.Value.MapIndex takes a Value and appears to be
|
|
||||||
// able to do the map lookup without an allocation.
|
|
||||||
if readValue.Interface() == compareValue.Interface() {
|
|
||||||
// The value at readIndex already exists somewhere in the output region
|
|
||||||
// of the slice before writeIndex, skip it.
|
|
||||||
continue outer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if readIndex != writeIndex {
|
|
||||||
writeValue := slice.Index(writeIndex)
|
|
||||||
writeValue.Set(readValue)
|
|
||||||
}
|
|
||||||
writeIndex++
|
|
||||||
}
|
|
||||||
return slice.Slice(0, writeIndex).Interface()
|
|
||||||
}
|
|
||||||
|
|
||||||
var trueValue = reflect.ValueOf(true)
|
|
||||||
|
|
||||||
// firstUniqueList is an implementation of firstUnique using an O(N) hash set lookup to look for
|
|
||||||
// duplicates.
|
|
||||||
func firstUniqueMap(in interface{}) interface{} {
|
|
||||||
writeIndex := 0
|
|
||||||
slice := reflect.ValueOf(in)
|
|
||||||
length := slice.Len()
|
|
||||||
seen := reflect.MakeMapWithSize(reflect.MapOf(slice.Type().Elem(), trueValue.Type()), slice.Len())
|
|
||||||
for readIndex := 0; readIndex < length; readIndex++ {
|
|
||||||
readValue := slice.Index(readIndex)
|
|
||||||
if seen.MapIndex(readValue).IsValid() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
seen.SetMapIndex(readValue, trueValue)
|
|
||||||
if readIndex != writeIndex {
|
|
||||||
writeValue := slice.Index(writeIndex)
|
|
||||||
writeValue.Set(readValue)
|
|
||||||
}
|
|
||||||
writeIndex++
|
|
||||||
}
|
|
||||||
return slice.Slice(0, writeIndex).Interface()
|
|
||||||
}
|
|
||||||
|
|
||||||
// reverseSliceInPlace reverses the elements of a slice in place. The argument must be a slice, but
|
|
||||||
// is not type-safe due to the lack of reflection in Go.
|
|
||||||
func reverseSliceInPlace(in interface{}) {
|
|
||||||
swapper := reflect.Swapper(in)
|
|
||||||
slice := reflect.ValueOf(in)
|
|
||||||
length := slice.Len()
|
|
||||||
for i, j := 0, length-1; i < j; i, j = i+1, j-1 {
|
|
||||||
swapper(i, j)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// reverseSlice returns a copy of a slice in reverse order. The argument must be a slice, but is
|
|
||||||
// not type-safe due to the lack of reflection in Go.
|
|
||||||
func reverseSlice(in interface{}) interface{} {
|
|
||||||
slice := reflect.ValueOf(in)
|
|
||||||
if !slice.IsValid() || slice.IsNil() {
|
|
||||||
return in
|
|
||||||
}
|
|
||||||
if slice.Kind() != reflect.Slice {
|
|
||||||
panic(fmt.Errorf("%t is not a slice", in))
|
|
||||||
}
|
|
||||||
length := slice.Len()
|
|
||||||
if length == 0 {
|
|
||||||
return in
|
|
||||||
}
|
|
||||||
out := reflect.MakeSlice(slice.Type(), length, length)
|
|
||||||
for i := 0; i < length; i++ {
|
|
||||||
out.Index(i).Set(slice.Index(length - 1 - i))
|
|
||||||
}
|
|
||||||
return out.Interface()
|
|
||||||
}
|
|
||||||
|
|
||||||
// copySlice returns a copy of a slice. The argument must be a slice, but is not type-safe due to
|
|
||||||
// the lack of reflection in Go.
|
|
||||||
func copySlice(in interface{}) interface{} {
|
|
||||||
slice := reflect.ValueOf(in)
|
|
||||||
if !slice.IsValid() || slice.IsNil() {
|
|
||||||
return in
|
|
||||||
}
|
|
||||||
length := slice.Len()
|
|
||||||
if length == 0 {
|
|
||||||
return in
|
|
||||||
}
|
|
||||||
out := reflect.MakeSlice(slice.Type(), length, length)
|
|
||||||
reflect.Copy(out, slice)
|
|
||||||
return out.Interface()
|
|
||||||
}
|
|
||||||
|
@@ -1,94 +0,0 @@
|
|||||||
// Copyright 2020 Google Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package android
|
|
||||||
|
|
||||||
// This file implements DepSet, a thin type-safe wrapper around depSet that contains Paths.
|
|
||||||
|
|
||||||
// A DepSet efficiently stores Paths from transitive dependencies without copying. It is stored
|
|
||||||
// as a DAG of DepSet nodes, each of which has some direct contents and a list of dependency
|
|
||||||
// DepSet nodes.
|
|
||||||
//
|
|
||||||
// A DepSet has an order that will be used to walk the DAG when ToList() is called. The order
|
|
||||||
// can be POSTORDER, PREORDER, or TOPOLOGICAL. POSTORDER and PREORDER orders return a postordered
|
|
||||||
// or preordered left to right flattened list. TOPOLOGICAL returns a list that guarantees that
|
|
||||||
// elements of children are listed after all of their parents (unless there are duplicate direct
|
|
||||||
// elements in the DepSet or any of its transitive dependencies, in which case the ordering of the
|
|
||||||
// duplicated element is not guaranteed).
|
|
||||||
//
|
|
||||||
// A DepSet is created by NewDepSet or NewDepSetBuilder.Build from the Paths for direct contents
|
|
||||||
// and the *DepSets of dependencies. A DepSet is immutable once created.
|
|
||||||
type DepSet struct {
|
|
||||||
depSet
|
|
||||||
}
|
|
||||||
|
|
||||||
// DepSetBuilder is used to create an immutable DepSet.
|
|
||||||
type DepSetBuilder struct {
|
|
||||||
depSetBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDepSet returns an immutable DepSet with the given order, direct and transitive contents.
|
|
||||||
func NewDepSet(order DepSetOrder, direct Paths, transitive []*DepSet) *DepSet {
|
|
||||||
return &DepSet{*newDepSet(order, direct, transitive)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDepSetBuilder returns a DepSetBuilder to create an immutable DepSet with the given order.
|
|
||||||
func NewDepSetBuilder(order DepSetOrder) *DepSetBuilder {
|
|
||||||
return &DepSetBuilder{*newDepSetBuilder(order, Paths(nil))}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Direct adds direct contents to the DepSet being built by a DepSetBuilder. Newly added direct
|
|
||||||
// contents are to the right of any existing direct contents.
|
|
||||||
func (b *DepSetBuilder) Direct(direct ...Path) *DepSetBuilder {
|
|
||||||
b.depSetBuilder.DirectSlice(direct)
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transitive adds transitive contents to the DepSet being built by a DepSetBuilder. Newly added
|
|
||||||
// transitive contents are to the right of any existing transitive contents.
|
|
||||||
func (b *DepSetBuilder) Transitive(transitive ...*DepSet) *DepSetBuilder {
|
|
||||||
b.depSetBuilder.Transitive(transitive)
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the DepSet being built by this DepSetBuilder. The DepSetBuilder retains its contents
|
|
||||||
// for creating more DepSets.
|
|
||||||
func (b *DepSetBuilder) Build() *DepSet {
|
|
||||||
return &DepSet{*b.depSetBuilder.Build()}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToList returns the DepSet flattened to a list. The order in the list is based on the order
|
|
||||||
// of the DepSet. POSTORDER and PREORDER orders return a postordered or preordered left to right
|
|
||||||
// flattened list. TOPOLOGICAL returns a list that guarantees that elements of children are listed
|
|
||||||
// after all of their parents (unless there are duplicate direct elements in the DepSet or any of
|
|
||||||
// its transitive dependencies, in which case the ordering of the duplicated element is not
|
|
||||||
// guaranteed).
|
|
||||||
func (d *DepSet) ToList() Paths {
|
|
||||||
if d == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return d.toList(func(paths interface{}) interface{} {
|
|
||||||
return FirstUniquePaths(paths.(Paths))
|
|
||||||
}).(Paths)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToSortedList returns the direct and transitive contents of a DepSet in lexically sorted order
|
|
||||||
// with duplicates removed.
|
|
||||||
func (d *DepSet) ToSortedList() Paths {
|
|
||||||
if d == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
paths := d.ToList()
|
|
||||||
return SortedUniquePaths(paths)
|
|
||||||
}
|
|
@@ -17,51 +17,40 @@ package android
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleDepSet_ToList_postordered() {
|
func ExampleDepSet_ToList_postordered() {
|
||||||
a := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("a")).Build()
|
a := NewDepSetBuilder[Path](POSTORDER).Direct(PathForTesting("a")).Build()
|
||||||
b := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("b")).Transitive(a).Build()
|
b := NewDepSetBuilder[Path](POSTORDER).Direct(PathForTesting("b")).Transitive(a).Build()
|
||||||
c := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("c")).Transitive(a).Build()
|
c := NewDepSetBuilder[Path](POSTORDER).Direct(PathForTesting("c")).Transitive(a).Build()
|
||||||
d := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("d")).Transitive(b, c).Build()
|
d := NewDepSetBuilder[Path](POSTORDER).Direct(PathForTesting("d")).Transitive(b, c).Build()
|
||||||
|
|
||||||
fmt.Println(d.ToList().Strings())
|
fmt.Println(Paths(d.ToList()).Strings())
|
||||||
// Output: [a b c d]
|
// Output: [a b c d]
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleDepSet_ToList_preordered() {
|
func ExampleDepSet_ToList_preordered() {
|
||||||
a := NewDepSetBuilder(PREORDER).Direct(PathForTesting("a")).Build()
|
a := NewDepSetBuilder[Path](PREORDER).Direct(PathForTesting("a")).Build()
|
||||||
b := NewDepSetBuilder(PREORDER).Direct(PathForTesting("b")).Transitive(a).Build()
|
b := NewDepSetBuilder[Path](PREORDER).Direct(PathForTesting("b")).Transitive(a).Build()
|
||||||
c := NewDepSetBuilder(PREORDER).Direct(PathForTesting("c")).Transitive(a).Build()
|
c := NewDepSetBuilder[Path](PREORDER).Direct(PathForTesting("c")).Transitive(a).Build()
|
||||||
d := NewDepSetBuilder(PREORDER).Direct(PathForTesting("d")).Transitive(b, c).Build()
|
d := NewDepSetBuilder[Path](PREORDER).Direct(PathForTesting("d")).Transitive(b, c).Build()
|
||||||
|
|
||||||
fmt.Println(d.ToList().Strings())
|
fmt.Println(Paths(d.ToList()).Strings())
|
||||||
// Output: [d b a c]
|
// Output: [d b a c]
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleDepSet_ToList_topological() {
|
func ExampleDepSet_ToList_topological() {
|
||||||
a := NewDepSetBuilder(TOPOLOGICAL).Direct(PathForTesting("a")).Build()
|
a := NewDepSetBuilder[Path](TOPOLOGICAL).Direct(PathForTesting("a")).Build()
|
||||||
b := NewDepSetBuilder(TOPOLOGICAL).Direct(PathForTesting("b")).Transitive(a).Build()
|
b := NewDepSetBuilder[Path](TOPOLOGICAL).Direct(PathForTesting("b")).Transitive(a).Build()
|
||||||
c := NewDepSetBuilder(TOPOLOGICAL).Direct(PathForTesting("c")).Transitive(a).Build()
|
c := NewDepSetBuilder[Path](TOPOLOGICAL).Direct(PathForTesting("c")).Transitive(a).Build()
|
||||||
d := NewDepSetBuilder(TOPOLOGICAL).Direct(PathForTesting("d")).Transitive(b, c).Build()
|
d := NewDepSetBuilder[Path](TOPOLOGICAL).Direct(PathForTesting("d")).Transitive(b, c).Build()
|
||||||
|
|
||||||
fmt.Println(d.ToList().Strings())
|
fmt.Println(Paths(d.ToList()).Strings())
|
||||||
// Output: [d b c a]
|
// Output: [d b c a]
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleDepSet_ToSortedList() {
|
|
||||||
a := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("a")).Build()
|
|
||||||
b := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("b")).Transitive(a).Build()
|
|
||||||
c := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("c")).Transitive(a).Build()
|
|
||||||
d := NewDepSetBuilder(POSTORDER).Direct(PathForTesting("d")).Transitive(b, c).Build()
|
|
||||||
|
|
||||||
fmt.Println(d.ToSortedList().Strings())
|
|
||||||
// Output: [a b c d]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests based on Bazel's ExpanderTestBase.java to ensure compatibility
|
// Tests based on Bazel's ExpanderTestBase.java to ensure compatibility
|
||||||
// https://github.com/bazelbuild/bazel/blob/master/src/test/java/com/google/devtools/build/lib/collect/nestedset/ExpanderTestBase.java
|
// https://github.com/bazelbuild/bazel/blob/master/src/test/java/com/google/devtools/build/lib/collect/nestedset/ExpanderTestBase.java
|
||||||
func TestDepSet(t *testing.T) {
|
func TestDepSet(t *testing.T) {
|
||||||
@@ -74,13 +63,13 @@ func TestDepSet(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
depSet func(t *testing.T, order DepSetOrder) *DepSet
|
depSet func(t *testing.T, order DepSetOrder) *DepSet[Path]
|
||||||
postorder, preorder, topological []string
|
postorder, preorder, topological []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "simple",
|
name: "simple",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
return NewDepSet(order, Paths{c, a, b}, nil)
|
return NewDepSet[Path](order, Paths{c, a, b}, nil)
|
||||||
},
|
},
|
||||||
postorder: []string{"c", "a", "b"},
|
postorder: []string{"c", "a", "b"},
|
||||||
preorder: []string{"c", "a", "b"},
|
preorder: []string{"c", "a", "b"},
|
||||||
@@ -88,8 +77,8 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "simpleNoDuplicates",
|
name: "simpleNoDuplicates",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
return NewDepSet(order, Paths{c, a, a, a, b}, nil)
|
return NewDepSet[Path](order, Paths{c, a, a, a, b}, nil)
|
||||||
},
|
},
|
||||||
postorder: []string{"c", "a", "b"},
|
postorder: []string{"c", "a", "b"},
|
||||||
preorder: []string{"c", "a", "b"},
|
preorder: []string{"c", "a", "b"},
|
||||||
@@ -97,9 +86,9 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nesting",
|
name: "nesting",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
subset := NewDepSet(order, Paths{c, a, e}, nil)
|
subset := NewDepSet[Path](order, Paths{c, a, e}, nil)
|
||||||
return NewDepSet(order, Paths{b, d}, []*DepSet{subset})
|
return NewDepSet[Path](order, Paths{b, d}, []*DepSet[Path]{subset})
|
||||||
},
|
},
|
||||||
postorder: []string{"c", "a", "e", "b", "d"},
|
postorder: []string{"c", "a", "e", "b", "d"},
|
||||||
preorder: []string{"b", "d", "c", "a", "e"},
|
preorder: []string{"b", "d", "c", "a", "e"},
|
||||||
@@ -107,14 +96,14 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "builderReuse",
|
name: "builderReuse",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
assertEquals := func(t *testing.T, w, g Paths) {
|
assertEquals := func(t *testing.T, w, g Paths) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if !reflect.DeepEqual(w, g) {
|
if !reflect.DeepEqual(w, g) {
|
||||||
t.Errorf("want %q, got %q", w, g)
|
t.Errorf("want %q, got %q", w, g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder := NewDepSetBuilder(order)
|
builder := NewDepSetBuilder[Path](order)
|
||||||
assertEquals(t, nil, builder.Build().ToList())
|
assertEquals(t, nil, builder.Build().ToList())
|
||||||
|
|
||||||
builder.Direct(b)
|
builder.Direct(b)
|
||||||
@@ -123,7 +112,7 @@ func TestDepSet(t *testing.T) {
|
|||||||
builder.Direct(d)
|
builder.Direct(d)
|
||||||
assertEquals(t, Paths{b, d}, builder.Build().ToList())
|
assertEquals(t, Paths{b, d}, builder.Build().ToList())
|
||||||
|
|
||||||
child := NewDepSetBuilder(order).Direct(c, a, e).Build()
|
child := NewDepSetBuilder[Path](order).Direct(c, a, e).Build()
|
||||||
builder.Transitive(child)
|
builder.Transitive(child)
|
||||||
return builder.Build()
|
return builder.Build()
|
||||||
},
|
},
|
||||||
@@ -133,9 +122,9 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "builderChaining",
|
name: "builderChaining",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
return NewDepSetBuilder(order).Direct(b).Direct(d).
|
return NewDepSetBuilder[Path](order).Direct(b).Direct(d).
|
||||||
Transitive(NewDepSetBuilder(order).Direct(c, a, e).Build()).Build()
|
Transitive(NewDepSetBuilder[Path](order).Direct(c, a, e).Build()).Build()
|
||||||
},
|
},
|
||||||
postorder: []string{"c", "a", "e", "b", "d"},
|
postorder: []string{"c", "a", "e", "b", "d"},
|
||||||
preorder: []string{"b", "d", "c", "a", "e"},
|
preorder: []string{"b", "d", "c", "a", "e"},
|
||||||
@@ -143,9 +132,9 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "transitiveDepsHandledSeparately",
|
name: "transitiveDepsHandledSeparately",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
subset := NewDepSetBuilder(order).Direct(c, a, e).Build()
|
subset := NewDepSetBuilder[Path](order).Direct(c, a, e).Build()
|
||||||
builder := NewDepSetBuilder(order)
|
builder := NewDepSetBuilder[Path](order)
|
||||||
// The fact that we add the transitive subset between the Direct(b) and Direct(d)
|
// The fact that we add the transitive subset between the Direct(b) and Direct(d)
|
||||||
// calls should not change the result.
|
// calls should not change the result.
|
||||||
builder.Direct(b)
|
builder.Direct(b)
|
||||||
@@ -159,9 +148,9 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nestingNoDuplicates",
|
name: "nestingNoDuplicates",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
subset := NewDepSetBuilder(order).Direct(c, a, e).Build()
|
subset := NewDepSetBuilder[Path](order).Direct(c, a, e).Build()
|
||||||
return NewDepSetBuilder(order).Direct(b, d, e).Transitive(subset).Build()
|
return NewDepSetBuilder[Path](order).Direct(b, d, e).Transitive(subset).Build()
|
||||||
},
|
},
|
||||||
postorder: []string{"c", "a", "e", "b", "d"},
|
postorder: []string{"c", "a", "e", "b", "d"},
|
||||||
preorder: []string{"b", "d", "e", "c", "a"},
|
preorder: []string{"b", "d", "e", "c", "a"},
|
||||||
@@ -169,10 +158,10 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "chain",
|
name: "chain",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
c := NewDepSetBuilder(order).Direct(c).Build()
|
c := NewDepSetBuilder[Path](order).Direct(c).Build()
|
||||||
b := NewDepSetBuilder(order).Direct(b).Transitive(c).Build()
|
b := NewDepSetBuilder[Path](order).Direct(b).Transitive(c).Build()
|
||||||
a := NewDepSetBuilder(order).Direct(a).Transitive(b).Build()
|
a := NewDepSetBuilder[Path](order).Direct(a).Transitive(b).Build()
|
||||||
|
|
||||||
return a
|
return a
|
||||||
},
|
},
|
||||||
@@ -182,11 +171,11 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "diamond",
|
name: "diamond",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
d := NewDepSetBuilder(order).Direct(d).Build()
|
d := NewDepSetBuilder[Path](order).Direct(d).Build()
|
||||||
c := NewDepSetBuilder(order).Direct(c).Transitive(d).Build()
|
c := NewDepSetBuilder[Path](order).Direct(c).Transitive(d).Build()
|
||||||
b := NewDepSetBuilder(order).Direct(b).Transitive(d).Build()
|
b := NewDepSetBuilder[Path](order).Direct(b).Transitive(d).Build()
|
||||||
a := NewDepSetBuilder(order).Direct(a).Transitive(b).Transitive(c).Build()
|
a := NewDepSetBuilder[Path](order).Direct(a).Transitive(b).Transitive(c).Build()
|
||||||
|
|
||||||
return a
|
return a
|
||||||
},
|
},
|
||||||
@@ -196,12 +185,12 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "extendedDiamond",
|
name: "extendedDiamond",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
d := NewDepSetBuilder(order).Direct(d).Build()
|
d := NewDepSetBuilder[Path](order).Direct(d).Build()
|
||||||
e := NewDepSetBuilder(order).Direct(e).Build()
|
e := NewDepSetBuilder[Path](order).Direct(e).Build()
|
||||||
b := NewDepSetBuilder(order).Direct(b).Transitive(d).Transitive(e).Build()
|
b := NewDepSetBuilder[Path](order).Direct(b).Transitive(d).Transitive(e).Build()
|
||||||
c := NewDepSetBuilder(order).Direct(c).Transitive(e).Transitive(d).Build()
|
c := NewDepSetBuilder[Path](order).Direct(c).Transitive(e).Transitive(d).Build()
|
||||||
a := NewDepSetBuilder(order).Direct(a).Transitive(b).Transitive(c).Build()
|
a := NewDepSetBuilder[Path](order).Direct(a).Transitive(b).Transitive(c).Build()
|
||||||
return a
|
return a
|
||||||
},
|
},
|
||||||
postorder: []string{"d", "e", "b", "c", "a"},
|
postorder: []string{"d", "e", "b", "c", "a"},
|
||||||
@@ -210,13 +199,13 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "extendedDiamondRightArm",
|
name: "extendedDiamondRightArm",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
d := NewDepSetBuilder(order).Direct(d).Build()
|
d := NewDepSetBuilder[Path](order).Direct(d).Build()
|
||||||
e := NewDepSetBuilder(order).Direct(e).Build()
|
e := NewDepSetBuilder[Path](order).Direct(e).Build()
|
||||||
b := NewDepSetBuilder(order).Direct(b).Transitive(d).Transitive(e).Build()
|
b := NewDepSetBuilder[Path](order).Direct(b).Transitive(d).Transitive(e).Build()
|
||||||
c2 := NewDepSetBuilder(order).Direct(c2).Transitive(e).Transitive(d).Build()
|
c2 := NewDepSetBuilder[Path](order).Direct(c2).Transitive(e).Transitive(d).Build()
|
||||||
c := NewDepSetBuilder(order).Direct(c).Transitive(c2).Build()
|
c := NewDepSetBuilder[Path](order).Direct(c).Transitive(c2).Build()
|
||||||
a := NewDepSetBuilder(order).Direct(a).Transitive(b).Transitive(c).Build()
|
a := NewDepSetBuilder[Path](order).Direct(a).Transitive(b).Transitive(c).Build()
|
||||||
return a
|
return a
|
||||||
},
|
},
|
||||||
postorder: []string{"d", "e", "b", "c2", "c", "a"},
|
postorder: []string{"d", "e", "b", "c2", "c", "a"},
|
||||||
@@ -225,10 +214,10 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "orderConflict",
|
name: "orderConflict",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
child1 := NewDepSetBuilder(order).Direct(a, b).Build()
|
child1 := NewDepSetBuilder[Path](order).Direct(a, b).Build()
|
||||||
child2 := NewDepSetBuilder(order).Direct(b, a).Build()
|
child2 := NewDepSetBuilder[Path](order).Direct(b, a).Build()
|
||||||
parent := NewDepSetBuilder(order).Transitive(child1).Transitive(child2).Build()
|
parent := NewDepSetBuilder[Path](order).Transitive(child1).Transitive(child2).Build()
|
||||||
return parent
|
return parent
|
||||||
},
|
},
|
||||||
postorder: []string{"a", "b"},
|
postorder: []string{"a", "b"},
|
||||||
@@ -237,12 +226,12 @@ func TestDepSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "orderConflictNested",
|
name: "orderConflictNested",
|
||||||
depSet: func(t *testing.T, order DepSetOrder) *DepSet {
|
depSet: func(t *testing.T, order DepSetOrder) *DepSet[Path] {
|
||||||
a := NewDepSetBuilder(order).Direct(a).Build()
|
a := NewDepSetBuilder[Path](order).Direct(a).Build()
|
||||||
b := NewDepSetBuilder(order).Direct(b).Build()
|
b := NewDepSetBuilder[Path](order).Direct(b).Build()
|
||||||
child1 := NewDepSetBuilder(order).Transitive(a).Transitive(b).Build()
|
child1 := NewDepSetBuilder[Path](order).Transitive(a).Transitive(b).Build()
|
||||||
child2 := NewDepSetBuilder(order).Transitive(b).Transitive(a).Build()
|
child2 := NewDepSetBuilder[Path](order).Transitive(b).Transitive(a).Build()
|
||||||
parent := NewDepSetBuilder(order).Transitive(child1).Transitive(child2).Build()
|
parent := NewDepSetBuilder[Path](order).Transitive(child1).Transitive(child2).Build()
|
||||||
return parent
|
return parent
|
||||||
},
|
},
|
||||||
postorder: []string{"a", "b"},
|
postorder: []string{"a", "b"},
|
||||||
@@ -255,19 +244,19 @@ func TestDepSet(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
t.Run("postorder", func(t *testing.T) {
|
t.Run("postorder", func(t *testing.T) {
|
||||||
depSet := tt.depSet(t, POSTORDER)
|
depSet := tt.depSet(t, POSTORDER)
|
||||||
if g, w := depSet.ToList().Strings(), tt.postorder; !reflect.DeepEqual(g, w) {
|
if g, w := Paths(depSet.ToList()).Strings(), tt.postorder; !reflect.DeepEqual(g, w) {
|
||||||
t.Errorf("expected ToList() = %q, got %q", w, g)
|
t.Errorf("expected ToList() = %q, got %q", w, g)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("preorder", func(t *testing.T) {
|
t.Run("preorder", func(t *testing.T) {
|
||||||
depSet := tt.depSet(t, PREORDER)
|
depSet := tt.depSet(t, PREORDER)
|
||||||
if g, w := depSet.ToList().Strings(), tt.preorder; !reflect.DeepEqual(g, w) {
|
if g, w := Paths(depSet.ToList()).Strings(), tt.preorder; !reflect.DeepEqual(g, w) {
|
||||||
t.Errorf("expected ToList() = %q, got %q", w, g)
|
t.Errorf("expected ToList() = %q, got %q", w, g)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("topological", func(t *testing.T) {
|
t.Run("topological", func(t *testing.T) {
|
||||||
depSet := tt.depSet(t, TOPOLOGICAL)
|
depSet := tt.depSet(t, TOPOLOGICAL)
|
||||||
if g, w := depSet.ToList().Strings(), tt.topological; !reflect.DeepEqual(g, w) {
|
if g, w := Paths(depSet.ToList()).Strings(), tt.topological; !reflect.DeepEqual(g, w) {
|
||||||
t.Errorf("expected ToList() = %q, got %q", w, g)
|
t.Errorf("expected ToList() = %q, got %q", w, g)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -288,7 +277,7 @@ func TestDepSetInvalidOrder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
NewDepSet(order1, nil, []*DepSet{NewDepSet(order2, nil, nil)})
|
NewDepSet(order1, nil, []*DepSet[Path]{NewDepSet[Path](order2, nil, nil)})
|
||||||
t.Fatal("expected panic")
|
t.Fatal("expected panic")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,87 +293,3 @@ func TestDepSetInvalidOrder(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_firstUnique(t *testing.T) {
|
|
||||||
f := func(t *testing.T, imp func([]string) []string, in, want []string) {
|
|
||||||
t.Helper()
|
|
||||||
out := imp(in)
|
|
||||||
if !reflect.DeepEqual(out, want) {
|
|
||||||
t.Errorf("incorrect output:")
|
|
||||||
t.Errorf(" input: %#v", in)
|
|
||||||
t.Errorf(" expected: %#v", want)
|
|
||||||
t.Errorf(" got: %#v", out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, testCase := range firstUniqueStringsTestCases {
|
|
||||||
t.Run("list", func(t *testing.T) {
|
|
||||||
f(t, func(s []string) []string {
|
|
||||||
return firstUniqueList(s).([]string)
|
|
||||||
}, testCase.in, testCase.out)
|
|
||||||
})
|
|
||||||
t.Run("map", func(t *testing.T) {
|
|
||||||
f(t, func(s []string) []string {
|
|
||||||
return firstUniqueMap(s).([]string)
|
|
||||||
}, testCase.in, testCase.out)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Benchmark_firstUnique(b *testing.B) {
|
|
||||||
implementations := []struct {
|
|
||||||
name string
|
|
||||||
f func([]string) []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "list",
|
|
||||||
f: func(slice []string) []string {
|
|
||||||
return firstUniqueList(slice).([]string)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "map",
|
|
||||||
f: func(slice []string) []string {
|
|
||||||
return firstUniqueMap(slice).([]string)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "optimal",
|
|
||||||
f: func(slice []string) []string {
|
|
||||||
return firstUnique(slice).([]string)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const maxSize = 1024
|
|
||||||
uniqueStrings := make([]string, maxSize)
|
|
||||||
for i := range uniqueStrings {
|
|
||||||
uniqueStrings[i] = strconv.Itoa(i)
|
|
||||||
}
|
|
||||||
sameString := make([]string, maxSize)
|
|
||||||
for i := range sameString {
|
|
||||||
sameString[i] = uniqueStrings[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
f := func(b *testing.B, imp func([]string) []string, s []string) {
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
b.ReportAllocs()
|
|
||||||
s = append([]string(nil), s...)
|
|
||||||
imp(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for n := 1; n <= maxSize; n <<= 1 {
|
|
||||||
b.Run(strconv.Itoa(n), func(b *testing.B) {
|
|
||||||
for _, implementation := range implementations {
|
|
||||||
b.Run(implementation.name, func(b *testing.B) {
|
|
||||||
b.Run("same", func(b *testing.B) {
|
|
||||||
f(b, implementation.f, sameString[:n])
|
|
||||||
})
|
|
||||||
b.Run("unique", func(b *testing.B) {
|
|
||||||
f(b, implementation.f, uniqueStrings[:n])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -55,7 +55,7 @@ func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) {
|
|||||||
var allDepMetadataFiles Paths
|
var allDepMetadataFiles Paths
|
||||||
var allDepMetadataArgs []string
|
var allDepMetadataArgs []string
|
||||||
var allDepOutputFiles Paths
|
var allDepOutputFiles Paths
|
||||||
var allDepMetadataDepSets []*PathsDepSet
|
var allDepMetadataDepSets []*DepSet[Path]
|
||||||
|
|
||||||
ctx.VisitDirectDepsBlueprint(func(bpdep blueprint.Module) {
|
ctx.VisitDirectDepsBlueprint(func(bpdep blueprint.Module) {
|
||||||
dep, _ := bpdep.(Module)
|
dep, _ := bpdep.(Module)
|
||||||
@@ -127,7 +127,7 @@ func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) {
|
|||||||
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.commonProperties.Effective_license_text.Strings()), "-n "))
|
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.commonProperties.Effective_license_text.Strings()), "-n "))
|
||||||
|
|
||||||
if isContainer {
|
if isContainer {
|
||||||
transitiveDeps := newPathsDepSet(nil, allDepMetadataDepSets).ToList()
|
transitiveDeps := Paths(NewDepSet[Path](TOPOLOGICAL, nil, allDepMetadataDepSets).ToList())
|
||||||
args = append(args,
|
args = append(args,
|
||||||
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(transitiveDeps.Strings()), "-d "))
|
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(transitiveDeps.Strings()), "-d "))
|
||||||
orderOnlyDeps = append(orderOnlyDeps, transitiveDeps...)
|
orderOnlyDeps = append(orderOnlyDeps, transitiveDeps...)
|
||||||
@@ -170,7 +170,7 @@ func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) {
|
|||||||
|
|
||||||
ctx.SetProvider(LicenseMetadataProvider, &LicenseMetadataInfo{
|
ctx.SetProvider(LicenseMetadataProvider, &LicenseMetadataInfo{
|
||||||
LicenseMetadataPath: licenseMetadataFile,
|
LicenseMetadataPath: licenseMetadataFile,
|
||||||
LicenseMetadataDepSet: newPathsDepSet(Paths{licenseMetadataFile}, allDepMetadataDepSets),
|
LicenseMetadataDepSet: NewDepSet(TOPOLOGICAL, Paths{licenseMetadataFile}, allDepMetadataDepSets),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ var LicenseMetadataProvider = blueprint.NewProvider(&LicenseMetadataInfo{})
|
|||||||
// LicenseMetadataInfo stores the license metadata path for a module.
|
// LicenseMetadataInfo stores the license metadata path for a module.
|
||||||
type LicenseMetadataInfo struct {
|
type LicenseMetadataInfo struct {
|
||||||
LicenseMetadataPath Path
|
LicenseMetadataPath Path
|
||||||
LicenseMetadataDepSet *PathsDepSet
|
LicenseMetadataDepSet *DepSet[Path]
|
||||||
}
|
}
|
||||||
|
|
||||||
// licenseAnnotationsFromTag returns the LicenseAnnotations for a tag (if any) converted into
|
// licenseAnnotationsFromTag returns the LicenseAnnotations for a tag (if any) converted into
|
||||||
|
@@ -1517,10 +1517,10 @@ type ModuleBase struct {
|
|||||||
|
|
||||||
noAddressSanitizer bool
|
noAddressSanitizer bool
|
||||||
installFiles InstallPaths
|
installFiles InstallPaths
|
||||||
installFilesDepSet *installPathsDepSet
|
installFilesDepSet *DepSet[InstallPath]
|
||||||
checkbuildFiles Paths
|
checkbuildFiles Paths
|
||||||
packagingSpecs []PackagingSpec
|
packagingSpecs []PackagingSpec
|
||||||
packagingSpecsDepSet *packagingSpecsDepSet
|
packagingSpecsDepSet *DepSet[PackagingSpec]
|
||||||
// katiInstalls tracks the install rules that were created by Soong but are being exported
|
// 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.
|
// to Make to convert to ninja rules so that Make can add additional dependencies.
|
||||||
katiInstalls katiInstalls
|
katiInstalls katiInstalls
|
||||||
@@ -2083,9 +2083,9 @@ func (m *ModuleBase) EffectiveLicenseFiles() Paths {
|
|||||||
|
|
||||||
// computeInstallDeps finds the installed paths of all dependencies that have a dependency
|
// computeInstallDeps finds the installed paths of all dependencies that have a dependency
|
||||||
// tag that is annotated as needing installation via the isInstallDepNeeded method.
|
// tag that is annotated as needing installation via the isInstallDepNeeded method.
|
||||||
func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*installPathsDepSet, []*packagingSpecsDepSet) {
|
func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*DepSet[InstallPath], []*DepSet[PackagingSpec]) {
|
||||||
var installDeps []*installPathsDepSet
|
var installDeps []*DepSet[InstallPath]
|
||||||
var packagingSpecs []*packagingSpecsDepSet
|
var packagingSpecs []*DepSet[PackagingSpec]
|
||||||
ctx.VisitDirectDeps(func(dep Module) {
|
ctx.VisitDirectDeps(func(dep Module) {
|
||||||
if isInstallDepNeeded(dep, ctx.OtherModuleDependencyTag(dep)) {
|
if isInstallDepNeeded(dep, ctx.OtherModuleDependencyTag(dep)) {
|
||||||
// Installation is still handled by Make, so anything hidden from Make is not
|
// Installation is still handled by Make, so anything hidden from Make is not
|
||||||
@@ -2380,7 +2380,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
|
|||||||
// set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies
|
// 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
|
// 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.
|
// 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
|
// Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
|
||||||
// reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
|
// reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
|
||||||
@@ -2487,8 +2487,8 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles)
|
m.installFilesDepSet = NewDepSet[InstallPath](TOPOLOGICAL, m.installFiles, dependencyInstallFiles)
|
||||||
m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs)
|
m.packagingSpecsDepSet = NewDepSet[PackagingSpec](TOPOLOGICAL, m.packagingSpecs, dependencyPackagingSpecs)
|
||||||
|
|
||||||
buildLicenseMetadata(ctx, m.licenseMetadataFile)
|
buildLicenseMetadata(ctx, m.licenseMetadataFile)
|
||||||
|
|
||||||
@@ -3369,7 +3369,7 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat
|
|||||||
m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
|
m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
|
||||||
|
|
||||||
if !m.skipInstall() {
|
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
|
var implicitDeps, orderOnlyDeps Paths
|
||||||
|
|
||||||
@@ -3944,26 +3944,6 @@ func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents strin
|
|||||||
return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
|
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) {
|
func registerSoongConfigTraceMutator(ctx RegisterMutatorsContext) {
|
||||||
ctx.BottomUp("soongconfigtrace", soongConfigTraceMutator).Parallel()
|
ctx.BottomUp("soongconfigtrace", soongConfigTraceMutator).Parallel()
|
||||||
}
|
}
|
||||||
|
@@ -282,23 +282,3 @@ func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, specs map[string]Packag
|
|||||||
builder.Build("zip_deps", fmt.Sprintf("Zipping deps for %s", ctx.ModuleName()))
|
builder.Build("zip_deps", fmt.Sprintf("Zipping deps for %s", ctx.ModuleName()))
|
||||||
return entries
|
return entries
|
||||||
}
|
}
|
||||||
|
|
||||||
// packagingSpecsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
|
|
||||||
// topological order.
|
|
||||||
type packagingSpecsDepSet struct {
|
|
||||||
depSet
|
|
||||||
}
|
|
||||||
|
|
||||||
// newPackagingSpecsDepSet returns an immutable packagingSpecsDepSet with the given direct and
|
|
||||||
// transitive contents.
|
|
||||||
func newPackagingSpecsDepSet(direct []PackagingSpec, transitive []*packagingSpecsDepSet) *packagingSpecsDepSet {
|
|
||||||
return &packagingSpecsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToList returns the packagingSpecsDepSet flattened to a list in topological order.
|
|
||||||
func (d *packagingSpecsDepSet) ToList() []PackagingSpec {
|
|
||||||
if d == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return d.depSet.ToList().([]PackagingSpec)
|
|
||||||
}
|
|
||||||
|
@@ -2199,23 +2199,3 @@ func IsThirdPartyPath(path string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
|
|
||||||
// topological order.
|
|
||||||
type PathsDepSet struct {
|
|
||||||
depSet
|
|
||||||
}
|
|
||||||
|
|
||||||
// newPathsDepSet returns an immutable PathsDepSet with the given direct and
|
|
||||||
// transitive contents.
|
|
||||||
func newPathsDepSet(direct Paths, transitive []*PathsDepSet) *PathsDepSet {
|
|
||||||
return &PathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToList returns the PathsDepSet flattened to a list in topological order.
|
|
||||||
func (d *PathsDepSet) ToList() Paths {
|
|
||||||
if d == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return d.depSet.ToList().(Paths)
|
|
||||||
}
|
|
||||||
|
@@ -284,38 +284,74 @@ func FirstUniqueStrings(list []string) []string {
|
|||||||
list = CopyOf(list)
|
list = CopyOf(list)
|
||||||
// 128 was chosen based on BenchmarkFirstUniqueStrings results.
|
// 128 was chosen based on BenchmarkFirstUniqueStrings results.
|
||||||
if len(list) > 128 {
|
if len(list) > 128 {
|
||||||
return firstUniqueStringsMap(list)
|
return firstUnique(list)
|
||||||
}
|
}
|
||||||
return firstUniqueStringsList(list)
|
return firstUnique(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
func firstUniqueStringsList(list []string) []string {
|
// firstUnique returns all unique elements of a slice, keeping the first copy of each. It
|
||||||
k := 0
|
// modifies the slice contents in place, and returns a subslice of the original slice.
|
||||||
|
func firstUnique[T comparable](slice []T) []T {
|
||||||
|
// 4 was chosen based on Benchmark_firstUnique results.
|
||||||
|
if len(slice) > 4 {
|
||||||
|
return firstUniqueMap(slice)
|
||||||
|
}
|
||||||
|
return firstUniqueList(slice)
|
||||||
|
}
|
||||||
|
|
||||||
|
// firstUniqueList is an implementation of firstUnique using an O(N^2) list comparison to look for
|
||||||
|
// duplicates.
|
||||||
|
func firstUniqueList[T any](in []T) []T {
|
||||||
|
writeIndex := 0
|
||||||
outer:
|
outer:
|
||||||
for i := 0; i < len(list); i++ {
|
for readIndex := 0; readIndex < len(in); readIndex++ {
|
||||||
for j := 0; j < k; j++ {
|
for compareIndex := 0; compareIndex < writeIndex; compareIndex++ {
|
||||||
if list[i] == list[j] {
|
if interface{}(in[readIndex]) == interface{}(in[compareIndex]) {
|
||||||
|
// The value at readIndex already exists somewhere in the output region
|
||||||
|
// of the slice before writeIndex, skip it.
|
||||||
continue outer
|
continue outer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list[k] = list[i]
|
if readIndex != writeIndex {
|
||||||
k++
|
in[writeIndex] = in[readIndex]
|
||||||
}
|
}
|
||||||
return list[:k]
|
writeIndex++
|
||||||
|
}
|
||||||
|
return in[0:writeIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
func firstUniqueStringsMap(list []string) []string {
|
// firstUniqueMap is an implementation of firstUnique using an O(N) hash set lookup to look for
|
||||||
k := 0
|
// duplicates.
|
||||||
seen := make(map[string]bool, len(list))
|
func firstUniqueMap[T comparable](in []T) []T {
|
||||||
for i := 0; i < len(list); i++ {
|
writeIndex := 0
|
||||||
if seen[list[i]] {
|
seen := make(map[T]bool, len(in))
|
||||||
|
for readIndex := 0; readIndex < len(in); readIndex++ {
|
||||||
|
if _, exists := seen[in[readIndex]]; exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen[list[i]] = true
|
seen[in[readIndex]] = true
|
||||||
list[k] = list[i]
|
if readIndex != writeIndex {
|
||||||
k++
|
in[writeIndex] = in[readIndex]
|
||||||
}
|
}
|
||||||
return list[:k]
|
writeIndex++
|
||||||
|
}
|
||||||
|
return in[0:writeIndex]
|
||||||
|
}
|
||||||
|
|
||||||
|
// reverseSliceInPlace reverses the elements of a slice in place.
|
||||||
|
func reverseSliceInPlace[T any](in []T) {
|
||||||
|
for i, j := 0, len(in)-1; i < j; i, j = i+1, j-1 {
|
||||||
|
in[i], in[j] = in[j], in[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// reverseSlice returns a copy of a slice in reverse order.
|
||||||
|
func reverseSlice[T any](in []T) []T {
|
||||||
|
out := make([]T, len(in))
|
||||||
|
for i := 0; i < len(in); i++ {
|
||||||
|
out[i] = in[len(in)-1-i]
|
||||||
|
}
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// LastUniqueStrings returns all unique elements of a slice of strings, keeping the last copy of
|
// LastUniqueStrings returns all unique elements of a slice of strings, keeping the last copy of
|
||||||
|
@@ -74,10 +74,10 @@ func TestFirstUniqueStrings(t *testing.T) {
|
|||||||
|
|
||||||
for _, testCase := range firstUniqueStringsTestCases {
|
for _, testCase := range firstUniqueStringsTestCases {
|
||||||
t.Run("list", func(t *testing.T) {
|
t.Run("list", func(t *testing.T) {
|
||||||
f(t, firstUniqueStringsList, testCase.in, testCase.out)
|
f(t, firstUniqueList[string], testCase.in, testCase.out)
|
||||||
})
|
})
|
||||||
t.Run("map", func(t *testing.T) {
|
t.Run("map", func(t *testing.T) {
|
||||||
f(t, firstUniqueStringsMap, testCase.in, testCase.out)
|
f(t, firstUniqueMap[string], testCase.in, testCase.out)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -604,11 +604,11 @@ func BenchmarkFirstUniqueStrings(b *testing.B) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "list",
|
name: "list",
|
||||||
f: firstUniqueStringsList,
|
f: firstUniqueList[string],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "map",
|
name: "map",
|
||||||
f: firstUniqueStringsMap,
|
f: firstUniqueMap[string],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "optimal",
|
name: "optimal",
|
||||||
|
6
cc/cc.go
6
cc/cc.go
@@ -150,7 +150,7 @@ type PathDeps struct {
|
|||||||
StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
|
StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
|
||||||
|
|
||||||
// Transitive static library dependencies of static libraries for use in ordering.
|
// Transitive static library dependencies of static libraries for use in ordering.
|
||||||
TranstiveStaticLibrariesForOrdering *android.DepSet
|
TranstiveStaticLibrariesForOrdering *android.DepSet[android.Path]
|
||||||
|
|
||||||
// Paths to .o files
|
// Paths to .o files
|
||||||
Objs Objects
|
Objs Objects
|
||||||
@@ -3549,8 +3549,8 @@ func ChooseStubOrImpl(ctx android.ModuleContext, dep android.Module) (SharedLibr
|
|||||||
// to match the topological order of the dependency tree, including any static analogues of
|
// to match the topological order of the dependency tree, including any static analogues of
|
||||||
// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
|
// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
|
||||||
// of the transitive dependencies.
|
// of the transitive dependencies.
|
||||||
func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
|
func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet[android.Path]) {
|
||||||
transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
|
transitiveStaticLibsBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL)
|
||||||
var staticPaths android.Paths
|
var staticPaths android.Paths
|
||||||
for _, staticDep := range staticDeps {
|
for _, staticDep := range staticDeps {
|
||||||
staticPaths = append(staticPaths, staticDep.StaticLibrary)
|
staticPaths = append(staticPaths, staticDep.StaticLibrary)
|
||||||
|
@@ -2700,8 +2700,8 @@ func TestStaticLibDepReordering(t *testing.T) {
|
|||||||
|
|
||||||
variant := "android_arm64_armv8-a_static"
|
variant := "android_arm64_armv8-a_static"
|
||||||
moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
|
moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
|
||||||
actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
|
actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
|
||||||
TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop()
|
TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop()
|
||||||
expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
|
expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
|
||||||
|
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
@@ -2736,8 +2736,8 @@ func TestStaticLibDepReorderingWithShared(t *testing.T) {
|
|||||||
|
|
||||||
variant := "android_arm64_armv8-a_static"
|
variant := "android_arm64_armv8-a_static"
|
||||||
moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
|
moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
|
||||||
actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
|
actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
|
||||||
TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop()
|
TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop()
|
||||||
expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"})
|
expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"})
|
||||||
|
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
@@ -892,7 +892,7 @@ func (handler *ccLibraryBazelHandler) generateStaticBazelBuildActions(ctx androi
|
|||||||
|
|
||||||
// TODO(b/190524881): Include transitive static libraries in this provider to support
|
// TODO(b/190524881): Include transitive static libraries in this provider to support
|
||||||
// static libraries with deps.
|
// static libraries with deps.
|
||||||
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder(android.TOPOLOGICAL).
|
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).
|
||||||
Direct(outputFilePath).
|
Direct(outputFilePath).
|
||||||
Build(),
|
Build(),
|
||||||
})
|
})
|
||||||
@@ -1649,7 +1649,7 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext,
|
|||||||
Objects: library.objects,
|
Objects: library.objects,
|
||||||
WholeStaticLibsFromPrebuilts: library.wholeStaticLibsFromPrebuilts,
|
WholeStaticLibsFromPrebuilts: library.wholeStaticLibsFromPrebuilts,
|
||||||
|
|
||||||
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder(android.TOPOLOGICAL).
|
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).
|
||||||
Direct(outputFile).
|
Direct(outputFile).
|
||||||
Transitive(deps.TranstiveStaticLibrariesForOrdering).
|
Transitive(deps.TranstiveStaticLibrariesForOrdering).
|
||||||
Build(),
|
Build(),
|
||||||
@@ -1794,7 +1794,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
library.coverageOutputFile = transformCoverageFilesToZip(ctx, objs, library.getLibName(ctx))
|
library.coverageOutputFile = transformCoverageFilesToZip(ctx, objs, library.getLibName(ctx))
|
||||||
library.linkSAbiDumpFiles(ctx, objs, fileName, unstrippedOutputFile)
|
library.linkSAbiDumpFiles(ctx, objs, fileName, unstrippedOutputFile)
|
||||||
|
|
||||||
var transitiveStaticLibrariesForOrdering *android.DepSet
|
var transitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
|
||||||
if static := ctx.GetDirectDepsWithTag(staticVariantTag); len(static) > 0 {
|
if static := ctx.GetDirectDepsWithTag(staticVariantTag); len(static) > 0 {
|
||||||
s := ctx.OtherModuleProvider(static[0], StaticLibraryInfoProvider).(StaticLibraryInfo)
|
s := ctx.OtherModuleProvider(static[0], StaticLibraryInfoProvider).(StaticLibraryInfo)
|
||||||
transitiveStaticLibrariesForOrdering = s.TransitiveStaticLibrariesForOrdering
|
transitiveStaticLibrariesForOrdering = s.TransitiveStaticLibrariesForOrdering
|
||||||
|
@@ -345,7 +345,7 @@ type SharedLibraryInfo struct {
|
|||||||
TableOfContents android.OptionalPath
|
TableOfContents android.OptionalPath
|
||||||
|
|
||||||
// should be obtained from static analogue
|
// should be obtained from static analogue
|
||||||
TransitiveStaticLibrariesForOrdering *android.DepSet
|
TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
|
||||||
}
|
}
|
||||||
|
|
||||||
var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
|
var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
|
||||||
@@ -387,7 +387,7 @@ type StaticLibraryInfo struct {
|
|||||||
// This isn't the actual transitive DepSet, shared library dependencies have been
|
// This isn't the actual transitive DepSet, shared library dependencies have been
|
||||||
// converted into static library analogues. It is only used to order the static
|
// converted into static library analogues. It is only used to order the static
|
||||||
// library dependencies that were specified for the current module.
|
// library dependencies that were specified for the current module.
|
||||||
TransitiveStaticLibrariesForOrdering *android.DepSet
|
TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
|
||||||
}
|
}
|
||||||
|
|
||||||
var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
|
var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
|
||||||
|
@@ -113,7 +113,7 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
|||||||
ndk.libraryDecorator.flagExporter.setProvider(ctx)
|
ndk.libraryDecorator.flagExporter.setProvider(ctx)
|
||||||
|
|
||||||
if ndk.static() {
|
if ndk.static() {
|
||||||
depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(lib).Build()
|
depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(lib).Build()
|
||||||
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
||||||
StaticLibrary: lib,
|
StaticLibrary: lib,
|
||||||
|
|
||||||
|
@@ -140,7 +140,7 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.static() {
|
if p.static() {
|
||||||
depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build()
|
depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(in).Build()
|
||||||
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
||||||
StaticLibrary: in,
|
StaticLibrary: in,
|
||||||
|
|
||||||
@@ -508,7 +508,7 @@ func (h *prebuiltLibraryBazelHandler) processStaticBazelQueryResponse(ctx androi
|
|||||||
|
|
||||||
h.module.outputFile = android.OptionalPathForPath(outputPath)
|
h.module.outputFile = android.OptionalPathForPath(outputPath)
|
||||||
|
|
||||||
depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(outputPath).Build()
|
depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(outputPath).Build()
|
||||||
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
||||||
StaticLibrary: outputPath,
|
StaticLibrary: outputPath,
|
||||||
TransitiveStaticLibrariesForOrdering: depSet,
|
TransitiveStaticLibrariesForOrdering: depSet,
|
||||||
|
@@ -499,7 +499,7 @@ func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps Pat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.static() {
|
if p.static() {
|
||||||
depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build()
|
depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(in).Build()
|
||||||
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
||||||
StaticLibrary: in,
|
StaticLibrary: in,
|
||||||
|
|
||||||
|
@@ -321,7 +321,7 @@ func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
|
|||||||
missingDepsCtx.AddMissingDependencies([]string{err.Error()})
|
missingDepsCtx.AddMissingDependencies([]string{err.Error()})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
android.ReportPathErrorf(ctx, "%w", err)
|
android.ReportPathErrorf(ctx, "%s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module android/soong
|
module android/soong
|
||||||
|
|
||||||
go 1.19
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/blueprint v0.0.0
|
github.com/google/blueprint v0.0.0
|
||||||
|
12
java/base.go
12
java/base.go
@@ -1747,24 +1747,24 @@ func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
|
|||||||
|
|
||||||
type providesTransitiveHeaderJars struct {
|
type providesTransitiveHeaderJars struct {
|
||||||
// set of header jars for all transitive libs deps
|
// 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
|
// 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
|
return j.transitiveLibsHeaderJars
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *providesTransitiveHeaderJars) TransitiveStaticLibsHeaderJars() *android.DepSet {
|
func (j *providesTransitiveHeaderJars) TransitiveStaticLibsHeaderJars() *android.DepSet[android.Path] {
|
||||||
return j.transitiveStaticLibsHeaderJars
|
return j.transitiveStaticLibsHeaderJars
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *providesTransitiveHeaderJars) collectTransitiveHeaderJars(ctx android.ModuleContext) {
|
func (j *providesTransitiveHeaderJars) collectTransitiveHeaderJars(ctx android.ModuleContext) {
|
||||||
directLibs := android.Paths{}
|
directLibs := android.Paths{}
|
||||||
directStaticLibs := android.Paths{}
|
directStaticLibs := android.Paths{}
|
||||||
transitiveLibs := []*android.DepSet{}
|
transitiveLibs := []*android.DepSet[android.Path]{}
|
||||||
transitiveStaticLibs := []*android.DepSet{}
|
transitiveStaticLibs := []*android.DepSet[android.Path]{}
|
||||||
ctx.VisitDirectDeps(func(module android.Module) {
|
ctx.VisitDirectDeps(func(module android.Module) {
|
||||||
// don't add deps of the prebuilt version of the same library
|
// don't add deps of the prebuilt version of the same library
|
||||||
if ctx.ModuleName() == android.RemoveOptionalPrebuiltPrefix(module.Name()) {
|
if ctx.ModuleName() == android.RemoveOptionalPrebuiltPrefix(module.Name()) {
|
||||||
|
@@ -231,10 +231,10 @@ type JavaInfo struct {
|
|||||||
HeaderJars android.Paths
|
HeaderJars android.Paths
|
||||||
|
|
||||||
// set of header jars for all transitive libs deps
|
// 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
|
// 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
|
// ImplementationAndResourceJars is a list of jars that contain the implementations of classes
|
||||||
// in the module as well as any resources included in the module.
|
// in the module as well as any resources included in the module.
|
||||||
|
16
java/lint.go
16
java/lint.go
@@ -117,18 +117,18 @@ type LintDepSetsIntf interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LintDepSets struct {
|
type LintDepSets struct {
|
||||||
HTML, Text, XML *android.DepSet
|
HTML, Text, XML *android.DepSet[android.Path]
|
||||||
}
|
}
|
||||||
|
|
||||||
type LintDepSetsBuilder struct {
|
type LintDepSetsBuilder struct {
|
||||||
HTML, Text, XML *android.DepSetBuilder
|
HTML, Text, XML *android.DepSetBuilder[android.Path]
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLintDepSetBuilder() LintDepSetsBuilder {
|
func NewLintDepSetBuilder() LintDepSetsBuilder {
|
||||||
return LintDepSetsBuilder{
|
return LintDepSetsBuilder{
|
||||||
HTML: android.NewDepSetBuilder(android.POSTORDER),
|
HTML: android.NewDepSetBuilder[android.Path](android.POSTORDER),
|
||||||
Text: android.NewDepSetBuilder(android.POSTORDER),
|
Text: android.NewDepSetBuilder[android.Path](android.POSTORDER),
|
||||||
XML: android.NewDepSetBuilder(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 {
|
func BuildModuleLintReportZips(ctx android.ModuleContext, depSets LintDepSets) android.Paths {
|
||||||
htmlList := depSets.HTML.ToSortedList()
|
htmlList := android.SortedUniquePaths(depSets.HTML.ToList())
|
||||||
textList := depSets.Text.ToSortedList()
|
textList := android.SortedUniquePaths(depSets.Text.ToList())
|
||||||
xmlList := depSets.XML.ToSortedList()
|
xmlList := android.SortedUniquePaths(depSets.XML.ToList())
|
||||||
|
|
||||||
if len(htmlList) == 0 && len(textList) == 0 && len(xmlList) == 0 {
|
if len(htmlList) == 0 && len(textList) == 0 && len(xmlList) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@@ -567,7 +567,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
if library.static() {
|
if library.static() {
|
||||||
depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(outputFile).Build()
|
depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(outputFile).Build()
|
||||||
ctx.SetProvider(cc.StaticLibraryInfoProvider, cc.StaticLibraryInfo{
|
ctx.SetProvider(cc.StaticLibraryInfoProvider, cc.StaticLibraryInfo{
|
||||||
StaticLibrary: outputFile,
|
StaticLibrary: outputFile,
|
||||||
|
|
||||||
|
@@ -230,7 +230,7 @@ func (m *Metrics) SetBuildDateTime(buildTimestamp time.Time) {
|
|||||||
|
|
||||||
func (m *Metrics) UpdateTotalRealTimeAndNonZeroExit(data []byte, bazelExitCode int32) error {
|
func (m *Metrics) UpdateTotalRealTimeAndNonZeroExit(data []byte, bazelExitCode int32) error {
|
||||||
if err := proto.Unmarshal(data, &m.metrics); err != nil {
|
if err := proto.Unmarshal(data, &m.metrics); err != nil {
|
||||||
return fmt.Errorf("Failed to unmarshal proto", err)
|
return fmt.Errorf("Failed to unmarshal proto: %w", err)
|
||||||
}
|
}
|
||||||
startTime := *m.metrics.Total.StartTime
|
startTime := *m.metrics.Total.StartTime
|
||||||
endTime := uint64(time.Now().UnixNano())
|
endTime := uint64(time.Now().UnixNano())
|
||||||
|
Reference in New Issue
Block a user