cc_prebuilt_binary_conversion_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. "fmt"
  17. "testing"
  18. "android/soong/cc"
  19. )
  20. func runCcPrebuiltBinaryTestCase(t *testing.T, testCase Bp2buildTestCase) {
  21. t.Helper()
  22. description := fmt.Sprintf("cc_prebuilt_binary: %s", testCase.Description)
  23. testCase.ModuleTypeUnderTest = "cc_prebuilt_binary"
  24. testCase.ModuleTypeUnderTestFactory = cc.PrebuiltBinaryFactory
  25. testCase.Description = description
  26. t.Run(description, func(t *testing.T) {
  27. t.Helper()
  28. RunBp2BuildTestCaseSimple(t, testCase)
  29. })
  30. }
  31. func TestPrebuiltBinary(t *testing.T) {
  32. runCcPrebuiltBinaryTestCase(t,
  33. Bp2buildTestCase{
  34. Description: "simple",
  35. Filesystem: map[string]string{
  36. "bin": "",
  37. },
  38. Blueprint: `
  39. cc_prebuilt_binary {
  40. name: "bintest",
  41. srcs: ["bin"],
  42. bazel_module: { bp2build_available: true },
  43. }`,
  44. ExpectedBazelTargets: []string{
  45. MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
  46. "src": `"bin"`,
  47. })},
  48. })
  49. }
  50. func TestPrebuiltBinaryWithStrip(t *testing.T) {
  51. runCcPrebuiltBinaryTestCase(t,
  52. Bp2buildTestCase{
  53. Description: "with strip",
  54. Filesystem: map[string]string{
  55. "bin": "",
  56. },
  57. Blueprint: `
  58. cc_prebuilt_binary {
  59. name: "bintest",
  60. srcs: ["bin"],
  61. strip: { all: true },
  62. bazel_module: { bp2build_available: true },
  63. }`, ExpectedBazelTargets: []string{
  64. MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
  65. "src": `"bin"`,
  66. "strip": `{
  67. "all": True,
  68. }`,
  69. }),
  70. },
  71. })
  72. }
  73. func TestPrebuiltBinaryWithArchVariance(t *testing.T) {
  74. runCcPrebuiltBinaryTestCase(t,
  75. Bp2buildTestCase{
  76. Description: "with arch variance",
  77. Filesystem: map[string]string{
  78. "bina": "",
  79. "binb": "",
  80. },
  81. Blueprint: `
  82. cc_prebuilt_binary {
  83. name: "bintest",
  84. arch: {
  85. arm64: { srcs: ["bina"], },
  86. arm: { srcs: ["binb"], },
  87. },
  88. bazel_module: { bp2build_available: true },
  89. }`, ExpectedBazelTargets: []string{
  90. MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
  91. "src": `select({
  92. "//build/bazel/platforms/arch:arm": "binb",
  93. "//build/bazel/platforms/arch:arm64": "bina",
  94. "//conditions:default": None,
  95. })`,
  96. }),
  97. },
  98. })
  99. }
  100. func TestPrebuiltBinaryMultipleSrcsFails(t *testing.T) {
  101. runCcPrebuiltBinaryTestCase(t,
  102. Bp2buildTestCase{
  103. Description: "fails because multiple sources",
  104. Filesystem: map[string]string{
  105. "bina": "",
  106. "binb": "",
  107. },
  108. Blueprint: `
  109. cc_prebuilt_binary {
  110. name: "bintest",
  111. srcs: ["bina", "binb"],
  112. bazel_module: { bp2build_available: true },
  113. }`,
  114. ExpectedErr: fmt.Errorf("Expected at most one source file"),
  115. })
  116. }
  117. // TODO: nosrcs test