Merge "Translate java libraries to java_library"
am: 5e48b1d183
Change-Id: Ieece3e42538a19f01bde82cf453afcbe072f3e1b
This commit is contained in:
commit
c376617cb5
4 changed files with 161 additions and 7 deletions
|
@ -747,8 +747,8 @@ var moduleTypes = map[string]string{
|
|||
"BUILD_NATIVE_BENCHMARK": "cc_benchmark",
|
||||
"BUILD_HOST_NATIVE_BENCHMARK": "cc_benchmark_host",
|
||||
|
||||
"BUILD_JAVA_LIBRARY": "java_library",
|
||||
"BUILD_STATIC_JAVA_LIBRARY": "java_library_static",
|
||||
"BUILD_JAVA_LIBRARY": "java_library_installable", // will be rewritten to java_library by bpfix
|
||||
"BUILD_STATIC_JAVA_LIBRARY": "java_library",
|
||||
"BUILD_HOST_JAVA_LIBRARY": "java_library_host",
|
||||
"BUILD_HOST_DALVIK_JAVA_LIBRARY": "java_library_host_dalvik",
|
||||
"BUILD_PACKAGE": "android_app",
|
||||
|
|
|
@ -512,7 +512,7 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
|
|||
LOCAL_PROGUARD_ENABLED := obfuscation optimization
|
||||
# Custom
|
||||
LOCAL_PROGUARD_ENABLED := custom
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
`,
|
||||
expected: `
|
||||
java_library {
|
||||
|
@ -534,12 +534,54 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
|
|||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
desc: "java library",
|
||||
in: `
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := a.java
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := b.java
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := c.java
|
||||
LOCAL_UNINSTALLABLE_MODULE := true
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := d.java
|
||||
LOCAL_UNINSTALLABLE_MODULE := false
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
`,
|
||||
expected: `
|
||||
java_library {
|
||||
srcs: ["a.java"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
installable: true,
|
||||
srcs: ["b.java"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
installable: false,
|
||||
srcs: ["c.java"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
installable: true,
|
||||
srcs: ["d.java"],
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
desc: "errorprone options for java library",
|
||||
in: `
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_ERROR_PRONE_FLAGS := -Xep:AsyncCallableReturnsNull:ERROR -Xep:AsyncFunctionReturnsNull:ERROR
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
`,
|
||||
expected: `
|
||||
java_library {
|
||||
|
@ -631,7 +673,7 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
|
|||
],
|
||||
}
|
||||
|
||||
java_library_static {
|
||||
java_library {
|
||||
srcs: ["test.java"],
|
||||
static_libs: [],
|
||||
}
|
||||
|
|
|
@ -70,6 +70,14 @@ var fixSteps = []fixStep{
|
|||
name: "rewriteTestModuleTypes",
|
||||
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 {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue