Merge "bp2build converts java_version property to javacopts attribute" am: 775b44fa50

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2072296

Change-Id: Ic0c085dfe91fb27fd33eeda4277a01c69723f06b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Vinh Tran
2022-04-29 18:03:28 +00:00
committed by Automerger Merge Worker
8 changed files with 40 additions and 4 deletions

View File

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

View File

@@ -74,7 +74,8 @@ android_app {
package_name: "com.google",
resource_dirs: ["resa", "resb"],
manifest: "manifest/AndroidManifest.xml",
static_libs: ["static_lib_dep"]
static_libs: ["static_lib_dep"],
java_version: "7",
}
`,
expectedBazelTargets: []string{
@@ -87,6 +88,7 @@ android_app {
]`,
"custom_package": `"com.google"`,
"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"],
javacflags: ["-Xdoclint:all/protected"],
bazel_module: { bp2build_available: true },
java_version: "8",
}`,
expectedBazelTargets: []string{
makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{
@@ -59,7 +60,10 @@ func TestJavaBinaryHost(t *testing.T) {
"main_class": `"com.android.test.MainClass"`,
"deps": `["//other:jni-lib-1"]`,
"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({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//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) {
runJavaLibraryTestCase(t, bp2buildTestCase{
blueprint: `java_library {

View File

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

View File

@@ -39,6 +39,7 @@ func TestJavaPlugin(t *testing.T) {
libs: ["java-lib-1"],
static_libs: ["java-lib-2"],
bazel_module: { bp2build_available: true },
java_version: "7",
}
java_library {
@@ -66,6 +67,7 @@ java_library {
"a.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 {
name: "java-protos",
srcs: ["a.proto"],
java_version: "7",
}
`,
expectedBazelTargets: []string{
@@ -115,7 +116,8 @@ func TestJavaProtoDefault(t *testing.T) {
"deps": `[":java-protos_proto"]`,
}),
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 {
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
//TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable
if Bool(epEnabled) {