ndk_abi.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. "android/soong/android"
  17. )
  18. func init() {
  19. android.RegisterParallelSingletonType("ndk_abi_dump", NdkAbiDumpSingleton)
  20. android.RegisterParallelSingletonType("ndk_abi_diff", NdkAbiDiffSingleton)
  21. }
  22. func getNdkAbiDumpInstallBase(ctx android.PathContext) android.OutputPath {
  23. return android.PathForOutput(ctx).Join(ctx, "abi-dumps/ndk")
  24. }
  25. func getNdkAbiDumpTimestampFile(ctx android.PathContext) android.OutputPath {
  26. return android.PathForOutput(ctx, "ndk_abi_dump.timestamp")
  27. }
  28. func NdkAbiDumpSingleton() android.Singleton {
  29. return &ndkAbiDumpSingleton{}
  30. }
  31. type ndkAbiDumpSingleton struct{}
  32. func (n *ndkAbiDumpSingleton) GenerateBuildActions(ctx android.SingletonContext) {
  33. var depPaths android.Paths
  34. ctx.VisitAllModules(func(module android.Module) {
  35. if !module.Enabled() {
  36. return
  37. }
  38. if m, ok := module.(*Module); ok {
  39. if installer, ok := m.installer.(*stubDecorator); ok {
  40. if canDumpAbi(ctx.Config()) {
  41. depPaths = append(depPaths, installer.abiDumpPath)
  42. }
  43. }
  44. }
  45. })
  46. // `m dump-ndk-abi` will dump the NDK ABI.
  47. // `development/tools/ndk/update_ndk_abi.sh` will dump the NDK ABI and
  48. // update the golden copies in prebuilts/abi-dumps/ndk.
  49. ctx.Build(pctx, android.BuildParams{
  50. Rule: android.Touch,
  51. Output: getNdkAbiDumpTimestampFile(ctx),
  52. Implicits: depPaths,
  53. })
  54. ctx.Phony("dump-ndk-abi", getNdkAbiDumpTimestampFile(ctx))
  55. }
  56. func getNdkAbiDiffTimestampFile(ctx android.PathContext) android.WritablePath {
  57. return android.PathForOutput(ctx, "ndk_abi_diff.timestamp")
  58. }
  59. func NdkAbiDiffSingleton() android.Singleton {
  60. return &ndkAbiDiffSingleton{}
  61. }
  62. type ndkAbiDiffSingleton struct{}
  63. func (n *ndkAbiDiffSingleton) GenerateBuildActions(ctx android.SingletonContext) {
  64. var depPaths android.Paths
  65. ctx.VisitAllModules(func(module android.Module) {
  66. if m, ok := module.(android.Module); ok && !m.Enabled() {
  67. return
  68. }
  69. if m, ok := module.(*Module); ok {
  70. if installer, ok := m.installer.(*stubDecorator); ok {
  71. depPaths = append(depPaths, installer.abiDiffPaths...)
  72. }
  73. }
  74. })
  75. depPaths = append(depPaths, getNdkAbiDumpTimestampFile(ctx))
  76. // `m diff-ndk-abi` will diff the NDK ABI.
  77. ctx.Build(pctx, android.BuildParams{
  78. Rule: android.Touch,
  79. Output: getNdkAbiDiffTimestampFile(ctx),
  80. Implicits: depPaths,
  81. })
  82. ctx.Phony("diff-ndk-abi", getNdkAbiDiffTimestampFile(ctx))
  83. }