snapshot_utils.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2021 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 rust
  15. import (
  16. "android/soong/android"
  17. )
  18. // snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
  19. type snapshotLibraryInterface interface {
  20. libraryInterface
  21. // collectHeadersForSnapshot is called in GenerateAndroidBuildActions for snapshot aware
  22. // modules (See isSnapshotAware below).
  23. // This function should gather all headers needed for snapshot.
  24. collectHeadersForSnapshot(ctx android.ModuleContext, deps PathDeps)
  25. // snapshotHeaders should return collected headers by collectHeadersForSnapshot.
  26. // Calling snapshotHeaders before collectHeadersForSnapshot is an error.
  27. snapshotHeaders() android.Paths
  28. }
  29. func (mod *Module) ExcludeFromVendorSnapshot() bool {
  30. return Bool(mod.Properties.Exclude_from_vendor_snapshot)
  31. }
  32. func (mod *Module) ExcludeFromRecoverySnapshot() bool {
  33. return Bool(mod.Properties.Exclude_from_recovery_snapshot)
  34. }
  35. func (mod *Module) IsSnapshotLibrary() bool {
  36. if lib, ok := mod.compiler.(libraryInterface); ok {
  37. // Rust-native dylibs are not snapshot supported yet. Only snapshot the rlib-std variants of rlibs.
  38. return lib.shared() || lib.static() || (lib.rlib() && lib.rlibStd())
  39. }
  40. return false
  41. }
  42. func (mod *Module) SnapshotRuntimeLibs() []string {
  43. // TODO Rust does not yet support a runtime libs notion similar to CC
  44. return []string{}
  45. }
  46. func (mod *Module) SnapshotSharedLibs() []string {
  47. return mod.Properties.SnapshotSharedLibs
  48. }
  49. func (mod *Module) SnapshotStaticLibs() []string {
  50. return mod.Properties.SnapshotStaticLibs
  51. }
  52. func (mod *Module) Symlinks() []string {
  53. // TODO update this to return the list of symlinks when Rust supports defining symlinks
  54. return nil
  55. }
  56. func (m *Module) SnapshotHeaders() android.Paths {
  57. if l, ok := m.compiler.(snapshotLibraryInterface); ok {
  58. return l.snapshotHeaders()
  59. }
  60. return android.Paths{}
  61. }