blob: 86f3d423bac45fa93a9fb2a1a8ec9c072d62b4ec [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
Sam Delmerico3177a6e2022-06-21 19:28:33 +000025func runJavaBinaryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
Wei Libafb6d62021-12-10 03:14:59 -080026 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000027 (&tc).ModuleTypeUnderTest = "java_binary_host"
28 (&tc).ModuleTypeUnderTestFactory = java.BinaryHostFactory
29 RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
Wei Libafb6d62021-12-10 03:14:59 -080030 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) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000044 runJavaBinaryHostTestCase(t, Bp2buildTestCase{
45 Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
46 Filesystem: fs,
47 Blueprint: `java_binary_host {
Wei Libafb6d62021-12-10 03:14:59 -080048 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 },
Vinh Tran3ac6daf2022-04-22 19:09:58 -040055 java_version: "8",
Wei Libafb6d62021-12-10 03:14:59 -080056}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000057 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +000058 MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
Wei Libafb6d62021-12-10 03:14:59 -080059 "srcs": `["a.java"]`,
60 "main_class": `"com.android.test.MainClass"`,
61 "deps": `["//other:jni-lib-1"]`,
62 "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`,
Vinh Tran3ac6daf2022-04-22 19:09:58 -040063 "javacopts": `[
64 "-Xdoclint:all/protected",
65 "-source 1.8 -target 1.8",
66 ]`,
Sam Delmerico75539d62022-01-31 14:37:29 +000067 "target_compatible_with": `select({
68 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
69 "//conditions:default": [],
70 })`,
Wei Libafb6d62021-12-10 03:14:59 -080071 }),
72 },
73 })
74}
Sam Delmericoc0161432022-02-25 21:34:51 +000075
76func TestJavaBinaryHostRuntimeDeps(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000077 runJavaBinaryHostTestCase(t, Bp2buildTestCase{
78 Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
79 Filesystem: fs,
80 Blueprint: `java_binary_host {
Sam Delmericoc0161432022-02-25 21:34:51 +000081 name: "java-binary-host-1",
82 static_libs: ["java-dep-1"],
83 manifest: "test.mf",
84 bazel_module: { bp2build_available: true },
85}
86
87java_library {
88 name: "java-dep-1",
89 srcs: ["a.java"],
90 bazel_module: { bp2build_available: false },
91}
92`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000093 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +000094 MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
Sam Delmericoc0161432022-02-25 21:34:51 +000095 "main_class": `"com.android.test.MainClass"`,
96 "runtime_deps": `[":java-dep-1"]`,
97 "target_compatible_with": `select({
98 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
99 "//conditions:default": [],
100 })`,
101 }),
102 },
103 })
104}