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{ |
| 44 | description: "java_binary_host with srcs, exclude_srcs, jni_libs and manifest.", |
| 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"], |
| 52 | bazel_module: { bp2build_available: true }, |
| 53 | }`, |
| 54 | expectedBazelTargets: []string{ |
| 55 | makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ |
| 56 | "srcs": `["a.java"]`, |
| 57 | "main_class": `"com.android.test.MainClass"`, |
| 58 | "deps": `["//other:jni-lib-1"]`, |
| 59 | "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`, |
| 60 | }), |
| 61 | }, |
| 62 | }) |
| 63 | } |