diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 26cfd5725..28dc8b452 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -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, diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go index 3824586c6..a216c9d11 100644 --- a/bp2build/android_app_conversion_test.go +++ b/bp2build/android_app_conversion_test.go @@ -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"]`, }), }}) } diff --git a/bp2build/java_binary_host_conversion_test.go b/bp2build/java_binary_host_conversion_test.go index 4fc07e014..d7a76a89f 100644 --- a/bp2build/java_binary_host_conversion_test.go +++ b/bp2build/java_binary_host_conversion_test.go @@ -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": [], diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go index ccc52ef12..3b6636975 100644 --- a/bp2build/java_library_conversion_test.go +++ b/bp2build/java_library_conversion_test.go @@ -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 { diff --git a/bp2build/java_library_host_conversion_test.go b/bp2build/java_library_host_conversion_test.go index 73abdd2ea..83cc5519a 100644 --- a/bp2build/java_library_host_conversion_test.go +++ b/bp2build/java_library_host_conversion_test.go @@ -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": [], diff --git a/bp2build/java_plugin_conversion_test.go b/bp2build/java_plugin_conversion_test.go index c2a2182bd..dc763e763 100644 --- a/bp2build/java_plugin_conversion_test.go +++ b/bp2build/java_plugin_conversion_test.go @@ -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"]`, }), }, }) diff --git a/bp2build/java_proto_conversion_test.go b/bp2build/java_proto_conversion_test.go index 67f80446e..c6feeb8dc 100644 --- a/bp2build/java_proto_conversion_test.go +++ b/bp2build/java_proto_conversion_test.go @@ -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"]`, }), }, }) diff --git a/java/java.go b/java/java.go index b34d6de8a..4e7e14c07 100644 --- a/java/java.go +++ b/java/java.go @@ -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) {