aboutsummaryrefslogtreecommitdiffstats
path: root/bpfix
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-11-01 15:31:18 -0700
committerSteven Moreland <smoreland@google.com>2019-11-06 11:35:55 -0800
commitc0647eb9ee8bb8bd3c0d4888095e0fb4eaa9f0d5 (patch)
treeb74d3c65f7c892b5bc83a4a0aa9ad9372231f95b /bpfix
parent109f64766e312fa4099227825e7827b3b9a13292 (diff)
downloadbuild_soong-c0647eb9ee8bb8bd3c0d4888095e0fb4eaa9f0d5.tar.gz
build_soong-c0647eb9ee8bb8bd3c0d4888095e0fb4eaa9f0d5.tar.bz2
build_soong-c0647eb9ee8bb8bd3c0d4888095e0fb4eaa9f0d5.zip
bpfix: remove empty HIDL libs
libhidltransport/libhwbinder are empty and disallowed in Android.bp (motivation is ~4kb per empty library per process overhead). Bug: 135686713 Test: bpfix Change-Id: I964215ad35068465217af74c5ef1322b43476428
Diffstat (limited to 'bpfix')
-rw-r--r--bpfix/bpfix/bpfix.go57
-rw-r--r--bpfix/bpfix/bpfix_test.go54
2 files changed, 111 insertions, 0 deletions
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index 9cba80a7..4633aa64 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -116,6 +116,10 @@ var fixSteps = []FixStep{
Name: "rewriteAndroidAppImport",
Fix: rewriteAndroidAppImport,
},
+ {
+ Name: "removeEmptyLibDependencies",
+ Fix: removeEmptyLibDependencies,
+ },
}
func NewFixRequest() FixRequest {
@@ -650,6 +654,50 @@ func rewriteAndroidAppImport(f *Fixer) error {
return nil
}
+// Removes library dependencies which are empty (and restricted from usage in Soong)
+func removeEmptyLibDependencies(f *Fixer) error {
+ emptyLibraries := []string{
+ "libhidltransport",
+ "libhwbinder",
+ }
+ relevantFields := []string{
+ "export_shared_lib_headers",
+ "export_static_lib_headers",
+ "static_libs",
+ "whole_static_libs",
+ "shared_libs",
+ }
+ for _, def := range f.tree.Defs {
+ mod, ok := def.(*parser.Module)
+ if !ok {
+ continue
+ }
+ for _, field := range relevantFields {
+ listValue, ok := getLiteralListProperty(mod, field)
+ if !ok {
+ continue
+ }
+ newValues := []parser.Expression{}
+ for _, v := range listValue.Values {
+ stringValue, ok := v.(*parser.String)
+ if !ok {
+ return fmt.Errorf("Expecting string for %s.%s fields", mod.Type, field)
+ }
+ if inList(stringValue.Value, emptyLibraries) {
+ continue
+ }
+ newValues = append(newValues, stringValue)
+ }
+ if len(newValues) == 0 && len(listValue.Values) != 0 {
+ removeProperty(mod, field)
+ } else {
+ listValue.Values = newValues
+ }
+ }
+ }
+ return nil
+}
+
// Converts the default source list property, 'srcs', to a single source property with a given name.
// "LOCAL_MODULE" reference is also resolved during the conversion process.
func convertToSingleSource(mod *parser.Module, srcPropertyName string) {
@@ -1084,3 +1132,12 @@ func removeProperty(mod *parser.Module, propertyName string) {
}
mod.Properties = newList
}
+
+func inList(s string, list []string) bool {
+ for _, v := range list {
+ if s == v {
+ return true
+ }
+ }
+ return false
+}
diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go
index 5e0b8175..032282f8 100644
--- a/bpfix/bpfix/bpfix_test.go
+++ b/bpfix/bpfix/bpfix_test.go
@@ -833,3 +833,57 @@ func TestRewriteAndroidAppImport(t *testing.T) {
})
}
}
+
+func TestRemoveEmptyLibDependencies(t *testing.T) {
+ tests := []struct {
+ name string
+ in string
+ out string
+ }{
+ {
+ name: "remove sole shared lib",
+ in: `
+ cc_library {
+ name: "foo",
+ shared_libs: ["libhwbinder"],
+ }
+ `,
+ out: `
+ cc_library {
+ name: "foo",
+
+ }
+ `,
+ },
+ {
+ name: "remove a shared lib",
+ in: `
+ cc_library {
+ name: "foo",
+ shared_libs: [
+ "libhwbinder",
+ "libfoo",
+ "libhidltransport",
+ ],
+ }
+ `,
+ out: `
+ cc_library {
+ name: "foo",
+ shared_libs: [
+
+ "libfoo",
+
+ ],
+ }
+ `,
+ },
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ runPass(t, test.in, test.out, func(fixer *Fixer) error {
+ return removeEmptyLibDependencies(fixer)
+ })
+ })
+ }
+}