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 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 24 | func runJavaPluginTestCase(t *testing.T, tc Bp2buildTestCase) { |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 25 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 26 | (&tc).ModuleTypeUnderTest = "java_plugin" |
| 27 | (&tc).ModuleTypeUnderTestFactory = java.PluginFactory |
| 28 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 29 | ctx.RegisterModuleType("java_library", java.LibraryFactory) |
| 30 | }, tc) |
| 31 | } |
| 32 | |
| 33 | func TestJavaPlugin(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 34 | runJavaPluginTestCase(t, Bp2buildTestCase{ |
| 35 | Description: "java_plugin with srcs, libs, static_libs", |
| 36 | Blueprint: `java_plugin { |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 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 }, |
Vinh Tran | 3ac6daf | 2022-04-22 19:09:58 -0400 | [diff] [blame] | 42 | java_version: "7", |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | java_library { |
| 46 | name: "java-lib-1", |
| 47 | srcs: ["b.java"], |
| 48 | bazel_module: { bp2build_available: false }, |
| 49 | } |
| 50 | |
| 51 | java_library { |
| 52 | name: "java-lib-2", |
| 53 | srcs: ["c.java"], |
| 54 | bazel_module: { bp2build_available: false }, |
| 55 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 56 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 57 | MakeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{ |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 58 | "target_compatible_with": `select({ |
| 59 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 60 | "//conditions:default": [], |
| 61 | })`, |
| 62 | "deps": `[ |
Alix | 53fae38 | 2022-11-08 17:22:18 +0000 | [diff] [blame] | 63 | ":java-lib-1-neverlink", |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 64 | ":java-lib-2", |
| 65 | ]`, |
| 66 | "srcs": `[ |
| 67 | "a.java", |
| 68 | "b.java", |
| 69 | ]`, |
Romain Jobredeaux | 2eef2e1 | 2023-02-24 12:07:08 -0500 | [diff] [blame] | 70 | "java_version": `"7"`, |
Sam Delmerico | c06ea03 | 2022-01-28 21:11:03 +0000 | [diff] [blame] | 71 | }), |
| 72 | }, |
| 73 | }) |
| 74 | } |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 75 | |
| 76 | func TestJavaPluginNoSrcs(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 77 | runJavaPluginTestCase(t, Bp2buildTestCase{ |
| 78 | Description: "java_plugin without srcs converts (static) libs to deps", |
| 79 | Blueprint: `java_plugin { |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 80 | name: "java-plug-1", |
| 81 | libs: ["java-lib-1"], |
| 82 | static_libs: ["java-lib-2"], |
| 83 | bazel_module: { bp2build_available: true }, |
| 84 | } |
| 85 | |
| 86 | java_library { |
| 87 | name: "java-lib-1", |
| 88 | srcs: ["b.java"], |
| 89 | bazel_module: { bp2build_available: false }, |
| 90 | } |
| 91 | |
| 92 | java_library { |
| 93 | name: "java-lib-2", |
| 94 | srcs: ["c.java"], |
| 95 | bazel_module: { bp2build_available: false }, |
| 96 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 97 | ExpectedBazelTargets: []string{ |
Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 98 | MakeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{ |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 99 | "target_compatible_with": `select({ |
| 100 | "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], |
| 101 | "//conditions:default": [], |
| 102 | })`, |
| 103 | "deps": `[ |
Alix | 53fae38 | 2022-11-08 17:22:18 +0000 | [diff] [blame] | 104 | ":java-lib-1-neverlink", |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 105 | ":java-lib-2", |
| 106 | ]`, |
| 107 | }), |
| 108 | }, |
| 109 | }) |
| 110 | } |