java_import_conversion_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2022 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. "android/soong/android"
  17. "android/soong/java"
  18. "testing"
  19. )
  20. func runJavaImportTestCase(t *testing.T, tc Bp2buildTestCase) {
  21. t.Helper()
  22. RunBp2BuildTestCase(t, registerJavaImportModuleTypes, tc)
  23. }
  24. func registerJavaImportModuleTypes(ctx android.RegistrationContext) {
  25. }
  26. func TestJavaImportMinimal(t *testing.T) {
  27. runJavaImportTestCase(t, Bp2buildTestCase{
  28. Description: "Java import - simple example",
  29. ModuleTypeUnderTest: "java_import",
  30. ModuleTypeUnderTestFactory: java.ImportFactory,
  31. Filesystem: map[string]string{
  32. "import.jar": "",
  33. },
  34. Blueprint: `
  35. java_import {
  36. name: "example_import",
  37. jars: ["import.jar"],
  38. bazel_module: { bp2build_available: true },
  39. }
  40. `,
  41. ExpectedBazelTargets: []string{
  42. MakeBazelTarget("java_import", "example_import", AttrNameToString{
  43. "jars": `["import.jar"]`,
  44. }),
  45. MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
  46. "exports": `[":example_import"]`,
  47. "neverlink": `True`,
  48. "sdk_version": `"none"`,
  49. }),
  50. }})
  51. }
  52. func TestJavaImportArchVariant(t *testing.T) {
  53. runJavaImportTestCase(t, Bp2buildTestCase{
  54. Description: "Java import - simple example",
  55. ModuleTypeUnderTest: "java_import",
  56. ModuleTypeUnderTestFactory: java.ImportFactory,
  57. Filesystem: map[string]string{
  58. "import.jar": "",
  59. },
  60. Blueprint: `
  61. java_import {
  62. name: "example_import",
  63. target: {
  64. android: {
  65. jars: ["android.jar"],
  66. },
  67. linux_glibc: {
  68. jars: ["linux.jar"],
  69. },
  70. },
  71. bazel_module: { bp2build_available: true },
  72. }
  73. `,
  74. ExpectedBazelTargets: []string{
  75. MakeBazelTarget("java_import", "example_import", AttrNameToString{
  76. "jars": `select({
  77. "//build/bazel/platforms/os:android": ["android.jar"],
  78. "//build/bazel/platforms/os:linux_glibc": ["linux.jar"],
  79. "//conditions:default": [],
  80. })`,
  81. }),
  82. MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
  83. "exports": `[":example_import"]`,
  84. "neverlink": `True`,
  85. "sdk_version": `"none"`,
  86. }),
  87. }})
  88. }
  89. func TestJavaImportHost(t *testing.T) {
  90. runJavaImportTestCase(t, Bp2buildTestCase{
  91. Description: "Java import host- simple example",
  92. ModuleTypeUnderTest: "java_import_host",
  93. ModuleTypeUnderTestFactory: java.ImportFactory,
  94. Filesystem: map[string]string{
  95. "import.jar": "",
  96. },
  97. Blueprint: `
  98. java_import_host {
  99. name: "example_import",
  100. jars: ["import.jar"],
  101. bazel_module: { bp2build_available: true },
  102. }
  103. `,
  104. ExpectedBazelTargets: []string{
  105. MakeBazelTarget("java_import", "example_import", AttrNameToString{
  106. "jars": `["import.jar"]`,
  107. }),
  108. MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
  109. "exports": `[":example_import"]`,
  110. "neverlink": `True`,
  111. "sdk_version": `"none"`,
  112. }),
  113. }})
  114. }