gensrcs_conversion_test.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2020 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/genrule"
  18. "testing"
  19. )
  20. func TestGensrcs(t *testing.T) {
  21. testcases := []struct {
  22. name string
  23. bp string
  24. expectedBazelAttrs AttrNameToString
  25. }{
  26. {
  27. name: "gensrcs with common usage of properties",
  28. bp: `
  29. gensrcs {
  30. name: "foo",
  31. srcs: ["test/input.txt", ":external_files"],
  32. tool_files: ["program.py"],
  33. cmd: "$(location program.py) $(in) $(out) $(location foo/file.txt) $(location :external_files)",
  34. data: ["foo/file.txt", ":external_files"],
  35. output_extension: "out",
  36. bazel_module: { bp2build_available: true },
  37. }`,
  38. expectedBazelAttrs: AttrNameToString{
  39. "srcs": `[
  40. "test/input.txt",
  41. ":external_files__BP2BUILD__MISSING__DEP",
  42. ]`,
  43. "tools": `["program.py"]`,
  44. "output_extension": `"out"`,
  45. "cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files__BP2BUILD__MISSING__DEP)"`,
  46. "data": `[
  47. "foo/file.txt",
  48. ":external_files__BP2BUILD__MISSING__DEP",
  49. ]`,
  50. },
  51. },
  52. {
  53. name: "gensrcs with out_extension unset",
  54. bp: `
  55. gensrcs {
  56. name: "foo",
  57. srcs: ["input.txt"],
  58. cmd: "cat $(in) > $(out)",
  59. bazel_module: { bp2build_available: true },
  60. }`,
  61. expectedBazelAttrs: AttrNameToString{
  62. "srcs": `["input.txt"]`,
  63. "cmd": `"cat $(SRC) > $(OUT)"`,
  64. },
  65. },
  66. }
  67. for _, test := range testcases {
  68. expectedBazelTargets := []string{
  69. MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
  70. }
  71. t.Run(test.name, func(t *testing.T) {
  72. RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
  73. Bp2buildTestCase{
  74. ModuleTypeUnderTest: "gensrcs",
  75. ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
  76. Blueprint: test.bp,
  77. ExpectedBazelTargets: expectedBazelTargets,
  78. })
  79. })
  80. }
  81. }