cc_prebuilt_object_conversion_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 runCcPrebuiltObjectTestCase(t *testing.T, testCase Bp2buildTestCase) {
  21. t.Helper()
  22. description := fmt.Sprintf("cc_prebuilt_object: %s", testCase.Description)
  23. testCase.ModuleTypeUnderTest = "cc_prebuilt_object"
  24. testCase.ModuleTypeUnderTestFactory = cc.PrebuiltObjectFactory
  25. testCase.Description = description
  26. t.Run(description, func(t *testing.T) {
  27. t.Helper()
  28. RunBp2BuildTestCaseSimple(t, testCase)
  29. })
  30. }
  31. func TestPrebuiltObject(t *testing.T) {
  32. runCcPrebuiltObjectTestCase(t,
  33. Bp2buildTestCase{
  34. Description: "simple",
  35. Filesystem: map[string]string{
  36. "obj.o": "",
  37. },
  38. Blueprint: `
  39. cc_prebuilt_object {
  40. name: "objtest",
  41. srcs: ["obj.o"],
  42. bazel_module: { bp2build_available: true },
  43. }`,
  44. ExpectedBazelTargets: []string{
  45. MakeBazelTarget("cc_prebuilt_object", "objtest", AttrNameToString{
  46. "src": `"obj.o"`,
  47. })},
  48. })
  49. }
  50. func TestPrebuiltObjectWithArchVariance(t *testing.T) {
  51. runCcPrebuiltObjectTestCase(t,
  52. Bp2buildTestCase{
  53. Description: "with arch variance",
  54. Filesystem: map[string]string{
  55. "obja.o": "",
  56. "objb.o": "",
  57. },
  58. Blueprint: `
  59. cc_prebuilt_object {
  60. name: "objtest",
  61. arch: {
  62. arm64: { srcs: ["obja.o"], },
  63. arm: { srcs: ["objb.o"], },
  64. },
  65. bazel_module: { bp2build_available: true },
  66. }`, ExpectedBazelTargets: []string{
  67. MakeBazelTarget("cc_prebuilt_object", "objtest", AttrNameToString{
  68. "src": `select({
  69. "//build/bazel/platforms/arch:arm": "objb.o",
  70. "//build/bazel/platforms/arch:arm64": "obja.o",
  71. "//conditions:default": None,
  72. })`,
  73. }),
  74. },
  75. })
  76. }
  77. func TestPrebuiltObjectMultipleSrcsFails(t *testing.T) {
  78. runCcPrebuiltObjectTestCase(t,
  79. Bp2buildTestCase{
  80. Description: "fails because multiple sources",
  81. Filesystem: map[string]string{
  82. "obja": "",
  83. "objb": "",
  84. },
  85. Blueprint: `
  86. cc_prebuilt_object {
  87. name: "objtest",
  88. srcs: ["obja.o", "objb.o"],
  89. bazel_module: { bp2build_available: true },
  90. }`,
  91. ExpectedErr: fmt.Errorf("Expected at most one source file"),
  92. })
  93. }
  94. // TODO: nosrcs test