blob: a5c01cb4fc41694718a9b6912dee566bb0581a64 [file] [log] [blame]
Romain Jobredeaux428a3662022-01-28 11:12:52 -05001// Copyright 2022 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 "android/soong/android"
19 "android/soong/java"
20
21 "testing"
22)
23
Sam Delmerico3177a6e2022-06-21 19:28:33 +000024func runJavaImportTestCase(t *testing.T, tc Bp2buildTestCase) {
Romain Jobredeaux428a3662022-01-28 11:12:52 -050025 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000026 RunBp2BuildTestCase(t, registerJavaImportModuleTypes, tc)
Romain Jobredeaux428a3662022-01-28 11:12:52 -050027}
28
29func registerJavaImportModuleTypes(ctx android.RegistrationContext) {
30}
31
Sam Delmerico48983162022-02-22 21:41:33 +000032func TestJavaImportMinimal(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000033 runJavaImportTestCase(t, Bp2buildTestCase{
34 Description: "Java import - simple example",
35 ModuleTypeUnderTest: "java_import",
36 ModuleTypeUnderTestFactory: java.ImportFactory,
37 Filesystem: map[string]string{
Romain Jobredeaux428a3662022-01-28 11:12:52 -050038 "import.jar": "",
39 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000040 Blueprint: `
Romain Jobredeaux428a3662022-01-28 11:12:52 -050041java_import {
42 name: "example_import",
43 jars: ["import.jar"],
44 bazel_module: { bp2build_available: true },
45}
46`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000047 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +000048 MakeBazelTarget("java_import", "example_import", AttrNameToString{
Romain Jobredeaux428a3662022-01-28 11:12:52 -050049 "jars": `["import.jar"]`,
50 }),
Alixb4e09a02022-09-27 15:36:01 +000051 MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
52 "exports": `[":example_import"]`,
53 "neverlink": `True`,
54 }),
Romain Jobredeaux428a3662022-01-28 11:12:52 -050055 }})
56}
Sam Delmerico48983162022-02-22 21:41:33 +000057
58func TestJavaImportArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000059 runJavaImportTestCase(t, Bp2buildTestCase{
60 Description: "Java import - simple example",
61 ModuleTypeUnderTest: "java_import",
62 ModuleTypeUnderTestFactory: java.ImportFactory,
63 Filesystem: map[string]string{
Sam Delmerico48983162022-02-22 21:41:33 +000064 "import.jar": "",
65 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000066 Blueprint: `
Sam Delmerico48983162022-02-22 21:41:33 +000067java_import {
68 name: "example_import",
69 target: {
70 android: {
71 jars: ["android.jar"],
72 },
73 linux_glibc: {
74 jars: ["linux.jar"],
75 },
76 },
77 bazel_module: { bp2build_available: true },
78}
79`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000080 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +000081 MakeBazelTarget("java_import", "example_import", AttrNameToString{
Sam Delmerico48983162022-02-22 21:41:33 +000082 "jars": `select({
83 "//build/bazel/platforms/os:android": ["android.jar"],
Colin Cross133782e2022-12-20 15:29:31 -080084 "//build/bazel/platforms/os:linux_glibc": ["linux.jar"],
Sam Delmerico48983162022-02-22 21:41:33 +000085 "//conditions:default": [],
86 })`,
87 }),
Alixb4e09a02022-09-27 15:36:01 +000088 MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
89 "exports": `[":example_import"]`,
90 "neverlink": `True`,
91 }),
92 }})
93}
94
95func TestJavaImportHost(t *testing.T) {
96 runJavaImportTestCase(t, Bp2buildTestCase{
97 Description: "Java import host- simple example",
98 ModuleTypeUnderTest: "java_import_host",
99 ModuleTypeUnderTestFactory: java.ImportFactory,
100 Filesystem: map[string]string{
101 "import.jar": "",
102 },
103 Blueprint: `
104java_import_host {
105 name: "example_import",
106 jars: ["import.jar"],
107 bazel_module: { bp2build_available: true },
108}
109`,
110 ExpectedBazelTargets: []string{
111 MakeBazelTarget("java_import", "example_import", AttrNameToString{
112 "jars": `["import.jar"]`,
113 }),
114 MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
115 "exports": `[":example_import"]`,
116 "neverlink": `True`,
117 }),
Sam Delmerico48983162022-02-22 21:41:33 +0000118 }})
119}