Merge "Add java_import_host handling logic."

This commit is contained in:
Jaewoong Jung 2019-01-08 15:14:51 +00:00 committed by Gerrit Code Review
commit 7494e7301a
2 changed files with 89 additions and 0 deletions

View File

@ -205,6 +205,11 @@ func rewriteIncorrectAndroidmkPrebuilts(f *Fixer) error {
if mod.Type != "java_import" {
continue
}
host, _ := getLiteralBoolPropertyValue(mod, "host")
if host {
mod.Type = "java_import_host"
removeProperty(mod, "host")
}
srcs, ok := getLiteralListProperty(mod, "srcs")
if !ok {
continue
@ -705,6 +710,24 @@ func getLiteralStringPropertyValue(mod *parser.Module, name string) (s string, f
return stringValue.Value, true
}
func getLiteralBoolProperty(mod *parser.Module, name string) (b *parser.Bool, found bool) {
prop, ok := mod.GetProperty(name)
if !ok {
return nil, false
}
b, ok = prop.Value.(*parser.Bool)
return b, ok
}
func getLiteralBoolPropertyValue(mod *parser.Module, name string) (s bool, found bool) {
boolValue, ok := getLiteralBoolProperty(mod, name)
if !ok {
return false, false
}
return boolValue.Value, true
}
func propertyIndex(props []*parser.Property, propertyName string) int {
for i, prop := range props {
if prop.Name == propertyName {

View File

@ -555,3 +555,69 @@ func TestReplaceJavaStaticLibs(t *testing.T) {
})
}
}
func TestRewritePrebuilts(t *testing.T) {
tests := []struct {
name string
in string
out string
}{
{
name: "jar srcs",
in: `
java_import {
name: "foo",
srcs: ["foo.jar"],
}
`,
out: `
java_import {
name: "foo",
jars: ["foo.jar"],
}
`,
},
{
name: "aar srcs",
in: `
java_import {
name: "foo",
srcs: ["foo.aar"],
installable: true,
}
`,
out: `
android_library_import {
name: "foo",
aars: ["foo.aar"],
}
`,
},
{
name: "host prebuilt",
in: `
java_import {
name: "foo",
srcs: ["foo.jar"],
host: true,
}
`,
out: `
java_import_host {
name: "foo",
jars: ["foo.jar"],
}
`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
runPass(t, test.in, test.out, func(fixer *Fixer) error {
return rewriteIncorrectAndroidmkPrebuilts(fixer)
})
})
}
}