2021-12-10 12:14:59 +01:00
|
|
|
// Copyright 2021 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package bp2build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
"android/soong/java"
|
|
|
|
)
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runJavaBinaryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2021-12-10 12:14:59 +01:00
|
|
|
t.Helper()
|
2022-06-21 21:28:33 +02:00
|
|
|
(&tc).ModuleTypeUnderTest = "java_binary_host"
|
|
|
|
(&tc).ModuleTypeUnderTestFactory = java.BinaryHostFactory
|
2023-09-19 03:12:48 +02:00
|
|
|
tc.StubbedBuildDefinitions = append(tc.StubbedBuildDefinitions, "//other:jni-lib-1")
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
2021-12-10 12:14:59 +01:00
|
|
|
ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory)
|
2022-02-25 22:34:51 +01:00
|
|
|
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
2022-09-27 17:36:01 +02:00
|
|
|
ctx.RegisterModuleType("java_import_host", java.ImportFactory)
|
2021-12-10 12:14:59 +01:00
|
|
|
}, tc)
|
|
|
|
}
|
|
|
|
|
2022-10-31 10:01:34 +01:00
|
|
|
var testFs = map[string]string{
|
2021-12-10 12:14:59 +01:00
|
|
|
"test.mf": "Main-Class: com.android.test.MainClass",
|
|
|
|
"other/Android.bp": `cc_library_host_shared {
|
|
|
|
name: "jni-lib-1",
|
|
|
|
stl: "none",
|
|
|
|
}`,
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaBinaryHost(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
|
2022-10-31 10:01:34 +01:00
|
|
|
Filesystem: testFs,
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_binary_host {
|
2021-12-10 12:14:59 +01:00
|
|
|
name: "java-binary-host-1",
|
|
|
|
srcs: ["a.java", "b.java"],
|
|
|
|
exclude_srcs: ["b.java"],
|
|
|
|
manifest: "test.mf",
|
|
|
|
jni_libs: ["jni-lib-1"],
|
2022-01-06 21:03:51 +01:00
|
|
|
javacflags: ["-Xdoclint:all/protected"],
|
2021-12-10 12:14:59 +01:00
|
|
|
bazel_module: { bp2build_available: true },
|
2022-04-23 01:09:58 +02:00
|
|
|
java_version: "8",
|
2021-12-10 12:14:59 +01:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2023-03-16 16:00:36 +01:00
|
|
|
MakeBazelTarget("java_library", "java-binary-host-1_lib", AttrNameToString{
|
2023-02-24 18:07:08 +01:00
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"deps": `["//other:jni-lib-1"]`,
|
|
|
|
"java_version": `"8"`,
|
|
|
|
"javacopts": `["-Xdoclint:all/protected"]`,
|
2022-01-31 15:37:29 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-01-31 15:37:29 +01:00
|
|
|
"//conditions:default": [],
|
2023-02-24 18:07:08 +01:00
|
|
|
})`,
|
|
|
|
}),
|
2023-03-16 16:00:36 +01:00
|
|
|
MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
|
2023-02-24 18:07:08 +01:00
|
|
|
"main_class": `"com.android.test.MainClass"`,
|
2023-06-01 04:48:09 +02:00
|
|
|
"jvm_flags": `["-Djava.library.path=$${RUNPATH}other/jni-lib-1"]`,
|
2023-03-16 16:00:36 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2023-03-16 16:00:36 +01:00
|
|
|
"//conditions:default": [],
|
2023-02-24 18:07:08 +01:00
|
|
|
})`,
|
|
|
|
"runtime_deps": `[":java-binary-host-1_lib"]`,
|
|
|
|
}),
|
2021-12-10 12:14:59 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-02-25 22:34:51 +01:00
|
|
|
|
|
|
|
func TestJavaBinaryHostRuntimeDeps(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
|
|
|
|
Filesystem: testFs,
|
|
|
|
StubbedBuildDefinitions: []string{"java-dep-1"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `java_binary_host {
|
2022-02-25 22:34:51 +01:00
|
|
|
name: "java-binary-host-1",
|
|
|
|
static_libs: ["java-dep-1"],
|
|
|
|
manifest: "test.mf",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "java-dep-1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
|
2022-02-25 22:34:51 +01:00
|
|
|
"main_class": `"com.android.test.MainClass"`,
|
|
|
|
"runtime_deps": `[":java-dep-1"]`,
|
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-02-25 22:34:51 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-09-27 17:36:01 +02:00
|
|
|
|
|
|
|
func TestJavaBinaryHostLibs(t *testing.T) {
|
|
|
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "java_binary_host with srcs, libs.",
|
|
|
|
Filesystem: testFs,
|
2023-09-21 22:36:35 +02:00
|
|
|
StubbedBuildDefinitions: []string{"java-lib-dep-1", "java-lib-dep-1-neverlink"},
|
2022-09-27 17:36:01 +02:00
|
|
|
Blueprint: `java_binary_host {
|
|
|
|
name: "java-binary-host-libs",
|
|
|
|
libs: ["java-lib-dep-1"],
|
|
|
|
manifest: "test.mf",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import_host{
|
|
|
|
name: "java-lib-dep-1",
|
|
|
|
jars: ["foo.jar"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2023-03-16 16:00:36 +01:00
|
|
|
MakeBazelTarget("java_library", "java-binary-host-libs_lib", AttrNameToString{
|
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"deps": `[":java-lib-dep-1-neverlink"]`,
|
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2023-03-16 16:00:36 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
2022-09-27 17:36:01 +02:00
|
|
|
MakeBazelTarget("java_binary", "java-binary-host-libs", AttrNameToString{
|
|
|
|
"main_class": `"com.android.test.MainClass"`,
|
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-09-27 17:36:01 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
2023-03-16 16:00:36 +01:00
|
|
|
"runtime_deps": `[":java-binary-host-libs_lib"]`,
|
2022-09-27 17:36:01 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-11-16 16:44:55 +01:00
|
|
|
|
|
|
|
func TestJavaBinaryHostKotlinSrcs(t *testing.T) {
|
|
|
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_binary_host with srcs, libs.",
|
|
|
|
Filesystem: testFs,
|
|
|
|
Blueprint: `java_binary_host {
|
|
|
|
name: "java-binary-host",
|
|
|
|
manifest: "test.mf",
|
|
|
|
srcs: ["a.java", "b.kt"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2023-03-16 16:00:36 +01:00
|
|
|
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
2022-11-16 16:44:55 +01:00
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.kt",
|
|
|
|
]`,
|
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-11-16 16:44:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
|
|
|
"main_class": `"com.android.test.MainClass"`,
|
2023-03-16 16:00:36 +01:00
|
|
|
"runtime_deps": `[":java-binary-host_lib"]`,
|
2022-11-16 16:44:55 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-11-16 16:44:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaBinaryHostKotlinCommonSrcs(t *testing.T) {
|
|
|
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_binary_host with common_srcs",
|
|
|
|
Filesystem: testFs,
|
|
|
|
Blueprint: `java_binary_host {
|
|
|
|
name: "java-binary-host",
|
|
|
|
manifest: "test.mf",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
common_srcs: ["b.kt"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2023-03-16 16:00:36 +01:00
|
|
|
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
2022-11-16 16:44:55 +01:00
|
|
|
"srcs": `["a.java"]`,
|
|
|
|
"common_srcs": `["b.kt"]`,
|
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-11-16 16:44:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
|
|
|
"main_class": `"com.android.test.MainClass"`,
|
2023-03-16 16:00:36 +01:00
|
|
|
"runtime_deps": `[":java-binary-host_lib"]`,
|
2022-11-16 16:44:55 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-11-16 16:44:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaBinaryHostKotlinWithResourceDir(t *testing.T) {
|
|
|
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_binary_host with srcs, libs, resource dir .",
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"test.mf": "Main-Class: com.android.test.MainClass",
|
|
|
|
"res/a.res": "",
|
|
|
|
"res/dir1/b.res": "",
|
|
|
|
},
|
|
|
|
Blueprint: `java_binary_host {
|
|
|
|
name: "java-binary-host",
|
|
|
|
manifest: "test.mf",
|
|
|
|
srcs: ["a.java", "b.kt"],
|
|
|
|
java_resource_dirs: ["res"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2023-03-16 16:00:36 +01:00
|
|
|
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
2022-11-16 16:44:55 +01:00
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.kt",
|
|
|
|
]`,
|
2023-03-03 20:22:15 +01:00
|
|
|
"resources": `[
|
|
|
|
"res/a.res",
|
|
|
|
"res/dir1/b.res",
|
|
|
|
]`,
|
|
|
|
"resource_strip_prefix": `"res"`,
|
2022-11-16 16:44:55 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-11-16 16:44:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
|
|
|
"main_class": `"com.android.test.MainClass"`,
|
2023-03-16 16:00:36 +01:00
|
|
|
"runtime_deps": `[":java-binary-host_lib"]`,
|
2022-11-16 16:44:55 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-11-16 16:44:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaBinaryHostKotlinWithResources(t *testing.T) {
|
|
|
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_binary_host with srcs, libs, resources.",
|
|
|
|
Filesystem: map[string]string{
|
2023-05-04 20:54:45 +02:00
|
|
|
"adir/test.mf": "Main-Class: com.android.test.MainClass",
|
|
|
|
"adir/res/a.res": "",
|
|
|
|
"adir/res/b.res": "",
|
|
|
|
"adir/Android.bp": `java_binary_host {
|
2022-11-16 16:44:55 +01:00
|
|
|
name: "java-binary-host",
|
|
|
|
manifest: "test.mf",
|
|
|
|
srcs: ["a.java", "b.kt"],
|
|
|
|
java_resources: ["res/a.res", "res/b.res"],
|
2023-05-04 20:54:45 +02:00
|
|
|
bazel_module: { bp2build_available: true },
|
2022-11-16 16:44:55 +01:00
|
|
|
}
|
|
|
|
`,
|
2023-05-04 20:54:45 +02:00
|
|
|
},
|
|
|
|
Dir: "adir",
|
|
|
|
Blueprint: "",
|
2022-11-16 16:44:55 +01:00
|
|
|
ExpectedBazelTargets: []string{
|
2023-03-16 16:00:36 +01:00
|
|
|
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
2022-11-16 16:44:55 +01:00
|
|
|
"srcs": `[
|
|
|
|
"a.java",
|
|
|
|
"b.kt",
|
|
|
|
]`,
|
|
|
|
"resources": `[
|
|
|
|
"res/a.res",
|
|
|
|
"res/b.res",
|
|
|
|
]`,
|
2023-05-04 20:54:45 +02:00
|
|
|
"resource_strip_prefix": `"adir"`,
|
2022-11-16 16:44:55 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-11-16 16:44:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
|
|
|
"main_class": `"com.android.test.MainClass"`,
|
2023-03-16 16:00:36 +01:00
|
|
|
"runtime_deps": `[":java-binary-host_lib"]`,
|
2022-11-16 16:44:55 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2022-11-16 16:44:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-03-06 20:43:55 +01:00
|
|
|
|
|
|
|
func TestJavaBinaryHostKotlinCflags(t *testing.T) {
|
|
|
|
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "java_binary_host with kotlincflags",
|
|
|
|
Filesystem: testFs,
|
|
|
|
Blueprint: `java_binary_host {
|
|
|
|
name: "java-binary-host",
|
|
|
|
manifest: "test.mf",
|
|
|
|
srcs: ["a.kt"],
|
|
|
|
kotlincflags: ["-flag1", "-flag2"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2023-03-16 16:00:36 +01:00
|
|
|
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
2023-03-06 20:43:55 +01:00
|
|
|
"srcs": `["a.kt"]`,
|
|
|
|
"kotlincflags": `[
|
|
|
|
"-flag1",
|
|
|
|
"-flag2",
|
|
|
|
]`,
|
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2023-03-06 20:43:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
|
|
|
"main_class": `"com.android.test.MainClass"`,
|
2023-03-16 16:00:36 +01:00
|
|
|
"runtime_deps": `[":java-binary-host_lib"]`,
|
2023-03-06 20:43:55 +01:00
|
|
|
"target_compatible_with": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
2023-03-06 20:43:55 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|