gen_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2017 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. "path/filepath"
  17. "strings"
  18. "testing"
  19. "android/soong/android"
  20. )
  21. func TestGen(t *testing.T) {
  22. t.Run("simple", func(t *testing.T) {
  23. ctx := testCc(t, `
  24. cc_library_shared {
  25. name: "libfoo",
  26. srcs: [
  27. "foo.c",
  28. "b.aidl",
  29. ],
  30. }`)
  31. aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("aidl")
  32. libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module)
  33. expected := "-I" + filepath.Dir(aidl.Output.String())
  34. actual := android.StringsRelativeToTop(ctx.Config(), libfoo.flags.Local.CommonFlags)
  35. if !inList(expected, actual) {
  36. t.Errorf("missing aidl includes in global flags, expected %q, actual %q", expected, actual)
  37. }
  38. })
  39. t.Run("filegroup", func(t *testing.T) {
  40. ctx := testCc(t, `
  41. filegroup {
  42. name: "fg",
  43. srcs: ["sub/c.aidl"],
  44. path: "sub",
  45. }
  46. cc_library_shared {
  47. name: "libfoo",
  48. srcs: [
  49. "foo.c",
  50. ":fg",
  51. ],
  52. }`)
  53. aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("aidl")
  54. aidlManifest := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("aidl.sbox.textproto")
  55. libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module)
  56. if !inList("-I"+filepath.Dir(aidl.Output.String()), android.StringsRelativeToTop(ctx.Config(), libfoo.flags.Local.CommonFlags)) {
  57. t.Errorf("missing aidl includes in global flags")
  58. }
  59. aidlCommand := android.RuleBuilderSboxProtoForTests(t, aidlManifest).Commands[0].GetCommand()
  60. if !strings.Contains(aidlCommand, "-Isub") {
  61. t.Errorf("aidl command for c.aidl should contain \"-Isub\", but was %q", aidlCommand)
  62. }
  63. })
  64. t.Run("sysprop", func(t *testing.T) {
  65. ctx := testCc(t, `
  66. cc_library {
  67. name: "libsysprop",
  68. srcs: [
  69. "path/to/foo.sysprop",
  70. ],
  71. }`)
  72. outDir := "out/soong/.intermediates/libsysprop/android_arm64_armv8-a_static/gen"
  73. syspropBuildParams := ctx.ModuleForTests("libsysprop", "android_arm64_armv8-a_static").Rule("sysprop")
  74. android.AssertStringEquals(t, "header output directory does not match", outDir+"/sysprop/include/path/to", syspropBuildParams.Args["headerOutDir"])
  75. android.AssertStringEquals(t, "public output directory does not match", outDir+"/sysprop/public/include/path/to", syspropBuildParams.Args["publicOutDir"])
  76. android.AssertStringEquals(t, "src output directory does not match", outDir+"/sysprop/path/to", syspropBuildParams.Args["srcOutDir"])
  77. android.AssertStringEquals(t, "output include name does not match", "path/to/foo.sysprop.h", syspropBuildParams.Args["includeName"])
  78. android.AssertStringEquals(t, "Input file does not match", "path/to/foo.sysprop", syspropBuildParams.Input.String())
  79. android.AssertStringEquals(t, "Output file does not match", outDir+"/sysprop/path/to/foo.sysprop.cpp", syspropBuildParams.Output.String())
  80. android.AssertStringListContains(t, "Implicit outputs does not contain header file", syspropBuildParams.ImplicitOutputs.Strings(), outDir+"/sysprop/include/path/to/foo.sysprop.h")
  81. android.AssertStringListContains(t, "Implicit outputs does not contain public header file", syspropBuildParams.ImplicitOutputs.Strings(), outDir+"/sysprop/public/include/path/to/foo.sysprop.h")
  82. android.AssertIntEquals(t, "Implicit outputs contains the incorrect number of elements", 2, len(syspropBuildParams.ImplicitOutputs.Strings()))
  83. })
  84. }