Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 1 | // 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 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/java" |
| 20 | |
| 21 | "testing" |
| 22 | ) |
| 23 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 24 | func runJavaImportTestCase(t *testing.T, tc Bp2buildTestCase) { |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 25 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 26 | RunBp2BuildTestCase(t, registerJavaImportModuleTypes, tc) |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | func registerJavaImportModuleTypes(ctx android.RegistrationContext) { |
| 30 | } |
| 31 | |
Sam Delmerico | 4898316 | 2022-02-22 21:41:33 +0000 | [diff] [blame] | 32 | func TestJavaImportMinimal(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 33 | runJavaImportTestCase(t, Bp2buildTestCase{ |
| 34 | Description: "Java import - simple example", |
| 35 | ModuleTypeUnderTest: "java_import", |
| 36 | ModuleTypeUnderTestFactory: java.ImportFactory, |
| 37 | Filesystem: map[string]string{ |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 38 | "import.jar": "", |
| 39 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 40 | Blueprint: ` |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 41 | java_import { |
| 42 | name: "example_import", |
| 43 | jars: ["import.jar"], |
| 44 | bazel_module: { bp2build_available: true }, |
| 45 | } |
| 46 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 47 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 48 | MakeBazelTarget("java_import", "example_import", AttrNameToString{ |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 49 | "jars": `["import.jar"]`, |
| 50 | }), |
Alix | b4e09a0 | 2022-09-27 15:36:01 +0000 | [diff] [blame] | 51 | MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{ |
Romain Jobredeaux | 2eef2e1 | 2023-02-24 12:07:08 -0500 | [diff] [blame^] | 52 | "exports": `[":example_import"]`, |
| 53 | "neverlink": `True`, |
| 54 | "sdk_version": `"none"`, |
Alix | b4e09a0 | 2022-09-27 15:36:01 +0000 | [diff] [blame] | 55 | }), |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 56 | }}) |
| 57 | } |
Sam Delmerico | 4898316 | 2022-02-22 21:41:33 +0000 | [diff] [blame] | 58 | |
| 59 | func TestJavaImportArchVariant(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 60 | runJavaImportTestCase(t, Bp2buildTestCase{ |
| 61 | Description: "Java import - simple example", |
| 62 | ModuleTypeUnderTest: "java_import", |
| 63 | ModuleTypeUnderTestFactory: java.ImportFactory, |
| 64 | Filesystem: map[string]string{ |
Sam Delmerico | 4898316 | 2022-02-22 21:41:33 +0000 | [diff] [blame] | 65 | "import.jar": "", |
| 66 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 67 | Blueprint: ` |
Sam Delmerico | 4898316 | 2022-02-22 21:41:33 +0000 | [diff] [blame] | 68 | java_import { |
| 69 | name: "example_import", |
| 70 | target: { |
| 71 | android: { |
| 72 | jars: ["android.jar"], |
| 73 | }, |
| 74 | linux_glibc: { |
| 75 | jars: ["linux.jar"], |
| 76 | }, |
| 77 | }, |
| 78 | bazel_module: { bp2build_available: true }, |
| 79 | } |
| 80 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 81 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 82 | MakeBazelTarget("java_import", "example_import", AttrNameToString{ |
Sam Delmerico | 4898316 | 2022-02-22 21:41:33 +0000 | [diff] [blame] | 83 | "jars": `select({ |
| 84 | "//build/bazel/platforms/os:android": ["android.jar"], |
Colin Cross | 133782e | 2022-12-20 15:29:31 -0800 | [diff] [blame] | 85 | "//build/bazel/platforms/os:linux_glibc": ["linux.jar"], |
Sam Delmerico | 4898316 | 2022-02-22 21:41:33 +0000 | [diff] [blame] | 86 | "//conditions:default": [], |
| 87 | })`, |
| 88 | }), |
Alix | b4e09a0 | 2022-09-27 15:36:01 +0000 | [diff] [blame] | 89 | MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{ |
Romain Jobredeaux | 2eef2e1 | 2023-02-24 12:07:08 -0500 | [diff] [blame^] | 90 | "exports": `[":example_import"]`, |
| 91 | "neverlink": `True`, |
| 92 | "sdk_version": `"none"`, |
Alix | b4e09a0 | 2022-09-27 15:36:01 +0000 | [diff] [blame] | 93 | }), |
| 94 | }}) |
| 95 | } |
| 96 | |
| 97 | func TestJavaImportHost(t *testing.T) { |
| 98 | runJavaImportTestCase(t, Bp2buildTestCase{ |
| 99 | Description: "Java import host- simple example", |
| 100 | ModuleTypeUnderTest: "java_import_host", |
| 101 | ModuleTypeUnderTestFactory: java.ImportFactory, |
| 102 | Filesystem: map[string]string{ |
| 103 | "import.jar": "", |
| 104 | }, |
| 105 | Blueprint: ` |
| 106 | java_import_host { |
| 107 | name: "example_import", |
| 108 | jars: ["import.jar"], |
| 109 | bazel_module: { bp2build_available: true }, |
| 110 | } |
| 111 | `, |
| 112 | ExpectedBazelTargets: []string{ |
| 113 | MakeBazelTarget("java_import", "example_import", AttrNameToString{ |
| 114 | "jars": `["import.jar"]`, |
| 115 | }), |
| 116 | MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{ |
Romain Jobredeaux | 2eef2e1 | 2023-02-24 12:07:08 -0500 | [diff] [blame^] | 117 | "exports": `[":example_import"]`, |
| 118 | "neverlink": `True`, |
| 119 | "sdk_version": `"none"`, |
Alix | b4e09a0 | 2022-09-27 15:36:01 +0000 | [diff] [blame] | 120 | }), |
Sam Delmerico | 4898316 | 2022-02-22 21:41:33 +0000 | [diff] [blame] | 121 | }}) |
| 122 | } |