java_plugin_conversion_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. package bp2build
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. "android/soong/java"
  19. )
  20. func runJavaPluginTestCase(t *testing.T, tc Bp2buildTestCase) {
  21. t.Helper()
  22. (&tc).ModuleTypeUnderTest = "java_plugin"
  23. (&tc).ModuleTypeUnderTestFactory = java.PluginFactory
  24. RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
  25. ctx.RegisterModuleType("java_library", java.LibraryFactory)
  26. }, tc)
  27. }
  28. func TestJavaPlugin(t *testing.T) {
  29. runJavaPluginTestCase(t, Bp2buildTestCase{
  30. Description: "java_plugin with srcs, libs, static_libs",
  31. Blueprint: `java_plugin {
  32. name: "java-plug-1",
  33. srcs: ["a.java", "b.java"],
  34. libs: ["java-lib-1"],
  35. static_libs: ["java-lib-2"],
  36. bazel_module: { bp2build_available: true },
  37. java_version: "7",
  38. }
  39. java_library {
  40. name: "java-lib-1",
  41. srcs: ["b.java"],
  42. bazel_module: { bp2build_available: false },
  43. }
  44. java_library {
  45. name: "java-lib-2",
  46. srcs: ["c.java"],
  47. bazel_module: { bp2build_available: false },
  48. }`,
  49. ExpectedBazelTargets: []string{
  50. MakeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{
  51. "target_compatible_with": `select({
  52. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  53. "//conditions:default": [],
  54. })`,
  55. "deps": `[
  56. ":java-lib-1-neverlink",
  57. ":java-lib-2",
  58. ]`,
  59. "srcs": `[
  60. "a.java",
  61. "b.java",
  62. ]`,
  63. "java_version": `"7"`,
  64. }),
  65. },
  66. })
  67. }
  68. func TestJavaPluginNoSrcs(t *testing.T) {
  69. runJavaPluginTestCase(t, Bp2buildTestCase{
  70. Description: "java_plugin without srcs converts (static) libs to deps",
  71. Blueprint: `java_plugin {
  72. name: "java-plug-1",
  73. libs: ["java-lib-1"],
  74. static_libs: ["java-lib-2"],
  75. bazel_module: { bp2build_available: true },
  76. }
  77. java_library {
  78. name: "java-lib-1",
  79. srcs: ["b.java"],
  80. bazel_module: { bp2build_available: false },
  81. }
  82. java_library {
  83. name: "java-lib-2",
  84. srcs: ["c.java"],
  85. bazel_module: { bp2build_available: false },
  86. }`,
  87. ExpectedBazelTargets: []string{
  88. MakeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{
  89. "target_compatible_with": `select({
  90. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  91. "//conditions:default": [],
  92. })`,
  93. "deps": `[
  94. ":java-lib-1-neverlink",
  95. ":java-lib-2",
  96. ]`,
  97. }),
  98. },
  99. })
  100. }