java_sdk_library_conversion_test.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 runJavaSdkLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
  21. t.Helper()
  22. (&tc).ModuleTypeUnderTest = "java_sdk_library"
  23. (&tc).ModuleTypeUnderTestFactory = java.SdkLibraryFactory
  24. RunBp2BuildTestCase(t, registrationCtxFunc, tc)
  25. }
  26. func runJavaSdkLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
  27. t.Helper()
  28. runJavaSdkLibraryTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {})
  29. }
  30. func TestJavaSdkLibraryApiSurfaceGeneral(t *testing.T) {
  31. runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
  32. Description: "limited java_sdk_library for api surfaces, general conversion",
  33. Filesystem: map[string]string{
  34. "build/soong/scripts/gen-java-current-api-files.sh": "",
  35. "api/current.txt": "",
  36. "api/system-current.txt": "",
  37. "api/test-current.txt": "",
  38. "api/module-lib-current.txt": "",
  39. "api/system-server-current.txt": "",
  40. "api/removed.txt": "",
  41. "api/system-removed.txt": "",
  42. "api/test-removed.txt": "",
  43. "api/module-lib-removed.txt": "",
  44. "api/system-server-removed.txt": "",
  45. },
  46. Blueprint: `java_sdk_library {
  47. name: "java-sdk-lib",
  48. srcs: ["a.java"],
  49. public: {enabled: true},
  50. system: {enabled: true},
  51. test: {enabled: true},
  52. module_lib: {enabled: true},
  53. system_server: {enabled: true},
  54. }`,
  55. ExpectedBazelTargets: []string{
  56. MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
  57. "public": `"api/current.txt"`,
  58. "system": `"api/system-current.txt"`,
  59. "test": `"api/test-current.txt"`,
  60. "module_lib": `"api/module-lib-current.txt"`,
  61. "system_server": `"api/system-server-current.txt"`,
  62. }),
  63. },
  64. })
  65. }
  66. func TestJavaSdkLibraryApiSurfacePublicDefault(t *testing.T) {
  67. runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
  68. Description: "limited java_sdk_library for api surfaces, public prop uses default value",
  69. Filesystem: map[string]string{
  70. "build/soong/scripts/gen-java-current-api-files.sh": "",
  71. "api/current.txt": "",
  72. "api/system-current.txt": "",
  73. "api/test-current.txt": "",
  74. "api/module-lib-current.txt": "",
  75. "api/system-server-current.txt": "",
  76. "api/removed.txt": "",
  77. "api/system-removed.txt": "",
  78. "api/test-removed.txt": "",
  79. "api/module-lib-removed.txt": "",
  80. "api/system-server-removed.txt": "",
  81. },
  82. Blueprint: `java_sdk_library {
  83. name: "java-sdk-lib",
  84. srcs: ["a.java"],
  85. system: {enabled: false},
  86. test: {enabled: false},
  87. module_lib: {enabled: false},
  88. system_server: {enabled: false},
  89. }`,
  90. ExpectedBazelTargets: []string{
  91. MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
  92. "public": `"api/current.txt"`,
  93. }),
  94. },
  95. })
  96. }
  97. func TestJavaSdkLibraryApiSurfacePublicNotEnabled(t *testing.T) {
  98. runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
  99. Description: "limited java_sdk_library for api surfaces, public enable is false",
  100. Filesystem: map[string]string{
  101. "build/soong/scripts/gen-java-current-api-files.sh": "",
  102. "api/current.txt": "",
  103. "api/removed.txt": "",
  104. },
  105. Blueprint: `java_sdk_library {
  106. name: "java-sdk-lib",
  107. srcs: ["a.java"],
  108. public: {enabled: false},
  109. }`,
  110. ExpectedBazelTargets: []string{
  111. MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{}),
  112. },
  113. })
  114. }
  115. func TestJavaSdkLibraryApiSurfaceNoScopeIsSet(t *testing.T) {
  116. runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
  117. Description: "limited java_sdk_library for api surfaces, none of the api scopes is set",
  118. Filesystem: map[string]string{
  119. "build/soong/scripts/gen-java-current-api-files.sh": "",
  120. "api/current.txt": "",
  121. "api/system-current.txt": "",
  122. "api/test-current.txt": "",
  123. "api/removed.txt": "",
  124. "api/system-removed.txt": "",
  125. "api/test-removed.txt": "",
  126. },
  127. Blueprint: `java_sdk_library {
  128. name: "java-sdk-lib",
  129. srcs: ["a.java"],
  130. }`,
  131. ExpectedBazelTargets: []string{
  132. MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
  133. "public": `"api/current.txt"`,
  134. "system": `"api/system-current.txt"`,
  135. "test": `"api/test-current.txt"`,
  136. }),
  137. },
  138. })
  139. }