blob: c2a2182bd96c160d2f380dd9f5b70dd4db9523fd [file] [log] [blame]
Sam Delmericoc06ea032022-01-28 21:11:03 +00001// 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/java"
22)
23
24func runJavaPluginTestCase(t *testing.T, tc bp2buildTestCase) {
25 t.Helper()
26 (&tc).moduleTypeUnderTest = "java_plugin"
27 (&tc).moduleTypeUnderTestFactory = java.PluginFactory
28 runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
29 ctx.RegisterModuleType("java_library", java.LibraryFactory)
30 }, tc)
31}
32
33func TestJavaPlugin(t *testing.T) {
34 runJavaPluginTestCase(t, bp2buildTestCase{
35 description: "java_plugin with srcs, libs, static_libs",
36 blueprint: `java_plugin {
37 name: "java-plug-1",
38 srcs: ["a.java", "b.java"],
39 libs: ["java-lib-1"],
40 static_libs: ["java-lib-2"],
41 bazel_module: { bp2build_available: true },
42}
43
44java_library {
45 name: "java-lib-1",
46 srcs: ["b.java"],
47 bazel_module: { bp2build_available: false },
48}
49
50java_library {
51 name: "java-lib-2",
52 srcs: ["c.java"],
53 bazel_module: { bp2build_available: false },
54}`,
55 expectedBazelTargets: []string{
56 makeBazelTarget("java_plugin", "java-plug-1", attrNameToString{
57 "target_compatible_with": `select({
58 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
59 "//conditions:default": [],
60 })`,
61 "deps": `[
62 ":java-lib-1",
63 ":java-lib-2",
64 ]`,
65 "srcs": `[
66 "a.java",
67 "b.java",
68 ]`,
69 }),
70 },
71 })
72}
Sam Delmericoc0161432022-02-25 21:34:51 +000073
74func TestJavaPluginNoSrcs(t *testing.T) {
75 runJavaPluginTestCase(t, bp2buildTestCase{
76 description: "java_plugin without srcs converts (static) libs to deps",
77 blueprint: `java_plugin {
78 name: "java-plug-1",
79 libs: ["java-lib-1"],
80 static_libs: ["java-lib-2"],
81 bazel_module: { bp2build_available: true },
82}
83
84java_library {
85 name: "java-lib-1",
86 srcs: ["b.java"],
87 bazel_module: { bp2build_available: false },
88}
89
90java_library {
91 name: "java-lib-2",
92 srcs: ["c.java"],
93 bazel_module: { bp2build_available: false },
94}`,
95 expectedBazelTargets: []string{
96 makeBazelTarget("java_plugin", "java-plug-1", attrNameToString{
97 "target_compatible_with": `select({
98 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
99 "//conditions:default": [],
100 })`,
101 "deps": `[
102 ":java-lib-1",
103 ":java-lib-2",
104 ]`,
105 }),
106 },
107 })
108}