Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [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 runJavaPluginTestCase(t *testing.T, tc bp2buildTestCase) { |
| 25 | t.Helper() |
| 26 | (&tc).moduleTypeUnderTest = "java_plugin" |
| 27 | (&tc).moduleTypeUnderTestFactory = java.PluginFactory |
| 28 | runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { |
| 29 | ctx.RegisterModuleType("java_library", java.LibraryFactory) |
| 30 | }, tc) |
| 31 | } |
| 32 | |
| 33 | func TestJavaPlugin(t *testing.T) { |
| 34 | runJavaPluginTestCase(t, bp2buildTestCase{ |
| 35 | description: "java_plugin with srcs, libs, static_libs", |
| 36 | blueprint: `java_plugin { |
| 37 | name: "java-plug-1", |
| 38 | srcs: ["a.java", "b.java"], |
| 39 | libs: ["java-lib-1"], |
| 40 | static_libs: ["java-lib-2"], |
| 41 | bazel_module: { bp2build_available: true }, |
| 42 | } |
| 43 | |
| 44 | java_library { |
| 45 | name: "java-lib-1", |
| 46 | srcs: ["b.java"], |
| 47 | bazel_module: { bp2build_available: false }, |
| 48 | } |
| 49 | |
| 50 | java_library { |
| 51 | name: "java-lib-2", |
| 52 | srcs: ["c.java"], |
| 53 | bazel_module: { bp2build_available: false }, |
| 54 | }`, |
| 55 | expectedBazelTargets: []string{ |
| 56 | makeBazelTarget("java_plugin", "java-plug-1", attrNameToString{ |
| 57 | "target_compatible_with": `select({ |
| 58 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 59 | "//conditions:default": [], |
| 60 | })`, |
| 61 | "deps": `[ |
| 62 | ":java-lib-1", |
| 63 | ":java-lib-2", |
| 64 | ]`, |
| 65 | "srcs": `[ |
| 66 | "a.java", |
| 67 | "b.java", |
| 68 | ]`, |
| 69 | }), |
| 70 | }, |
| 71 | }) |
| 72 | } |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 73 | |
| 74 | func TestJavaPluginNoSrcs(t *testing.T) { |
| 75 | runJavaPluginTestCase(t, bp2buildTestCase{ |
| 76 | description: "java_plugin without srcs converts (static) libs to deps", |
| 77 | blueprint: `java_plugin { |
| 78 | name: "java-plug-1", |
| 79 | libs: ["java-lib-1"], |
| 80 | static_libs: ["java-lib-2"], |
| 81 | bazel_module: { bp2build_available: true }, |
| 82 | } |
| 83 | |
| 84 | java_library { |
| 85 | name: "java-lib-1", |
| 86 | srcs: ["b.java"], |
| 87 | bazel_module: { bp2build_available: false }, |
| 88 | } |
| 89 | |
| 90 | java_library { |
| 91 | name: "java-lib-2", |
| 92 | srcs: ["c.java"], |
| 93 | bazel_module: { bp2build_available: false }, |
| 94 | }`, |
| 95 | expectedBazelTargets: []string{ |
| 96 | makeBazelTarget("java_plugin", "java-plug-1", attrNameToString{ |
| 97 | "target_compatible_with": `select({ |
| 98 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 99 | "//conditions:default": [], |
| 100 | })`, |
| 101 | "deps": `[ |
| 102 | ":java-lib-1", |
| 103 | ":java-lib-2", |
| 104 | ]`, |
| 105 | }), |
| 106 | }, |
| 107 | }) |
| 108 | } |