Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/cc" |
| 22 | "android/soong/java" |
| 23 | ) |
| 24 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 25 | func runJavaBinaryHostTestCase(t *testing.T, tc Bp2buildTestCase) { |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 26 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 27 | (&tc).ModuleTypeUnderTest = "java_binary_host" |
| 28 | (&tc).ModuleTypeUnderTestFactory = java.BinaryHostFactory |
| 29 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 30 | ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory) |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 31 | ctx.RegisterModuleType("java_library", java.LibraryFactory) |
Alix | b4e09a0 | 2022-09-27 15:36:01 +0000 | [diff] [blame] | 32 | ctx.RegisterModuleType("java_import_host", java.ImportFactory) |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 33 | }, tc) |
| 34 | } |
| 35 | |
Lukacs T. Berki | bc5f731 | 2022-10-31 09:01:34 +0000 | [diff] [blame^] | 36 | var testFs = map[string]string{ |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 37 | "test.mf": "Main-Class: com.android.test.MainClass", |
| 38 | "other/Android.bp": `cc_library_host_shared { |
| 39 | name: "jni-lib-1", |
| 40 | stl: "none", |
| 41 | }`, |
| 42 | } |
| 43 | |
| 44 | func TestJavaBinaryHost(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 45 | runJavaBinaryHostTestCase(t, Bp2buildTestCase{ |
| 46 | Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", |
Lukacs T. Berki | bc5f731 | 2022-10-31 09:01:34 +0000 | [diff] [blame^] | 47 | Filesystem: testFs, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 48 | Blueprint: `java_binary_host { |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 49 | name: "java-binary-host-1", |
| 50 | srcs: ["a.java", "b.java"], |
| 51 | exclude_srcs: ["b.java"], |
| 52 | manifest: "test.mf", |
| 53 | jni_libs: ["jni-lib-1"], |
Sam Delmerico | 4e27229 | 2022-01-06 20:03:51 +0000 | [diff] [blame] | 54 | javacflags: ["-Xdoclint:all/protected"], |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 55 | bazel_module: { bp2build_available: true }, |
Vinh Tran | 3ac6daf | 2022-04-22 19:09:58 -0400 | [diff] [blame] | 56 | java_version: "8", |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 57 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 58 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 59 | MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{ |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 60 | "srcs": `["a.java"]`, |
| 61 | "main_class": `"com.android.test.MainClass"`, |
| 62 | "deps": `["//other:jni-lib-1"]`, |
| 63 | "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`, |
Vinh Tran | 3ac6daf | 2022-04-22 19:09:58 -0400 | [diff] [blame] | 64 | "javacopts": `[ |
| 65 | "-Xdoclint:all/protected", |
| 66 | "-source 1.8 -target 1.8", |
| 67 | ]`, |
Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 68 | "target_compatible_with": `select({ |
| 69 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 70 | "//conditions:default": [], |
| 71 | })`, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 72 | }), |
| 73 | }, |
| 74 | }) |
| 75 | } |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 76 | |
| 77 | func TestJavaBinaryHostRuntimeDeps(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 78 | runJavaBinaryHostTestCase(t, Bp2buildTestCase{ |
| 79 | Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", |
Lukacs T. Berki | bc5f731 | 2022-10-31 09:01:34 +0000 | [diff] [blame^] | 80 | Filesystem: testFs, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 81 | Blueprint: `java_binary_host { |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 82 | name: "java-binary-host-1", |
| 83 | static_libs: ["java-dep-1"], |
| 84 | manifest: "test.mf", |
| 85 | bazel_module: { bp2build_available: true }, |
| 86 | } |
| 87 | |
| 88 | java_library { |
| 89 | name: "java-dep-1", |
| 90 | srcs: ["a.java"], |
| 91 | bazel_module: { bp2build_available: false }, |
| 92 | } |
| 93 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 94 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 95 | MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{ |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 96 | "main_class": `"com.android.test.MainClass"`, |
| 97 | "runtime_deps": `[":java-dep-1"]`, |
| 98 | "target_compatible_with": `select({ |
| 99 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 100 | "//conditions:default": [], |
| 101 | })`, |
| 102 | }), |
| 103 | }, |
| 104 | }) |
| 105 | } |
Alix | b4e09a0 | 2022-09-27 15:36:01 +0000 | [diff] [blame] | 106 | |
| 107 | func TestJavaBinaryHostLibs(t *testing.T) { |
| 108 | runJavaBinaryHostTestCase(t, Bp2buildTestCase{ |
| 109 | Description: "java_binary_host with srcs, libs.", |
Lukacs T. Berki | bc5f731 | 2022-10-31 09:01:34 +0000 | [diff] [blame^] | 110 | Filesystem: testFs, |
Alix | b4e09a0 | 2022-09-27 15:36:01 +0000 | [diff] [blame] | 111 | Blueprint: `java_binary_host { |
| 112 | name: "java-binary-host-libs", |
| 113 | libs: ["java-lib-dep-1"], |
| 114 | manifest: "test.mf", |
| 115 | srcs: ["a.java"], |
| 116 | } |
| 117 | |
| 118 | java_import_host{ |
| 119 | name: "java-lib-dep-1", |
| 120 | jars: ["foo.jar"], |
| 121 | bazel_module: { bp2build_available: false }, |
| 122 | } |
| 123 | `, |
| 124 | ExpectedBazelTargets: []string{ |
| 125 | MakeBazelTarget("java_binary", "java-binary-host-libs", AttrNameToString{ |
| 126 | "main_class": `"com.android.test.MainClass"`, |
| 127 | "srcs": `["a.java"]`, |
| 128 | "deps": `[":java-lib-dep-1-neverlink"]`, |
| 129 | "target_compatible_with": `select({ |
| 130 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 131 | "//conditions:default": [], |
| 132 | })`, |
| 133 | }), |
| 134 | }, |
| 135 | }) |
| 136 | } |