blob: 4fc07e0147c99653e21cbbfccbbff881626cc814 [file] [log] [blame]
Wei Libafb6d62021-12-10 03:14:59 -08001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package bp2build
16
17import (
18 "testing"
19
20 "android/soong/android"
21 "android/soong/cc"
22 "android/soong/java"
23)
24
25func runJavaBinaryHostTestCase(t *testing.T, tc bp2buildTestCase) {
26 t.Helper()
27 (&tc).moduleTypeUnderTest = "java_binary_host"
28 (&tc).moduleTypeUnderTestFactory = java.BinaryHostFactory
29 runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
30 ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory)
Sam Delmericoc0161432022-02-25 21:34:51 +000031 ctx.RegisterModuleType("java_library", java.LibraryFactory)
Wei Libafb6d62021-12-10 03:14:59 -080032 }, tc)
33}
34
35var fs = map[string]string{
36 "test.mf": "Main-Class: com.android.test.MainClass",
37 "other/Android.bp": `cc_library_host_shared {
38 name: "jni-lib-1",
39 stl: "none",
40}`,
41}
42
43func TestJavaBinaryHost(t *testing.T) {
44 runJavaBinaryHostTestCase(t, bp2buildTestCase{
Sam Delmerico4e272292022-01-06 20:03:51 +000045 description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
Wei Libafb6d62021-12-10 03:14:59 -080046 filesystem: fs,
47 blueprint: `java_binary_host {
48 name: "java-binary-host-1",
49 srcs: ["a.java", "b.java"],
50 exclude_srcs: ["b.java"],
51 manifest: "test.mf",
52 jni_libs: ["jni-lib-1"],
Sam Delmerico4e272292022-01-06 20:03:51 +000053 javacflags: ["-Xdoclint:all/protected"],
Wei Libafb6d62021-12-10 03:14:59 -080054 bazel_module: { bp2build_available: true },
55}`,
56 expectedBazelTargets: []string{
57 makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{
58 "srcs": `["a.java"]`,
59 "main_class": `"com.android.test.MainClass"`,
60 "deps": `["//other:jni-lib-1"]`,
61 "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`,
Sam Delmerico4e272292022-01-06 20:03:51 +000062 "javacopts": `["-Xdoclint:all/protected"]`,
Sam Delmerico75539d62022-01-31 14:37:29 +000063 "target_compatible_with": `select({
64 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
65 "//conditions:default": [],
66 })`,
Wei Libafb6d62021-12-10 03:14:59 -080067 }),
68 },
69 })
70}
Sam Delmericoc0161432022-02-25 21:34:51 +000071
72func TestJavaBinaryHostRuntimeDeps(t *testing.T) {
73 runJavaBinaryHostTestCase(t, bp2buildTestCase{
74 description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
75 filesystem: fs,
76 blueprint: `java_binary_host {
77 name: "java-binary-host-1",
78 static_libs: ["java-dep-1"],
79 manifest: "test.mf",
80 bazel_module: { bp2build_available: true },
81}
82
83java_library {
84 name: "java-dep-1",
85 srcs: ["a.java"],
86 bazel_module: { bp2build_available: false },
87}
88`,
89 expectedBazelTargets: []string{
90 makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{
91 "main_class": `"com.android.test.MainClass"`,
92 "runtime_deps": `[":java-dep-1"]`,
93 "target_compatible_with": `select({
94 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
95 "//conditions:default": [],
96 })`,
97 }),
98 },
99 })
100}