blob: 5c65ec2306d39689d67497b00e126d6b79de97ca [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/java"
22)
23
24func runJavaLibraryTestCase(t *testing.T, tc bp2buildTestCase) {
25 t.Helper()
26 (&tc).moduleTypeUnderTest = "java_library"
27 (&tc).moduleTypeUnderTestFactory = java.LibraryFactory
28 runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
29}
30
31func TestJavaLibrary(t *testing.T) {
32 runJavaLibraryTestCase(t, bp2buildTestCase{
33 description: "java_library with srcs, exclude_srcs and libs",
34 blueprint: `java_library {
35 name: "java-lib-1",
36 srcs: ["a.java", "b.java"],
37 exclude_srcs: ["b.java"],
38 libs: ["java-lib-2"],
39 bazel_module: { bp2build_available: true },
40}
41
42java_library {
43 name: "java-lib-2",
44 srcs: ["b.java"],
45 bazel_module: { bp2build_available: true },
46}`,
47 expectedBazelTargets: []string{
48 makeBazelTarget("java_library", "java-lib-1", attrNameToString{
49 "srcs": `["a.java"]`,
50 "deps": `[":java-lib-2"]`,
51 }),
52 makeBazelTarget("java_library", "java-lib-2", attrNameToString{
53 "srcs": `["b.java"]`,
54 }),
55 },
56 })
57}