blob: 14854c06a6c79780934740a5a5e4718a3b9c8b7f [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
Sam Delmerico3177a6e2022-06-21 19:28:33 +000024func runJavaLibraryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
Wei Libafb6d62021-12-10 03:14:59 -080025 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000026 (&tc).ModuleTypeUnderTest = "java_library_host"
27 (&tc).ModuleTypeUnderTestFactory = java.LibraryHostFactory
28 RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
Wei Libafb6d62021-12-10 03:14:59 -080029}
30
31func TestJavaLibraryHost(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000032 runJavaLibraryHostTestCase(t, Bp2buildTestCase{
33 Description: "java_library_host with srcs, exclude_srcs and libs",
34 Blueprint: `java_library_host {
Wei Libafb6d62021-12-10 03:14:59 -080035 name: "java-lib-host-1",
36 srcs: ["a.java", "b.java"],
37 exclude_srcs: ["b.java"],
38 libs: ["java-lib-host-2"],
39 bazel_module: { bp2build_available: true },
40}
41
42java_library_host {
43 name: "java-lib-host-2",
44 srcs: ["c.java"],
45 bazel_module: { bp2build_available: true },
Vinh Tran3ac6daf2022-04-22 19:09:58 -040046 java_version: "9",
Wei Libafb6d62021-12-10 03:14:59 -080047}`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000048 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +000049 MakeBazelTarget("java_library", "java-lib-host-1", AttrNameToString{
Wei Libafb6d62021-12-10 03:14:59 -080050 "srcs": `["a.java"]`,
Alix341484b2022-10-31 19:08:18 +000051 "deps": `[":java-lib-host-2-neverlink"]`,
52 "target_compatible_with": `select({
53 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
54 "//conditions:default": [],
55 })`,
56 }),
57 MakeBazelTarget("java_library", "java-lib-host-1-neverlink", AttrNameToString{
58 "exports": `[":java-lib-host-1"]`,
59 "neverlink": `True`,
Sam Delmerico75539d62022-01-31 14:37:29 +000060 "target_compatible_with": `select({
61 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
62 "//conditions:default": [],
63 })`,
Wei Libafb6d62021-12-10 03:14:59 -080064 }),
Alixe06d75b2022-08-31 18:28:19 +000065 MakeBazelTarget("java_library", "java-lib-host-2", AttrNameToString{
Vinh Tran3ac6daf2022-04-22 19:09:58 -040066 "javacopts": `["-source 1.9 -target 1.9"]`,
67 "srcs": `["c.java"]`,
Sam Delmerico75539d62022-01-31 14:37:29 +000068 "target_compatible_with": `select({
69 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
70 "//conditions:default": [],
71 })`,
Wei Libafb6d62021-12-10 03:14:59 -080072 }),
Alix341484b2022-10-31 19:08:18 +000073 MakeBazelTarget("java_library", "java-lib-host-2-neverlink", AttrNameToString{
74 "exports": `[":java-lib-host-2"]`,
75 "neverlink": `True`,
76 "target_compatible_with": `select({
77 "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
78 "//conditions:default": [],
79 })`,
80 }),
Wei Libafb6d62021-12-10 03:14:59 -080081 },
82 })
83}