vendor_public_library_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2021 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. "strings"
  17. "testing"
  18. )
  19. func TestVendorPublicLibraries(t *testing.T) {
  20. ctx := testCc(t, `
  21. cc_library_headers {
  22. name: "libvendorpublic_headers",
  23. product_available: true,
  24. export_include_dirs: ["my_include"],
  25. }
  26. cc_library {
  27. name: "libvendorpublic",
  28. srcs: ["foo.c"],
  29. vendor: true,
  30. no_libcrt: true,
  31. nocrt: true,
  32. vendor_public_library: {
  33. symbol_file: "libvendorpublic.map.txt",
  34. export_public_headers: ["libvendorpublic_headers"],
  35. },
  36. }
  37. cc_library {
  38. name: "libsystem",
  39. shared_libs: ["libvendorpublic"],
  40. vendor: false,
  41. srcs: ["foo.c"],
  42. no_libcrt: true,
  43. nocrt: true,
  44. }
  45. cc_library {
  46. name: "libproduct",
  47. shared_libs: ["libvendorpublic"],
  48. product_specific: true,
  49. srcs: ["foo.c"],
  50. no_libcrt: true,
  51. nocrt: true,
  52. }
  53. cc_library {
  54. name: "libvendor",
  55. shared_libs: ["libvendorpublic"],
  56. vendor: true,
  57. srcs: ["foo.c"],
  58. no_libcrt: true,
  59. nocrt: true,
  60. }
  61. `)
  62. coreVariant := "android_arm64_armv8-a_shared"
  63. vendorVariant := "android_vendor.29_arm64_armv8-a_shared"
  64. productVariant := "android_product.29_arm64_armv8-a_shared"
  65. // test if header search paths are correctly added
  66. // _static variant is used since _shared reuses *.o from the static variant
  67. cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
  68. cflags := cc.Args["cFlags"]
  69. if !strings.Contains(cflags, "-Imy_include") {
  70. t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
  71. }
  72. // test if libsystem is linked to the stub
  73. ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
  74. libflags := ld.Args["libFlags"]
  75. stubPaths := GetOutputPaths(ctx, coreVariant, []string{"libvendorpublic"})
  76. if !strings.Contains(libflags, stubPaths[0].String()) {
  77. t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
  78. }
  79. // test if libsystem is linked to the stub
  80. ld = ctx.ModuleForTests("libproduct", productVariant).Rule("ld")
  81. libflags = ld.Args["libFlags"]
  82. stubPaths = GetOutputPaths(ctx, productVariant, []string{"libvendorpublic"})
  83. if !strings.Contains(libflags, stubPaths[0].String()) {
  84. t.Errorf("libflags for libproduct must contain %#v, but was %#v", stubPaths[0], libflags)
  85. }
  86. // test if libvendor is linked to the real shared lib
  87. ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
  88. libflags = ld.Args["libFlags"]
  89. stubPaths = GetOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
  90. if !strings.Contains(libflags, stubPaths[0].String()) {
  91. t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
  92. }
  93. }