blob: e29c446e7d87818d28d40f74096df098822bf241 [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."
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400103 SnapshotDylibSuffix = "_dylib."
Inseob Kimde5744a2020-12-02 13:14:28 +0900104)
105
Colin Crosse0edaf92021-01-11 17:31:17 -0800106type SnapshotProperties struct {
107 Header_libs []string `android:"arch_variant"`
108 Static_libs []string `android:"arch_variant"`
109 Shared_libs []string `android:"arch_variant"`
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400110 Rlibs []string `android:"arch_variant"`
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400111 Dylibs []string `android:"arch_variant"`
Colin Crosse0edaf92021-01-11 17:31:17 -0800112 Vndk_libs []string `android:"arch_variant"`
113 Binaries []string `android:"arch_variant"`
114 Objects []string `android:"arch_variant"`
115}
Kiyoung Kim48f37782021-07-07 12:42:39 +0900116type snapshotModule struct {
Colin Crosse0edaf92021-01-11 17:31:17 -0800117 android.ModuleBase
118
119 properties SnapshotProperties
120
Ivan Lozanod1dec542021-05-26 15:33:11 -0400121 baseSnapshot BaseSnapshotDecorator
Colin Crosse0edaf92021-01-11 17:31:17 -0800122
Ivan Lozanod1dec542021-05-26 15:33:11 -0400123 image SnapshotImage
Colin Crosse0edaf92021-01-11 17:31:17 -0800124}
125
Kiyoung Kim48f37782021-07-07 12:42:39 +0900126func (s *snapshotModule) ImageMutatorBegin(ctx android.BaseModuleContext) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800127 cfg := ctx.DeviceConfig()
Kiyoung Kim48f37782021-07-07 12:42:39 +0900128 if !s.image.IsUsingSnapshot(cfg) || s.image.TargetSnapshotVersion(cfg) != s.baseSnapshot.Version() {
Colin Crosse0edaf92021-01-11 17:31:17 -0800129 s.Disable()
130 }
131}
132
Kiyoung Kim48f37782021-07-07 12:42:39 +0900133func (s *snapshotModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800134 return false
135}
136
Kiyoung Kim48f37782021-07-07 12:42:39 +0900137func (s *snapshotModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800138 return false
139}
140
Kiyoung Kim48f37782021-07-07 12:42:39 +0900141func (s *snapshotModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800142 return false
143}
144
Kiyoung Kim48f37782021-07-07 12:42:39 +0900145func (s *snapshotModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
Inseob Kim08758f02021-04-08 21:13:22 +0900146 return false
147}
148
Kiyoung Kim48f37782021-07-07 12:42:39 +0900149func (s *snapshotModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
Colin Crosse0edaf92021-01-11 17:31:17 -0800150 return false
151}
152
Kiyoung Kim48f37782021-07-07 12:42:39 +0900153func (s *snapshotModule) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800154 return []string{s.image.imageVariantName(ctx.DeviceConfig())}
155}
156
Kiyoung Kim48f37782021-07-07 12:42:39 +0900157func (s *snapshotModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800158}
159
Kiyoung Kim48f37782021-07-07 12:42:39 +0900160func (s *snapshotModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosse0edaf92021-01-11 17:31:17 -0800161 // Nothing, the snapshot module is only used to forward dependency information in DepsMutator.
162}
163
Justin Yun07b9f862021-02-26 14:00:03 +0900164func getSnapshotNameSuffix(moduleSuffix, version, arch string) string {
165 versionSuffix := version
166 if arch != "" {
167 versionSuffix += "." + arch
168 }
169 return moduleSuffix + versionSuffix
170}
Colin Crosse0edaf92021-01-11 17:31:17 -0800171
Kiyoung Kim48f37782021-07-07 12:42:39 +0900172func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Justin Yun07b9f862021-02-26 14:00:03 +0900173 collectSnapshotMap := func(names []string, snapshotSuffix, moduleSuffix string) map[string]string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800174 snapshotMap := make(map[string]string)
Justin Yun48138672021-02-25 18:21:27 +0900175 for _, name := range names {
176 snapshotMap[name] = name +
Justin Yun07b9f862021-02-26 14:00:03 +0900177 getSnapshotNameSuffix(snapshotSuffix+moduleSuffix,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400178 s.baseSnapshot.Version(),
Jose Galmesf9523ed2021-04-06 19:48:10 -0700179 ctx.DeviceConfig().Arches()[0].ArchType.String())
Colin Crosse0edaf92021-01-11 17:31:17 -0800180 }
181 return snapshotMap
182 }
183
184 snapshotSuffix := s.image.moduleNameSuffix()
Justin Yun07b9f862021-02-26 14:00:03 +0900185 headers := collectSnapshotMap(s.properties.Header_libs, snapshotSuffix, snapshotHeaderSuffix)
186 binaries := collectSnapshotMap(s.properties.Binaries, snapshotSuffix, snapshotBinarySuffix)
187 objects := collectSnapshotMap(s.properties.Objects, snapshotSuffix, snapshotObjectSuffix)
Ivan Lozanod1dec542021-05-26 15:33:11 -0400188 staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix)
189 sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix)
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400190 rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix)
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400191 dylibs := collectSnapshotMap(s.properties.Dylibs, snapshotSuffix, SnapshotDylibSuffix)
Justin Yun07b9f862021-02-26 14:00:03 +0900192 vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix)
Colin Crosse0edaf92021-01-11 17:31:17 -0800193 for k, v := range vndkLibs {
194 sharedLibs[k] = v
195 }
Justin Yun07b9f862021-02-26 14:00:03 +0900196
Colin Crosse0edaf92021-01-11 17:31:17 -0800197 ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{
198 HeaderLibs: headers,
199 Binaries: binaries,
200 Objects: objects,
201 StaticLibs: staticLibs,
202 SharedLibs: sharedLibs,
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400203 Rlibs: rlibs,
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400204 Dylibs: dylibs,
Colin Crosse0edaf92021-01-11 17:31:17 -0800205 })
206}
207
208type SnapshotInfo struct {
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400209 HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs, Dylibs map[string]string
Colin Crosse0edaf92021-01-11 17:31:17 -0800210}
211
212var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps")
213
Kiyoung Kim48f37782021-07-07 12:42:39 +0900214var _ android.ImageInterface = (*snapshotModule)(nil)
Colin Crosse0edaf92021-01-11 17:31:17 -0800215
Justin Yund9e05752021-07-13 11:36:24 +0900216func snapshotMakeVarsProvider(ctx android.MakeVarsContext) {
217 snapshotSet := map[string]struct{}{}
218 ctx.VisitAllModules(func(m android.Module) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900219 if s, ok := m.(*snapshotModule); ok {
Justin Yund9e05752021-07-13 11:36:24 +0900220 if _, ok := snapshotSet[s.Name()]; ok {
221 // arch variant generates duplicated modules
222 // skip this as we only need to know the path of the module.
223 return
224 }
225 snapshotSet[s.Name()] = struct{}{}
226 imageNameVersion := strings.Split(s.image.imageVariantName(ctx.DeviceConfig()), ".")
227 ctx.Strict(
228 strings.Join([]string{strings.ToUpper(imageNameVersion[0]), s.baseSnapshot.Version(), "SNAPSHOT_DIR"}, "_"),
229 ctx.ModuleDir(s))
230 }
231 })
232}
233
Colin Crosse0edaf92021-01-11 17:31:17 -0800234func vendorSnapshotFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400235 return snapshotFactory(VendorSnapshotImageSingleton)
Colin Crosse0edaf92021-01-11 17:31:17 -0800236}
237
238func recoverySnapshotFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700239 return snapshotFactory(RecoverySnapshotImageSingleton)
Colin Crosse0edaf92021-01-11 17:31:17 -0800240}
241
Ivan Lozanod1dec542021-05-26 15:33:11 -0400242func snapshotFactory(image SnapshotImage) android.Module {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900243 snapshotModule := &snapshotModule{}
244 snapshotModule.image = image
245 snapshotModule.AddProperties(
246 &snapshotModule.properties,
247 &snapshotModule.baseSnapshot.baseProperties)
248 android.InitAndroidArchModule(snapshotModule, android.DeviceSupported, android.MultilibBoth)
249 return snapshotModule
Colin Crosse0edaf92021-01-11 17:31:17 -0800250}
251
Ivan Lozanod1dec542021-05-26 15:33:11 -0400252type BaseSnapshotDecoratorProperties struct {
Inseob Kimde5744a2020-12-02 13:14:28 +0900253 // snapshot version.
254 Version string
255
256 // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64')
257 Target_arch string
Jose Galmes6f843bc2020-12-11 13:36:29 -0800258
Colin Crossa8890802021-01-22 14:06:33 -0800259 // Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor".
Inseob Kim1b6fb872021-04-05 13:37:02 +0900260 Androidmk_suffix string `blueprint:"mutated"`
Colin Crossa8890802021-01-22 14:06:33 -0800261
Jose Galmes6f843bc2020-12-11 13:36:29 -0800262 // Suffix to be added to the module name, e.g., vendor_shared,
263 // recovery_shared, etc.
Colin Crosse0edaf92021-01-11 17:31:17 -0800264 ModuleSuffix string `blueprint:"mutated"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900265}
266
Ivan Lozanod1dec542021-05-26 15:33:11 -0400267// BaseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot
Inseob Kimde5744a2020-12-02 13:14:28 +0900268// version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't
269// collide with source modules. e.g. the following example module,
270//
Colin Crossd079e0b2022-08-16 10:27:33 -0700271// vendor_snapshot_static {
272// name: "libbase",
273// arch: "arm64",
274// version: 30,
275// ...
276// }
Inseob Kimde5744a2020-12-02 13:14:28 +0900277//
278// will be seen as "libbase.vendor_static.30.arm64" by Soong.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400279type BaseSnapshotDecorator struct {
280 baseProperties BaseSnapshotDecoratorProperties
Kiyoung Kim48f37782021-07-07 12:42:39 +0900281 Image SnapshotImage
Inseob Kimde5744a2020-12-02 13:14:28 +0900282}
283
Ivan Lozanod1dec542021-05-26 15:33:11 -0400284func (p *BaseSnapshotDecorator) Name(name string) string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900285 return name + p.NameSuffix()
286}
287
Ivan Lozanod1dec542021-05-26 15:33:11 -0400288func (p *BaseSnapshotDecorator) NameSuffix() string {
289 return getSnapshotNameSuffix(p.moduleSuffix(), p.Version(), p.Arch())
Inseob Kimde5744a2020-12-02 13:14:28 +0900290}
291
Ivan Lozanod1dec542021-05-26 15:33:11 -0400292func (p *BaseSnapshotDecorator) Version() string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900293 return p.baseProperties.Version
294}
295
Ivan Lozanod1dec542021-05-26 15:33:11 -0400296func (p *BaseSnapshotDecorator) Arch() string {
Inseob Kimde5744a2020-12-02 13:14:28 +0900297 return p.baseProperties.Target_arch
298}
299
Ivan Lozanod1dec542021-05-26 15:33:11 -0400300func (p *BaseSnapshotDecorator) moduleSuffix() string {
Colin Crosse0edaf92021-01-11 17:31:17 -0800301 return p.baseProperties.ModuleSuffix
Jose Galmes6f843bc2020-12-11 13:36:29 -0800302}
303
Ivan Lozanod1dec542021-05-26 15:33:11 -0400304func (p *BaseSnapshotDecorator) IsSnapshotPrebuilt() bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900305 return true
306}
307
Ivan Lozanod1dec542021-05-26 15:33:11 -0400308func (p *BaseSnapshotDecorator) SnapshotAndroidMkSuffix() string {
Colin Crossa8890802021-01-22 14:06:33 -0800309 return p.baseProperties.Androidmk_suffix
310}
311
Ivan Lozanod1dec542021-05-26 15:33:11 -0400312func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleContext, variant string) {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700313 // If there are any 2 or more variations among {core, product, vendor, recovery}
314 // we have to add the androidmk suffix to avoid duplicate modules with the same
315 // name.
316 variations := append(ctx.Target().Variations(), blueprint.Variation{
Bill Peckham4016d7b2021-05-20 11:54:21 -0700317 Mutator: "image",
318 Variation: android.CoreVariation})
319
Ivan Lozanod1dec542021-05-26 15:33:11 -0400320 if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900321 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Bill Peckham4016d7b2021-05-20 11:54:21 -0700322 return
Inseob Kim1b6fb872021-04-05 13:37:02 +0900323 }
Bill Peckham4016d7b2021-05-20 11:54:21 -0700324
Jose Galmes7fdc3362021-05-26 21:16:52 -0700325 variations = append(ctx.Target().Variations(), blueprint.Variation{
Bill Peckham4016d7b2021-05-20 11:54:21 -0700326 Mutator: "image",
327 Variation: ProductVariationPrefix + ctx.DeviceConfig().PlatformVndkVersion()})
328
Ivan Lozanod1dec542021-05-26 15:33:11 -0400329 if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900330 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Bill Peckham4016d7b2021-05-20 11:54:21 -0700331 return
332 }
333
Jose Galmesd7d99be2021-11-05 14:04:54 -0700334 images := []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton}
Jose Galmes7fdc3362021-05-26 21:16:52 -0700335
336 for _, image := range images {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900337 if p.Image == image {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700338 continue
339 }
340 variations = append(ctx.Target().Variations(), blueprint.Variation{
341 Mutator: "image",
342 Variation: image.imageVariantName(ctx.DeviceConfig())})
343
344 if ctx.OtherModuleFarDependencyVariantExists(variations,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400345 ctx.Module().(LinkableInterface).BaseModuleName()+
Jose Galmes7fdc3362021-05-26 21:16:52 -0700346 getSnapshotNameSuffix(
347 image.moduleNameSuffix()+variant,
Ivan Lozanod1dec542021-05-26 15:33:11 -0400348 p.Version(),
Jose Galmes7fdc3362021-05-26 21:16:52 -0700349 ctx.DeviceConfig().Arches()[0].ArchType.String())) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900350 p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix()
Jose Galmes7fdc3362021-05-26 21:16:52 -0700351 return
352 }
353 }
354
Bill Peckham4016d7b2021-05-20 11:54:21 -0700355 p.baseProperties.Androidmk_suffix = ""
Inseob Kim1b6fb872021-04-05 13:37:02 +0900356}
357
Inseob Kimde5744a2020-12-02 13:14:28 +0900358// Call this with a module suffix after creating a snapshot module, such as
359// vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400360func (p *BaseSnapshotDecorator) Init(m LinkableInterface, image SnapshotImage, moduleSuffix string) {
Kiyoung Kim48f37782021-07-07 12:42:39 +0900361 p.Image = image
Inseob Kim1b6fb872021-04-05 13:37:02 +0900362 p.baseProperties.ModuleSuffix = image.moduleNameSuffix() + moduleSuffix
Inseob Kimde5744a2020-12-02 13:14:28 +0900363 m.AddProperties(&p.baseProperties)
364 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
365 vendorSnapshotLoadHook(ctx, p)
366 })
367}
368
369// vendorSnapshotLoadHook disables snapshots if it's not BOARD_VNDK_VERSION.
370// As vendor snapshot is only for vendor, such modules won't be used at all.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400371func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *BaseSnapshotDecorator) {
372 if p.Version() != ctx.DeviceConfig().VndkVersion() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900373 ctx.Module().Disable()
374 return
375 }
376}
377
Inseob Kimde5744a2020-12-02 13:14:28 +0900378// Module definitions for snapshots of libraries (shared, static, header).
379//
380// Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and
381// static libraries have their prebuilt library files (.so for shared, .a for static) as their src,
382// which can be installed or linked against. Also they export flags needed when linked, such as
383// include directories, c flags, sanitize dependency information, etc.
384//
385// These modules are auto-generated by development/vendor_snapshot/update.py.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400386type SnapshotLibraryProperties struct {
Inseob Kimde5744a2020-12-02 13:14:28 +0900387 // Prebuilt file for each arch.
388 Src *string `android:"arch_variant"`
389
390 // list of directories that will be added to the include path (using -I).
391 Export_include_dirs []string `android:"arch_variant"`
392
393 // list of directories that will be added to the system path (using -isystem).
394 Export_system_include_dirs []string `android:"arch_variant"`
395
396 // list of flags that will be used for any module that links against this module.
397 Export_flags []string `android:"arch_variant"`
398
399 // Whether this prebuilt needs to depend on sanitize ubsan runtime or not.
400 Sanitize_ubsan_dep *bool `android:"arch_variant"`
401
402 // Whether this prebuilt needs to depend on sanitize minimal runtime or not.
403 Sanitize_minimal_dep *bool `android:"arch_variant"`
404}
405
Ivan Lozano5467a392023-08-23 14:20:25 -0400406type SnapshotSanitizer interface {
407 IsSanitizerAvailable(t SanitizerType) bool
408 SetSanitizerVariation(t SanitizerType, enabled bool)
409 IsSanitizerEnabled(t SanitizerType) bool
410 IsUnsanitizedVariant() bool
Inseob Kimde5744a2020-12-02 13:14:28 +0900411}
412
413type snapshotLibraryDecorator struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400414 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900415 *libraryDecorator
Ivan Lozanod1dec542021-05-26 15:33:11 -0400416 properties SnapshotLibraryProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900417 sanitizerProperties struct {
Justin Yun39c30312022-11-23 16:20:12 +0900418 SanitizerVariation SanitizerType `blueprint:"mutated"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900419
420 // Library flags for cfi variant.
Ivan Lozanod1dec542021-05-26 15:33:11 -0400421 Cfi SnapshotLibraryProperties `android:"arch_variant"`
Justin Yun39c30312022-11-23 16:20:12 +0900422
423 // Library flags for hwasan variant.
424 Hwasan SnapshotLibraryProperties `android:"arch_variant"`
Inseob Kimde5744a2020-12-02 13:14:28 +0900425 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900426}
427
428func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
429 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
430 return p.libraryDecorator.linkerFlags(ctx, flags)
431}
432
Ivan Lozanod1dec542021-05-26 15:33:11 -0400433func (p *snapshotLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900434 arches := config.Arches()
Ivan Lozanod1dec542021-05-26 15:33:11 -0400435 if len(arches) == 0 || arches[0].ArchType.String() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900436 return false
437 }
438 if !p.header() && p.properties.Src == nil {
439 return false
440 }
441 return true
442}
443
444// cc modules' link functions are to link compiled objects into final binaries.
445// As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are
446// done by normal library decorator, e.g. exporting flags.
447func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Jose Galmes7fdc3362021-05-26 21:16:52 -0700448 var variant string
449 if p.shared() {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400450 variant = SnapshotSharedSuffix
Jose Galmes7fdc3362021-05-26 21:16:52 -0700451 } else if p.static() {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400452 variant = SnapshotStaticSuffix
Jose Galmes7fdc3362021-05-26 21:16:52 -0700453 } else {
454 variant = snapshotHeaderSuffix
455 }
456
Ivan Lozanod1dec542021-05-26 15:33:11 -0400457 p.SetSnapshotAndroidMkSuffix(ctx, variant)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900458
Inseob Kimde5744a2020-12-02 13:14:28 +0900459 if p.header() {
460 return p.libraryDecorator.link(ctx, flags, deps, objs)
461 }
462
Ivan Lozano5467a392023-08-23 14:20:25 -0400463 if p.IsSanitizerEnabled(cfi) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900464 p.properties = p.sanitizerProperties.Cfi
Ivan Lozano5467a392023-08-23 14:20:25 -0400465 } else if p.IsSanitizerEnabled(Hwasan) {
Justin Yun39c30312022-11-23 16:20:12 +0900466 p.properties = p.sanitizerProperties.Hwasan
Inseob Kimde5744a2020-12-02 13:14:28 +0900467 }
468
Ivan Lozanod1dec542021-05-26 15:33:11 -0400469 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900470 return nil
471 }
472
Inseob Kimdd0295d2021-04-12 21:09:59 +0900473 // Flags specified directly to this module.
Inseob Kimde5744a2020-12-02 13:14:28 +0900474 p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...)
475 p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...)
476 p.libraryDecorator.reexportFlags(p.properties.Export_flags...)
477
Inseob Kimdd0295d2021-04-12 21:09:59 +0900478 // Flags reexported from dependencies. (e.g. vndk_prebuilt_shared)
479 p.libraryDecorator.reexportDirs(deps.ReexportedDirs...)
480 p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...)
481 p.libraryDecorator.reexportFlags(deps.ReexportedFlags...)
482 p.libraryDecorator.reexportDeps(deps.ReexportedDeps...)
483 p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
484
Inseob Kimde5744a2020-12-02 13:14:28 +0900485 in := android.PathForModuleSrc(ctx, *p.properties.Src)
486 p.unstrippedOutputFile = in
487
488 if p.shared() {
489 libName := in.Base()
Inseob Kimde5744a2020-12-02 13:14:28 +0900490
491 // Optimize out relinking against shared libraries whose interface hasn't changed by
492 // depending on a table of contents file instead of the library itself.
493 tocFile := android.PathForModuleOut(ctx, libName+".toc")
494 p.tocFile = android.OptionalPathForPath(tocFile)
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400495 TransformSharedObjectToToc(ctx, in, tocFile)
Inseob Kimde5744a2020-12-02 13:14:28 +0900496
497 ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
Liz Kammeref6dfea2021-06-08 15:37:09 -0400498 SharedLibrary: in,
499 Target: ctx.Target(),
Inseob Kimde5744a2020-12-02 13:14:28 +0900500
501 TableOfContents: p.tocFile,
502 })
503 }
504
505 if p.static() {
Colin Crossc85750b2022-04-21 12:50:51 -0700506 depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(in).Build()
Inseob Kimde5744a2020-12-02 13:14:28 +0900507 ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
508 StaticLibrary: in,
509
510 TransitiveStaticLibrariesForOrdering: depSet,
511 })
512 }
513
514 p.libraryDecorator.flagExporter.setProvider(ctx)
515
516 return in
517}
518
519func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) {
Inseob Kimbf1b63f2022-01-21 18:12:48 +0900520 if p.MatchesWithDevice(ctx.DeviceConfig()) && p.shared() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900521 p.baseInstaller.install(ctx, file)
522 }
523}
524
525func (p *snapshotLibraryDecorator) nativeCoverage() bool {
526 return false
527}
528
Ivan Lozano5467a392023-08-23 14:20:25 -0400529var _ SnapshotSanitizer = (*snapshotLibraryDecorator)(nil)
Justin Yun24b246a2023-03-16 10:36:16 +0900530
Ivan Lozano5467a392023-08-23 14:20:25 -0400531func (p *snapshotLibraryDecorator) IsSanitizerAvailable(t SanitizerType) bool {
Inseob Kimde5744a2020-12-02 13:14:28 +0900532 switch t {
533 case cfi:
534 return p.sanitizerProperties.Cfi.Src != nil
Justin Yun39c30312022-11-23 16:20:12 +0900535 case Hwasan:
536 return p.sanitizerProperties.Hwasan.Src != nil
Inseob Kimde5744a2020-12-02 13:14:28 +0900537 default:
538 return false
539 }
540}
541
Ivan Lozano5467a392023-08-23 14:20:25 -0400542func (p *snapshotLibraryDecorator) SetSanitizerVariation(t SanitizerType, enabled bool) {
543 if !enabled || p.IsSanitizerEnabled(t) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900544 return
545 }
Ivan Lozano5467a392023-08-23 14:20:25 -0400546 if !p.IsUnsanitizedVariant() {
Justin Yun39c30312022-11-23 16:20:12 +0900547 panic(fmt.Errorf("snapshot Sanitizer must be one of Cfi or Hwasan but not both"))
Inseob Kimde5744a2020-12-02 13:14:28 +0900548 }
Justin Yun39c30312022-11-23 16:20:12 +0900549 p.sanitizerProperties.SanitizerVariation = t
550}
551
Ivan Lozano5467a392023-08-23 14:20:25 -0400552func (p *snapshotLibraryDecorator) IsSanitizerEnabled(t SanitizerType) bool {
Justin Yun39c30312022-11-23 16:20:12 +0900553 return p.sanitizerProperties.SanitizerVariation == t
554}
555
Ivan Lozano5467a392023-08-23 14:20:25 -0400556func (p *snapshotLibraryDecorator) IsUnsanitizedVariant() bool {
557 return !p.IsSanitizerEnabled(Asan) &&
558 !p.IsSanitizerEnabled(Hwasan)
Inseob Kimde5744a2020-12-02 13:14:28 +0900559}
560
Ivan Lozanod1dec542021-05-26 15:33:11 -0400561func snapshotLibraryFactory(image SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900562 module, library := NewLibrary(android.DeviceSupported)
563
564 module.stl = nil
565 module.sanitize = nil
566 library.disableStripping()
567
568 prebuilt := &snapshotLibraryDecorator{
569 libraryDecorator: library,
570 }
571
572 prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true)
573 prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true)
574
575 // Prevent default system libs (libc, libm, and libdl) from being linked
576 if prebuilt.baseLinker.Properties.System_shared_libs == nil {
577 prebuilt.baseLinker.Properties.System_shared_libs = []string{}
578 }
579
580 module.compiler = nil
581 module.linker = prebuilt
582 module.installer = prebuilt
583
Ivan Lozanod1dec542021-05-26 15:33:11 -0400584 prebuilt.Init(module, image, moduleSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900585 module.AddProperties(
586 &prebuilt.properties,
587 &prebuilt.sanitizerProperties,
588 )
589
590 return module, prebuilt
591}
592
593// vendor_snapshot_shared is a special prebuilt shared library which is auto-generated by
594// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_shared
595// overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
596// is set.
597func VendorSnapshotSharedFactory() android.Module {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400598 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotSharedSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900599 prebuilt.libraryDecorator.BuildOnlyShared()
600 return module.Init()
601}
602
603// recovery_snapshot_shared is a special prebuilt shared library which is auto-generated by
604// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_shared
605// overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
606// is set.
607func RecoverySnapshotSharedFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700608 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotSharedSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900609 prebuilt.libraryDecorator.BuildOnlyShared()
610 return module.Init()
611}
612
613// vendor_snapshot_static is a special prebuilt static library which is auto-generated by
614// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_static
615// overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION
616// is set.
617func VendorSnapshotStaticFactory() android.Module {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400618 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotStaticSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900619 prebuilt.libraryDecorator.BuildOnlyStatic()
620 return module.Init()
621}
622
623// recovery_snapshot_static is a special prebuilt static library which is auto-generated by
624// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_static
625// overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION
626// is set.
627func RecoverySnapshotStaticFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700628 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotStaticSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900629 prebuilt.libraryDecorator.BuildOnlyStatic()
630 return module.Init()
631}
632
633// vendor_snapshot_header is a special header library which is auto-generated by
634// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_header
635// overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION
636// is set.
637func VendorSnapshotHeaderFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400638 module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotHeaderSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900639 prebuilt.libraryDecorator.HeaderOnly()
640 return module.Init()
641}
642
643// recovery_snapshot_header is a special header library which is auto-generated by
644// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_header
645// overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION
646// is set.
647func RecoverySnapshotHeaderFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700648 module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, snapshotHeaderSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900649 prebuilt.libraryDecorator.HeaderOnly()
650 return module.Init()
651}
652
Inseob Kimde5744a2020-12-02 13:14:28 +0900653// Module definitions for snapshots of executable binaries.
654//
655// Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable
656// binaries (e.g. toybox, sh) as their src, which can be installed.
657//
658// These modules are auto-generated by development/vendor_snapshot/update.py.
659type snapshotBinaryProperties struct {
660 // Prebuilt file for each arch.
661 Src *string `android:"arch_variant"`
662}
663
664type snapshotBinaryDecorator struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400665 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900666 *binaryDecorator
Colin Crossa8890802021-01-22 14:06:33 -0800667 properties snapshotBinaryProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900668}
669
Ivan Lozanod1dec542021-05-26 15:33:11 -0400670func (p *snapshotBinaryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
671 if config.DeviceArch() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900672 return false
673 }
674 if p.properties.Src == nil {
675 return false
676 }
677 return true
678}
679
680// cc modules' link functions are to link compiled objects into final binaries.
681// As snapshots are prebuilts, this just returns the prebuilt binary
682func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400683 p.SetSnapshotAndroidMkSuffix(ctx, snapshotBinarySuffix)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900684
Ivan Lozanod1dec542021-05-26 15:33:11 -0400685 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900686 return nil
687 }
688
689 in := android.PathForModuleSrc(ctx, *p.properties.Src)
690 p.unstrippedOutputFile = in
691 binName := in.Base()
692
Inseob Kimde5744a2020-12-02 13:14:28 +0900693 // use cpExecutable to make it executable
694 outputFile := android.PathForModuleOut(ctx, binName)
695 ctx.Build(pctx, android.BuildParams{
696 Rule: android.CpExecutable,
697 Description: "prebuilt",
698 Output: outputFile,
699 Input: in,
700 })
701
Inseob Kim4d945ee2022-02-24 10:29:18 +0900702 // binary snapshots need symlinking
703 p.setSymlinkList(ctx)
704
Inseob Kimde5744a2020-12-02 13:14:28 +0900705 return outputFile
706}
707
708func (p *snapshotBinaryDecorator) nativeCoverage() bool {
709 return false
710}
711
712// vendor_snapshot_binary is a special prebuilt executable binary which is auto-generated by
713// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary
714// overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
715func VendorSnapshotBinaryFactory() android.Module {
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400716 return snapshotBinaryFactory(VendorSnapshotImageSingleton, snapshotBinarySuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900717}
718
719// recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by
720// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary
721// overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
722func RecoverySnapshotBinaryFactory() android.Module {
Jose Galmesd7d99be2021-11-05 14:04:54 -0700723 return snapshotBinaryFactory(RecoverySnapshotImageSingleton, snapshotBinarySuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900724}
725
Ivan Lozanod1dec542021-05-26 15:33:11 -0400726func snapshotBinaryFactory(image SnapshotImage, moduleSuffix string) android.Module {
Inseob Kimde5744a2020-12-02 13:14:28 +0900727 module, binary := NewBinary(android.DeviceSupported)
728 binary.baseLinker.Properties.No_libcrt = BoolPtr(true)
729 binary.baseLinker.Properties.Nocrt = BoolPtr(true)
730
731 // Prevent default system libs (libc, libm, and libdl) from being linked
732 if binary.baseLinker.Properties.System_shared_libs == nil {
733 binary.baseLinker.Properties.System_shared_libs = []string{}
734 }
735
736 prebuilt := &snapshotBinaryDecorator{
737 binaryDecorator: binary,
738 }
739
740 module.compiler = nil
741 module.sanitize = nil
742 module.stl = nil
743 module.linker = prebuilt
744
Ivan Lozanod1dec542021-05-26 15:33:11 -0400745 prebuilt.Init(module, image, moduleSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900746 module.AddProperties(&prebuilt.properties)
747 return module.Init()
748}
749
Inseob Kimde5744a2020-12-02 13:14:28 +0900750// Module definitions for snapshots of object files (*.o).
751//
752// Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object
753// files (*.o) as their src.
754//
755// These modules are auto-generated by development/vendor_snapshot/update.py.
756type vendorSnapshotObjectProperties struct {
757 // Prebuilt file for each arch.
758 Src *string `android:"arch_variant"`
759}
760
761type snapshotObjectLinker struct {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400762 BaseSnapshotDecorator
Inseob Kimde5744a2020-12-02 13:14:28 +0900763 objectLinker
Colin Crossa8890802021-01-22 14:06:33 -0800764 properties vendorSnapshotObjectProperties
Inseob Kimde5744a2020-12-02 13:14:28 +0900765}
766
Ivan Lozanod1dec542021-05-26 15:33:11 -0400767func (p *snapshotObjectLinker) MatchesWithDevice(config android.DeviceConfig) bool {
768 if config.DeviceArch() != p.Arch() {
Inseob Kimde5744a2020-12-02 13:14:28 +0900769 return false
770 }
771 if p.properties.Src == nil {
772 return false
773 }
774 return true
775}
776
777// cc modules' link functions are to link compiled objects into final binaries.
778// As snapshots are prebuilts, this just returns the prebuilt binary
779func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400780 p.SetSnapshotAndroidMkSuffix(ctx, snapshotObjectSuffix)
Inseob Kim1b6fb872021-04-05 13:37:02 +0900781
Ivan Lozanod1dec542021-05-26 15:33:11 -0400782 if !p.MatchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900783 return nil
784 }
785
Inseob Kimde5744a2020-12-02 13:14:28 +0900786 return android.PathForModuleSrc(ctx, *p.properties.Src)
787}
788
789func (p *snapshotObjectLinker) nativeCoverage() bool {
790 return false
791}
792
793// vendor_snapshot_object is a special prebuilt compiled object file which is auto-generated by
794// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_object
795// overrides the vendor variant of the cc object with the same name, if BOARD_VNDK_VERSION is set.
796func VendorSnapshotObjectFactory() android.Module {
Colin Cross7cabd422021-06-25 14:21:04 -0700797 module := newObject(android.DeviceSupported)
Inseob Kimde5744a2020-12-02 13:14:28 +0900798
799 prebuilt := &snapshotObjectLinker{
800 objectLinker: objectLinker{
801 baseLinker: NewBaseLinker(nil),
802 },
803 }
804 module.linker = prebuilt
805
Ivan Lozanod1dec542021-05-26 15:33:11 -0400806 prebuilt.Init(module, VendorSnapshotImageSingleton, snapshotObjectSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900807 module.AddProperties(&prebuilt.properties)
Justin Yun08270c62022-12-19 17:01:26 +0900808
809 // vendor_snapshot_object module does not provide sanitizer variants
810 module.sanitize.Properties.Sanitize.Never = BoolPtr(true)
811
Inseob Kimde5744a2020-12-02 13:14:28 +0900812 return module.Init()
813}
814
815// recovery_snapshot_object is a special prebuilt compiled object file which is auto-generated by
816// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_object
817// overrides the recovery variant of the cc object with the same name, if BOARD_VNDK_VERSION is set.
818func RecoverySnapshotObjectFactory() android.Module {
Colin Cross7cabd422021-06-25 14:21:04 -0700819 module := newObject(android.DeviceSupported)
Inseob Kimde5744a2020-12-02 13:14:28 +0900820
821 prebuilt := &snapshotObjectLinker{
822 objectLinker: objectLinker{
823 baseLinker: NewBaseLinker(nil),
824 },
825 }
826 module.linker = prebuilt
827
Jose Galmesd7d99be2021-11-05 14:04:54 -0700828 prebuilt.Init(module, RecoverySnapshotImageSingleton, snapshotObjectSuffix)
Inseob Kimde5744a2020-12-02 13:14:28 +0900829 module.AddProperties(&prebuilt.properties)
830 return module.Init()
831}
832
Ivan Lozanod1dec542021-05-26 15:33:11 -0400833type SnapshotInterface interface {
834 MatchesWithDevice(config android.DeviceConfig) bool
835 IsSnapshotPrebuilt() bool
836 Version() string
837 SnapshotAndroidMkSuffix() string
Inseob Kimde5744a2020-12-02 13:14:28 +0900838}
839
Ivan Lozanod1dec542021-05-26 15:33:11 -0400840var _ SnapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
841var _ SnapshotInterface = (*snapshotLibraryDecorator)(nil)
842var _ SnapshotInterface = (*snapshotBinaryDecorator)(nil)
843var _ SnapshotInterface = (*snapshotObjectLinker)(nil)