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) |
| 31 | }, tc) |
| 32 | } |
| 33 | |
| 34 | var fs = map[string]string{ |
| 35 | "test.mf": "Main-Class: com.android.test.MainClass", |
| 36 | "other/Android.bp": `cc_library_host_shared { |
| 37 | name: "jni-lib-1", |
| 38 | stl: "none", |
| 39 | }`, |
| 40 | } |
| 41 | |
| 42 | func TestJavaBinaryHost(t *testing.T) { |
| 43 | runJavaBinaryHostTestCase(t, bp2buildTestCase{ |
Sam Delmerico | 4e27229 | 2022-01-06 20:03:51 +0000 | [diff] [blame] | 44 | 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] | 45 | filesystem: fs, |
| 46 | blueprint: `java_binary_host { |
| 47 | name: "java-binary-host-1", |
| 48 | srcs: ["a.java", "b.java"], |
| 49 | exclude_srcs: ["b.java"], |
| 50 | manifest: "test.mf", |
| 51 | jni_libs: ["jni-lib-1"], |
Sam Delmerico | 4e27229 | 2022-01-06 20:03:51 +0000 | [diff] [blame] | 52 | javacflags: ["-Xdoclint:all/protected"], |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 53 | bazel_module: { bp2build_available: true }, |
| 54 | }`, |
| 55 | expectedBazelTargets: []string{ |
| 56 | makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ |
| 57 | "srcs": `["a.java"]`, |
| 58 | "main_class": `"com.android.test.MainClass"`, |
| 59 | "deps": `["//other:jni-lib-1"]`, |
| 60 | "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`, |
Sam Delmerico | 4e27229 | 2022-01-06 20:03:51 +0000 | [diff] [blame] | 61 | "javacopts": `["-Xdoclint:all/protected"]`, |
Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 62 | "target_compatible_with": `select({ |
| 63 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 64 | "//conditions:default": [], |
| 65 | })`, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 66 | }), |
| 67 | }, |
| 68 | }) |
| 69 | } |