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