blob: ff13bb054dd126f327ba216c3aa52cd07d7aee30 [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}