gen_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. )
  20. func TestGen(t *testing.T) {
  21. t.Run("simple", func(t *testing.T) {
  22. ctx := testCc(t, `
  23. cc_library_shared {
  24. name: "libfoo",
  25. srcs: [
  26. "foo.c",
  27. "b.aidl",
  28. ],
  29. }`)
  30. aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("aidl")
  31. libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module)
  32. if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) {
  33. t.Errorf("missing aidl includes in global flags")
  34. }
  35. })
  36. t.Run("filegroup", func(t *testing.T) {
  37. ctx := testCc(t, `
  38. filegroup {
  39. name: "fg",
  40. srcs: ["sub/c.aidl"],
  41. path: "sub",
  42. }
  43. cc_library_shared {
  44. name: "libfoo",
  45. srcs: [
  46. "foo.c",
  47. ":fg",
  48. ],
  49. }`)
  50. aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("aidl")
  51. libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module)
  52. if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) {
  53. t.Errorf("missing aidl includes in global flags")
  54. }
  55. aidlCommand := aidl.RuleParams.Command
  56. if !strings.Contains(aidlCommand, "-Isub") {
  57. t.Errorf("aidl command for c.aidl should contain \"-Isub\", but was %q", aidlCommand)
  58. }
  59. })
  60. }