blob: 05d7142400ba4ed3d717a65e5c7675bb4ff851c3 [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 }),
51 }})
52}
Sam Delmerico48983162022-02-22 21:41:33 +000053
54func TestJavaImportArchVariant(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000055 runJavaImportTestCase(t, Bp2buildTestCase{
56 Description: "Java import - simple example",
57 ModuleTypeUnderTest: "java_import",
58 ModuleTypeUnderTestFactory: java.ImportFactory,
59 Filesystem: map[string]string{
Sam Delmerico48983162022-02-22 21:41:33 +000060 "import.jar": "",
61 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +000062 Blueprint: `
Sam Delmerico48983162022-02-22 21:41:33 +000063java_import {
64 name: "example_import",
65 target: {
66 android: {
67 jars: ["android.jar"],
68 },
69 linux_glibc: {
70 jars: ["linux.jar"],
71 },
72 },
73 bazel_module: { bp2build_available: true },
74}
75`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000076 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +000077 MakeBazelTarget("java_import", "example_import", AttrNameToString{
Sam Delmerico48983162022-02-22 21:41:33 +000078 "jars": `select({
79 "//build/bazel/platforms/os:android": ["android.jar"],
80 "//build/bazel/platforms/os:linux": ["linux.jar"],
81 "//conditions:default": [],
82 })`,
83 }),
84 }})
85}