blob: 792ffe36452490fa6ff49255008c9a41e03c03cc [file] [log] [blame]
Inseob Kimde5744a2020-12-02 13:14:28 +09001// Copyright 2020 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
Inseob Kimde5744a2020-12-02 13:14:28 +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 cc
15
16// This file defines snapshot prebuilt modules, e.g. vendor snapshot and recovery snapshot. Such
17// snapshot modules will override original source modules with setting BOARD_VNDK_VERSION, with
18// snapshot mutators and snapshot information maps which are also defined in this file.
19
20import (
21 "strings"
Inseob Kimde5744a2020-12-02 13:14:28 +090022
23 "android/soong/android"
Kiyoung Kim48f37782021-07-07 12:42:39 +090024 "android/soong/snapshot"
Jose Galmes6f843bc2020-12-11 13:36:29 -080025
Colin Crosse0edaf92021-01-11 17:31:17 -080026 "github.com/google/blueprint"
Inseob Kimde5744a2020-12-02 13:14:28 +090027)
28
Kiyoung Kim48f37782021-07-07 12:42:39 +090029// This interface overrides snapshot.SnapshotImage to implement cc module specific functions
Ivan Lozanod1dec542021-05-26 15:33:11 -040030type SnapshotImage interface {
Kiyoung Kim48f37782021-07-07 12:42:39 +090031 snapshot.SnapshotImage
Colin Crosse0edaf92021-01-11 17:31:17 -080032
33 // The image variant name for this snapshot image.
34 // For example, recovery snapshot image will return "recovery", and vendor snapshot image will
35 // return "vendor." + version.
36 imageVariantName(cfg android.DeviceConfig) string
37
38 // The variant suffix for snapshot modules. For example, vendor snapshot modules will have
39 // ".vendor" as their suffix.
40 moduleNameSuffix() string
Inseob Kimde5744a2020-12-02 13:14:28 +090041}
42
Kiyoung Kim48f37782021-07-07 12:42:39 +090043type vendorSnapshotImage struct {
44 *snapshot.VendorSnapshotImage
Inseob Kimde5744a2020-12-02 13:14:28 +090045}
46
Kiyoung Kim48f37782021-07-07 12:42:39 +090047type recoverySnapshotImage struct {
48 *snapshot.RecoverySnapshotImage
Inseob Kim7cf14652021-01-06 23:06:52 +090049}
50
Colin Crosse0edaf92021-01-11 17:31:17 -080051func (vendorSnapshotImage) imageVariantName(cfg android.DeviceConfig) string {
52 return VendorVariationPrefix + cfg.VndkVersion()
53}
54
55func (vendorSnapshotImage) moduleNameSuffix() string {
Ivan Lozanoe6d30982021-02-05 10:57:43 -050056 return VendorSuffix
Colin Crosse0edaf92021-01-11 17:31:17 -080057}
58
Colin Crosse0edaf92021-01-11 17:31:17 -080059func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string {
60 return android.RecoveryVariation
61}
62
63func (recoverySnapshotImage) moduleNameSuffix() string {
Matthew Maurer460ee942021-02-11 12:31:46 -080064 return RecoverySuffix
Colin Crosse0edaf92021-01-11 17:31:17 -080065}
66
Kiyoung Kim48f37782021-07-07 12:42:39 +090067// Override existing vendor and recovery snapshot for cc module specific extra functions
68var VendorSnapshotImageSingleton vendorSnapshotImage = vendorSnapshotImage{&snapshot.VendorSnapshotImageSingleton}
Jose Galmesd7d99be2021-11-05 14:04:54 -070069var RecoverySnapshotImageSingleton recoverySnapshotImage = recoverySnapshotImage{&snapshot.RecoverySnapshotImageSingleton}
Kiyoung Kim48f37782021-07-07 12:42:39 +090070
71func RegisterVendorSnapshotModules(ctx android.RegistrationContext) {
72 ctx.RegisterModuleType("vendor_snapshot", vendorSnapshotFactory)
73 ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
74 ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
75 ctx.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory)
76 ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
77 ctx.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory)
78}
79
80func RegisterRecoverySnapshotModules(ctx android.RegistrationContext) {
81 ctx.RegisterModuleType("recovery_snapshot", recoverySnapshotFactory)
82 ctx.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory)
83 ctx.RegisterModuleType("recovery_snapshot_static", RecoverySnapshotStaticFactory)
84 ctx.RegisterModuleType("recovery_snapshot_header", RecoverySnapshotHeaderFactory)
85 ctx.RegisterModuleType("recovery_snapshot_binary", RecoverySnapshotBinaryFactory)
86 ctx.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory)
87}
Inseob Kimde5744a2020-12-02 13:14:28 +090088
89func init() {
Kiyoung Kim48f37782021-07-07 12:42:39 +090090 RegisterVendorSnapshotModules(android.InitRegistrationContext)
91 RegisterRecoverySnapshotModules(android.InitRegistrationContext)
Justin Yund9e05752021-07-13 11:36:24 +090092 android.RegisterMakeVarsProvider(pctx, snapshotMakeVarsProvider)
Inseob Kimde5744a2020-12-02 13:14:28 +090093}
94
95const (
Colin Crosse0edaf92021-01-11 17:31:17 -080096 snapshotHeaderSuffix = "_header."
Ivan Lozanod1dec542021-05-26 15:33:11 -040097 SnapshotSharedSuffix = "_shared."
98 SnapshotStaticSuffix = "_static."
Colin Crosse0edaf92021-01-11 17:31:17 -080099 snapshotBinarySuffix = "_binary."
100 snapshotObjectSuffix = "_object."
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400101 SnapshotRlibSuffix = "_rlib."
Inseob Kimde5744a2020-12-02 13:14:28 +0900102)
103
Colin Crosse0edaf92021-01-11 17:31:17 -0800104type SnapshotProperties struct {
105 Header_libs []string `android:"arch_variant"`
106 Static_libs []string `android:"arch_variant"`
107 Shared_libs []string `android:"arch_variant"`
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400108 Rlibs []string `android:"arch_variant"`
Colin Crosse0edaf92021-01-11 17:31:17 -0800109 Vndk_libs []string `android:"arch_variant"`
110 Binaries []string `android:"arch_variant"`
111 Objects []string `android:"arch_variant"`
112}
Kiyoung Kim48f37782021-07-07 12:42:39 +0900113type snapshotModule struct {
Colin Crosse0edaf92021-01-11 17:31:17 -0800114 android.ModuleBase
115
116 properties SnapshotProperties
117
Ivan Lozanod1dec542021-05-26 15:33:11 -0400118 baseSnapshot BaseSnapshotDecorator
Colin Crosse0edaf92021-01-11 17:31:17 -0800119
Ivan Lozanod1dec542021-05-26 15:33:11 -0400120 image SnapshotImage
Colin Crosse0edaf92021-01-11 17:31:17 -0800121}
122
Kiyoung Kim48f37782021-07-07 12:42:39 +0900123func (s *snapshotModule) ImageMutatorBegin(ctx android.BaseModuleContext) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800124 cfg := ctx.DeviceConfig()
Kiyoung Kim48f37782021-07-07 12:42:39 +0900125 if !s.image.IsUsingSnapshot(cfg) || s.image.TargetSnapshotVersion(cfg) != s.baseSnapshot.Version() {
Colin Crosse0edaf92021-01-11 17:31:17 -0800126 s.Disable()
127 }
128}
129
Kiyoung Kim48f37782021-07-07 12:42:39 +0900130func (s *snapshotModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800131 return false
132}
133
Kiyoung Kim48f37782021-07-07 12:42:39 +0900134func (s *snapshotModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800135 return false
136}
137
Kiyoung Kim48f37782021-07-07 12:42:39 +0900138func (s *snapshotModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800139 return false
140}
141
Kiyoung Kim48f37782021-07-07 12:42:39 +0900142func (s *snapshotModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Inseob Kim08758f02021-04-08 21:13:22 +0900143 return false
144}
145
Kiyoung Kim48f37782021-07-07 12:42:39 +0900146func (s *snapshotModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800147 return false
148}
149
Kiyoung Kim48f37782021-07-07 12:42:39 +0900150func (s *snapshotModule) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800151 return []string{s.image.imageVariantName(ctx.DeviceConfig())}
152}
153
Kiyoung Kim48f37782021-07-07 12:42:39 +0900154func (s *snapshotModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800155}
156
Kiyoung Kim48f37782021-07-07 12:42:39 +0900157func (s *snapshotModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800158 // Nothing, the snapshot module is only used to forward dependency information in DepsMutator.
159}
160
Justin Yun07b9f862021-02-26 14:00:03 +0900161func getSnapshotNameSuffix(moduleSuffix, version, arch string) string {
162 versionSuffix := version
163 if arch != "" {
164 versionSuffix += "." + arch
165 }
166 return moduleSuffix + versionSuffix
167}
Colin Crosse0edaf92021-01-11 17:31:17 -0800168
Kiyoung Kim48f37782021-07-07 12:42:39 +0900169func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Justin Yun07b9f862021-02-26 14:00:03 +0900170 collectSnapshotMap := func(names []string, snapshotSuffix, moduleSuffix string) map[string]string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800171 snapshotMap := make(map[string]string)
Justin Yun48138672021-02-25 18:21:27 +0900172 for _, name := range names {
173 snapshotMap[name] = name +
Justin Yun07b9f862021-02-26 14:00:03 +0900174 getSnapshotNameSuffix(snapshotSuffix+moduleSuffix,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400175 s.baseSnapshot.Version(),
Jose Galmesf9523ed2021-04-06 19:48:10 -0700176 ctx.DeviceConfig().Arches()[0].ArchType.String())
Colin Crosse0edaf92021-01-11 17:31:17 -0800177 }
178 return snapshotMap
179 }
180
181 snapshotSuffix := s.image.moduleNameSuffix()
Justin Yun07b9f862021-02-26 14:00:03 +0900182 headers := collectSnapshotMap(s.properties.Header_libs, snapshotSuffix, snapshotHeaderSuffix)
183 binaries := collectSnapshotMap(s.properties.Binaries, snapshotSuffix, snapshotBinarySuffix)
184 objects := collectSnapshotMap(s.properties.Objects, snapshotSuffix, snapshotObjectSuffix)
Ivan Lozanod1dec542021-05-26 15:33:11 -0400185 staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix)
186 sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400187 rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix)
Justin Yun07b9f862021-02-26 14:00:03 +0900188 vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix)
Colin Crosse0edaf92021-01-11 17:31:17 -0800189 for k, v := range vndkLibs {
190 sharedLibs[k] = v
191 }
Justin Yun07b9f862021-02-26 14:00:03 +0900192
Colin Crosse0edaf92021-01-11 17:31:17 -0800193 ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{
194 HeaderLibs: headers,
195 Binaries: binaries,
196 Objects: objects,
197 StaticLibs: staticLibs,
198 SharedLibs: sharedLibs,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400199 Rlibs: rlibs,
Colin Crosse0edaf92021-01-11 17:31:17 -0800200 })
201}
202
203type SnapshotInfo struct {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400204 HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs map[string]string
Colin Crosse0edaf92021-01-11 17:31:17 -0800205}
206
207var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps")
208
Kiyoung Kim48f37782021-07-07 12:42:39 +0900209var _ android.ImageInterface = (*snapshotModule)(nil)
Colin Crosse0edaf92021-01-11 17:31:17 -0800210
Justin Yund9e05752021-07-13 11:36:24 +0900211func snapshotMakeVarsProvider(ctx android.MakeVarsContext) {
212 snapshotSet := map[string]struct{}{}
213 ctx.VisitAllModules(func(m android.Module) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900214 if s, ok := m.(*snapshotModule); ok {
Justin Yund9e05752021-07-13 11:36:24 +0900215 if _, ok := snapshotSet[s.Name()]; ok {
216 // arch variant generates duplicated modules
217 // skip this as we only need to know the path of the module.
218 return
219 }
220 snapshotSet[s.Name()] = struct{}{}
221 imageNameVersion := strings.Split(s.image.imageVariantName(ctx.DeviceConfig()), ".")
222 ctx.Strict(
223 strings.Join([]string{strings.ToUpper(imageNameVersion[0]), s.baseSnapshot.Version(), "SNAPSHOT_DIR"}, "_"),
224 ctx.ModuleDir(s))
225 }
226 })
227}
228
Colin Crosse0edaf92021-01-11 17:31:17 -0800229func vendorSnapshotFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400230 return snapshotFactory(VendorSnapshotImageSingleton)
Colin Crosse0edaf92021-01-11 17:31:17 -0800231}
232
233func recoverySnapshotFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700234 return snapshotFactory(RecoverySnapshotImageSingleton)
Colin Crosse0edaf92021-01-11 17:31:17 -0800235}
236
Ivan Lozanod1dec542021-05-26 15:33:11 -0400237func snapshotFactory(image SnapshotImage) android.Module {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900238 snapshotModule := &snapshotModule{}
239 snapshotModule.image = image
240 snapshotModule.AddProperties(
241 &snapshotModule.properties,
242 &snapshotModule.baseSnapshot.baseProperties)
243 android.InitAndroidArchModule(snapshotModule, android.DeviceSupported, android.MultilibBoth)
244 return snapshotModule
Colin Crosse0edaf92021-01-11 17:31:17 -0800245}
246
Ivan Lozanod1dec542021-05-26 15:33:11 -0400247type BaseSnapshotDecoratorProperties struct {
Inseob Kimde5744a2020-12-02 13:14:28 +0900248 // snapshot version.
249 Version string
250
251 // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64')
252 Target_arch string
Jose Galmes6f843bc2020-12-11 13:36:29 -0800253
Colin Crossa8890802021-01-22 14:06:33 -0800254 // Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor".
Inseob Kim1b6fb872021-04-05 13:37:02 +0900255 Androidmk_suffix string `blueprint:"mutated"`
Colin Crossa8890802021-01-22 14:06:33 -0800256
Jose Galmes6f843bc2020-12-11 13:36:29 -0800257 // Suffix to be added to the module name, e.g., vendor_shared,
258 // recovery_shared, etc.
Colin Crosse0edaf92021-01-11 17:31:17 -0800259 ModuleSuffix string `blueprint:"mutated"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900260}
261
Ivan Lozanod1dec542021-05-26 15:33:11 -0400262// BaseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot
Inseob Kimde5744a2020-12-02 13:14:28 +0900263// version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't
264// collide with source modules. e.g. the following example module,
265//
Colin Crossd079e0b2022-08-16 10:27:33 -0700266// vendor_snapshot_static {
267// name: "libbase",
268// arch: "arm64",
269// version: 30,
270// ...
271// }
Inseob Kimde5744a2020-12-02 13:14:28 +0900272//
273// will be seen as "libbase.vendor_static.30.arm64" by Soong.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400274type BaseSnapshotDecorator struct {
275 baseProperties BaseSnapshotDecoratorProperties
Kiyoung Kim48f37782021-07-07 12:42:39 +0900276 Image SnapshotImage
Inseob Kimde5744a2020-12-02 13:14:28 +0900277}
278
Ivan Lozanod1dec542021-05-26 15:33:11 -0400279func (p *BaseSnapshotDecorator) Name(name string) string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900280 return name + p.NameSuffix()
281}
282
Ivan Lozanod1dec542021-05-26 15:33:11 -0400283func (p *BaseSnapshotDecorator) NameSuffix() string {
284 return getSnapshotNameSuffix(p.moduleSuffix(), p.Version(), p.Arch())
Inseob Kimde5744a2020-12-02 13:14:28 +0900285}
286
Ivan Lozanod1dec542021-05-26 15:33:11 -0400287func (p *BaseSnapshotDecorator) Version() string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900288 return p.baseProperties.Version
289}
290
Ivan Lozanod1dec542021-05-26 15:33:11 -0400291func (p *BaseSnapshotDecorator) Arch() string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900292 return p.baseProperties.Target_arch
293}
294
Ivan Lozanod1dec542021-05-26 15:33:11 -0400295func (p *BaseSnapshotDecorator) moduleSuffix() string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800296 return p.baseProperties.ModuleSuffix
Jose Galmes6f843bc2020-12-11 13:36:29 -0800297}
298
Ivan Lozanod1dec542021-05-26 15:33:11 -0400299func (p *BaseSnapshotDecorator) IsSnapshotPrebuilt() bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900300 return true
301}
302
Ivan Lozanod1dec542021-05-26 15:33:11 -0400303func (p *BaseSnapshotDecorator) SnapshotAndroidMkSuffix() string {
Colin Crossa8890802021-01-22 14:06:33 -0800304 return p.baseProperties.Androidmk_suffix
305}
306
Ivan Lozanod1dec542021-05-26 15:33:11 -0400307func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleContext, variant string) {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700308 // If there are any 2 or more variations among {core, product, vendor, recovery}
309 // we have to add the androidmk suffix to avoid duplicate modules with the same
310 // name.
311 variations := append(ctx.Target().Variations(), blueprint.Variation{
Bill Peckham4016d7b2021-05-20 11:54:21 -0700312 Mutator: "image",
313 Variation: android.CoreVariation})
314
Ivan Lozanod1dec542021-05-26 15:33:11 -0400315 if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900316 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Bill Peckham4016d7b2021-05-20 11:54:21 -0700317 return
Inseob Kim1b6fb872021-04-05 13:37:02 +0900318 }
Bill Peckham4016d7b2021-05-20 11:54:21 -0700319
Jose Galmes7fdc3362021-05-26 21:16:52 -0700320 variations = append(ctx.Target().Variations(), blueprint.Variation{
Bill Peckham4016d7b2021-05-20 11:54:21 -0700321 Mutator: "image",
322 Variation: ProductVariationPrefix + ctx.DeviceConfig().PlatformVndkVersion()})
323
Ivan Lozanod1dec542021-05-26 15:33:11 -0400324 if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900325 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Bill Peckham4016d7b2021-05-20 11:54:21 -0700326 return
327 }
328
Jose Galmesd7d99be2021-11-05 14:04:54 -0700329 images := []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton}
Jose Galmes7fdc3362021-05-26 21:16:52 -0700330
331 for _, image := range images {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900332 if p.Image == image {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700333 continue
334 }
335 variations = append(ctx.Target().Variations(), blueprint.Variation{
336 Mutator: "image",
337 Variation: image.imageVariantName(ctx.DeviceConfig())})
338
339 if ctx.OtherModuleFarDependencyVariantExists(variations,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400340 ctx.Module().(LinkableInterface).BaseModuleName()+
Jose Galmes7fdc3362021-05-26 21:16:52 -0700341 getSnapshotNameSuffix(
342 image.moduleNameSuffix()+variant,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400343 p.Version(),
Jose Galmes7fdc3362021-05-26 21:16:52 -0700344 ctx.DeviceConfig().Arches()[0].ArchType.String())) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900345 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Jose Galmes7fdc3362021-05-26 21:16:52 -0700346 return
347 }
348 }
349
Bill Peckham4016d7b2021-05-20 11:54:21 -0700350 p.baseProperties.Androidmk_suffix = ""
Inseob Kim1b6fb872021-04-05 13:37:02 +0900351}
352
Inseob Kimde5744a2020-12-02 13:14:28 +0900353// Call this with a module suffix after creating a snapshot module, such as
354// vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400355func (p *BaseSnapshotDecorator) Init(m LinkableInterface, image SnapshotImage, moduleSuffix string) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900356 p.Image = image
Inseob Kim1b6fb872021-04-05 13:37:02 +0900357 p.baseProperties.ModuleSuffix = image.moduleNameSuffix() + moduleSuffix
Inseob Kimde5744a2020-12-02 13:14:28 +0900358 m.AddProperties(&p.baseProperties)
359 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
360 vendorSnapshotLoadHook(ctx, p)
361 })
362}
363
364// vendorSnapshotLoadHook disables snapshots if it's not BOARD_VNDK_VERSION.
365// As vendor snapshot is only for vendor, such modules won't be used at all.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400366func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *BaseSnapshotDecorator) {
367 if p.Version() != ctx.DeviceConfig().VndkVersion() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900368 ctx.Module().Disable()
369 return
370 }
371}
372
Inseob Kimde5744a2020-12-02 13:14:28 +0900373// Module definitions for snapshots of libraries (shared, static, header).
374//
375// Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and
376// static libraries have their prebuilt library files (.so for shared, .a for static) as their src,
377// which can be installed or linked against. Also they export flags needed when linked, such as
378// include directories, c flags, sanitize dependency information, etc.
379//
380// These modules are auto-generated by development/vendor_snapshot/update.py.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400381type SnapshotLibraryProperties struct {
Inseob Kimde5744a2020-12-02 13:14:28 +0900382 // Prebuilt file for each arch.
383 Src *string `android:"arch_variant"`
384
385 // list of directories that will be added to the include path (using -I).
386 Export_include_dirs []string `android:"arch_variant"`
387
388 // list of directories that will be added to the system path (using -isystem).
389 Export_system_include_dirs []string `android:"arch_variant"`
390
391 // list of flags that will be used for any module that links against this module.
392 Export_flags []string `android:"arch_variant"`
393
394 // Whether this prebuilt needs to depend on sanitize ubsan runtime or not.
395 Sanitize_ubsan_dep *bool `android:"arch_variant"`
396
397 // Whether this prebuilt needs to depend on sanitize minimal runtime or not.
398 Sanitize_minimal_dep *bool `android:"arch_variant"`
399}
400
401type snapshotSanitizer interface {
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500402 isSanitizerEnabled(t SanitizerType) bool
403 setSanitizerVariation(t SanitizerType, enabled bool)
Inseob Kimde5744a2020-12-02 13:14:28 +0900404}
405
406type snapshotLibraryDecorator struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400407 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900408 *libraryDecorator
Ivan Lozanod1dec542021-05-26 15:33:11 -0400409 properties SnapshotLibraryProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900410 sanitizerProperties struct {
411 CfiEnabled bool `blueprint:"mutated"`
412
413 // Library flags for cfi variant.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400414 Cfi SnapshotLibraryProperties `android:"arch_variant"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900415 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900416}
417
418func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
419 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
420 return p.libraryDecorator.linkerFlags(ctx, flags)
421}
422
Ivan Lozanod1dec542021-05-26 15:33:11 -0400423func (p *snapshotLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900424 arches := config.Arches()
Ivan Lozanod1dec542021-05-26 15:33:11 -0400425 if len(arches) == 0 || arches[0].ArchType.String() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900426 return false
427 }
428 if !p.header() && p.properties.Src == nil {
429 return false
430 }
431 return true
432}
433
434// cc modules' link functions are to link compiled objects into final binaries.
435// As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are
436// done by normal library decorator, e.g. exporting flags.
437func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700438 var variant string
439 if p.shared() {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400440 variant = SnapshotSharedSuffix
Jose Galmes7fdc3362021-05-26 21:16:52 -0700441 } else if p.static() {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400442 variant = SnapshotStaticSuffix
Jose Galmes7fdc3362021-05-26 21:16:52 -0700443 } else {
444 variant = snapshotHeaderSuffix
445 }
446
Ivan Lozanod1dec542021-05-26 15:33:11 -0400447 p.SetSnapshotAndroidMkSuffix(ctx, variant)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900448
Inseob Kimde5744a2020-12-02 13:14:28 +0900449 if p.header() {
450 return p.libraryDecorator.link(ctx, flags, deps, objs)
451 }
452
453 if p.sanitizerProperties.CfiEnabled {
454 p.properties = p.sanitizerProperties.Cfi
455 }
456
Ivan Lozanod1dec542021-05-26 15:33:11 -0400457 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900458 return nil
459 }
460
Inseob Kimdd0295d2021-04-12 21:09:59 +0900461 // Flags specified directly to this module.
Inseob Kimde5744a2020-12-02 13:14:28 +0900462 p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...)
463 p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...)
464 p.libraryDecorator.reexportFlags(p.properties.Export_flags...)
465
Inseob Kimdd0295d2021-04-12 21:09:59 +0900466 // Flags reexported from dependencies. (e.g. vndk_prebuilt_shared)
467 p.libraryDecorator.reexportDirs(deps.ReexportedDirs...)
468 p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...)
469 p.libraryDecorator.reexportFlags(deps.ReexportedFlags...)
470 p.libraryDecorator.reexportDeps(deps.ReexportedDeps...)
471 p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
472
Inseob Kimde5744a2020-12-02 13:14:28 +0900473 in := android.PathForModuleSrc(ctx, *p.properties.Src)
474 p.unstrippedOutputFile = in
475
476 if p.shared() {
477 libName := in.Base()
Inseob Kimde5744a2020-12-02 13:14:28 +0900478
479 // Optimize out relinking against shared libraries whose interface hasn't changed by
480 // depending on a table of contents file instead of the library itself.
481 tocFile := android.PathForModuleOut(ctx, libName+".toc")
482 p.tocFile = android.OptionalPathForPath(tocFile)
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400483 TransformSharedObjectToToc(ctx, in, tocFile)
Inseob Kimde5744a2020-12-02 13:14:28 +0900484
485 ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
Liz Kammeref6dfea2021-06-08 15:37:09 -0400486 SharedLibrary: in,
487 Target: ctx.Target(),
Inseob Kimde5744a2020-12-02 13:14:28 +0900488
489 TableOfContents: p.tocFile,
490 })
491 }
492
493 if p.static() {
494 depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build()
495 ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
496 StaticLibrary: in,
497
498 TransitiveStaticLibrariesForOrdering: depSet,
499 })
500 }
501
502 p.libraryDecorator.flagExporter.setProvider(ctx)
503
504 return in
505}
506
507func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) {
Inseob Kimbf1b63f2022-01-21 18:12:48 +0900508 if p.MatchesWithDevice(ctx.DeviceConfig()) && p.shared() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900509 p.baseInstaller.install(ctx, file)
510 }
511}
512
513func (p *snapshotLibraryDecorator) nativeCoverage() bool {
514 return false
515}
516
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500517func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900518 switch t {
519 case cfi:
520 return p.sanitizerProperties.Cfi.Src != nil
521 default:
522 return false
523 }
524}
525
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500526func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900527 if !enabled {
528 return
529 }
530 switch t {
531 case cfi:
532 p.sanitizerProperties.CfiEnabled = true
533 default:
534 return
535 }
536}
537
Ivan Lozanod1dec542021-05-26 15:33:11 -0400538func snapshotLibraryFactory(image SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900539 module, library := NewLibrary(android.DeviceSupported)
540
541 module.stl = nil
542 module.sanitize = nil
543 library.disableStripping()
544
545 prebuilt := &snapshotLibraryDecorator{
546 libraryDecorator: library,
547 }
548
549 prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true)
550 prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true)
551
552 // Prevent default system libs (libc, libm, and libdl) from being linked
553 if prebuilt.baseLinker.Properties.System_shared_libs == nil {
554 prebuilt.baseLinker.Properties.System_shared_libs = []string{}
555 }
556
557 module.compiler = nil
558 module.linker = prebuilt
559 module.installer = prebuilt
560
Ivan Lozanod1dec542021-05-26 15:33:11 -0400561 prebuilt.Init(module, image, moduleSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900562 module.AddProperties(
563 &prebuilt.properties,
564 &prebuilt.sanitizerProperties,
565 )
566
567 return module, prebuilt
568}
569
570// vendor_snapshot_shared is a special prebuilt shared library which is auto-generated by
571// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_shared
572// overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
573// is set.
574func VendorSnapshotSharedFactory() android.Module {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400575 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotSharedSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900576 prebuilt.libraryDecorator.BuildOnlyShared()
577 return module.Init()
578}
579
580// recovery_snapshot_shared is a special prebuilt shared library which is auto-generated by
581// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_shared
582// overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
583// is set.
584func RecoverySnapshotSharedFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700585 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotSharedSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900586 prebuilt.libraryDecorator.BuildOnlyShared()
587 return module.Init()
588}
589
590// vendor_snapshot_static is a special prebuilt static library which is auto-generated by
591// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_static
592// overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION
593// is set.
594func VendorSnapshotStaticFactory() android.Module {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400595 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotStaticSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900596 prebuilt.libraryDecorator.BuildOnlyStatic()
597 return module.Init()
598}
599
600// recovery_snapshot_static is a special prebuilt static library which is auto-generated by
601// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_static
602// overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION
603// is set.
604func RecoverySnapshotStaticFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700605 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotStaticSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900606 prebuilt.libraryDecorator.BuildOnlyStatic()
607 return module.Init()
608}
609
610// vendor_snapshot_header is a special header library which is auto-generated by
611// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_header
612// overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION
613// is set.
614func VendorSnapshotHeaderFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400615 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotHeaderSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900616 prebuilt.libraryDecorator.HeaderOnly()
617 return module.Init()
618}
619
620// recovery_snapshot_header is a special header library which is auto-generated by
621// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_header
622// overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION
623// is set.
624func RecoverySnapshotHeaderFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700625 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, snapshotHeaderSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900626 prebuilt.libraryDecorator.HeaderOnly()
627 return module.Init()
628}
629
630var _ snapshotSanitizer = (*snapshotLibraryDecorator)(nil)
631
Inseob Kimde5744a2020-12-02 13:14:28 +0900632// Module definitions for snapshots of executable binaries.
633//
634// Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable
635// binaries (e.g. toybox, sh) as their src, which can be installed.
636//
637// These modules are auto-generated by development/vendor_snapshot/update.py.
638type snapshotBinaryProperties struct {
639 // Prebuilt file for each arch.
640 Src *string `android:"arch_variant"`
641}
642
643type snapshotBinaryDecorator struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400644 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900645 *binaryDecorator
Colin Crossa8890802021-01-22 14:06:33 -0800646 properties snapshotBinaryProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900647}
648
Ivan Lozanod1dec542021-05-26 15:33:11 -0400649func (p *snapshotBinaryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
650 if config.DeviceArch() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900651 return false
652 }
653 if p.properties.Src == nil {
654 return false
655 }
656 return true
657}
658
659// cc modules' link functions are to link compiled objects into final binaries.
660// As snapshots are prebuilts, this just returns the prebuilt binary
661func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400662 p.SetSnapshotAndroidMkSuffix(ctx, snapshotBinarySuffix)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900663
Ivan Lozanod1dec542021-05-26 15:33:11 -0400664 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900665 return nil
666 }
667
668 in := android.PathForModuleSrc(ctx, *p.properties.Src)
669 p.unstrippedOutputFile = in
670 binName := in.Base()
671
Inseob Kimde5744a2020-12-02 13:14:28 +0900672 // use cpExecutable to make it executable
673 outputFile := android.PathForModuleOut(ctx, binName)
674 ctx.Build(pctx, android.BuildParams{
675 Rule: android.CpExecutable,
676 Description: "prebuilt",
677 Output: outputFile,
678 Input: in,
679 })
680
Inseob Kim4d945ee2022-02-24 10:29:18 +0900681 // binary snapshots need symlinking
682 p.setSymlinkList(ctx)
683
Inseob Kimde5744a2020-12-02 13:14:28 +0900684 return outputFile
685}
686
687func (p *snapshotBinaryDecorator) nativeCoverage() bool {
688 return false
689}
690
691// vendor_snapshot_binary is a special prebuilt executable binary which is auto-generated by
692// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary
693// overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
694func VendorSnapshotBinaryFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400695 return snapshotBinaryFactory(VendorSnapshotImageSingleton, snapshotBinarySuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900696}
697
698// recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by
699// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary
700// overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
701func RecoverySnapshotBinaryFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700702 return snapshotBinaryFactory(RecoverySnapshotImageSingleton, snapshotBinarySuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900703}
704
Ivan Lozanod1dec542021-05-26 15:33:11 -0400705func snapshotBinaryFactory(image SnapshotImage, moduleSuffix string) android.Module {
Inseob Kimde5744a2020-12-02 13:14:28 +0900706 module, binary := NewBinary(android.DeviceSupported)
707 binary.baseLinker.Properties.No_libcrt = BoolPtr(true)
708 binary.baseLinker.Properties.Nocrt = BoolPtr(true)
709
710 // Prevent default system libs (libc, libm, and libdl) from being linked
711 if binary.baseLinker.Properties.System_shared_libs == nil {
712 binary.baseLinker.Properties.System_shared_libs = []string{}
713 }
714
715 prebuilt := &snapshotBinaryDecorator{
716 binaryDecorator: binary,
717 }
718
719 module.compiler = nil
720 module.sanitize = nil
721 module.stl = nil
722 module.linker = prebuilt
723
Ivan Lozanod1dec542021-05-26 15:33:11 -0400724 prebuilt.Init(module, image, moduleSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900725 module.AddProperties(&prebuilt.properties)
726 return module.Init()
727}
728
Inseob Kimde5744a2020-12-02 13:14:28 +0900729// Module definitions for snapshots of object files (*.o).
730//
731// Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object
732// files (*.o) as their src.
733//
734// These modules are auto-generated by development/vendor_snapshot/update.py.
735type vendorSnapshotObjectProperties struct {
736 // Prebuilt file for each arch.
737 Src *string `android:"arch_variant"`
738}
739
740type snapshotObjectLinker struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400741 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900742 objectLinker
Colin Crossa8890802021-01-22 14:06:33 -0800743 properties vendorSnapshotObjectProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900744}
745
Ivan Lozanod1dec542021-05-26 15:33:11 -0400746func (p *snapshotObjectLinker) MatchesWithDevice(config android.DeviceConfig) bool {
747 if config.DeviceArch() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900748 return false
749 }
750 if p.properties.Src == nil {
751 return false
752 }
753 return true
754}
755
756// cc modules' link functions are to link compiled objects into final binaries.
757// As snapshots are prebuilts, this just returns the prebuilt binary
758func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400759 p.SetSnapshotAndroidMkSuffix(ctx, snapshotObjectSuffix)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900760
Ivan Lozanod1dec542021-05-26 15:33:11 -0400761 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900762 return nil
763 }
764
Inseob Kimde5744a2020-12-02 13:14:28 +0900765 return android.PathForModuleSrc(ctx, *p.properties.Src)
766}
767
768func (p *snapshotObjectLinker) nativeCoverage() bool {
769 return false
770}
771
772// vendor_snapshot_object is a special prebuilt compiled object file which is auto-generated by
773// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_object
774// overrides the vendor variant of the cc object with the same name, if BOARD_VNDK_VERSION is set.
775func VendorSnapshotObjectFactory() android.Module {
Colin Cross7cabd422021-06-25 14:21:04 -0700776 module := newObject(android.DeviceSupported)
Inseob Kimde5744a2020-12-02 13:14:28 +0900777
778 prebuilt := &snapshotObjectLinker{
779 objectLinker: objectLinker{
780 baseLinker: NewBaseLinker(nil),
781 },
782 }
783 module.linker = prebuilt
784
Ivan Lozanod1dec542021-05-26 15:33:11 -0400785 prebuilt.Init(module, VendorSnapshotImageSingleton, snapshotObjectSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900786 module.AddProperties(&prebuilt.properties)
787 return module.Init()
788}
789
790// recovery_snapshot_object is a special prebuilt compiled object file which is auto-generated by
791// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_object
792// overrides the recovery variant of the cc object with the same name, if BOARD_VNDK_VERSION is set.
793func RecoverySnapshotObjectFactory() android.Module {
Colin Cross7cabd422021-06-25 14:21:04 -0700794 module := newObject(android.DeviceSupported)
Inseob Kimde5744a2020-12-02 13:14:28 +0900795
796 prebuilt := &snapshotObjectLinker{
797 objectLinker: objectLinker{
798 baseLinker: NewBaseLinker(nil),
799 },
800 }
801 module.linker = prebuilt
802
Jose Galmesd7d99be2021-11-05 14:04:54 -0700803 prebuilt.Init(module, RecoverySnapshotImageSingleton, snapshotObjectSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900804 module.AddProperties(&prebuilt.properties)
805 return module.Init()
806}
807
Ivan Lozanod1dec542021-05-26 15:33:11 -0400808type SnapshotInterface interface {
809 MatchesWithDevice(config android.DeviceConfig) bool
810 IsSnapshotPrebuilt() bool
811 Version() string
812 SnapshotAndroidMkSuffix() string
Inseob Kimde5744a2020-12-02 13:14:28 +0900813}
814
Ivan Lozanod1dec542021-05-26 15:33:11 -0400815var _ SnapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
816var _ SnapshotInterface = (*snapshotLibraryDecorator)(nil)
817var _ SnapshotInterface = (*snapshotBinaryDecorator)(nil)
818var _ SnapshotInterface = (*snapshotObjectLinker)(nil)