Start using Providers instead of direct module access
Export information about static libraries, shared libraries and
exported flags through Providers instead of accessing the module
directly. Much more is left to be converted, but this significantly
simplifies the dependencies on libraries with stubs by making it easy
for a module to masquerade as another by simply exporting the
providers from the other module. Instead of depending on all the
versions of a library and then picking which one to use later, it
can depend only on the implementation variant and then select the
right SharedLibraryInfo from the variant.
Test: m checkbuild
Test: only expected changes to build.ninja
Change-Id: I1fd9eb4d251cf96ed8398d586efc3e0817663c76
diff --git a/android/apex.go b/android/apex.go
index c01b716..3039e79 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -145,11 +145,6 @@
// check-platform-availability mutator in the apex package.
SetNotAvailableForPlatform()
- // Returns the highest version which is <= maxSdkVersion.
- // For example, with maxSdkVersion is 10 and versionList is [9,11]
- // it returns 9 as string
- ChooseSdkVersion(ctx BaseModuleContext, versionList []string, maxSdkVersion ApiLevel) (string, error)
-
// List of APEXes that this module tests. The module has access to
// the private part of the listed APEXes even when it is not included in the
// APEXes.
@@ -310,20 +305,6 @@
return true
}
-func (m *ApexModuleBase) ChooseSdkVersion(ctx BaseModuleContext, versionList []string, maxSdkVersion ApiLevel) (string, error) {
- for i := range versionList {
- version := versionList[len(versionList)-i-1]
- ver, err := ApiLevelFromUser(ctx, version)
- if err != nil {
- return "", err
- }
- if ver.LessThanOrEqualTo(maxSdkVersion) {
- return version, nil
- }
- }
- return "", fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion, versionList)
-}
-
func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
for _, n := range m.ApexProperties.Apex_available {
if n == AvailableToPlatform || n == AvailableToAnyApex || n == AvailableToGkiApex {
diff --git a/android/depset.go b/android/depset.go
index f707094..60ebcac 100644
--- a/android/depset.go
+++ b/android/depset.go
@@ -71,24 +71,26 @@
// NewDepSet returns an immutable DepSet with the given order, direct and transitive contents.
func NewDepSet(order DepSetOrder, direct Paths, transitive []*DepSet) *DepSet {
var directCopy Paths
- var transitiveCopy []*DepSet
+ transitiveCopy := make([]*DepSet, 0, len(transitive))
+
+ for _, dep := range transitive {
+ if dep != nil {
+ if dep.order != order {
+ panic(fmt.Errorf("incompatible order, new DepSet is %s but transitive DepSet is %s",
+ order, dep.order))
+ }
+ transitiveCopy = append(transitiveCopy, dep)
+ }
+ }
+
if order == TOPOLOGICAL {
directCopy = ReversePaths(direct)
- transitiveCopy = reverseDepSets(transitive)
+ reverseDepSetsInPlace(transitiveCopy)
} else {
// Use copy instead of append(nil, ...) to make a slice that is exactly the size of the input
// slice. The DepSet is immutable, there is no need for additional capacity.
directCopy = make(Paths, len(direct))
copy(directCopy, direct)
- transitiveCopy = make([]*DepSet, len(transitive))
- copy(transitiveCopy, transitive)
- }
-
- for _, dep := range transitive {
- if dep.order != order {
- panic(fmt.Errorf("incompatible order, new DepSet is %s but transitive DepSet is %s",
- order, dep.order))
- }
}
return &DepSet{
@@ -157,6 +159,9 @@
// 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
+ }
var list Paths
d.walk(func(paths Paths) {
list = append(list, paths...)
@@ -181,10 +186,9 @@
}
}
-func reverseDepSets(list []*DepSet) []*DepSet {
- ret := make([]*DepSet, len(list))
- for i := range list {
- ret[i] = list[len(list)-1-i]
+func reverseDepSetsInPlace(list []*DepSet) {
+ for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
+ list[i], list[j] = list[j], list[i]
}
- return ret
+
}