recovery_snapshot.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 snapshot
  15. import "android/soong/android"
  16. // Interface for modules which can be captured in the recovery snapshot.
  17. type RecoverySnapshotModuleInterface interface {
  18. SnapshotModuleInterfaceBase
  19. InRecovery() bool
  20. ExcludeFromRecoverySnapshot() bool
  21. }
  22. var recoverySnapshotSingleton = SnapshotSingleton{
  23. "recovery", // name
  24. "SOONG_RECOVERY_SNAPSHOT_ZIP", // makeVar
  25. android.OptionalPath{}, // snapshotZipFile
  26. RecoverySnapshotImageSingleton, // Image
  27. false, // Fake
  28. }
  29. func RecoverySnapshotSingleton() android.Singleton {
  30. return &recoverySnapshotSingleton
  31. }
  32. // Determine if a dir under source tree is an SoC-owned proprietary directory based
  33. // on recovery snapshot configuration
  34. // Examples: device/, vendor/
  35. func isRecoveryProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
  36. return RecoverySnapshotSingleton().(*SnapshotSingleton).Image.IsProprietaryPath(dir, deviceConfig)
  37. }
  38. func IsRecoveryProprietaryModule(ctx android.BaseModuleContext) bool {
  39. // Any module in a recovery proprietary path is a recovery proprietary
  40. // module.
  41. if isRecoveryProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) {
  42. return true
  43. }
  44. // However if the module is not in a recovery proprietary path, it may
  45. // still be a recovery proprietary module. This happens for cc modules
  46. // that are excluded from the recovery snapshot, and it means that the
  47. // vendor has assumed control of the framework-provided module.
  48. if c, ok := ctx.Module().(RecoverySnapshotModuleInterface); ok {
  49. if c.ExcludeFromRecoverySnapshot() {
  50. return true
  51. }
  52. }
  53. return false
  54. }
  55. var RecoverySnapshotImageName = "recovery"
  56. type RecoverySnapshotImage struct{}
  57. func (RecoverySnapshotImage) Init(ctx android.RegistrationContext) {
  58. ctx.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton)
  59. }
  60. func (RecoverySnapshotImage) RegisterAdditionalModule(ctx android.RegistrationContext, name string, factory android.ModuleFactory) {
  61. ctx.RegisterModuleType(name, factory)
  62. }
  63. func (RecoverySnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool {
  64. // RECOVERY_SNAPSHOT_VERSION must be set to 'current' in order to generate a
  65. // snapshot.
  66. return ctx.DeviceConfig().RecoverySnapshotVersion() == "current"
  67. }
  68. func (RecoverySnapshotImage) InImage(m SnapshotModuleInterfaceBase) func() bool {
  69. r, ok := m.(RecoverySnapshotModuleInterface)
  70. if !ok {
  71. // This module does not support recovery snapshot
  72. return func() bool { return false }
  73. }
  74. return r.InRecovery
  75. }
  76. func (RecoverySnapshotImage) IsProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
  77. return isDirectoryExcluded(dir, deviceConfig.RecoverySnapshotDirsExcludedMap(), deviceConfig.RecoverySnapshotDirsIncludedMap())
  78. }
  79. func (RecoverySnapshotImage) ExcludeFromSnapshot(m SnapshotModuleInterfaceBase) bool {
  80. r, ok := m.(RecoverySnapshotModuleInterface)
  81. if !ok {
  82. // This module does not support recovery snapshot
  83. return true
  84. }
  85. return r.ExcludeFromRecoverySnapshot()
  86. }
  87. func (RecoverySnapshotImage) IsUsingSnapshot(cfg android.DeviceConfig) bool {
  88. recoverySnapshotVersion := cfg.RecoverySnapshotVersion()
  89. return recoverySnapshotVersion != "current" && recoverySnapshotVersion != ""
  90. }
  91. func (RecoverySnapshotImage) TargetSnapshotVersion(cfg android.DeviceConfig) string {
  92. return cfg.RecoverySnapshotVersion()
  93. }
  94. func (RecoverySnapshotImage) ExcludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool {
  95. // If we're using full snapshot, not directed snapshot, capture every module
  96. if !cfg.DirectedRecoverySnapshot() {
  97. return false
  98. }
  99. // Else, checks if name is in RECOVERY_SNAPSHOT_MODULES.
  100. return !cfg.RecoverySnapshotModules()[name]
  101. }
  102. func (RecoverySnapshotImage) ImageName() string {
  103. return RecoverySnapshotImageName
  104. }
  105. var RecoverySnapshotImageSingleton RecoverySnapshotImage
  106. func init() {
  107. RecoverySnapshotImageSingleton.Init(android.InitRegistrationContext)
  108. }