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." |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 103 | ) |
| 104 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 105 | type SnapshotProperties struct { |
| 106 | Header_libs []string `android:"arch_variant"` |
| 107 | Static_libs []string `android:"arch_variant"` |
| 108 | Shared_libs []string `android:"arch_variant"` |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 109 | Rlibs []string `android:"arch_variant"` |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 110 | Vndk_libs []string `android:"arch_variant"` |
| 111 | Binaries []string `android:"arch_variant"` |
| 112 | Objects []string `android:"arch_variant"` |
| 113 | } |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 114 | type snapshotModule struct { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 115 | android.ModuleBase |
| 116 | |
| 117 | properties SnapshotProperties |
| 118 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 119 | baseSnapshot BaseSnapshotDecorator |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 120 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 121 | image SnapshotImage |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 124 | func (s *snapshotModule) ImageMutatorBegin(ctx android.BaseModuleContext) { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 125 | cfg := ctx.DeviceConfig() |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 126 | if !s.image.IsUsingSnapshot(cfg) || s.image.TargetSnapshotVersion(cfg) != s.baseSnapshot.Version() { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 127 | s.Disable() |
| 128 | } |
| 129 | } |
| 130 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 131 | func (s *snapshotModule) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 132 | return false |
| 133 | } |
| 134 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 135 | func (s *snapshotModule) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 136 | return false |
| 137 | } |
| 138 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 139 | func (s *snapshotModule) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 140 | return false |
| 141 | } |
| 142 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 143 | func (s *snapshotModule) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 144 | return false |
| 145 | } |
| 146 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 147 | func (s *snapshotModule) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 148 | return false |
| 149 | } |
| 150 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 151 | func (s *snapshotModule) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 152 | return []string{s.image.imageVariantName(ctx.DeviceConfig())} |
| 153 | } |
| 154 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 155 | func (s *snapshotModule) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 158 | func (s *snapshotModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 159 | // Nothing, the snapshot module is only used to forward dependency information in DepsMutator. |
| 160 | } |
| 161 | |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 162 | func getSnapshotNameSuffix(moduleSuffix, version, arch string) string { |
| 163 | versionSuffix := version |
| 164 | if arch != "" { |
| 165 | versionSuffix += "." + arch |
| 166 | } |
| 167 | return moduleSuffix + versionSuffix |
| 168 | } |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 169 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 170 | func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) { |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 171 | collectSnapshotMap := func(names []string, snapshotSuffix, moduleSuffix string) map[string]string { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 172 | snapshotMap := make(map[string]string) |
Justin Yun | 4813867 | 2021-02-25 18:21:27 +0900 | [diff] [blame] | 173 | for _, name := range names { |
| 174 | snapshotMap[name] = name + |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 175 | getSnapshotNameSuffix(snapshotSuffix+moduleSuffix, |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 176 | s.baseSnapshot.Version(), |
Jose Galmes | f9523ed | 2021-04-06 19:48:10 -0700 | [diff] [blame] | 177 | ctx.DeviceConfig().Arches()[0].ArchType.String()) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 178 | } |
| 179 | return snapshotMap |
| 180 | } |
| 181 | |
| 182 | snapshotSuffix := s.image.moduleNameSuffix() |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 183 | headers := collectSnapshotMap(s.properties.Header_libs, snapshotSuffix, snapshotHeaderSuffix) |
| 184 | binaries := collectSnapshotMap(s.properties.Binaries, snapshotSuffix, snapshotBinarySuffix) |
| 185 | objects := collectSnapshotMap(s.properties.Objects, snapshotSuffix, snapshotObjectSuffix) |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 186 | staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix) |
| 187 | sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 188 | rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix) |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 189 | vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 190 | for k, v := range vndkLibs { |
| 191 | sharedLibs[k] = v |
| 192 | } |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame] | 193 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 194 | ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{ |
| 195 | HeaderLibs: headers, |
| 196 | Binaries: binaries, |
| 197 | Objects: objects, |
| 198 | StaticLibs: staticLibs, |
| 199 | SharedLibs: sharedLibs, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 200 | Rlibs: rlibs, |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 201 | }) |
| 202 | } |
| 203 | |
| 204 | type SnapshotInfo struct { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 205 | HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs map[string]string |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") |
| 209 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 210 | var _ android.ImageInterface = (*snapshotModule)(nil) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 211 | |
Justin Yun | d9e0575 | 2021-07-13 11:36:24 +0900 | [diff] [blame] | 212 | func snapshotMakeVarsProvider(ctx android.MakeVarsContext) { |
| 213 | snapshotSet := map[string]struct{}{} |
| 214 | ctx.VisitAllModules(func(m android.Module) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 215 | if s, ok := m.(*snapshotModule); ok { |
Justin Yun | d9e0575 | 2021-07-13 11:36:24 +0900 | [diff] [blame] | 216 | if _, ok := snapshotSet[s.Name()]; ok { |
| 217 | // arch variant generates duplicated modules |
| 218 | // skip this as we only need to know the path of the module. |
| 219 | return |
| 220 | } |
| 221 | snapshotSet[s.Name()] = struct{}{} |
| 222 | imageNameVersion := strings.Split(s.image.imageVariantName(ctx.DeviceConfig()), ".") |
| 223 | ctx.Strict( |
| 224 | strings.Join([]string{strings.ToUpper(imageNameVersion[0]), s.baseSnapshot.Version(), "SNAPSHOT_DIR"}, "_"), |
| 225 | ctx.ModuleDir(s)) |
| 226 | } |
| 227 | }) |
| 228 | } |
| 229 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 230 | func vendorSnapshotFactory() android.Module { |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 231 | return snapshotFactory(VendorSnapshotImageSingleton) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | func recoverySnapshotFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 235 | return snapshotFactory(RecoverySnapshotImageSingleton) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 238 | func snapshotFactory(image SnapshotImage) android.Module { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 239 | snapshotModule := &snapshotModule{} |
| 240 | snapshotModule.image = image |
| 241 | snapshotModule.AddProperties( |
| 242 | &snapshotModule.properties, |
| 243 | &snapshotModule.baseSnapshot.baseProperties) |
| 244 | android.InitAndroidArchModule(snapshotModule, android.DeviceSupported, android.MultilibBoth) |
| 245 | return snapshotModule |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 248 | type BaseSnapshotDecoratorProperties struct { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 249 | // snapshot version. |
| 250 | Version string |
| 251 | |
| 252 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') |
| 253 | Target_arch string |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 254 | |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 255 | // 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] | 256 | Androidmk_suffix string `blueprint:"mutated"` |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 257 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 258 | // Suffix to be added to the module name, e.g., vendor_shared, |
| 259 | // recovery_shared, etc. |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 260 | ModuleSuffix string `blueprint:"mutated"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 261 | } |
| 262 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 263 | // BaseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 264 | // version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't |
| 265 | // collide with source modules. e.g. the following example module, |
| 266 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 267 | // vendor_snapshot_static { |
| 268 | // name: "libbase", |
| 269 | // arch: "arm64", |
| 270 | // version: 30, |
| 271 | // ... |
| 272 | // } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 273 | // |
| 274 | // will be seen as "libbase.vendor_static.30.arm64" by Soong. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 275 | type BaseSnapshotDecorator struct { |
| 276 | baseProperties BaseSnapshotDecoratorProperties |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 277 | Image SnapshotImage |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 278 | } |
| 279 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 280 | func (p *BaseSnapshotDecorator) Name(name string) string { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 281 | return name + p.NameSuffix() |
| 282 | } |
| 283 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 284 | func (p *BaseSnapshotDecorator) NameSuffix() string { |
| 285 | return getSnapshotNameSuffix(p.moduleSuffix(), p.Version(), p.Arch()) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 286 | } |
| 287 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 288 | func (p *BaseSnapshotDecorator) Version() string { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 289 | return p.baseProperties.Version |
| 290 | } |
| 291 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 292 | func (p *BaseSnapshotDecorator) Arch() string { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 293 | return p.baseProperties.Target_arch |
| 294 | } |
| 295 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 296 | func (p *BaseSnapshotDecorator) moduleSuffix() string { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 297 | return p.baseProperties.ModuleSuffix |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 300 | func (p *BaseSnapshotDecorator) IsSnapshotPrebuilt() bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 301 | return true |
| 302 | } |
| 303 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 304 | func (p *BaseSnapshotDecorator) SnapshotAndroidMkSuffix() string { |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 305 | return p.baseProperties.Androidmk_suffix |
| 306 | } |
| 307 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 308 | func (p *BaseSnapshotDecorator) SetSnapshotAndroidMkSuffix(ctx android.ModuleContext, variant string) { |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 309 | // If there are any 2 or more variations among {core, product, vendor, recovery} |
| 310 | // we have to add the androidmk suffix to avoid duplicate modules with the same |
| 311 | // name. |
| 312 | variations := append(ctx.Target().Variations(), blueprint.Variation{ |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 313 | Mutator: "image", |
| 314 | Variation: android.CoreVariation}) |
| 315 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 316 | if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 317 | p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 318 | return |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 319 | } |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 320 | |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 321 | variations = append(ctx.Target().Variations(), blueprint.Variation{ |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 322 | Mutator: "image", |
| 323 | Variation: ProductVariationPrefix + ctx.DeviceConfig().PlatformVndkVersion()}) |
| 324 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 325 | if ctx.OtherModuleFarDependencyVariantExists(variations, ctx.Module().(LinkableInterface).BaseModuleName()) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 326 | p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 327 | return |
| 328 | } |
| 329 | |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 330 | images := []SnapshotImage{VendorSnapshotImageSingleton, RecoverySnapshotImageSingleton} |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 331 | |
| 332 | for _, image := range images { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 333 | if p.Image == image { |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 334 | continue |
| 335 | } |
| 336 | variations = append(ctx.Target().Variations(), blueprint.Variation{ |
| 337 | Mutator: "image", |
| 338 | Variation: image.imageVariantName(ctx.DeviceConfig())}) |
| 339 | |
| 340 | if ctx.OtherModuleFarDependencyVariantExists(variations, |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 341 | ctx.Module().(LinkableInterface).BaseModuleName()+ |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 342 | getSnapshotNameSuffix( |
| 343 | image.moduleNameSuffix()+variant, |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 344 | p.Version(), |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 345 | ctx.DeviceConfig().Arches()[0].ArchType.String())) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 346 | p.baseProperties.Androidmk_suffix = p.Image.moduleNameSuffix() |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 347 | return |
| 348 | } |
| 349 | } |
| 350 | |
Bill Peckham | 4016d7b | 2021-05-20 11:54:21 -0700 | [diff] [blame] | 351 | p.baseProperties.Androidmk_suffix = "" |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 352 | } |
| 353 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 354 | // Call this with a module suffix after creating a snapshot module, such as |
| 355 | // vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 356 | func (p *BaseSnapshotDecorator) Init(m LinkableInterface, image SnapshotImage, moduleSuffix string) { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 357 | p.Image = image |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 358 | p.baseProperties.ModuleSuffix = image.moduleNameSuffix() + moduleSuffix |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 359 | m.AddProperties(&p.baseProperties) |
| 360 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
| 361 | vendorSnapshotLoadHook(ctx, p) |
| 362 | }) |
| 363 | } |
| 364 | |
| 365 | // vendorSnapshotLoadHook disables snapshots if it's not BOARD_VNDK_VERSION. |
| 366 | // As vendor snapshot is only for vendor, such modules won't be used at all. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 367 | func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *BaseSnapshotDecorator) { |
| 368 | if p.Version() != ctx.DeviceConfig().VndkVersion() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 369 | ctx.Module().Disable() |
| 370 | return |
| 371 | } |
| 372 | } |
| 373 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 374 | // Module definitions for snapshots of libraries (shared, static, header). |
| 375 | // |
| 376 | // Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and |
| 377 | // static libraries have their prebuilt library files (.so for shared, .a for static) as their src, |
| 378 | // which can be installed or linked against. Also they export flags needed when linked, such as |
| 379 | // include directories, c flags, sanitize dependency information, etc. |
| 380 | // |
| 381 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 382 | type SnapshotLibraryProperties struct { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 383 | // Prebuilt file for each arch. |
| 384 | Src *string `android:"arch_variant"` |
| 385 | |
| 386 | // list of directories that will be added to the include path (using -I). |
| 387 | Export_include_dirs []string `android:"arch_variant"` |
| 388 | |
| 389 | // list of directories that will be added to the system path (using -isystem). |
| 390 | Export_system_include_dirs []string `android:"arch_variant"` |
| 391 | |
| 392 | // list of flags that will be used for any module that links against this module. |
| 393 | Export_flags []string `android:"arch_variant"` |
| 394 | |
| 395 | // Whether this prebuilt needs to depend on sanitize ubsan runtime or not. |
| 396 | Sanitize_ubsan_dep *bool `android:"arch_variant"` |
| 397 | |
| 398 | // Whether this prebuilt needs to depend on sanitize minimal runtime or not. |
| 399 | Sanitize_minimal_dep *bool `android:"arch_variant"` |
| 400 | } |
| 401 | |
| 402 | type snapshotSanitizer interface { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 403 | isSanitizerAvailable(t SanitizerType) bool |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 404 | setSanitizerVariation(t SanitizerType, enabled bool) |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 405 | isSanitizerEnabled(t SanitizerType) bool |
| 406 | isUnsanitizedVariant() bool |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | type snapshotLibraryDecorator struct { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 410 | BaseSnapshotDecorator |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 411 | *libraryDecorator |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 412 | properties SnapshotLibraryProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 413 | sanitizerProperties struct { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 414 | SanitizerVariation SanitizerType `blueprint:"mutated"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 415 | |
| 416 | // Library flags for cfi variant. |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 417 | Cfi SnapshotLibraryProperties `android:"arch_variant"` |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 418 | |
| 419 | // Library flags for hwasan variant. |
| 420 | Hwasan SnapshotLibraryProperties `android:"arch_variant"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 421 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 425 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
| 426 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 427 | } |
| 428 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 429 | func (p *snapshotLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 430 | arches := config.Arches() |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 431 | if len(arches) == 0 || arches[0].ArchType.String() != p.Arch() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 432 | return false |
| 433 | } |
| 434 | if !p.header() && p.properties.Src == nil { |
| 435 | return false |
| 436 | } |
| 437 | return true |
| 438 | } |
| 439 | |
| 440 | // cc modules' link functions are to link compiled objects into final binaries. |
| 441 | // As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are |
| 442 | // done by normal library decorator, e.g. exporting flags. |
| 443 | 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] | 444 | var variant string |
| 445 | if p.shared() { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 446 | variant = SnapshotSharedSuffix |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 447 | } else if p.static() { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 448 | variant = SnapshotStaticSuffix |
Jose Galmes | 7fdc336 | 2021-05-26 21:16:52 -0700 | [diff] [blame] | 449 | } else { |
| 450 | variant = snapshotHeaderSuffix |
| 451 | } |
| 452 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 453 | p.SetSnapshotAndroidMkSuffix(ctx, variant) |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 454 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 455 | if p.header() { |
| 456 | return p.libraryDecorator.link(ctx, flags, deps, objs) |
| 457 | } |
| 458 | |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 459 | if p.isSanitizerEnabled(cfi) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 460 | p.properties = p.sanitizerProperties.Cfi |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 461 | } else if p.isSanitizerEnabled(Hwasan) { |
| 462 | p.properties = p.sanitizerProperties.Hwasan |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 463 | } |
| 464 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 465 | if !p.MatchesWithDevice(ctx.DeviceConfig()) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 466 | return nil |
| 467 | } |
| 468 | |
Inseob Kim | dd0295d | 2021-04-12 21:09:59 +0900 | [diff] [blame] | 469 | // Flags specified directly to this module. |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 470 | p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...) |
| 471 | p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...) |
| 472 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
| 473 | |
Inseob Kim | dd0295d | 2021-04-12 21:09:59 +0900 | [diff] [blame] | 474 | // Flags reexported from dependencies. (e.g. vndk_prebuilt_shared) |
| 475 | p.libraryDecorator.reexportDirs(deps.ReexportedDirs...) |
| 476 | p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...) |
| 477 | p.libraryDecorator.reexportFlags(deps.ReexportedFlags...) |
| 478 | p.libraryDecorator.reexportDeps(deps.ReexportedDeps...) |
| 479 | p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...) |
| 480 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 481 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 482 | p.unstrippedOutputFile = in |
| 483 | |
| 484 | if p.shared() { |
| 485 | libName := in.Base() |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 486 | |
| 487 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 488 | // depending on a table of contents file instead of the library itself. |
| 489 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 490 | p.tocFile = android.OptionalPathForPath(tocFile) |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 491 | TransformSharedObjectToToc(ctx, in, tocFile) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 492 | |
| 493 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
Liz Kammer | ef6dfea | 2021-06-08 15:37:09 -0400 | [diff] [blame] | 494 | SharedLibrary: in, |
| 495 | Target: ctx.Target(), |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 496 | |
| 497 | TableOfContents: p.tocFile, |
| 498 | }) |
| 499 | } |
| 500 | |
| 501 | if p.static() { |
| 502 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() |
| 503 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ |
| 504 | StaticLibrary: in, |
| 505 | |
| 506 | TransitiveStaticLibrariesForOrdering: depSet, |
| 507 | }) |
| 508 | } |
| 509 | |
| 510 | p.libraryDecorator.flagExporter.setProvider(ctx) |
| 511 | |
| 512 | return in |
| 513 | } |
| 514 | |
| 515 | func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
Inseob Kim | bf1b63f | 2022-01-21 18:12:48 +0900 | [diff] [blame] | 516 | if p.MatchesWithDevice(ctx.DeviceConfig()) && p.shared() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 517 | p.baseInstaller.install(ctx, file) |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | func (p *snapshotLibraryDecorator) nativeCoverage() bool { |
| 522 | return false |
| 523 | } |
| 524 | |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 525 | func (p *snapshotLibraryDecorator) isSanitizerAvailable(t SanitizerType) bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 526 | switch t { |
| 527 | case cfi: |
| 528 | return p.sanitizerProperties.Cfi.Src != nil |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 529 | case Hwasan: |
| 530 | return p.sanitizerProperties.Hwasan.Src != nil |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 531 | default: |
| 532 | return false |
| 533 | } |
| 534 | } |
| 535 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 536 | func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 537 | if !enabled || p.isSanitizerEnabled(t) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 538 | return |
| 539 | } |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 540 | if !p.isUnsanitizedVariant() { |
| 541 | 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] | 542 | } |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 543 | p.sanitizerProperties.SanitizerVariation = t |
| 544 | } |
| 545 | |
| 546 | func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool { |
| 547 | return p.sanitizerProperties.SanitizerVariation == t |
| 548 | } |
| 549 | |
| 550 | func (p *snapshotLibraryDecorator) isUnsanitizedVariant() bool { |
| 551 | return !p.isSanitizerEnabled(Asan) && |
| 552 | !p.isSanitizerEnabled(Hwasan) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 553 | } |
| 554 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 555 | func snapshotLibraryFactory(image SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 556 | module, library := NewLibrary(android.DeviceSupported) |
| 557 | |
| 558 | module.stl = nil |
| 559 | module.sanitize = nil |
| 560 | library.disableStripping() |
| 561 | |
| 562 | prebuilt := &snapshotLibraryDecorator{ |
| 563 | libraryDecorator: library, |
| 564 | } |
| 565 | |
| 566 | prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 567 | prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 568 | |
| 569 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 570 | if prebuilt.baseLinker.Properties.System_shared_libs == nil { |
| 571 | prebuilt.baseLinker.Properties.System_shared_libs = []string{} |
| 572 | } |
| 573 | |
| 574 | module.compiler = nil |
| 575 | module.linker = prebuilt |
| 576 | module.installer = prebuilt |
| 577 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 578 | prebuilt.Init(module, image, moduleSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 579 | module.AddProperties( |
| 580 | &prebuilt.properties, |
| 581 | &prebuilt.sanitizerProperties, |
| 582 | ) |
| 583 | |
| 584 | return module, prebuilt |
| 585 | } |
| 586 | |
| 587 | // vendor_snapshot_shared is a special prebuilt shared library which is auto-generated by |
| 588 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_shared |
| 589 | // overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION |
| 590 | // is set. |
| 591 | func VendorSnapshotSharedFactory() android.Module { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 592 | module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotSharedSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 593 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 594 | return module.Init() |
| 595 | } |
| 596 | |
| 597 | // recovery_snapshot_shared is a special prebuilt shared library which is auto-generated by |
| 598 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_shared |
| 599 | // overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION |
| 600 | // is set. |
| 601 | func RecoverySnapshotSharedFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 602 | module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotSharedSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 603 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 604 | return module.Init() |
| 605 | } |
| 606 | |
| 607 | // vendor_snapshot_static is a special prebuilt static library which is auto-generated by |
| 608 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_static |
| 609 | // overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION |
| 610 | // is set. |
| 611 | func VendorSnapshotStaticFactory() android.Module { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 612 | module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, SnapshotStaticSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 613 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 614 | return module.Init() |
| 615 | } |
| 616 | |
| 617 | // recovery_snapshot_static is a special prebuilt static library which is auto-generated by |
| 618 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_static |
| 619 | // overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION |
| 620 | // is set. |
| 621 | func RecoverySnapshotStaticFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 622 | module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, SnapshotStaticSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 623 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 624 | return module.Init() |
| 625 | } |
| 626 | |
| 627 | // vendor_snapshot_header is a special header library which is auto-generated by |
| 628 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_header |
| 629 | // overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION |
| 630 | // is set. |
| 631 | func VendorSnapshotHeaderFactory() android.Module { |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 632 | module, prebuilt := snapshotLibraryFactory(VendorSnapshotImageSingleton, snapshotHeaderSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 633 | prebuilt.libraryDecorator.HeaderOnly() |
| 634 | return module.Init() |
| 635 | } |
| 636 | |
| 637 | // recovery_snapshot_header is a special header library which is auto-generated by |
| 638 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_header |
| 639 | // overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION |
| 640 | // is set. |
| 641 | func RecoverySnapshotHeaderFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 642 | module, prebuilt := snapshotLibraryFactory(RecoverySnapshotImageSingleton, snapshotHeaderSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 643 | prebuilt.libraryDecorator.HeaderOnly() |
| 644 | return module.Init() |
| 645 | } |
| 646 | |
| 647 | var _ snapshotSanitizer = (*snapshotLibraryDecorator)(nil) |
| 648 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 649 | // Module definitions for snapshots of executable binaries. |
| 650 | // |
| 651 | // Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable |
| 652 | // binaries (e.g. toybox, sh) as their src, which can be installed. |
| 653 | // |
| 654 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 655 | type snapshotBinaryProperties struct { |
| 656 | // Prebuilt file for each arch. |
| 657 | Src *string `android:"arch_variant"` |
| 658 | } |
| 659 | |
| 660 | type snapshotBinaryDecorator struct { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 661 | BaseSnapshotDecorator |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 662 | *binaryDecorator |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 663 | properties snapshotBinaryProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 664 | } |
| 665 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 666 | func (p *snapshotBinaryDecorator) MatchesWithDevice(config android.DeviceConfig) bool { |
| 667 | if config.DeviceArch() != p.Arch() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 668 | return false |
| 669 | } |
| 670 | if p.properties.Src == nil { |
| 671 | return false |
| 672 | } |
| 673 | return true |
| 674 | } |
| 675 | |
| 676 | // cc modules' link functions are to link compiled objects into final binaries. |
| 677 | // As snapshots are prebuilts, this just returns the prebuilt binary |
| 678 | 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] | 679 | p.SetSnapshotAndroidMkSuffix(ctx, snapshotBinarySuffix) |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 680 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 681 | if !p.MatchesWithDevice(ctx.DeviceConfig()) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 682 | return nil |
| 683 | } |
| 684 | |
| 685 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 686 | p.unstrippedOutputFile = in |
| 687 | binName := in.Base() |
| 688 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 689 | // use cpExecutable to make it executable |
| 690 | outputFile := android.PathForModuleOut(ctx, binName) |
| 691 | ctx.Build(pctx, android.BuildParams{ |
| 692 | Rule: android.CpExecutable, |
| 693 | Description: "prebuilt", |
| 694 | Output: outputFile, |
| 695 | Input: in, |
| 696 | }) |
| 697 | |
Inseob Kim | 4d945ee | 2022-02-24 10:29:18 +0900 | [diff] [blame] | 698 | // binary snapshots need symlinking |
| 699 | p.setSymlinkList(ctx) |
| 700 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 701 | return outputFile |
| 702 | } |
| 703 | |
| 704 | func (p *snapshotBinaryDecorator) nativeCoverage() bool { |
| 705 | return false |
| 706 | } |
| 707 | |
| 708 | // vendor_snapshot_binary is a special prebuilt executable binary which is auto-generated by |
| 709 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary |
| 710 | // overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. |
| 711 | func VendorSnapshotBinaryFactory() android.Module { |
Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 712 | return snapshotBinaryFactory(VendorSnapshotImageSingleton, snapshotBinarySuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | // recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by |
| 716 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary |
| 717 | // overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. |
| 718 | func RecoverySnapshotBinaryFactory() android.Module { |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 719 | return snapshotBinaryFactory(RecoverySnapshotImageSingleton, snapshotBinarySuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 720 | } |
| 721 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 722 | func snapshotBinaryFactory(image SnapshotImage, moduleSuffix string) android.Module { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 723 | module, binary := NewBinary(android.DeviceSupported) |
| 724 | binary.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 725 | binary.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 726 | |
| 727 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 728 | if binary.baseLinker.Properties.System_shared_libs == nil { |
| 729 | binary.baseLinker.Properties.System_shared_libs = []string{} |
| 730 | } |
| 731 | |
| 732 | prebuilt := &snapshotBinaryDecorator{ |
| 733 | binaryDecorator: binary, |
| 734 | } |
| 735 | |
| 736 | module.compiler = nil |
| 737 | module.sanitize = nil |
| 738 | module.stl = nil |
| 739 | module.linker = prebuilt |
| 740 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 741 | prebuilt.Init(module, image, moduleSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 742 | module.AddProperties(&prebuilt.properties) |
| 743 | return module.Init() |
| 744 | } |
| 745 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 746 | // Module definitions for snapshots of object files (*.o). |
| 747 | // |
| 748 | // Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object |
| 749 | // files (*.o) as their src. |
| 750 | // |
| 751 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 752 | type vendorSnapshotObjectProperties struct { |
| 753 | // Prebuilt file for each arch. |
| 754 | Src *string `android:"arch_variant"` |
| 755 | } |
| 756 | |
| 757 | type snapshotObjectLinker struct { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 758 | BaseSnapshotDecorator |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 759 | objectLinker |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 760 | properties vendorSnapshotObjectProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 761 | } |
| 762 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 763 | func (p *snapshotObjectLinker) MatchesWithDevice(config android.DeviceConfig) bool { |
| 764 | if config.DeviceArch() != p.Arch() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 765 | return false |
| 766 | } |
| 767 | if p.properties.Src == nil { |
| 768 | return false |
| 769 | } |
| 770 | return true |
| 771 | } |
| 772 | |
| 773 | // cc modules' link functions are to link compiled objects into final binaries. |
| 774 | // As snapshots are prebuilts, this just returns the prebuilt binary |
| 775 | 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] | 776 | p.SetSnapshotAndroidMkSuffix(ctx, snapshotObjectSuffix) |
Inseob Kim | 1b6fb87 | 2021-04-05 13:37:02 +0900 | [diff] [blame] | 777 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 778 | if !p.MatchesWithDevice(ctx.DeviceConfig()) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 779 | return nil |
| 780 | } |
| 781 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 782 | return android.PathForModuleSrc(ctx, *p.properties.Src) |
| 783 | } |
| 784 | |
| 785 | func (p *snapshotObjectLinker) nativeCoverage() bool { |
| 786 | return false |
| 787 | } |
| 788 | |
| 789 | // vendor_snapshot_object is a special prebuilt compiled object file which is auto-generated by |
| 790 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_object |
| 791 | // overrides the vendor variant of the cc object with the same name, if BOARD_VNDK_VERSION is set. |
| 792 | func VendorSnapshotObjectFactory() android.Module { |
Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 793 | module := newObject(android.DeviceSupported) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 794 | |
| 795 | prebuilt := &snapshotObjectLinker{ |
| 796 | objectLinker: objectLinker{ |
| 797 | baseLinker: NewBaseLinker(nil), |
| 798 | }, |
| 799 | } |
| 800 | module.linker = prebuilt |
| 801 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 802 | prebuilt.Init(module, VendorSnapshotImageSingleton, snapshotObjectSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 803 | module.AddProperties(&prebuilt.properties) |
| 804 | return module.Init() |
| 805 | } |
| 806 | |
| 807 | // recovery_snapshot_object is a special prebuilt compiled object file which is auto-generated by |
| 808 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_object |
| 809 | // overrides the recovery variant of the cc object with the same name, if BOARD_VNDK_VERSION is set. |
| 810 | func RecoverySnapshotObjectFactory() android.Module { |
Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 811 | module := newObject(android.DeviceSupported) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 812 | |
| 813 | prebuilt := &snapshotObjectLinker{ |
| 814 | objectLinker: objectLinker{ |
| 815 | baseLinker: NewBaseLinker(nil), |
| 816 | }, |
| 817 | } |
| 818 | module.linker = prebuilt |
| 819 | |
Jose Galmes | d7d99be | 2021-11-05 14:04:54 -0700 | [diff] [blame] | 820 | prebuilt.Init(module, RecoverySnapshotImageSingleton, snapshotObjectSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 821 | module.AddProperties(&prebuilt.properties) |
| 822 | return module.Init() |
| 823 | } |
| 824 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 825 | type SnapshotInterface interface { |
| 826 | MatchesWithDevice(config android.DeviceConfig) bool |
| 827 | IsSnapshotPrebuilt() bool |
| 828 | Version() string |
| 829 | SnapshotAndroidMkSuffix() string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 830 | } |
| 831 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 832 | var _ SnapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) |
| 833 | var _ SnapshotInterface = (*snapshotLibraryDecorator)(nil) |
| 834 | var _ SnapshotInterface = (*snapshotBinaryDecorator)(nil) |
| 835 | var _ SnapshotInterface = (*snapshotObjectLinker)(nil) |