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/java" |
| 22 | ) |
| 23 | |
| 24 | func runJavaLibraryHostTestCase(t *testing.T, tc bp2buildTestCase) { |
| 25 | t.Helper() |
| 26 | (&tc).moduleTypeUnderTest = "java_library_host" |
| 27 | (&tc).moduleTypeUnderTestFactory = java.LibraryHostFactory |
| 28 | runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) |
| 29 | } |
| 30 | |
| 31 | func TestJavaLibraryHost(t *testing.T) { |
| 32 | runJavaLibraryHostTestCase(t, bp2buildTestCase{ |
| 33 | description: "java_library_host with srcs, exclude_srcs and libs", |
| 34 | blueprint: `java_library_host { |
| 35 | name: "java-lib-host-1", |
| 36 | srcs: ["a.java", "b.java"], |
| 37 | exclude_srcs: ["b.java"], |
| 38 | libs: ["java-lib-host-2"], |
| 39 | bazel_module: { bp2build_available: true }, |
| 40 | } |
| 41 | |
| 42 | java_library_host { |
| 43 | name: "java-lib-host-2", |
| 44 | srcs: ["c.java"], |
| 45 | bazel_module: { bp2build_available: true }, |
Vinh Tran | 3ac6daf | 2022-04-22 19:09:58 -0400 | [diff] [blame] | 46 | java_version: "9", |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 47 | }`, |
| 48 | expectedBazelTargets: []string{ |
| 49 | makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{ |
| 50 | "srcs": `["a.java"]`, |
| 51 | "deps": `[":java-lib-host-2"]`, |
Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 52 | "target_compatible_with": `select({ |
| 53 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 54 | "//conditions:default": [], |
| 55 | })`, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 56 | }), |
| 57 | makeBazelTarget("java_library", "java-lib-host-2", attrNameToString{ |
Vinh Tran | 3ac6daf | 2022-04-22 19:09:58 -0400 | [diff] [blame] | 58 | "javacopts": `["-source 1.9 -target 1.9"]`, |
| 59 | "srcs": `["c.java"]`, |
Sam Delmerico | 75539d6 | 2022-01-31 14:37:29 +0000 | [diff] [blame] | 60 | "target_compatible_with": `select({ |
| 61 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 62 | "//conditions:default": [], |
| 63 | })`, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 64 | }), |
| 65 | }, |
| 66 | }) |
| 67 | } |