java_library_host_conversion_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 runJavaLibraryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
  21. t.Helper()
  22. (&tc).ModuleTypeUnderTest = "java_library_host"
  23. (&tc).ModuleTypeUnderTestFactory = java.LibraryHostFactory
  24. RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
  25. }
  26. func TestJavaLibraryHost(t *testing.T) {
  27. runJavaLibraryHostTestCase(t, Bp2buildTestCase{
  28. Description: "java_library_host with srcs, exclude_srcs and libs",
  29. Blueprint: `java_library_host {
  30. name: "java-lib-host-1",
  31. srcs: ["a.java", "b.java"],
  32. exclude_srcs: ["b.java"],
  33. libs: ["java-lib-host-2"],
  34. bazel_module: { bp2build_available: true },
  35. }
  36. java_library_host {
  37. name: "java-lib-host-2",
  38. srcs: ["c.java"],
  39. bazel_module: { bp2build_available: true },
  40. java_version: "9",
  41. }`,
  42. ExpectedBazelTargets: []string{
  43. MakeBazelTarget("java_library", "java-lib-host-1", AttrNameToString{
  44. "srcs": `["a.java"]`,
  45. "deps": `[":java-lib-host-2-neverlink"]`,
  46. "target_compatible_with": `select({
  47. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  48. "//conditions:default": [],
  49. })`,
  50. }),
  51. MakeBazelTarget("java_library", "java-lib-host-1-neverlink", AttrNameToString{
  52. "exports": `[":java-lib-host-1"]`,
  53. "neverlink": `True`,
  54. "target_compatible_with": `select({
  55. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  56. "//conditions:default": [],
  57. })`,
  58. }),
  59. MakeBazelTarget("java_library", "java-lib-host-2", AttrNameToString{
  60. "java_version": `"9"`,
  61. "srcs": `["c.java"]`,
  62. "target_compatible_with": `select({
  63. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  64. "//conditions:default": [],
  65. })`,
  66. }),
  67. MakeBazelTarget("java_library", "java-lib-host-2-neverlink", AttrNameToString{
  68. "exports": `[":java-lib-host-2"]`,
  69. "neverlink": `True`,
  70. "target_compatible_with": `select({
  71. "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
  72. "//conditions:default": [],
  73. })`,
  74. "java_version": `"9"`,
  75. }),
  76. },
  77. })
  78. }