Merge "bp2build converts java_version property to javacopts attribute"

This commit is contained in:
Vinh Tran
2022-04-29 01:43:20 +00:00
committed by Gerrit Code Review
8 changed files with 40 additions and 4 deletions

View File

@@ -104,12 +104,14 @@ var (
"external/google-benchmark": Bp2BuildDefaultTrueRecursively, "external/google-benchmark": Bp2BuildDefaultTrueRecursively,
"external/googletest": Bp2BuildDefaultTrueRecursively, "external/googletest": Bp2BuildDefaultTrueRecursively,
"external/gwp_asan": Bp2BuildDefaultTrueRecursively, "external/gwp_asan": Bp2BuildDefaultTrueRecursively,
"external/hamcrest": Bp2BuildDefaultTrueRecursively,
"external/icu": Bp2BuildDefaultTrueRecursively, "external/icu": Bp2BuildDefaultTrueRecursively,
"external/icu/android_icu4j": Bp2BuildDefaultFalse, // java rules incomplete "external/icu/android_icu4j": Bp2BuildDefaultFalse, // java rules incomplete
"external/icu/icu4j": Bp2BuildDefaultFalse, // java rules incomplete "external/icu/icu4j": Bp2BuildDefaultFalse, // java rules incomplete
"external/javapoet": Bp2BuildDefaultTrueRecursively, "external/javapoet": Bp2BuildDefaultTrueRecursively,
"external/jemalloc_new": Bp2BuildDefaultTrueRecursively, "external/jemalloc_new": Bp2BuildDefaultTrueRecursively,
"external/jsoncpp": Bp2BuildDefaultTrueRecursively, "external/jsoncpp": Bp2BuildDefaultTrueRecursively,
"external/junit": Bp2BuildDefaultTrueRecursively,
"external/libcap": Bp2BuildDefaultTrueRecursively, "external/libcap": Bp2BuildDefaultTrueRecursively,
"external/libcxx": Bp2BuildDefaultTrueRecursively, "external/libcxx": Bp2BuildDefaultTrueRecursively,
"external/libcxxabi": Bp2BuildDefaultTrueRecursively, "external/libcxxabi": Bp2BuildDefaultTrueRecursively,
@@ -122,6 +124,7 @@ var (
"external/pcre": Bp2BuildDefaultTrueRecursively, "external/pcre": Bp2BuildDefaultTrueRecursively,
"external/protobuf": Bp2BuildDefaultTrueRecursively, "external/protobuf": Bp2BuildDefaultTrueRecursively,
"external/python/six": Bp2BuildDefaultTrueRecursively, "external/python/six": Bp2BuildDefaultTrueRecursively,
"external/rappor": Bp2BuildDefaultTrueRecursively,
"external/scudo": Bp2BuildDefaultTrueRecursively, "external/scudo": Bp2BuildDefaultTrueRecursively,
"external/selinux/libselinux": Bp2BuildDefaultTrueRecursively, "external/selinux/libselinux": Bp2BuildDefaultTrueRecursively,
"external/selinux/libsepol": Bp2BuildDefaultTrueRecursively, "external/selinux/libsepol": Bp2BuildDefaultTrueRecursively,

View File

@@ -74,7 +74,8 @@ android_app {
package_name: "com.google", package_name: "com.google",
resource_dirs: ["resa", "resb"], resource_dirs: ["resa", "resb"],
manifest: "manifest/AndroidManifest.xml", manifest: "manifest/AndroidManifest.xml",
static_libs: ["static_lib_dep"] static_libs: ["static_lib_dep"],
java_version: "7",
} }
`, `,
expectedBazelTargets: []string{ expectedBazelTargets: []string{
@@ -87,6 +88,7 @@ android_app {
]`, ]`,
"custom_package": `"com.google"`, "custom_package": `"com.google"`,
"deps": `[":static_lib_dep"]`, "deps": `[":static_lib_dep"]`,
"javacopts": `["-source 1.7 -target 1.7"]`,
}), }),
}}) }})
} }

View File

@@ -52,6 +52,7 @@ func TestJavaBinaryHost(t *testing.T) {
jni_libs: ["jni-lib-1"], jni_libs: ["jni-lib-1"],
javacflags: ["-Xdoclint:all/protected"], javacflags: ["-Xdoclint:all/protected"],
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
java_version: "8",
}`, }`,
expectedBazelTargets: []string{ expectedBazelTargets: []string{
makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{
@@ -59,7 +60,10 @@ func TestJavaBinaryHost(t *testing.T) {
"main_class": `"com.android.test.MainClass"`, "main_class": `"com.android.test.MainClass"`,
"deps": `["//other:jni-lib-1"]`, "deps": `["//other:jni-lib-1"]`,
"jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`, "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`,
"javacopts": `["-Xdoclint:all/protected"]`, "javacopts": `[
"-Xdoclint:all/protected",
"-source 1.8 -target 1.8",
]`,
"target_compatible_with": `select({ "target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [], "//conditions:default": [],

View File

@@ -158,6 +158,22 @@ java_plugin {
}) })
} }
func TestJavaLibraryJavaVersion(t *testing.T) {
runJavaLibraryTestCase(t, bp2buildTestCase{
blueprint: `java_library {
name: "java-lib-1",
srcs: ["a.java"],
java_version: "11",
}`,
expectedBazelTargets: []string{
makeBazelTarget("java_library", "java-lib-1", attrNameToString{
"srcs": `["a.java"]`,
"javacopts": `["-source 11 -target 11"]`,
}),
},
})
}
func TestJavaLibraryErrorproneJavacflagsEnabledManually(t *testing.T) { func TestJavaLibraryErrorproneJavacflagsEnabledManually(t *testing.T) {
runJavaLibraryTestCase(t, bp2buildTestCase{ runJavaLibraryTestCase(t, bp2buildTestCase{
blueprint: `java_library { blueprint: `java_library {

View File

@@ -43,6 +43,7 @@ java_library_host {
name: "java-lib-host-2", name: "java-lib-host-2",
srcs: ["c.java"], srcs: ["c.java"],
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
java_version: "9",
}`, }`,
expectedBazelTargets: []string{ expectedBazelTargets: []string{
makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{ makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{
@@ -54,7 +55,8 @@ java_library_host {
})`, })`,
}), }),
makeBazelTarget("java_library", "java-lib-host-2", attrNameToString{ makeBazelTarget("java_library", "java-lib-host-2", attrNameToString{
"srcs": `["c.java"]`, "javacopts": `["-source 1.9 -target 1.9"]`,
"srcs": `["c.java"]`,
"target_compatible_with": `select({ "target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [], "//conditions:default": [],

View File

@@ -39,6 +39,7 @@ func TestJavaPlugin(t *testing.T) {
libs: ["java-lib-1"], libs: ["java-lib-1"],
static_libs: ["java-lib-2"], static_libs: ["java-lib-2"],
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
java_version: "7",
} }
java_library { java_library {
@@ -66,6 +67,7 @@ java_library {
"a.java", "a.java",
"b.java", "b.java",
]`, ]`,
"javacopts": `["-source 1.7 -target 1.7"]`,
}), }),
}, },
}) })

View File

@@ -102,6 +102,7 @@ func TestJavaProtoDefault(t *testing.T) {
blueprint: `java_library_static { blueprint: `java_library_static {
name: "java-protos", name: "java-protos",
srcs: ["a.proto"], srcs: ["a.proto"],
java_version: "7",
} }
`, `,
expectedBazelTargets: []string{ expectedBazelTargets: []string{
@@ -115,7 +116,8 @@ func TestJavaProtoDefault(t *testing.T) {
"deps": `[":java-protos_proto"]`, "deps": `[":java-protos_proto"]`,
}), }),
makeBazelTarget("java_library", "java-protos", attrNameToString{ makeBazelTarget("java_library", "java-protos", attrNameToString{
"exports": `[":java-protos_java_proto_lite"]`, "exports": `[":java-protos_java_proto_lite"]`,
"javacopts": `["-source 1.7 -target 1.7"]`,
}), }),
}, },
}) })

View File

@@ -2089,6 +2089,11 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
if m.properties.Javacflags != nil { if m.properties.Javacflags != nil {
javacopts = append(javacopts, m.properties.Javacflags...) javacopts = append(javacopts, m.properties.Javacflags...)
} }
if m.properties.Java_version != nil {
javaVersion := normalizeJavaVersion(ctx, *m.properties.Java_version).String()
javacopts = append(javacopts, fmt.Sprintf("-source %s -target %s", javaVersion, javaVersion))
}
epEnabled := m.properties.Errorprone.Enabled epEnabled := m.properties.Errorprone.Enabled
//TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable //TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable
if Bool(epEnabled) { if Bool(epEnabled) {