cc_prebuilt_library_shared_conversion_test.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. "testing"
  17. "android/soong/cc"
  18. )
  19. func runCcPrebuiltLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
  20. t.Parallel()
  21. t.Helper()
  22. (&tc).ModuleTypeUnderTest = "cc_prebuilt_library_shared"
  23. (&tc).ModuleTypeUnderTestFactory = cc.PrebuiltSharedLibraryFactory
  24. RunBp2BuildTestCaseSimple(t, tc)
  25. }
  26. func TestPrebuiltLibrarySharedSimple(t *testing.T) {
  27. runCcPrebuiltLibrarySharedTestCase(t,
  28. Bp2buildTestCase{
  29. Description: "prebuilt library shared simple",
  30. Filesystem: map[string]string{
  31. "libf.so": "",
  32. },
  33. Blueprint: `
  34. cc_prebuilt_library_shared {
  35. name: "libtest",
  36. srcs: ["libf.so"],
  37. bazel_module: { bp2build_available: true },
  38. }`,
  39. ExpectedBazelTargets: []string{
  40. MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
  41. "shared_library": `"libf.so"`,
  42. }),
  43. },
  44. })
  45. }
  46. func TestPrebuiltLibrarySharedWithArchVariance(t *testing.T) {
  47. runCcPrebuiltLibrarySharedTestCase(t,
  48. Bp2buildTestCase{
  49. Description: "prebuilt library shared with arch variance",
  50. Filesystem: map[string]string{
  51. "libf.so": "",
  52. "libg.so": "",
  53. },
  54. Blueprint: `
  55. cc_prebuilt_library_shared {
  56. name: "libtest",
  57. arch: {
  58. arm64: { srcs: ["libf.so"], },
  59. arm: { srcs: ["libg.so"], },
  60. },
  61. bazel_module: { bp2build_available: true },
  62. }`,
  63. ExpectedBazelTargets: []string{
  64. MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
  65. "shared_library": `select({
  66. "//build/bazel/platforms/arch:arm": "libg.so",
  67. "//build/bazel/platforms/arch:arm64": "libf.so",
  68. "//conditions:default": None,
  69. })`,
  70. }),
  71. },
  72. })
  73. }
  74. func TestPrebuiltLibrarySharedAdditionalAttrs(t *testing.T) {
  75. runCcPrebuiltLibrarySharedTestCase(t,
  76. Bp2buildTestCase{
  77. Description: "prebuilt library shared additional attributes",
  78. Filesystem: map[string]string{
  79. "libf.so": "",
  80. "testdir/1/include.h": "",
  81. "testdir/2/other.h": "",
  82. },
  83. Blueprint: `
  84. cc_prebuilt_library_shared {
  85. name: "libtest",
  86. srcs: ["libf.so"],
  87. export_include_dirs: ["testdir/1/"],
  88. export_system_include_dirs: ["testdir/2/"],
  89. bazel_module: { bp2build_available: true },
  90. }`,
  91. ExpectedBazelTargets: []string{
  92. MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
  93. "shared_library": `"libf.so"`,
  94. "export_includes": `["testdir/1/"]`,
  95. "export_system_includes": `["testdir/2/"]`,
  96. }),
  97. },
  98. })
  99. }
  100. func TestPrebuiltLibrarySharedWithExportIncludesArchVariant(t *testing.T) {
  101. runCcPrebuiltLibrarySharedTestCase(t, Bp2buildTestCase{
  102. Description: "cc_prebuilt_library_shared correctly translates export_includes with arch variance",
  103. Filesystem: map[string]string{
  104. "libf.so": "",
  105. "libg.so": "",
  106. },
  107. Blueprint: `
  108. cc_prebuilt_library_shared {
  109. name: "libtest",
  110. srcs: ["libf.so"],
  111. arch: {
  112. arm: { export_include_dirs: ["testdir/1/"], },
  113. arm64: { export_include_dirs: ["testdir/2/"], },
  114. },
  115. bazel_module: { bp2build_available: true },
  116. }`,
  117. ExpectedBazelTargets: []string{
  118. MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
  119. "shared_library": `"libf.so"`,
  120. "export_includes": `select({
  121. "//build/bazel/platforms/arch:arm": ["testdir/1/"],
  122. "//build/bazel/platforms/arch:arm64": ["testdir/2/"],
  123. "//conditions:default": [],
  124. })`,
  125. }),
  126. },
  127. })
  128. }
  129. func TestPrebuiltLibrarySharedWithExportSystemIncludesArchVariant(t *testing.T) {
  130. runCcPrebuiltLibrarySharedTestCase(t, Bp2buildTestCase{
  131. Description: "cc_prebuilt_library_shared correctly translates export_system_includes with arch variance",
  132. Filesystem: map[string]string{
  133. "libf.so": "",
  134. "libg.so": "",
  135. },
  136. Blueprint: `
  137. cc_prebuilt_library_shared {
  138. name: "libtest",
  139. srcs: ["libf.so"],
  140. arch: {
  141. arm: { export_system_include_dirs: ["testdir/1/"], },
  142. arm64: { export_system_include_dirs: ["testdir/2/"], },
  143. },
  144. bazel_module: { bp2build_available: true },
  145. }`,
  146. ExpectedBazelTargets: []string{
  147. MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
  148. "shared_library": `"libf.so"`,
  149. "export_system_includes": `select({
  150. "//build/bazel/platforms/arch:arm": ["testdir/1/"],
  151. "//build/bazel/platforms/arch:arm64": ["testdir/2/"],
  152. "//conditions:default": [],
  153. })`,
  154. }),
  155. },
  156. })
  157. }