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
This commit is contained in:
parent
109f64766e
commit
c0647eb9ee
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue