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