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 | |
| 25 | func runJavaBinaryHostTestCase(t *testing.T, tc bp2buildTestCase) { |
| 26 | t.Helper() |
| 27 | (&tc).moduleTypeUnderTest = "java_binary_host" |
| 28 | (&tc).moduleTypeUnderTestFactory = java.BinaryHostFactory |
| 29 | runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { |
| 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) |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 32 | }, tc) |
| 33 | } |
| 34 | |
| 35 | var fs = map[string]string{ |
| 36 | "test.mf": "Main-Class: com.android.test.MainClass", |
| 37 | "other/Android.bp": `cc_library_host_shared { |
| 38 | name: "jni-lib-1", |
| 39 | stl: "none", |
| 40 | }`, |
| 41 | } |
| 42 | |
| 43 | func TestJavaBinaryHost(t *testing.T) { |
| 44 | runJavaBinaryHostTestCase(t, bp2buildTestCase{ |
Sam Delmerico | 4e27229 | 2022-01-06 20:03:51 +0000 | [diff] [blame] | 45 | description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 46 | filesystem: fs, |
| 47 | blueprint: `java_binary_host { |
| 48 | name: "java-binary-host-1", |
| 49 | srcs: ["a.java", "b.java"], |
| 50 | exclude_srcs: ["b.java"], |
| 51 | manifest: "test.mf", |
| 52 | jni_libs: ["jni-lib-1"], |
Sam Delmerico | 4e27229 | 2022-01-06 20:03:51 +0000 | [diff] [blame] | 53 | javacflags: ["-Xdoclint:all/protected"], |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 54 | bazel_module: { bp2build_available: true }, |
| 55 | }`, |
| 56 | expectedBazelTargets: []string{ |
| 57 | makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ |
| 58 | "srcs": `["a.java"]`, |
| 59 | "main_class": `"com.android.test.MainClass"`, |
| 60 | "deps": `["//other:jni-lib-1"]`, |
| 61 | "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`, |
Sam Delmerico | 4e27229 | 2022-01-06 20:03:51 +0000 | [diff] [blame] | 62 | "javacopts": `["-Xdoclint:all/protected"]`, |
Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 63 | "target_compatible_with": `select({ |
| 64 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 65 | "//conditions:default": [], |
| 66 | })`, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 67 | }), |
| 68 | }, |
| 69 | }) |
| 70 | } |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame^] | 71 | |
| 72 | func TestJavaBinaryHostRuntimeDeps(t *testing.T) { |
| 73 | runJavaBinaryHostTestCase(t, bp2buildTestCase{ |
| 74 | description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", |
| 75 | filesystem: fs, |
| 76 | blueprint: `java_binary_host { |
| 77 | name: "java-binary-host-1", |
| 78 | static_libs: ["java-dep-1"], |
| 79 | manifest: "test.mf", |
| 80 | bazel_module: { bp2build_available: true }, |
| 81 | } |
| 82 | |
| 83 | java_library { |
| 84 | name: "java-dep-1", |
| 85 | srcs: ["a.java"], |
| 86 | bazel_module: { bp2build_available: false }, |
| 87 | } |
| 88 | `, |
| 89 | expectedBazelTargets: []string{ |
| 90 | makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ |
| 91 | "main_class": `"com.android.test.MainClass"`, |
| 92 | "runtime_deps": `[":java-dep-1"]`, |
| 93 | "target_compatible_with": `select({ |
| 94 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 95 | "//conditions:default": [], |
| 96 | })`, |
| 97 | }), |
| 98 | }, |
| 99 | }) |
| 100 | } |