java_test_host_conversion_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Copyright 2023 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 runJavaTestHostTestCase(t *testing.T, tc Bp2buildTestCase) {
  21. t.Helper()
  22. (&tc).ModuleTypeUnderTest = "java_test_host"
  23. (&tc).ModuleTypeUnderTestFactory = java.TestHostFactory
  24. RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
  25. ctx.RegisterModuleType("java_library", java.LibraryFactory)
  26. }, tc)
  27. }
  28. func TestJavaTestHostGeneral(t *testing.T) {
  29. runJavaTestHostTestCase(t, Bp2buildTestCase{
  30. Description: "java_test_host general",
  31. Filesystem: map[string]string{},
  32. Blueprint: `
  33. java_test_host {
  34. name: "java_test_host-1",
  35. srcs: ["a.java", "b.java"],
  36. libs: ["lib_a"],
  37. static_libs: ["static_libs_a"],
  38. exclude_srcs: ["b.java"],
  39. javacflags: ["-Xdoclint:all/protected"],
  40. java_version: "8",
  41. }
  42. java_library {
  43. name: "lib_a",
  44. bazel_module: { bp2build_available: false },
  45. }
  46. java_library {
  47. name: "static_libs_a",
  48. bazel_module: { bp2build_available: false },
  49. }
  50. `,
  51. ExpectedBazelTargets: []string{
  52. MakeBazelTarget("java_library", "java_test_host-1_lib", AttrNameToString{
  53. "deps": `[
  54. ":lib_a-neverlink",
  55. ":static_libs_a",
  56. ]`,
  57. "java_version": `"8"`,
  58. "javacopts": `["-Xdoclint:all/protected"]`,
  59. "srcs": `["a.java"]`,
  60. "target_compatible_with": `select({
  61. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  62. "//conditions:default": [],
  63. })`,
  64. }),
  65. MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
  66. "runtime_deps": `[":java_test_host-1_lib"]`,
  67. "target_compatible_with": `select({
  68. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  69. "//conditions:default": [],
  70. })`,
  71. }),
  72. },
  73. })
  74. }
  75. func TestJavaTestHostNoSrcs(t *testing.T) {
  76. runJavaTestHostTestCase(t, Bp2buildTestCase{
  77. Description: "java_test_host without srcs",
  78. Filesystem: map[string]string{},
  79. Blueprint: `
  80. java_test_host {
  81. name: "java_test_host-1",
  82. libs: ["lib_a"],
  83. static_libs: ["static_libs_a"],
  84. }
  85. java_library {
  86. name: "lib_a",
  87. bazel_module: { bp2build_available: false },
  88. }
  89. java_library {
  90. name: "static_libs_a",
  91. bazel_module: { bp2build_available: false },
  92. }
  93. `,
  94. ExpectedBazelTargets: []string{
  95. MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
  96. "runtime_deps": `[
  97. ":lib_a-neverlink",
  98. ":static_libs_a",
  99. ]`,
  100. "target_compatible_with": `select({
  101. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  102. "//conditions:default": [],
  103. })`,
  104. }),
  105. },
  106. })
  107. }
  108. func TestJavaTestHostKotlinSrcs(t *testing.T) {
  109. runJavaTestHostTestCase(t, Bp2buildTestCase{
  110. Description: "java_test_host with .kt in srcs",
  111. Filesystem: map[string]string{},
  112. Blueprint: `
  113. java_test_host {
  114. name: "java_test_host-1",
  115. srcs: ["a.java", "b.kt"],
  116. }
  117. `,
  118. ExpectedBazelTargets: []string{
  119. MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
  120. "runtime_deps": `[":java_test_host-1_lib"]`,
  121. "target_compatible_with": `select({
  122. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  123. "//conditions:default": [],
  124. })`,
  125. }),
  126. MakeBazelTarget("kt_jvm_library", "java_test_host-1_lib", AttrNameToString{
  127. "srcs": `[
  128. "a.java",
  129. "b.kt",
  130. ]`,
  131. "target_compatible_with": `select({
  132. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  133. "//conditions:default": [],
  134. })`,
  135. }),
  136. },
  137. })
  138. }