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