sdk_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 cc
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. )
  19. func TestSdkMutator(t *testing.T) {
  20. bp := `
  21. cc_library {
  22. name: "libsdk",
  23. shared_libs: ["libsdkdep"],
  24. sdk_version: "current",
  25. stl: "c++_shared",
  26. }
  27. cc_library {
  28. name: "libsdkdep",
  29. sdk_version: "current",
  30. stl: "c++_shared",
  31. }
  32. cc_library {
  33. name: "libplatform",
  34. shared_libs: ["libsdk"],
  35. stl: "libc++",
  36. }
  37. cc_binary {
  38. name: "platformbinary",
  39. shared_libs: ["libplatform"],
  40. stl: "libc++",
  41. }
  42. cc_binary {
  43. name: "sdkbinary",
  44. shared_libs: ["libsdk"],
  45. sdk_version: "current",
  46. stl: "libc++",
  47. }
  48. `
  49. assertDep := func(t *testing.T, from, to android.TestingModule) {
  50. t.Helper()
  51. found := false
  52. var toFile android.Path
  53. m := to.Module().(*Module)
  54. if toc := m.Toc(); toc.Valid() {
  55. toFile = toc.Path()
  56. } else {
  57. toFile = m.outputFile.Path()
  58. }
  59. toFile = toFile.RelativeToTop()
  60. rule := from.Description("link")
  61. for _, dep := range rule.Implicits {
  62. if dep.String() == toFile.String() {
  63. found = true
  64. }
  65. }
  66. if !found {
  67. t.Errorf("expected %q in %q", toFile.String(), rule.Implicits.Strings())
  68. }
  69. }
  70. ctx := testCc(t, bp)
  71. libsdkNDK := ctx.ModuleForTests("libsdk", "android_arm64_armv8-a_sdk_shared")
  72. libsdkPlatform := ctx.ModuleForTests("libsdk", "android_arm64_armv8-a_shared")
  73. libsdkdepNDK := ctx.ModuleForTests("libsdkdep", "android_arm64_armv8-a_sdk_shared")
  74. libsdkdepPlatform := ctx.ModuleForTests("libsdkdep", "android_arm64_armv8-a_shared")
  75. libplatform := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared")
  76. platformbinary := ctx.ModuleForTests("platformbinary", "android_arm64_armv8-a")
  77. sdkbinary := ctx.ModuleForTests("sdkbinary", "android_arm64_armv8-a_sdk")
  78. libcxxNDK := ctx.ModuleForTests("ndk_libc++_shared", "android_arm64_armv8-a_sdk_shared")
  79. libcxxPlatform := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared")
  80. assertDep(t, libsdkNDK, libsdkdepNDK)
  81. assertDep(t, libsdkPlatform, libsdkdepPlatform)
  82. assertDep(t, libplatform, libsdkPlatform)
  83. assertDep(t, platformbinary, libplatform)
  84. assertDep(t, sdkbinary, libsdkNDK)
  85. assertDep(t, libsdkNDK, libcxxNDK)
  86. assertDep(t, libsdkPlatform, libcxxPlatform)
  87. }