vendor_snapshot.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 vendor snapshot.
  17. type VendorSnapshotModuleInterface interface {
  18. SnapshotModuleInterfaceBase
  19. InVendor() bool
  20. ExcludeFromVendorSnapshot() bool
  21. }
  22. var vendorSnapshotSingleton = SnapshotSingleton{
  23. "vendor", // name
  24. "SOONG_VENDOR_SNAPSHOT_ZIP", // makeVar
  25. android.OptionalPath{}, // snapshotZipFile
  26. VendorSnapshotImageSingleton, // Image
  27. false, // Fake
  28. }
  29. var vendorFakeSnapshotSingleton = SnapshotSingleton{
  30. "vendor", // name
  31. "SOONG_VENDOR_FAKE_SNAPSHOT_ZIP", // makeVar
  32. android.OptionalPath{}, // snapshotZipFile
  33. VendorSnapshotImageSingleton, // Image
  34. true, // Fake
  35. }
  36. func VendorSnapshotSingleton() android.Singleton {
  37. return &vendorSnapshotSingleton
  38. }
  39. func VendorFakeSnapshotSingleton() android.Singleton {
  40. return &vendorFakeSnapshotSingleton
  41. }
  42. // Determine if a dir under source tree is an SoC-owned proprietary directory based
  43. // on vendor snapshot configuration
  44. // Examples: device/, vendor/
  45. func isVendorProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
  46. return VendorSnapshotSingleton().(*SnapshotSingleton).Image.IsProprietaryPath(dir, deviceConfig)
  47. }
  48. func IsVendorProprietaryModule(ctx android.BaseModuleContext) bool {
  49. // Any module in a vendor proprietary path is a vendor proprietary
  50. // module.
  51. if isVendorProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) {
  52. return true
  53. }
  54. // However if the module is not in a vendor proprietary path, it may
  55. // still be a vendor proprietary module. This happens for cc modules
  56. // that are excluded from the vendor snapshot, and it means that the
  57. // vendor has assumed control of the framework-provided module.
  58. if c, ok := ctx.Module().(VendorSnapshotModuleInterface); ok {
  59. if c.ExcludeFromVendorSnapshot() {
  60. return true
  61. }
  62. }
  63. return false
  64. }
  65. var VendorSnapshotImageName = "vendor"
  66. type VendorSnapshotImage struct{}
  67. func (VendorSnapshotImage) Init(ctx android.RegistrationContext) {
  68. ctx.RegisterParallelSingletonType("vendor-snapshot", VendorSnapshotSingleton)
  69. ctx.RegisterParallelSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton)
  70. }
  71. func (VendorSnapshotImage) RegisterAdditionalModule(ctx android.RegistrationContext, name string, factory android.ModuleFactory) {
  72. ctx.RegisterModuleType(name, factory)
  73. }
  74. func (VendorSnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool {
  75. // BOARD_VNDK_VERSION must be set to 'current' in order to generate a snapshot.
  76. return ctx.DeviceConfig().VndkVersion() == "current"
  77. }
  78. func (VendorSnapshotImage) InImage(m SnapshotModuleInterfaceBase) func() bool {
  79. v, ok := m.(VendorSnapshotModuleInterface)
  80. if !ok {
  81. // This module does not support Vendor snapshot
  82. return func() bool { return false }
  83. }
  84. return v.InVendor
  85. }
  86. func (VendorSnapshotImage) IsProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
  87. return isDirectoryExcluded(dir, deviceConfig.VendorSnapshotDirsExcludedMap(), deviceConfig.VendorSnapshotDirsIncludedMap())
  88. }
  89. func (VendorSnapshotImage) ExcludeFromSnapshot(m SnapshotModuleInterfaceBase) bool {
  90. v, ok := m.(VendorSnapshotModuleInterface)
  91. if !ok {
  92. // This module does not support Vendor snapshot
  93. return true
  94. }
  95. return v.ExcludeFromVendorSnapshot()
  96. }
  97. func (VendorSnapshotImage) IsUsingSnapshot(cfg android.DeviceConfig) bool {
  98. vndkVersion := cfg.VndkVersion()
  99. return vndkVersion != "current" && vndkVersion != ""
  100. }
  101. func (VendorSnapshotImage) TargetSnapshotVersion(cfg android.DeviceConfig) string {
  102. return cfg.VndkVersion()
  103. }
  104. // returns true iff a given module SHOULD BE EXCLUDED, false if included
  105. func (VendorSnapshotImage) ExcludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool {
  106. // If we're using full snapshot, not directed snapshot, capture every module
  107. if !cfg.DirectedVendorSnapshot() {
  108. return false
  109. }
  110. // Else, checks if name is in VENDOR_SNAPSHOT_MODULES.
  111. return !cfg.VendorSnapshotModules()[name]
  112. }
  113. func (VendorSnapshotImage) ImageName() string {
  114. return VendorSnapshotImageName
  115. }
  116. var VendorSnapshotImageSingleton VendorSnapshotImage
  117. func init() {
  118. VendorSnapshotImageSingleton.Init(android.InitRegistrationContext)
  119. }