aboutsummaryrefslogtreecommitdiffstats
path: root/bpfix
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-06-27 13:50:14 -0700
committerColin Cross <ccross@android.com>2018-07-11 05:50:32 +0000
commit0fa89a3ff91acd1465081fdaca731f99bfa88188 (patch)
treea996606e45aaa75b0ef56360d1c5a802be992be3 /bpfix
parent9ae1b927d46cab40a3d42945c46199471f2d541e (diff)
downloadbuild_soong-0fa89a3ff91acd1465081fdaca731f99bfa88188.tar.gz
build_soong-0fa89a3ff91acd1465081fdaca731f99bfa88188.tar.bz2
build_soong-0fa89a3ff91acd1465081fdaca731f99bfa88188.zip
Translate java libraries to java_library
In androidmk, translate BUILD_JAVA_LIBRARY to java_library plus installable: true, and BUILD_STATIC_JAVA_LIBRARY to java_library. In bpfix, rewrite java_library_static to java_library. Bug: 110885583 Test: androidmk_test.go, bpfix_test.go Change-Id: I63c2f759ae9c62a43f3439526552d2cd8e8cedc3
Diffstat (limited to 'bpfix')
-rw-r--r--bpfix/bpfix/bpfix.go58
-rw-r--r--bpfix/bpfix/bpfix_test.go58
2 files changed, 114 insertions, 2 deletions
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index 05be3bd5..056a01b7 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -71,6 +71,14 @@ var fixSteps = []fixStep{
fix: rewriteTestModuleTypes,
},
{
+ name: "rewriteAndroidmkJavaLibs",
+ fix: rewriteAndroidmkJavaLibs,
+ },
+ {
+ name: "rewriteJavaStaticLibs",
+ fix: rewriteJavaStaticLibs,
+ },
+ {
name: "mergeMatchingModuleProperties",
fix: runPatchListMod(mergeMatchingModuleProperties),
},
@@ -241,7 +249,7 @@ func rewriteIncorrectAndroidmkAndroidLibraries(f *Fixer) error {
hasResourceDirs := hasNonEmptyLiteralListProperty(mod, "resource_dirs")
if hasAndroidLibraries || hasStaticAndroidLibraries || hasResourceDirs {
- if mod.Type == "java_library_static" {
+ if mod.Type == "java_library_static" || mod.Type == "java_library" {
mod.Type = "android_library"
}
}
@@ -289,7 +297,7 @@ func rewriteTestModuleTypes(f *Fixer) error {
switch mod.Type {
case "android_app":
mod.Type = "android_test"
- case "java_library":
+ case "java_library", "java_library_installable":
mod.Type = "java_test"
case "java_library_host":
mod.Type = "java_test_host"
@@ -300,6 +308,51 @@ func rewriteTestModuleTypes(f *Fixer) error {
return nil
}
+// rewriteJavaStaticLibs rewrites java_library_static into java_library
+func rewriteJavaStaticLibs(f *Fixer) error {
+ for _, def := range f.tree.Defs {
+ mod, ok := def.(*parser.Module)
+ if !ok {
+ continue
+ }
+
+ if mod.Type == "java_library_static" {
+ mod.Type = "java_library"
+ }
+ }
+
+ return nil
+}
+
+// rewriteAndroidmkJavaLibs rewrites java_library_installable into java_library plus installable: true
+func rewriteAndroidmkJavaLibs(f *Fixer) error {
+ for _, def := range f.tree.Defs {
+ mod, ok := def.(*parser.Module)
+ if !ok {
+ continue
+ }
+
+ if mod.Type != "java_library_installable" {
+ continue
+ }
+
+ mod.Type = "java_library"
+
+ _, hasInstallable := mod.GetProperty("installable")
+ if !hasInstallable {
+ prop := &parser.Property{
+ Name: "installable",
+ Value: &parser.Bool{
+ Value: true,
+ },
+ }
+ mod.Properties = append(mod.Properties, prop)
+ }
+ }
+
+ return nil
+}
+
func runPatchListMod(modFunc func(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error) func(*Fixer) error {
return func(f *Fixer) error {
// Make sure all the offsets are accurate
@@ -346,6 +399,7 @@ var commonPropertyPriorities = []string{
"defaults",
"device_supported",
"host_supported",
+ "installable",
}
func reorderCommonProperties(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error {
diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go
index 6ba93f69..16dfce0f 100644
--- a/bpfix/bpfix/bpfix_test.go
+++ b/bpfix/bpfix/bpfix_test.go
@@ -497,3 +497,61 @@ func TestRemoveMatchingModuleListProperties(t *testing.T) {
})
}
}
+
+func TestReplaceJavaStaticLibs(t *testing.T) {
+ tests := []struct {
+ name string
+ in string
+ out string
+ }{
+ {
+ name: "static lib",
+ in: `
+ java_library_static {
+ name: "foo",
+ }
+ `,
+ out: `
+ java_library {
+ name: "foo",
+ }
+ `,
+ },
+ {
+ name: "java lib",
+ in: `
+ java_library {
+ name: "foo",
+ }
+ `,
+ out: `
+ java_library {
+ name: "foo",
+ }
+ `,
+ },
+ {
+ name: "java installable lib",
+ in: `
+ java_library {
+ name: "foo",
+ installable: true,
+ }
+ `,
+ out: `
+ java_library {
+ name: "foo",
+ installable: true,
+ }
+ `,
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ runPass(t, test.in, test.out, func(fixer *Fixer) error {
+ return rewriteJavaStaticLibs(fixer)
+ })
+ })
+ }
+}