genrule_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2018 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 cc
  15. import (
  16. "reflect"
  17. "testing"
  18. "android/soong/android"
  19. )
  20. func testGenruleContext(config android.Config) *android.TestContext {
  21. ctx := android.NewTestArchContext()
  22. ctx.RegisterModuleType("cc_genrule", genRuleFactory)
  23. ctx.Register(config)
  24. return ctx
  25. }
  26. func TestArchGenruleCmd(t *testing.T) {
  27. fs := map[string][]byte{
  28. "tool": nil,
  29. "foo": nil,
  30. "bar": nil,
  31. }
  32. bp := `
  33. cc_genrule {
  34. name: "gen",
  35. tool_files: ["tool"],
  36. cmd: "$(location tool) $(in) $(out)",
  37. arch: {
  38. arm: {
  39. srcs: ["foo"],
  40. out: ["out_arm"],
  41. },
  42. arm64: {
  43. srcs: ["bar"],
  44. out: ["out_arm64"],
  45. },
  46. },
  47. }
  48. `
  49. config := android.TestArchConfig(buildDir, nil, bp, fs)
  50. ctx := testGenruleContext(config)
  51. _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
  52. if errs == nil {
  53. _, errs = ctx.PrepareBuildActions(config)
  54. }
  55. if errs != nil {
  56. t.Fatal(errs)
  57. }
  58. gen := ctx.ModuleForTests("gen", "android_arm_armv7-a-neon").Output("out_arm")
  59. expected := []string{"foo"}
  60. if !reflect.DeepEqual(expected, gen.Inputs.Strings()) {
  61. t.Errorf(`want arm inputs %v, got %v`, expected, gen.Inputs.Strings())
  62. }
  63. gen = ctx.ModuleForTests("gen", "android_arm64_armv8-a").Output("out_arm64")
  64. expected = []string{"bar"}
  65. if !reflect.DeepEqual(expected, gen.Inputs.Strings()) {
  66. t.Errorf(`want arm64 inputs %v, got %v`, expected, gen.Inputs.Strings())
  67. }
  68. }
  69. func TestLibraryGenruleCmd(t *testing.T) {
  70. bp := `
  71. cc_library {
  72. name: "libboth",
  73. }
  74. cc_library_shared {
  75. name: "libshared",
  76. }
  77. cc_library_static {
  78. name: "libstatic",
  79. }
  80. cc_genrule {
  81. name: "gen",
  82. tool_files: ["tool"],
  83. srcs: [
  84. ":libboth",
  85. ":libshared",
  86. ":libstatic",
  87. ],
  88. cmd: "$(location tool) $(in) $(out)",
  89. out: ["out"],
  90. }
  91. `
  92. ctx := testCc(t, bp)
  93. gen := ctx.ModuleForTests("gen", "android_arm_armv7-a-neon").Output("out")
  94. expected := []string{"libboth.so", "libshared.so", "libstatic.a"}
  95. var got []string
  96. for _, input := range gen.Inputs {
  97. got = append(got, input.Base())
  98. }
  99. if !reflect.DeepEqual(expected, got) {
  100. t.Errorf(`want inputs %v, got %v`, expected, got)
  101. }
  102. }