blob: 4484c855dab02e1882f9e181b40c2376007bdca6 [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
25var vendorSnapshotSingleton = SnapshotSingleton{
26 "vendor", // name
27 "SOONG_VENDOR_SNAPSHOT_ZIP", // makeVar
28 android.OptionalPath{}, // snapshotZipFile
29 VendorSnapshotImageSingleton, // Image
30 false, // Fake
31}
32
33var vendorFakeSnapshotSingleton = SnapshotSingleton{
34 "vendor", // name
35 "SOONG_VENDOR_FAKE_SNAPSHOT_ZIP", // makeVar
36 android.OptionalPath{}, // snapshotZipFile
37 VendorSnapshotImageSingleton, // Image
38 true, // Fake
39}
40
41func VendorSnapshotSingleton() android.Singleton {
42 return &vendorSnapshotSingleton
43}
44
45func 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/
52func isVendorProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
53 return VendorSnapshotSingleton().(*SnapshotSingleton).Image.IsProprietaryPath(dir, deviceConfig)
54}
55
56func 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
76var VendorSnapshotImageName = "vendor"
77
78type VendorSnapshotImage struct{}
79
80func (VendorSnapshotImage) Init(ctx android.RegistrationContext) {
LaMont Jones0c10e4d2023-05-16 00:58:37 +000081 ctx.RegisterParallelSingletonType("vendor-snapshot", VendorSnapshotSingleton)
82 ctx.RegisterParallelSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton)
Kiyoung Kim48f37782021-07-07 12:42:39 +090083}
84
85func (VendorSnapshotImage) RegisterAdditionalModule(ctx android.RegistrationContext, name string, factory android.ModuleFactory) {
86 ctx.RegisterModuleType(name, factory)
87}
88
89func (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
94func (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
105func (VendorSnapshotImage) IsProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
106 return isDirectoryExcluded(dir, deviceConfig.VendorSnapshotDirsExcludedMap(), deviceConfig.VendorSnapshotDirsIncludedMap())
107}
108
109func (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
120func (VendorSnapshotImage) IsUsingSnapshot(cfg android.DeviceConfig) bool {
121 vndkVersion := cfg.VndkVersion()
122 return vndkVersion != "current" && vndkVersion != ""
123}
124
125func (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
130func (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
139func (VendorSnapshotImage) ImageName() string {
140 return VendorSnapshotImageName
141}
142
143var VendorSnapshotImageSingleton VendorSnapshotImage
144
145func init() {
146 VendorSnapshotImageSingleton.Init(android.InitRegistrationContext)
147}