Automatically reorder C/C++ link dependencies in Soong
This uses knowledge of transitive dependencies to reorder
linker command line arguments such that if module A depends
on module B, then module A is automatically listed before
module B in the linker command line.
This should mostly remove the need for Android.bp files to
list all of their static dependencies in link order
Bug: 66260943
Test: reorder the entries of static_libs in an Android.bp and see that linking still succeeds
Change-Id: I20f851ab9f2f30031254e4f30023b6140d15d6c3
diff --git a/android/paths.go b/android/paths.go
index f88d650..ed1e607 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -303,6 +303,32 @@
return list[:k]
}
+func indexPathList(s Path, list []Path) int {
+ for i, l := range list {
+ if l == s {
+ return i
+ }
+ }
+
+ return -1
+}
+
+func inPathList(p Path, list []Path) bool {
+ return indexPathList(p, list) != -1
+}
+
+func FilterPathList(list []Path, filter []Path) (remainder []Path, filtered []Path) {
+ for _, l := range list {
+ if inPathList(l, filter) {
+ filtered = append(filtered, l)
+ } else {
+ remainder = append(remainder, l)
+ }
+ }
+
+ return
+}
+
// HasExt returns true of any of the paths have extension ext, otherwise false
func (p Paths) HasExt(ext string) bool {
for _, path := range p {
diff --git a/android/testing.go b/android/testing.go
index 519e279..667c1aa 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -65,7 +65,14 @@
})
if module == nil {
- panic(fmt.Errorf("failed to find module %q variant %q", name, variant))
+ // find all the modules that do exist
+ allModuleNames := []string{}
+ ctx.VisitAllModules(func(m blueprint.Module) {
+ allModuleNames = append(allModuleNames, m.(Module).Name()+"("+ctx.ModuleSubDir(m)+")")
+ })
+
+ panic(fmt.Errorf("failed to find module %q variant %q."+
+ "\nall modules: %v", name, variant, allModuleNames))
}
return TestingModule{module}