snapshot_utils.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2020 The Android Open Source Project
  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. // This file contains utility types and functions for VNDK / vendor snapshot.
  16. import (
  17. "android/soong/android"
  18. )
  19. var (
  20. HeaderExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
  21. )
  22. func (m *Module) IsSnapshotLibrary() bool {
  23. if _, ok := m.linker.(snapshotLibraryInterface); ok {
  24. return true
  25. }
  26. return false
  27. }
  28. func (m *Module) SnapshotHeaders() android.Paths {
  29. if m.IsSnapshotLibrary() {
  30. return m.linker.(snapshotLibraryInterface).snapshotHeaders()
  31. }
  32. return android.Paths{}
  33. }
  34. func (m *Module) Dylib() bool {
  35. return false
  36. }
  37. func (m *Module) Rlib() bool {
  38. return false
  39. }
  40. func (m *Module) SnapshotRuntimeLibs() []string {
  41. return m.Properties.SnapshotRuntimeLibs
  42. }
  43. func (m *Module) SnapshotSharedLibs() []string {
  44. return m.Properties.SnapshotSharedLibs
  45. }
  46. func (m *Module) SnapshotStaticLibs() []string {
  47. return m.Properties.SnapshotStaticLibs
  48. }
  49. // snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
  50. type snapshotLibraryInterface interface {
  51. libraryInterface
  52. // collectHeadersForSnapshot is called in GenerateAndroidBuildActions for snapshot aware
  53. // modules (See isSnapshotAware below).
  54. // This function should gather all headers needed for snapshot.
  55. collectHeadersForSnapshot(ctx android.ModuleContext)
  56. // snapshotHeaders should return collected headers by collectHeadersForSnapshot.
  57. // Calling snapshotHeaders before collectHeadersForSnapshot is an error.
  58. snapshotHeaders() android.Paths
  59. }
  60. var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
  61. var _ snapshotLibraryInterface = (*libraryDecorator)(nil)
  62. // snapshotMap is a helper wrapper to a map from base module name to snapshot module name.
  63. type snapshotMap struct {
  64. snapshots map[string]string
  65. }
  66. func newSnapshotMap() *snapshotMap {
  67. return &snapshotMap{
  68. snapshots: make(map[string]string),
  69. }
  70. }
  71. func snapshotMapKey(name string, arch android.ArchType) string {
  72. return name + ":" + arch.String()
  73. }
  74. // Adds a snapshot name for given module name and architecture.
  75. // e.g. add("libbase", X86, "libbase.vndk.29.x86")
  76. func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) {
  77. s.snapshots[snapshotMapKey(name, arch)] = snapshot
  78. }
  79. // Returns snapshot name for given module name and architecture, if found.
  80. // e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true
  81. func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) {
  82. snapshot, found = s.snapshots[snapshotMapKey(name, arch)]
  83. return snapshot, found
  84. }
  85. // ShouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot.
  86. // If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions.
  87. func ShouldCollectHeadersForSnapshot(ctx android.ModuleContext, m LinkableInterface, apexInfo android.ApexInfo) bool {
  88. if ctx.DeviceConfig().VndkVersion() != "current" &&
  89. ctx.DeviceConfig().RecoverySnapshotVersion() != "current" {
  90. return false
  91. }
  92. if _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok {
  93. return ctx.Config().VndkSnapshotBuildArtifacts()
  94. }
  95. for _, image := range []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton} {
  96. if isSnapshotAware(ctx.DeviceConfig(), m, image.IsProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()), apexInfo, image) {
  97. return true
  98. }
  99. }
  100. return false
  101. }