Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 1 | // 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 Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 8 | // |
| 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. |
| 14 | package 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 | |
| 20 | import ( |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 21 | "fmt" |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 22 | "strings" |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 23 | |
| 24 | "android/soong/android" |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 25 | "android/soong/snapshot" |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 26 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 27 | "github.com/google/blueprint" |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 28 | ) |
| 29 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 30 | // This interface overrides snapshot.SnapshotImage to implement cc module specific functions |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 31 | type SnapshotImage interface { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 32 | snapshot.SnapshotImage |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 33 | |
| 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 Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 42 | } |
| 43 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 44 | type vendorSnapshotImage struct { |
| 45 | *snapshot.VendorSnapshotImage |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 46 | } |
| 47 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 48 | type recoverySnapshotImage struct { |
| 49 | *snapshot.RecoverySnapshotImage |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 50 | } |
| 51 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 52 | func (vendorSnapshotImage) imageVariantName(cfg android.DeviceConfig) string { |
| 53 | return VendorVariationPrefix + cfg.VndkVersion() |
| 54 | } |
| 55 | |
| 56 | func (vendorSnapshotImage) moduleNameSuffix() string { |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 57 | return VendorSuffix |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 60 | func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string { |
| 61 | return android.RecoveryVariation |
| 62 | } |
| 63 | |
| 64 | func (recoverySnapshotImage) moduleNameSuffix() string { |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 65 | return RecoverySuffix |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 68 | // Override existing vendor and recovery snapshot for cc module specific extra functions |
| 69 | var VendorSnapshotImageSingleton vendorSnapshotImage = vendorSnapshotImage{&snapshot.VendorSnapshotImageSingleton} |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 70 | var RecoverySnapshotImageSingleton recoverySnapshotImage = recoverySnapshotImage{&snapshot.RecoverySnapshotImageSingleton} |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 71 | |
| 72 | func 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 | |
| 81 | func 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 Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 89 | |
| 90 | func init() { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 91 | RegisterVendorSnapshotModules(android.InitRegistrationContext) |
| 92 | RegisterRecoverySnapshotModules(android.InitRegistrationContext) |
Justin Yun | d9e0575 | 2021-07-13 11:36:24 +0900 | [diff] [blame] | 93 | android.RegisterMakeVarsProvider(pctx, snapshotMakeVarsProvider) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | const ( |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 97 | snapshotHeaderSuffix = "_header." |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 98 | SnapshotSharedSuffix = "_shared." |
| 99 | SnapshotStaticSuffix = "_static." |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 100 | snapshotBinarySuffix = "_binary." |
| 101 | snapshotObjectSuffix = "_object." |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 102 | SnapshotRlibSuffix = "_rlib." |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 103 | SnapshotDylibSuffix = "_dylib." |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 104 | ) |
| 105 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 106 | type SnapshotProperties struct { |
| 107 | Header_libs []string `android:"arch_variant"` |
| 108 | Static_libs []string `android:"arch_variant"` |
| 109 | Shared_libs []string `android:"arch_variant"` |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 110 | Rlibs []string `android:"arch_variant"` |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 111 | Dylibs []string `android:"arch_variant"` |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 112 | Vndk_libs []string `android:"arch_variant"` |
| 113 | Binaries []string `android:"arch_variant"` |
| 114 | Objects []string `android:"arch_variant"` |
| 115 | } |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 116 | type snapshotModule struct { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 117 | android.ModuleBase |
| 118 | |
| 119 | properties SnapshotProperties |
| 120 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 121 | baseSnapshot BaseSnapshotDecorator |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 122 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 123 | image SnapshotImage |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 126 | func (s *snapshotModule) ImageMutatorBegin(ctx android.BaseModuleContext) { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 127 | cfg := ctx.DeviceConfig() |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 128 | if !s.image.IsUsingSnapshot(cfg) || s.image.TargetSnapshotVersion(cfg) != s.baseSnapshot.Version() { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 129 | s.Disable() |
| 130 | } |
| 131 | } |
| 132 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 133 | func (s *snapshotModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 134 | return false |
| 135 | } |
| 136 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 137 | func (s *snapshotModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 138 | return false |
| 139 | } |
| 140 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 141 | func (s *snapshotModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 142 | return false |
| 143 | } |
| 144 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 145 | func (s *snapshotModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 146 | return false |
| 147 | } |
| 148 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 149 | func (s *snapshotModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 150 | return false |
| 151 | } |
| 152 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 153 | func (s *snapshotModule) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 154 | return []string{s.image.imageVariantName(ctx.DeviceConfig())} |
| 155 | } |
| 156 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 157 | func (s *snapshotModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 160 | func (s *snapshotModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 161 | // Nothing, the snapshot module is only used to forward dependency information in DepsMutator. |
| 162 | } |
| 163 | |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 164 | func getSnapshotNameSuffix(moduleSuffix, version, arch string) string { |
| 165 | versionSuffix := version |
| 166 | if arch != "" { |
| 167 | versionSuffix += "." + arch |
| 168 | } |
| 169 | return moduleSuffix + versionSuffix |
| 170 | } |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 171 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 172 | func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) { |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 173 | collectSnapshotMap := func(names []string, snapshotSuffix, moduleSuffix string) map[string]string { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 174 | snapshotMap := make(map[string]string) |
Justin Yun | 4813867 | 2021-02-25 18:21:27 +0900 | [diff] [blame] | 175 | for _, name := range names { |
| 176 | snapshotMap[name] = name + |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 177 | getSnapshotNameSuffix(snapshotSuffix+moduleSuffix, |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 178 | s.baseSnapshot.Version(), |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 179 | ctx.DeviceConfig().Arches()[0].ArchType.String()) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 180 | } |
| 181 | return snapshotMap |
| 182 | } |
| 183 | |
| 184 | snapshotSuffix := s.image.moduleNameSuffix() |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 185 | 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 Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 188 | staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix) |
| 189 | sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 190 | rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 191 | dylibs := collectSnapshotMap(s.properties.Dylibs, snapshotSuffix, SnapshotDylibSuffix) |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 192 | vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 193 | for k, v := range vndkLibs { |
| 194 | sharedLibs[k] = v |
| 195 | } |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 196 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 197 | ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{ |
| 198 | HeaderLibs: headers, |
| 199 | Binaries: binaries, |
| 200 | Objects: objects, |
| 201 | StaticLibs: staticLibs, |
| 202 | SharedLibs: sharedLibs, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 203 | Rlibs: rlibs, |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 204 | Dylibs: dylibs, |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 205 | }) |
| 206 | } |
| 207 | |
| 208 | type SnapshotInfo struct { |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 209 | HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs, Dylibs map[string]string |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") |
| 213 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 214 | var _ android.ImageInterface = (*snapshotModule)(nil) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 215 | |
Justin Yun | d9e0575 | 2021-07-13 11:36:24 +0900 | [diff] [blame] | 216 | func snapshotMakeVarsProvider(ctx android.MakeVarsContext) { |
| 217 | snapshotSet := map[string]struct{}{} |
| 218 | ctx.VisitAllModules(func(m android.Module) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 219 | if s, ok := m.(*snapshotModule); ok { |
Justin Yun | d9e0575 | 2021-07-13 11:36:24 +0900 | [diff] [blame] | 220 | 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 Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 234 | func vendorSnapshotFactory() android.Module { |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 235 | return snapshotFactory(VendorSnapshotImageSingleton) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | func recoverySnapshotFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 239 | return snapshotFactory(RecoverySnapshotImageSingleton) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 242 | func snapshotFactory(image SnapshotImage) android.Module { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 243 | 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 Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 252 | type BaseSnapshotDecoratorProperties struct { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 253 | // 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 Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 258 | |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 259 | // Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor". |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 260 | Androidmk_suffix string `blueprint:"mutated"` |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 261 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 262 | // Suffix to be added to the module name, e.g., vendor_shared, |
| 263 | // recovery_shared, etc. |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 264 | ModuleSuffix string `blueprint:"mutated"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 265 | } |
| 266 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 267 | // BaseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 268 | // 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 Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 271 | // vendor_snapshot_static { |
| 272 | // name: "libbase", |
| 273 | // arch: "arm64", |
| 274 | // version: 30, |
| 275 | // ... |
| 276 | // } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 277 | // |
| 278 | // will be seen as "libbase.vendor_static.30.arm64" by Soong. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 279 | type BaseSnapshotDecorator struct { |
| 280 | baseProperties BaseSnapshotDecoratorProperties |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 281 | Image SnapshotImage |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 282 | } |
| 283 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 284 | func (p *BaseSnapshotDecorator) Name(name string) string { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 285 | return name + p.NameSuffix() |
| 286 | } |
| 287 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 288 | func (p *BaseSnapshotDecorator) NameSuffix() string { |
| 289 | return getSnapshotNameSuffix(p.moduleSuffix(), p.Version(), p.Arch()) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 290 | } |
| 291 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 292 | func (p *BaseSnapshotDecorator) Version() string { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 293 | return p.baseProperties.Version |
| 294 | } |
| 295 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 296 | func (p *BaseSnapshotDecorator) Arch() string { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 297 | return p.baseProperties.Target_arch |
| 298 | } |
| 299 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 300 | func (p *BaseSnapshotDecorator) moduleSuffix() string { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 301 | return p.baseProperties.ModuleSuffix |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 304 | func (p *BaseSnapshotDecorator) IsSnapshotPrebuilt() bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 305 | return true |
| 306 | } |
| 307 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 308 | func (p *BaseSnapshotDecorator) SnapshotAndroidMkSuffix() string { |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 309 | return p.baseProperties.Androidmk_suffix |
| 310 | } |
| 311 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 312 | func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleContext, variant string) { |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 313 | // 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 Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 317 | Mutator: "image", |
| 318 | Variation: android.CoreVariation}) |
| 319 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 320 | if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 321 | p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 322 | return |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 323 | } |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 324 | |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 325 | variations = append(ctx.Target().Variations(), blueprint.Variation{ |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 326 | Mutator: "image", |
| 327 | Variation: ProductVariationPrefix + ctx.DeviceConfig().PlatformVndkVersion()}) |
| 328 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 329 | if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 330 | p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 331 | return |
| 332 | } |
| 333 | |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 334 | images := []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton} |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 335 | |
| 336 | for _, image := range images { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 337 | if p.Image == image { |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 338 | 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 Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 345 | ctx.Module().(LinkableInterface).BaseModuleName()+ |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 346 | getSnapshotNameSuffix( |
| 347 | image.moduleNameSuffix()+variant, |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 348 | p.Version(), |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 349 | ctx.DeviceConfig().Arches()[0].ArchType.String())) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 350 | p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 351 | return |
| 352 | } |
| 353 | } |
| 354 | |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 355 | p.baseProperties.Androidmk_suffix = "" |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 356 | } |
| 357 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 358 | // Call this with a module suffix after creating a snapshot module, such as |
| 359 | // vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 360 | func (p *BaseSnapshotDecorator) Init(m LinkableInterface, image SnapshotImage, moduleSuffix string) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 361 | p.Image = image |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 362 | p.baseProperties.ModuleSuffix = image.moduleNameSuffix() + moduleSuffix |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 363 | 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 Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 371 | func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *BaseSnapshotDecorator) { |
| 372 | if p.Version() != ctx.DeviceConfig().VndkVersion() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 373 | ctx.Module().Disable() |
| 374 | return |
| 375 | } |
| 376 | } |
| 377 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 378 | // 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 Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 386 | type SnapshotLibraryProperties struct { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 387 | // 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 Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 406 | type SnapshotSanitizer interface { |
| 407 | IsSanitizerAvailable(t SanitizerType) bool |
| 408 | SetSanitizerVariation(t SanitizerType, enabled bool) |
| 409 | IsSanitizerEnabled(t SanitizerType) bool |
| 410 | IsUnsanitizedVariant() bool |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | type snapshotLibraryDecorator struct { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 414 | BaseSnapshotDecorator |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 415 | *libraryDecorator |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 416 | properties SnapshotLibraryProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 417 | sanitizerProperties struct { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 418 | SanitizerVariation SanitizerType `blueprint:"mutated"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 419 | |
| 420 | // Library flags for cfi variant. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 421 | Cfi SnapshotLibraryProperties `android:"arch_variant"` |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 422 | |
| 423 | // Library flags for hwasan variant. |
| 424 | Hwasan SnapshotLibraryProperties `android:"arch_variant"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 425 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | func (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 Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 433 | func (p *snapshotLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 434 | arches := config.Arches() |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 435 | if len(arches) == 0 || arches[0].ArchType.String() != p.Arch() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 436 | 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. |
| 447 | func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 448 | var variant string |
| 449 | if p.shared() { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 450 | variant = SnapshotSharedSuffix |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 451 | } else if p.static() { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 452 | variant = SnapshotStaticSuffix |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 453 | } else { |
| 454 | variant = snapshotHeaderSuffix |
| 455 | } |
| 456 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 457 | p.SetSnapshotAndroidMkSuffix(ctx, variant) |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 458 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 459 | if p.header() { |
| 460 | return p.libraryDecorator.link(ctx, flags, deps, objs) |
| 461 | } |
| 462 | |
Ivan Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 463 | if p.IsSanitizerEnabled(cfi) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 464 | p.properties = p.sanitizerProperties.Cfi |
Ivan Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 465 | } else if p.IsSanitizerEnabled(Hwasan) { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 466 | p.properties = p.sanitizerProperties.Hwasan |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 467 | } |
| 468 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 469 | if !p.MatchesWithDevice(ctx.DeviceConfig()) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 470 | return nil |
| 471 | } |
| 472 | |
Inseob Kim | dd0295d | 2021-04-12 21:09:59 +0900 | [diff] [blame] | 473 | // Flags specified directly to this module. |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 474 | 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 Kim | dd0295d | 2021-04-12 21:09:59 +0900 | [diff] [blame] | 478 | // 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 Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 485 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 486 | p.unstrippedOutputFile = in |
| 487 | |
| 488 | if p.shared() { |
| 489 | libName := in.Base() |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 490 | |
| 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 Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 495 | TransformSharedObjectToToc(ctx, in, tocFile) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 496 | |
| 497 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
Liz Kammer | ef6dfea | 2021-06-08 15:37:09 -0400 | [diff] [blame] | 498 | SharedLibrary: in, |
| 499 | Target: ctx.Target(), |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 500 | |
| 501 | TableOfContents: p.tocFile, |
| 502 | }) |
| 503 | } |
| 504 | |
| 505 | if p.static() { |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 506 | depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(in).Build() |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 507 | 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 | |
| 519 | func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
Inseob Kim | bf1b63f | 2022-01-21 18:12:48 +0900 | [diff] [blame] | 520 | if p.MatchesWithDevice(ctx.DeviceConfig()) && p.shared() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 521 | p.baseInstaller.install(ctx, file) |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | func (p *snapshotLibraryDecorator) nativeCoverage() bool { |
| 526 | return false |
| 527 | } |
| 528 | |
Ivan Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 529 | var _ SnapshotSanitizer = (*snapshotLibraryDecorator)(nil) |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 530 | |
Ivan Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 531 | func (p *snapshotLibraryDecorator) IsSanitizerAvailable(t SanitizerType) bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 532 | switch t { |
| 533 | case cfi: |
| 534 | return p.sanitizerProperties.Cfi.Src != nil |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 535 | case Hwasan: |
| 536 | return p.sanitizerProperties.Hwasan.Src != nil |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 537 | default: |
| 538 | return false |
| 539 | } |
| 540 | } |
| 541 | |
Ivan Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 542 | func (p *snapshotLibraryDecorator) SetSanitizerVariation(t SanitizerType, enabled bool) { |
| 543 | if !enabled || p.IsSanitizerEnabled(t) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 544 | return |
| 545 | } |
Ivan Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 546 | if !p.IsUnsanitizedVariant() { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 547 | panic(fmt.Errorf("snapshot Sanitizer must be one of Cfi or Hwasan but not both")) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 548 | } |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 549 | p.sanitizerProperties.SanitizerVariation = t |
| 550 | } |
| 551 | |
Ivan Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 552 | func (p *snapshotLibraryDecorator) IsSanitizerEnabled(t SanitizerType) bool { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 553 | return p.sanitizerProperties.SanitizerVariation == t |
| 554 | } |
| 555 | |
Ivan Lozano | 5467a39 | 2023-08-23 14:20:25 -0400 | [diff] [blame^] | 556 | func (p *snapshotLibraryDecorator) IsUnsanitizedVariant() bool { |
| 557 | return !p.IsSanitizerEnabled(Asan) && |
| 558 | !p.IsSanitizerEnabled(Hwasan) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 559 | } |
| 560 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 561 | func snapshotLibraryFactory(image SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 562 | 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 Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 584 | prebuilt.Init(module, image, moduleSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 585 | 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. |
| 597 | func VendorSnapshotSharedFactory() android.Module { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 598 | module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotSharedSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 599 | 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. |
| 607 | func RecoverySnapshotSharedFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 608 | module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotSharedSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 609 | 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. |
| 617 | func VendorSnapshotStaticFactory() android.Module { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 618 | module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotStaticSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 619 | 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. |
| 627 | func RecoverySnapshotStaticFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 628 | module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotStaticSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 629 | 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. |
| 637 | func VendorSnapshotHeaderFactory() android.Module { |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 638 | module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotHeaderSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 639 | 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. |
| 647 | func RecoverySnapshotHeaderFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 648 | module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, snapshotHeaderSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 649 | prebuilt.libraryDecorator.HeaderOnly() |
| 650 | return module.Init() |
| 651 | } |
| 652 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 653 | // 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. |
| 659 | type snapshotBinaryProperties struct { |
| 660 | // Prebuilt file for each arch. |
| 661 | Src *string `android:"arch_variant"` |
| 662 | } |
| 663 | |
| 664 | type snapshotBinaryDecorator struct { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 665 | BaseSnapshotDecorator |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 666 | *binaryDecorator |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 667 | properties snapshotBinaryProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 668 | } |
| 669 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 670 | func (p *snapshotBinaryDecorator) MatchesWithDevice(config android.DeviceConfig) bool { |
| 671 | if config.DeviceArch() != p.Arch() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 672 | 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 |
| 682 | func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 683 | p.SetSnapshotAndroidMkSuffix(ctx, snapshotBinarySuffix) |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 684 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 685 | if !p.MatchesWithDevice(ctx.DeviceConfig()) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 686 | return nil |
| 687 | } |
| 688 | |
| 689 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 690 | p.unstrippedOutputFile = in |
| 691 | binName := in.Base() |
| 692 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 693 | // 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 Kim | 4d945ee | 2022-02-24 10:29:18 +0900 | [diff] [blame] | 702 | // binary snapshots need symlinking |
| 703 | p.setSymlinkList(ctx) |
| 704 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 705 | return outputFile |
| 706 | } |
| 707 | |
| 708 | func (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. |
| 715 | func VendorSnapshotBinaryFactory() android.Module { |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 716 | return snapshotBinaryFactory(VendorSnapshotImageSingleton, snapshotBinarySuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 717 | } |
| 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. |
| 722 | func RecoverySnapshotBinaryFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 723 | return snapshotBinaryFactory(RecoverySnapshotImageSingleton, snapshotBinarySuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 724 | } |
| 725 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 726 | func snapshotBinaryFactory(image SnapshotImage, moduleSuffix string) android.Module { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 727 | 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 Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 745 | prebuilt.Init(module, image, moduleSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 746 | module.AddProperties(&prebuilt.properties) |
| 747 | return module.Init() |
| 748 | } |
| 749 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 750 | // 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. |
| 756 | type vendorSnapshotObjectProperties struct { |
| 757 | // Prebuilt file for each arch. |
| 758 | Src *string `android:"arch_variant"` |
| 759 | } |
| 760 | |
| 761 | type snapshotObjectLinker struct { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 762 | BaseSnapshotDecorator |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 763 | objectLinker |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 764 | properties vendorSnapshotObjectProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 765 | } |
| 766 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 767 | func (p *snapshotObjectLinker) MatchesWithDevice(config android.DeviceConfig) bool { |
| 768 | if config.DeviceArch() != p.Arch() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 769 | 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 |
| 779 | func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 780 | p.SetSnapshotAndroidMkSuffix(ctx, snapshotObjectSuffix) |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 781 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 782 | if !p.MatchesWithDevice(ctx.DeviceConfig()) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 783 | return nil |
| 784 | } |
| 785 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 786 | return android.PathForModuleSrc(ctx, *p.properties.Src) |
| 787 | } |
| 788 | |
| 789 | func (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. |
| 796 | func VendorSnapshotObjectFactory() android.Module { |
Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 797 | module := newObject(android.DeviceSupported) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 798 | |
| 799 | prebuilt := &snapshotObjectLinker{ |
| 800 | objectLinker: objectLinker{ |
| 801 | baseLinker: NewBaseLinker(nil), |
| 802 | }, |
| 803 | } |
| 804 | module.linker = prebuilt |
| 805 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 806 | prebuilt.Init(module, VendorSnapshotImageSingleton, snapshotObjectSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 807 | module.AddProperties(&prebuilt.properties) |
Justin Yun | 08270c6 | 2022-12-19 17:01:26 +0900 | [diff] [blame] | 808 | |
| 809 | // vendor_snapshot_object module does not provide sanitizer variants |
| 810 | module.sanitize.Properties.Sanitize.Never = BoolPtr(true) |
| 811 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 812 | 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. |
| 818 | func RecoverySnapshotObjectFactory() android.Module { |
Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 819 | module := newObject(android.DeviceSupported) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 820 | |
| 821 | prebuilt := &snapshotObjectLinker{ |
| 822 | objectLinker: objectLinker{ |
| 823 | baseLinker: NewBaseLinker(nil), |
| 824 | }, |
| 825 | } |
| 826 | module.linker = prebuilt |
| 827 | |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 828 | prebuilt.Init(module, RecoverySnapshotImageSingleton, snapshotObjectSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 829 | module.AddProperties(&prebuilt.properties) |
| 830 | return module.Init() |
| 831 | } |
| 832 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 833 | type SnapshotInterface interface { |
| 834 | MatchesWithDevice(config android.DeviceConfig) bool |
| 835 | IsSnapshotPrebuilt() bool |
| 836 | Version() string |
| 837 | SnapshotAndroidMkSuffix() string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 838 | } |
| 839 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 840 | var _ SnapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) |
| 841 | var _ SnapshotInterface = (*snapshotLibraryDecorator)(nil) |
| 842 | var _ SnapshotInterface = (*snapshotBinaryDecorator)(nil) |
| 843 | var _ SnapshotInterface = (*snapshotObjectLinker)(nil) |