bp2build converts java_version property to javacopts attribute
This CL also converts `external/rappor` (which already set `java_version` to `1.7`) to be bazelable to testify the changes. Results from `b build //external/rappor && cat bazel-bin/external/rappor/librappor.jar-0.params`: https://paste.googleplex.com/5518725462622208. Test: go test ./bp2build/... Bug: 227618664 Change-Id: I8d370d4639f70fba51e6de6ceb7bcb5ace9ccd91
This commit is contained in:
parent
184a6b87e5
commit
3ac6daf47c
8 changed files with 40 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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"]`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
|
|
@ -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": [],
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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": [],
|
||||
|
|
|
@ -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"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
|
|
@ -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"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue