blob: 570300b9154d7340ee9f37ba667b616cef140715 [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 (
Justin Yun39c30312022-11-23 16:20:12 +090021 "fmt"
Inseob Kimde5744a2020-12-02 13:14:28 +090022 "strings"
Inseob Kimde5744a2020-12-02 13:14:28 +090023
24 "android/soong/android"
Kiyoung Kim48f37782021-07-07 12:42:39 +090025 "android/soong/snapshot"
Jose Galmes6f843bc2020-12-11 13:36:29 -080026
Colin Crosse0edaf92021-01-11 17:31:17 -080027 "github.com/google/blueprint"
Inseob Kimde5744a2020-12-02 13:14:28 +090028)
29
Kiyoung Kim48f37782021-07-07 12:42:39 +090030// This interface overrides snapshot.SnapshotImage to implement cc module specific functions
Ivan Lozanod1dec542021-05-26 15:33:11 -040031type SnapshotImage interface {
Kiyoung Kim48f37782021-07-07 12:42:39 +090032 snapshot.SnapshotImage
Colin Crosse0edaf92021-01-11 17:31:17 -080033
34 // The image variant name for this snapshot image.
35 // For example, recovery snapshot image will return "recovery", and vendor snapshot image will
36 // return "vendor." + version.
37 imageVariantName(cfg android.DeviceConfig) string
38
39 // The variant suffix for snapshot modules. For example, vendor snapshot modules will have
40 // ".vendor" as their suffix.
41 moduleNameSuffix() string
Inseob Kimde5744a2020-12-02 13:14:28 +090042}
43
Kiyoung Kim48f37782021-07-07 12:42:39 +090044type vendorSnapshotImage struct {
45 *snapshot.VendorSnapshotImage
Inseob Kimde5744a2020-12-02 13:14:28 +090046}
47
Kiyoung Kim48f37782021-07-07 12:42:39 +090048type recoverySnapshotImage struct {
49 *snapshot.RecoverySnapshotImage
Inseob Kim7cf14652021-01-06 23:06:52 +090050}
51
Colin Crosse0edaf92021-01-11 17:31:17 -080052func (vendorSnapshotImage) imageVariantName(cfg android.DeviceConfig) string {
53 return VendorVariationPrefix + cfg.VndkVersion()
54}
55
56func (vendorSnapshotImage) moduleNameSuffix() string {
Ivan Lozanoe6d30982021-02-05 10:57:43 -050057 return VendorSuffix
Colin Crosse0edaf92021-01-11 17:31:17 -080058}
59
Colin Crosse0edaf92021-01-11 17:31:17 -080060func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string {
61 return android.RecoveryVariation
62}
63
64func (recoverySnapshotImage) moduleNameSuffix() string {
Matthew Maurer460ee942021-02-11 12:31:46 -080065 return RecoverySuffix
Colin Crosse0edaf92021-01-11 17:31:17 -080066}
67
Kiyoung Kim48f37782021-07-07 12:42:39 +090068// Override existing vendor and recovery snapshot for cc module specific extra functions
69var VendorSnapshotImageSingleton vendorSnapshotImage = vendorSnapshotImage{&snapshot.VendorSnapshotImageSingleton}
Jose Galmesd7d99be2021-11-05 14:04:54 -070070var RecoverySnapshotImageSingleton recoverySnapshotImage = recoverySnapshotImage{&snapshot.RecoverySnapshotImageSingleton}
Kiyoung Kim48f37782021-07-07 12:42:39 +090071
72func RegisterVendorSnapshotModules(ctx android.RegistrationContext) {
73 ctx.RegisterModuleType("vendor_snapshot", vendorSnapshotFactory)
74 ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
75 ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
76 ctx.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory)
77 ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
78 ctx.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory)
79}
80
81func RegisterRecoverySnapshotModules(ctx android.RegistrationContext) {
82 ctx.RegisterModuleType("recovery_snapshot", recoverySnapshotFactory)
83 ctx.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory)
84 ctx.RegisterModuleType("recovery_snapshot_static", RecoverySnapshotStaticFactory)
85 ctx.RegisterModuleType("recovery_snapshot_header", RecoverySnapshotHeaderFactory)
86 ctx.RegisterModuleType("recovery_snapshot_binary", RecoverySnapshotBinaryFactory)
87 ctx.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory)
88}
Inseob Kimde5744a2020-12-02 13:14:28 +090089
90func init() {
Kiyoung Kim48f37782021-07-07 12:42:39 +090091 RegisterVendorSnapshotModules(android.InitRegistrationContext)
92 RegisterRecoverySnapshotModules(android.InitRegistrationContext)
Justin Yund9e05752021-07-13 11:36:24 +090093 android.RegisterMakeVarsProvider(pctx, snapshotMakeVarsProvider)
Inseob Kimde5744a2020-12-02 13:14:28 +090094}
95
96const (
Colin Crosse0edaf92021-01-11 17:31:17 -080097 snapshotHeaderSuffix = "_header."
Ivan Lozanod1dec542021-05-26 15:33:11 -040098 SnapshotSharedSuffix = "_shared."
99 SnapshotStaticSuffix = "_static."
Colin Crosse0edaf92021-01-11 17:31:17 -0800100 snapshotBinarySuffix = "_binary."
101 snapshotObjectSuffix = "_object."
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400102 SnapshotRlibSuffix = "_rlib."
Inseob Kimde5744a2020-12-02 13:14:28 +0900103)
104
Colin Crosse0edaf92021-01-11 17:31:17 -0800105type SnapshotProperties struct {
106 Header_libs []string `android:"arch_variant"`
107 Static_libs []string `android:"arch_variant"`
108 Shared_libs []string `android:"arch_variant"`
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400109 Rlibs []string `android:"arch_variant"`
Colin Crosse0edaf92021-01-11 17:31:17 -0800110 Vndk_libs []string `android:"arch_variant"`
111 Binaries []string `android:"arch_variant"`
112 Objects []string `android:"arch_variant"`
113}
Kiyoung Kim48f37782021-07-07 12:42:39 +0900114type snapshotModule struct {
Colin Crosse0edaf92021-01-11 17:31:17 -0800115 android.ModuleBase
116
117 properties SnapshotProperties
118
Ivan Lozanod1dec542021-05-26 15:33:11 -0400119 baseSnapshot BaseSnapshotDecorator
Colin Crosse0edaf92021-01-11 17:31:17 -0800120
Ivan Lozanod1dec542021-05-26 15:33:11 -0400121 image SnapshotImage
Colin Crosse0edaf92021-01-11 17:31:17 -0800122}
123
Kiyoung Kim48f37782021-07-07 12:42:39 +0900124func (s *snapshotModule) ImageMutatorBegin(ctx android.BaseModuleContext) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800125 cfg := ctx.DeviceConfig()
Kiyoung Kim48f37782021-07-07 12:42:39 +0900126 if !s.image.IsUsingSnapshot(cfg) || s.image.TargetSnapshotVersion(cfg) != s.baseSnapshot.Version() {
Colin Crosse0edaf92021-01-11 17:31:17 -0800127 s.Disable()
128 }
129}
130
Kiyoung Kim48f37782021-07-07 12:42:39 +0900131func (s *snapshotModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800132 return false
133}
134
Kiyoung Kim48f37782021-07-07 12:42:39 +0900135func (s *snapshotModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800136 return false
137}
138
Kiyoung Kim48f37782021-07-07 12:42:39 +0900139func (s *snapshotModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800140 return false
141}
142
Kiyoung Kim48f37782021-07-07 12:42:39 +0900143func (s *snapshotModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Inseob Kim08758f02021-04-08 21:13:22 +0900144 return false
145}
146
Kiyoung Kim48f37782021-07-07 12:42:39 +0900147func (s *snapshotModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800148 return false
149}
150
Kiyoung Kim48f37782021-07-07 12:42:39 +0900151func (s *snapshotModule) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800152 return []string{s.image.imageVariantName(ctx.DeviceConfig())}
153}
154
Kiyoung Kim48f37782021-07-07 12:42:39 +0900155func (s *snapshotModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800156}
157
Kiyoung Kim48f37782021-07-07 12:42:39 +0900158func (s *snapshotModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800159 // Nothing, the snapshot module is only used to forward dependency information in DepsMutator.
160}
161
Justin Yun07b9f862021-02-26 14:00:03 +0900162func getSnapshotNameSuffix(moduleSuffix, version, arch string) string {
163 versionSuffix := version
164 if arch != "" {
165 versionSuffix += "." + arch
166 }
167 return moduleSuffix + versionSuffix
168}
Colin Crosse0edaf92021-01-11 17:31:17 -0800169
Kiyoung Kim48f37782021-07-07 12:42:39 +0900170func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Justin Yun07b9f862021-02-26 14:00:03 +0900171 collectSnapshotMap := func(names []string, snapshotSuffix, moduleSuffix string) map[string]string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800172 snapshotMap := make(map[string]string)
Justin Yun48138672021-02-25 18:21:27 +0900173 for _, name := range names {
174 snapshotMap[name] = name +
Justin Yun07b9f862021-02-26 14:00:03 +0900175 getSnapshotNameSuffix(snapshotSuffix+moduleSuffix,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400176 s.baseSnapshot.Version(),
Jose Galmesf9523ed2021-04-06 19:48:10 -0700177 ctx.DeviceConfig().Arches()[0].ArchType.String())
Colin Crosse0edaf92021-01-11 17:31:17 -0800178 }
179 return snapshotMap
180 }
181
182 snapshotSuffix := s.image.moduleNameSuffix()
Justin Yun07b9f862021-02-26 14:00:03 +0900183 headers := collectSnapshotMap(s.properties.Header_libs, snapshotSuffix, snapshotHeaderSuffix)
184 binaries := collectSnapshotMap(s.properties.Binaries, snapshotSuffix, snapshotBinarySuffix)
185 objects := collectSnapshotMap(s.properties.Objects, snapshotSuffix, snapshotObjectSuffix)
Ivan Lozanod1dec542021-05-26 15:33:11 -0400186 staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix)
187 sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400188 rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix)
Justin Yun07b9f862021-02-26 14:00:03 +0900189 vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix)
Colin Crosse0edaf92021-01-11 17:31:17 -0800190 for k, v := range vndkLibs {
191 sharedLibs[k] = v
192 }
Justin Yun07b9f862021-02-26 14:00:03 +0900193
Colin Crosse0edaf92021-01-11 17:31:17 -0800194 ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{
195 HeaderLibs: headers,
196 Binaries: binaries,
197 Objects: objects,
198 StaticLibs: staticLibs,
199 SharedLibs: sharedLibs,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400200 Rlibs: rlibs,
Colin Crosse0edaf92021-01-11 17:31:17 -0800201 })
202}
203
204type SnapshotInfo struct {
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400205 HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs map[string]string
Colin Crosse0edaf92021-01-11 17:31:17 -0800206}
207
208var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps")
209
Kiyoung Kim48f37782021-07-07 12:42:39 +0900210var _ android.ImageInterface = (*snapshotModule)(nil)
Colin Crosse0edaf92021-01-11 17:31:17 -0800211
Justin Yund9e05752021-07-13 11:36:24 +0900212func snapshotMakeVarsProvider(ctx android.MakeVarsContext) {
213 snapshotSet := map[string]struct{}{}
214 ctx.VisitAllModules(func(m android.Module) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900215 if s, ok := m.(*snapshotModule); ok {
Justin Yund9e05752021-07-13 11:36:24 +0900216 if _, ok := snapshotSet[s.Name()]; ok {
217 // arch variant generates duplicated modules
218 // skip this as we only need to know the path of the module.
219 return
220 }
221 snapshotSet[s.Name()] = struct{}{}
222 imageNameVersion := strings.Split(s.image.imageVariantName(ctx.DeviceConfig()), ".")
223 ctx.Strict(
224 strings.Join([]string{strings.ToUpper(imageNameVersion[0]), s.baseSnapshot.Version(), "SNAPSHOT_DIR"}, "_"),
225 ctx.ModuleDir(s))
226 }
227 })
228}
229
Colin Crosse0edaf92021-01-11 17:31:17 -0800230func vendorSnapshotFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400231 return snapshotFactory(VendorSnapshotImageSingleton)
Colin Crosse0edaf92021-01-11 17:31:17 -0800232}
233
234func recoverySnapshotFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700235 return snapshotFactory(RecoverySnapshotImageSingleton)
Colin Crosse0edaf92021-01-11 17:31:17 -0800236}
237
Ivan Lozanod1dec542021-05-26 15:33:11 -0400238func snapshotFactory(image SnapshotImage) android.Module {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900239 snapshotModule := &snapshotModule{}
240 snapshotModule.image = image
241 snapshotModule.AddProperties(
242 &snapshotModule.properties,
243 &snapshotModule.baseSnapshot.baseProperties)
244 android.InitAndroidArchModule(snapshotModule, android.DeviceSupported, android.MultilibBoth)
245 return snapshotModule
Colin Crosse0edaf92021-01-11 17:31:17 -0800246}
247
Ivan Lozanod1dec542021-05-26 15:33:11 -0400248type BaseSnapshotDecoratorProperties struct {
Inseob Kimde5744a2020-12-02 13:14:28 +0900249 // snapshot version.
250 Version string
251
252 // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64')
253 Target_arch string
Jose Galmes6f843bc2020-12-11 13:36:29 -0800254
Colin Crossa8890802021-01-22 14:06:33 -0800255 // Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor".
Inseob Kim1b6fb872021-04-05 13:37:02 +0900256 Androidmk_suffix string `blueprint:"mutated"`
Colin Crossa8890802021-01-22 14:06:33 -0800257
Jose Galmes6f843bc2020-12-11 13:36:29 -0800258 // Suffix to be added to the module name, e.g., vendor_shared,
259 // recovery_shared, etc.
Colin Crosse0edaf92021-01-11 17:31:17 -0800260 ModuleSuffix string `blueprint:"mutated"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900261}
262
Ivan Lozanod1dec542021-05-26 15:33:11 -0400263// BaseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot
Inseob Kimde5744a2020-12-02 13:14:28 +0900264// version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't
265// collide with source modules. e.g. the following example module,
266//
Colin Crossd079e0b2022-08-16 10:27:33 -0700267// vendor_snapshot_static {
268// name: "libbase",
269// arch: "arm64",
270// version: 30,
271// ...
272// }
Inseob Kimde5744a2020-12-02 13:14:28 +0900273//
274// will be seen as "libbase.vendor_static.30.arm64" by Soong.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400275type BaseSnapshotDecorator struct {
276 baseProperties BaseSnapshotDecoratorProperties
Kiyoung Kim48f37782021-07-07 12:42:39 +0900277 Image SnapshotImage
Inseob Kimde5744a2020-12-02 13:14:28 +0900278}
279
Ivan Lozanod1dec542021-05-26 15:33:11 -0400280func (p *BaseSnapshotDecorator) Name(name string) string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900281 return name + p.NameSuffix()
282}
283
Ivan Lozanod1dec542021-05-26 15:33:11 -0400284func (p *BaseSnapshotDecorator) NameSuffix() string {
285 return getSnapshotNameSuffix(p.moduleSuffix(), p.Version(), p.Arch())
Inseob Kimde5744a2020-12-02 13:14:28 +0900286}
287
Ivan Lozanod1dec542021-05-26 15:33:11 -0400288func (p *BaseSnapshotDecorator) Version() string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900289 return p.baseProperties.Version
290}
291
Ivan Lozanod1dec542021-05-26 15:33:11 -0400292func (p *BaseSnapshotDecorator) Arch() string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900293 return p.baseProperties.Target_arch
294}
295
Ivan Lozanod1dec542021-05-26 15:33:11 -0400296func (p *BaseSnapshotDecorator) moduleSuffix() string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800297 return p.baseProperties.ModuleSuffix
Jose Galmes6f843bc2020-12-11 13:36:29 -0800298}
299
Ivan Lozanod1dec542021-05-26 15:33:11 -0400300func (p *BaseSnapshotDecorator) IsSnapshotPrebuilt() bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900301 return true
302}
303
Ivan Lozanod1dec542021-05-26 15:33:11 -0400304func (p *BaseSnapshotDecorator) SnapshotAndroidMkSuffix() string {
Colin Crossa8890802021-01-22 14:06:33 -0800305 return p.baseProperties.Androidmk_suffix
306}
307
Ivan Lozanod1dec542021-05-26 15:33:11 -0400308func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleContext, variant string) {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700309 // If there are any 2 or more variations among {core, product, vendor, recovery}
310 // we have to add the androidmk suffix to avoid duplicate modules with the same
311 // name.
312 variations := append(ctx.Target().Variations(), blueprint.Variation{
Bill Peckham4016d7b2021-05-20 11:54:21 -0700313 Mutator: "image",
314 Variation: android.CoreVariation})
315
Ivan Lozanod1dec542021-05-26 15:33:11 -0400316 if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900317 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Bill Peckham4016d7b2021-05-20 11:54:21 -0700318 return
Inseob Kim1b6fb872021-04-05 13:37:02 +0900319 }
Bill Peckham4016d7b2021-05-20 11:54:21 -0700320
Jose Galmes7fdc3362021-05-26 21:16:52 -0700321 variations = append(ctx.Target().Variations(), blueprint.Variation{
Bill Peckham4016d7b2021-05-20 11:54:21 -0700322 Mutator: "image",
323 Variation: ProductVariationPrefix + ctx.DeviceConfig().PlatformVndkVersion()})
324
Ivan Lozanod1dec542021-05-26 15:33:11 -0400325 if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900326 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Bill Peckham4016d7b2021-05-20 11:54:21 -0700327 return
328 }
329
Jose Galmesd7d99be2021-11-05 14:04:54 -0700330 images := []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton}
Jose Galmes7fdc3362021-05-26 21:16:52 -0700331
332 for _, image := range images {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900333 if p.Image == image {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700334 continue
335 }
336 variations = append(ctx.Target().Variations(), blueprint.Variation{
337 Mutator: "image",
338 Variation: image.imageVariantName(ctx.DeviceConfig())})
339
340 if ctx.OtherModuleFarDependencyVariantExists(variations,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400341 ctx.Module().(LinkableInterface).BaseModuleName()+
Jose Galmes7fdc3362021-05-26 21:16:52 -0700342 getSnapshotNameSuffix(
343 image.moduleNameSuffix()+variant,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400344 p.Version(),
Jose Galmes7fdc3362021-05-26 21:16:52 -0700345 ctx.DeviceConfig().Arches()[0].ArchType.String())) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900346 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Jose Galmes7fdc3362021-05-26 21:16:52 -0700347 return
348 }
349 }
350
Bill Peckham4016d7b2021-05-20 11:54:21 -0700351 p.baseProperties.Androidmk_suffix = ""
Inseob Kim1b6fb872021-04-05 13:37:02 +0900352}
353
Inseob Kimde5744a2020-12-02 13:14:28 +0900354// Call this with a module suffix after creating a snapshot module, such as
355// vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400356func (p *BaseSnapshotDecorator) Init(m LinkableInterface, image SnapshotImage, moduleSuffix string) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900357 p.Image = image
Inseob Kim1b6fb872021-04-05 13:37:02 +0900358 p.baseProperties.ModuleSuffix = image.moduleNameSuffix() + moduleSuffix
Inseob Kimde5744a2020-12-02 13:14:28 +0900359 m.AddProperties(&p.baseProperties)
360 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
361 vendorSnapshotLoadHook(ctx, p)
362 })
363}
364
365// vendorSnapshotLoadHook disables snapshots if it's not BOARD_VNDK_VERSION.
366// As vendor snapshot is only for vendor, such modules won't be used at all.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400367func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *BaseSnapshotDecorator) {
368 if p.Version() != ctx.DeviceConfig().VndkVersion() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900369 ctx.Module().Disable()
370 return
371 }
372}
373
Inseob Kimde5744a2020-12-02 13:14:28 +0900374// Module definitions for snapshots of libraries (shared, static, header).
375//
376// Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and
377// static libraries have their prebuilt library files (.so for shared, .a for static) as their src,
378// which can be installed or linked against. Also they export flags needed when linked, such as
379// include directories, c flags, sanitize dependency information, etc.
380//
381// These modules are auto-generated by development/vendor_snapshot/update.py.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400382type SnapshotLibraryProperties struct {
Inseob Kimde5744a2020-12-02 13:14:28 +0900383 // Prebuilt file for each arch.
384 Src *string `android:"arch_variant"`
385
386 // list of directories that will be added to the include path (using -I).
387 Export_include_dirs []string `android:"arch_variant"`
388
389 // list of directories that will be added to the system path (using -isystem).
390 Export_system_include_dirs []string `android:"arch_variant"`
391
392 // list of flags that will be used for any module that links against this module.
393 Export_flags []string `android:"arch_variant"`
394
395 // Whether this prebuilt needs to depend on sanitize ubsan runtime or not.
396 Sanitize_ubsan_dep *bool `android:"arch_variant"`
397
398 // Whether this prebuilt needs to depend on sanitize minimal runtime or not.
399 Sanitize_minimal_dep *bool `android:"arch_variant"`
400}
401
402type snapshotSanitizer interface {
Justin Yun39c30312022-11-23 16:20:12 +0900403 isSanitizerAvailable(t SanitizerType) bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500404 setSanitizerVariation(t SanitizerType, enabled bool)
Justin Yun39c30312022-11-23 16:20:12 +0900405 isSanitizerEnabled(t SanitizerType) bool
406 isUnsanitizedVariant() bool
Inseob Kimde5744a2020-12-02 13:14:28 +0900407}
408
409type snapshotLibraryDecorator struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400410 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900411 *libraryDecorator
Ivan Lozanod1dec542021-05-26 15:33:11 -0400412 properties SnapshotLibraryProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900413 sanitizerProperties struct {
Justin Yun39c30312022-11-23 16:20:12 +0900414 SanitizerVariation SanitizerType `blueprint:"mutated"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900415
416 // Library flags for cfi variant.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400417 Cfi SnapshotLibraryProperties `android:"arch_variant"`
Justin Yun39c30312022-11-23 16:20:12 +0900418
419 // Library flags for hwasan variant.
420 Hwasan SnapshotLibraryProperties `android:"arch_variant"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900421 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900422}
423
424func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
425 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
426 return p.libraryDecorator.linkerFlags(ctx, flags)
427}
428
Ivan Lozanod1dec542021-05-26 15:33:11 -0400429func (p *snapshotLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900430 arches := config.Arches()
Ivan Lozanod1dec542021-05-26 15:33:11 -0400431 if len(arches) == 0 || arches[0].ArchType.String() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900432 return false
433 }
434 if !p.header() && p.properties.Src == nil {
435 return false
436 }
437 return true
438}
439
440// cc modules' link functions are to link compiled objects into final binaries.
441// As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are
442// done by normal library decorator, e.g. exporting flags.
443func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700444 var variant string
445 if p.shared() {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400446 variant = SnapshotSharedSuffix
Jose Galmes7fdc3362021-05-26 21:16:52 -0700447 } else if p.static() {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400448 variant = SnapshotStaticSuffix
Jose Galmes7fdc3362021-05-26 21:16:52 -0700449 } else {
450 variant = snapshotHeaderSuffix
451 }
452
Ivan Lozanod1dec542021-05-26 15:33:11 -0400453 p.SetSnapshotAndroidMkSuffix(ctx, variant)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900454
Inseob Kimde5744a2020-12-02 13:14:28 +0900455 if p.header() {
456 return p.libraryDecorator.link(ctx, flags, deps, objs)
457 }
458
Justin Yun39c30312022-11-23 16:20:12 +0900459 if p.isSanitizerEnabled(cfi) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900460 p.properties = p.sanitizerProperties.Cfi
Justin Yun39c30312022-11-23 16:20:12 +0900461 } else if p.isSanitizerEnabled(Hwasan) {
462 p.properties = p.sanitizerProperties.Hwasan
Inseob Kimde5744a2020-12-02 13:14:28 +0900463 }
464
Ivan Lozanod1dec542021-05-26 15:33:11 -0400465 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900466 return nil
467 }
468
Inseob Kimdd0295d2021-04-12 21:09:59 +0900469 // Flags specified directly to this module.
Inseob Kimde5744a2020-12-02 13:14:28 +0900470 p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...)
471 p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...)
472 p.libraryDecorator.reexportFlags(p.properties.Export_flags...)
473
Inseob Kimdd0295d2021-04-12 21:09:59 +0900474 // Flags reexported from dependencies. (e.g. vndk_prebuilt_shared)
475 p.libraryDecorator.reexportDirs(deps.ReexportedDirs...)
476 p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...)
477 p.libraryDecorator.reexportFlags(deps.ReexportedFlags...)
478 p.libraryDecorator.reexportDeps(deps.ReexportedDeps...)
479 p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
480
Inseob Kimde5744a2020-12-02 13:14:28 +0900481 in := android.PathForModuleSrc(ctx, *p.properties.Src)
482 p.unstrippedOutputFile = in
483
484 if p.shared() {
485 libName := in.Base()
Inseob Kimde5744a2020-12-02 13:14:28 +0900486
487 // Optimize out relinking against shared libraries whose interface hasn't changed by
488 // depending on a table of contents file instead of the library itself.
489 tocFile := android.PathForModuleOut(ctx, libName+".toc")
490 p.tocFile = android.OptionalPathForPath(tocFile)
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400491 TransformSharedObjectToToc(ctx, in, tocFile)
Inseob Kimde5744a2020-12-02 13:14:28 +0900492
493 ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
Liz Kammeref6dfea2021-06-08 15:37:09 -0400494 SharedLibrary: in,
495 Target: ctx.Target(),
Inseob Kimde5744a2020-12-02 13:14:28 +0900496
497 TableOfContents: p.tocFile,
498 })
499 }
500
501 if p.static() {
502 depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build()
503 ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
504 StaticLibrary: in,
505
506 TransitiveStaticLibrariesForOrdering: depSet,
507 })
508 }
509
510 p.libraryDecorator.flagExporter.setProvider(ctx)
511
512 return in
513}
514
515func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) {
Inseob Kimbf1b63f2022-01-21 18:12:48 +0900516 if p.MatchesWithDevice(ctx.DeviceConfig()) && p.shared() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900517 p.baseInstaller.install(ctx, file)
518 }
519}
520
521func (p *snapshotLibraryDecorator) nativeCoverage() bool {
522 return false
523}
524
Justin Yun39c30312022-11-23 16:20:12 +0900525func (p *snapshotLibraryDecorator) isSanitizerAvailable(t SanitizerType) bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900526 switch t {
527 case cfi:
528 return p.sanitizerProperties.Cfi.Src != nil
Justin Yun39c30312022-11-23 16:20:12 +0900529 case Hwasan:
530 return p.sanitizerProperties.Hwasan.Src != nil
Inseob Kimde5744a2020-12-02 13:14:28 +0900531 default:
532 return false
533 }
534}
535
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500536func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) {
Justin Yun39c30312022-11-23 16:20:12 +0900537 if !enabled || p.isSanitizerEnabled(t) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900538 return
539 }
Justin Yun39c30312022-11-23 16:20:12 +0900540 if !p.isUnsanitizedVariant() {
541 panic(fmt.Errorf("snapshot Sanitizer must be one of Cfi or Hwasan but not both"))
Inseob Kimde5744a2020-12-02 13:14:28 +0900542 }
Justin Yun39c30312022-11-23 16:20:12 +0900543 p.sanitizerProperties.SanitizerVariation = t
544}
545
546func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool {
547 return p.sanitizerProperties.SanitizerVariation == t
548}
549
550func (p *snapshotLibraryDecorator) isUnsanitizedVariant() bool {
551 return !p.isSanitizerEnabled(Asan) &&
552 !p.isSanitizerEnabled(Hwasan)
Inseob Kimde5744a2020-12-02 13:14:28 +0900553}
554
Ivan Lozanod1dec542021-05-26 15:33:11 -0400555func snapshotLibraryFactory(image SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900556 module, library := NewLibrary(android.DeviceSupported)
557
558 module.stl = nil
559 module.sanitize = nil
560 library.disableStripping()
561
562 prebuilt := &snapshotLibraryDecorator{
563 libraryDecorator: library,
564 }
565
566 prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true)
567 prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true)
568
569 // Prevent default system libs (libc, libm, and libdl) from being linked
570 if prebuilt.baseLinker.Properties.System_shared_libs == nil {
571 prebuilt.baseLinker.Properties.System_shared_libs = []string{}
572 }
573
574 module.compiler = nil
575 module.linker = prebuilt
576 module.installer = prebuilt
577
Ivan Lozanod1dec542021-05-26 15:33:11 -0400578 prebuilt.Init(module, image, moduleSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900579 module.AddProperties(
580 &prebuilt.properties,
581 &prebuilt.sanitizerProperties,
582 )
583
584 return module, prebuilt
585}
586
587// vendor_snapshot_shared is a special prebuilt shared library which is auto-generated by
588// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_shared
589// overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
590// is set.
591func VendorSnapshotSharedFactory() android.Module {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400592 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotSharedSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900593 prebuilt.libraryDecorator.BuildOnlyShared()
594 return module.Init()
595}
596
597// recovery_snapshot_shared is a special prebuilt shared library which is auto-generated by
598// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_shared
599// overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
600// is set.
601func RecoverySnapshotSharedFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700602 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotSharedSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900603 prebuilt.libraryDecorator.BuildOnlyShared()
604 return module.Init()
605}
606
607// vendor_snapshot_static is a special prebuilt static library which is auto-generated by
608// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_static
609// overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION
610// is set.
611func VendorSnapshotStaticFactory() android.Module {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400612 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotStaticSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900613 prebuilt.libraryDecorator.BuildOnlyStatic()
614 return module.Init()
615}
616
617// recovery_snapshot_static is a special prebuilt static library which is auto-generated by
618// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_static
619// overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION
620// is set.
621func RecoverySnapshotStaticFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700622 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotStaticSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900623 prebuilt.libraryDecorator.BuildOnlyStatic()
624 return module.Init()
625}
626
627// vendor_snapshot_header is a special header library which is auto-generated by
628// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_header
629// overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION
630// is set.
631func VendorSnapshotHeaderFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400632 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotHeaderSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900633 prebuilt.libraryDecorator.HeaderOnly()
634 return module.Init()
635}
636
637// recovery_snapshot_header is a special header library which is auto-generated by
638// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_header
639// overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION
640// is set.
641func RecoverySnapshotHeaderFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700642 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, snapshotHeaderSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900643 prebuilt.libraryDecorator.HeaderOnly()
644 return module.Init()
645}
646
647var _ snapshotSanitizer = (*snapshotLibraryDecorator)(nil)
648
Inseob Kimde5744a2020-12-02 13:14:28 +0900649// Module definitions for snapshots of executable binaries.
650//
651// Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable
652// binaries (e.g. toybox, sh) as their src, which can be installed.
653//
654// These modules are auto-generated by development/vendor_snapshot/update.py.
655type snapshotBinaryProperties struct {
656 // Prebuilt file for each arch.
657 Src *string `android:"arch_variant"`
658}
659
660type snapshotBinaryDecorator struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400661 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900662 *binaryDecorator
Colin Crossa8890802021-01-22 14:06:33 -0800663 properties snapshotBinaryProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900664}
665
Ivan Lozanod1dec542021-05-26 15:33:11 -0400666func (p *snapshotBinaryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
667 if config.DeviceArch() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900668 return false
669 }
670 if p.properties.Src == nil {
671 return false
672 }
673 return true
674}
675
676// cc modules' link functions are to link compiled objects into final binaries.
677// As snapshots are prebuilts, this just returns the prebuilt binary
678func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400679 p.SetSnapshotAndroidMkSuffix(ctx, snapshotBinarySuffix)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900680
Ivan Lozanod1dec542021-05-26 15:33:11 -0400681 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900682 return nil
683 }
684
685 in := android.PathForModuleSrc(ctx, *p.properties.Src)
686 p.unstrippedOutputFile = in
687 binName := in.Base()
688
Inseob Kimde5744a2020-12-02 13:14:28 +0900689 // use cpExecutable to make it executable
690 outputFile := android.PathForModuleOut(ctx, binName)
691 ctx.Build(pctx, android.BuildParams{
692 Rule: android.CpExecutable,
693 Description: "prebuilt",
694 Output: outputFile,
695 Input: in,
696 })
697
Inseob Kim4d945ee2022-02-24 10:29:18 +0900698 // binary snapshots need symlinking
699 p.setSymlinkList(ctx)
700
Inseob Kimde5744a2020-12-02 13:14:28 +0900701 return outputFile
702}
703
704func (p *snapshotBinaryDecorator) nativeCoverage() bool {
705 return false
706}
707
708// vendor_snapshot_binary is a special prebuilt executable binary which is auto-generated by
709// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary
710// overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
711func VendorSnapshotBinaryFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400712 return snapshotBinaryFactory(VendorSnapshotImageSingleton, snapshotBinarySuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900713}
714
715// recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by
716// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary
717// overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
718func RecoverySnapshotBinaryFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700719 return snapshotBinaryFactory(RecoverySnapshotImageSingleton, snapshotBinarySuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900720}
721
Ivan Lozanod1dec542021-05-26 15:33:11 -0400722func snapshotBinaryFactory(image SnapshotImage, moduleSuffix string) android.Module {
Inseob Kimde5744a2020-12-02 13:14:28 +0900723 module, binary := NewBinary(android.DeviceSupported)
724 binary.baseLinker.Properties.No_libcrt = BoolPtr(true)
725 binary.baseLinker.Properties.Nocrt = BoolPtr(true)
726
727 // Prevent default system libs (libc, libm, and libdl) from being linked
728 if binary.baseLinker.Properties.System_shared_libs == nil {
729 binary.baseLinker.Properties.System_shared_libs = []string{}
730 }
731
732 prebuilt := &snapshotBinaryDecorator{
733 binaryDecorator: binary,
734 }
735
736 module.compiler = nil
737 module.sanitize = nil
738 module.stl = nil
739 module.linker = prebuilt
740
Ivan Lozanod1dec542021-05-26 15:33:11 -0400741 prebuilt.Init(module, image, moduleSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900742 module.AddProperties(&prebuilt.properties)
743 return module.Init()
744}
745
Inseob Kimde5744a2020-12-02 13:14:28 +0900746// Module definitions for snapshots of object files (*.o).
747//
748// Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object
749// files (*.o) as their src.
750//
751// These modules are auto-generated by development/vendor_snapshot/update.py.
752type vendorSnapshotObjectProperties struct {
753 // Prebuilt file for each arch.
754 Src *string `android:"arch_variant"`
755}
756
757type snapshotObjectLinker struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400758 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900759 objectLinker
Colin Crossa8890802021-01-22 14:06:33 -0800760 properties vendorSnapshotObjectProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900761}
762
Ivan Lozanod1dec542021-05-26 15:33:11 -0400763func (p *snapshotObjectLinker) MatchesWithDevice(config android.DeviceConfig) bool {
764 if config.DeviceArch() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900765 return false
766 }
767 if p.properties.Src == nil {
768 return false
769 }
770 return true
771}
772
773// cc modules' link functions are to link compiled objects into final binaries.
774// As snapshots are prebuilts, this just returns the prebuilt binary
775func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400776 p.SetSnapshotAndroidMkSuffix(ctx, snapshotObjectSuffix)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900777
Ivan Lozanod1dec542021-05-26 15:33:11 -0400778 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900779 return nil
780 }
781
Inseob Kimde5744a2020-12-02 13:14:28 +0900782 return android.PathForModuleSrc(ctx, *p.properties.Src)
783}
784
785func (p *snapshotObjectLinker) nativeCoverage() bool {
786 return false
787}
788
789// vendor_snapshot_object is a special prebuilt compiled object file which is auto-generated by
790// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_object
791// overrides the vendor variant of the cc object with the same name, if BOARD_VNDK_VERSION is set.
792func VendorSnapshotObjectFactory() android.Module {
Colin Cross7cabd422021-06-25 14:21:04 -0700793 module := newObject(android.DeviceSupported)
Inseob Kimde5744a2020-12-02 13:14:28 +0900794
795 prebuilt := &snapshotObjectLinker{
796 objectLinker: objectLinker{
797 baseLinker: NewBaseLinker(nil),
798 },
799 }
800 module.linker = prebuilt
801
Ivan Lozanod1dec542021-05-26 15:33:11 -0400802 prebuilt.Init(module, VendorSnapshotImageSingleton, snapshotObjectSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900803 module.AddProperties(&prebuilt.properties)
804 return module.Init()
805}
806
807// recovery_snapshot_object is a special prebuilt compiled object file which is auto-generated by
808// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_object
809// overrides the recovery variant of the cc object with the same name, if BOARD_VNDK_VERSION is set.
810func RecoverySnapshotObjectFactory() android.Module {
Colin Cross7cabd422021-06-25 14:21:04 -0700811 module := newObject(android.DeviceSupported)
Inseob Kimde5744a2020-12-02 13:14:28 +0900812
813 prebuilt := &snapshotObjectLinker{
814 objectLinker: objectLinker{
815 baseLinker: NewBaseLinker(nil),
816 },
817 }
818 module.linker = prebuilt
819
Jose Galmesd7d99be2021-11-05 14:04:54 -0700820 prebuilt.Init(module, RecoverySnapshotImageSingleton, snapshotObjectSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900821 module.AddProperties(&prebuilt.properties)
822 return module.Init()
823}
824
Ivan Lozanod1dec542021-05-26 15:33:11 -0400825type SnapshotInterface interface {
826 MatchesWithDevice(config android.DeviceConfig) bool
827 IsSnapshotPrebuilt() bool
828 Version() string
829 SnapshotAndroidMkSuffix() string
Inseob Kimde5744a2020-12-02 13:14:28 +0900830}
831
Ivan Lozanod1dec542021-05-26 15:33:11 -0400832var _ SnapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
833var _ SnapshotInterface = (*snapshotLibraryDecorator)(nil)
834var _ SnapshotInterface = (*snapshotBinaryDecorator)(nil)
835var _ SnapshotInterface = (*snapshotObjectLinker)(nil)