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" |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 24 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | // Defines the specifics of different images to which the snapshot process is applicable, e.g., |
| 29 | // vendor, recovery, ramdisk. |
| 30 | type snapshotImage interface { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 31 | // Returns true if a snapshot should be generated for this image. |
| 32 | shouldGenerateSnapshot(ctx android.SingletonContext) bool |
| 33 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 34 | // Function that returns true if the module is included in this image. |
| 35 | // Using a function return instead of a value to prevent early |
| 36 | // evalution of a function that may be not be defined. |
| 37 | inImage(m *Module) func() bool |
| 38 | |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 39 | // Returns true if the module is private and must not be included in the |
| 40 | // snapshot. For example VNDK-private modules must return true for the |
| 41 | // vendor snapshots. But false for the recovery snapshots. |
| 42 | private(m *Module) bool |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 43 | |
| 44 | // Returns true if a dir under source tree is an SoC-owned proprietary |
| 45 | // directory, such as device/, vendor/, etc. |
| 46 | // |
| 47 | // For a given snapshot (e.g., vendor, recovery, etc.) if |
| 48 | // isProprietaryPath(dir) returns true, then the module in dir will be |
| 49 | // built from sources. |
| 50 | isProprietaryPath(dir string) bool |
| 51 | |
| 52 | // Whether to include VNDK in the snapshot for this image. |
| 53 | includeVndk() bool |
| 54 | |
| 55 | // Whether a given module has been explicitly excluded from the |
| 56 | // snapshot, e.g., using the exclude_from_vendor_snapshot or |
| 57 | // exclude_from_recovery_snapshot properties. |
| 58 | excludeFromSnapshot(m *Module) bool |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 59 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 60 | // Returns true if the build is using a snapshot for this image. |
| 61 | isUsingSnapshot(cfg android.DeviceConfig) bool |
| 62 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 63 | // Returns a version of which the snapshot should be used in this target. |
| 64 | // This will only be meaningful when isUsingSnapshot is true. |
| 65 | targetSnapshotVersion(cfg android.DeviceConfig) string |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 66 | |
| 67 | // Whether to exclude a given module from the directed snapshot or not. |
| 68 | // If the makefile variable DIRECTED_{IMAGE}_SNAPSHOT is true, directed snapshot is turned on, |
| 69 | // and only modules listed in {IMAGE}_SNAPSHOT_MODULES will be captured. |
| 70 | excludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 71 | |
| 72 | // The image variant name for this snapshot image. |
| 73 | // For example, recovery snapshot image will return "recovery", and vendor snapshot image will |
| 74 | // return "vendor." + version. |
| 75 | imageVariantName(cfg android.DeviceConfig) string |
| 76 | |
| 77 | // The variant suffix for snapshot modules. For example, vendor snapshot modules will have |
| 78 | // ".vendor" as their suffix. |
| 79 | moduleNameSuffix() string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | type vendorSnapshotImage struct{} |
| 83 | type recoverySnapshotImage struct{} |
| 84 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 85 | func (vendorSnapshotImage) init(ctx android.RegistrationContext) { |
| 86 | ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton) |
| 87 | ctx.RegisterModuleType("vendor_snapshot", vendorSnapshotFactory) |
| 88 | ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) |
| 89 | ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory) |
| 90 | ctx.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory) |
| 91 | ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory) |
| 92 | ctx.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory) |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 93 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 94 | ctx.RegisterSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 95 | } |
| 96 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 97 | func (vendorSnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool { |
| 98 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a snapshot. |
| 99 | return ctx.DeviceConfig().VndkVersion() == "current" |
| 100 | } |
| 101 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 102 | func (vendorSnapshotImage) inImage(m *Module) func() bool { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 103 | return m.InVendor |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 104 | } |
| 105 | |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 106 | func (vendorSnapshotImage) private(m *Module) bool { |
| 107 | return m.IsVndkPrivate() |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | func (vendorSnapshotImage) isProprietaryPath(dir string) bool { |
| 111 | return isVendorProprietaryPath(dir) |
| 112 | } |
| 113 | |
| 114 | // vendor snapshot includes static/header libraries with vndk: {enabled: true}. |
| 115 | func (vendorSnapshotImage) includeVndk() bool { |
| 116 | return true |
| 117 | } |
| 118 | |
| 119 | func (vendorSnapshotImage) excludeFromSnapshot(m *Module) bool { |
| 120 | return m.ExcludeFromVendorSnapshot() |
| 121 | } |
| 122 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 123 | func (vendorSnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool { |
| 124 | vndkVersion := cfg.VndkVersion() |
| 125 | return vndkVersion != "current" && vndkVersion != "" |
| 126 | } |
| 127 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 128 | func (vendorSnapshotImage) targetSnapshotVersion(cfg android.DeviceConfig) string { |
| 129 | return cfg.VndkVersion() |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 132 | // returns true iff a given module SHOULD BE EXCLUDED, false if included |
| 133 | func (vendorSnapshotImage) excludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool { |
| 134 | // If we're using full snapshot, not directed snapshot, capture every module |
| 135 | if !cfg.DirectedVendorSnapshot() { |
| 136 | return false |
| 137 | } |
| 138 | // Else, checks if name is in VENDOR_SNAPSHOT_MODULES. |
| 139 | return !cfg.VendorSnapshotModules()[name] |
| 140 | } |
| 141 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 142 | func (vendorSnapshotImage) imageVariantName(cfg android.DeviceConfig) string { |
| 143 | return VendorVariationPrefix + cfg.VndkVersion() |
| 144 | } |
| 145 | |
| 146 | func (vendorSnapshotImage) moduleNameSuffix() string { |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame^] | 147 | return VendorSuffix |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | func (recoverySnapshotImage) init(ctx android.RegistrationContext) { |
| 151 | ctx.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton) |
| 152 | ctx.RegisterModuleType("recovery_snapshot", recoverySnapshotFactory) |
| 153 | ctx.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory) |
| 154 | ctx.RegisterModuleType("recovery_snapshot_static", RecoverySnapshotStaticFactory) |
| 155 | ctx.RegisterModuleType("recovery_snapshot_header", RecoverySnapshotHeaderFactory) |
| 156 | ctx.RegisterModuleType("recovery_snapshot_binary", RecoverySnapshotBinaryFactory) |
| 157 | ctx.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 158 | } |
| 159 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 160 | func (recoverySnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool { |
| 161 | // RECOVERY_SNAPSHOT_VERSION must be set to 'current' in order to generate a |
| 162 | // snapshot. |
| 163 | return ctx.DeviceConfig().RecoverySnapshotVersion() == "current" |
| 164 | } |
| 165 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 166 | func (recoverySnapshotImage) inImage(m *Module) func() bool { |
| 167 | return m.InRecovery |
| 168 | } |
| 169 | |
Justin Yun | e09ac17 | 2021-01-20 19:49:01 +0900 | [diff] [blame] | 170 | // recovery snapshot does not have private libraries. |
| 171 | func (recoverySnapshotImage) private(m *Module) bool { |
| 172 | return false |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | func (recoverySnapshotImage) isProprietaryPath(dir string) bool { |
| 176 | return isRecoveryProprietaryPath(dir) |
| 177 | } |
| 178 | |
| 179 | // recovery snapshot does NOT treat vndk specially. |
| 180 | func (recoverySnapshotImage) includeVndk() bool { |
| 181 | return false |
| 182 | } |
| 183 | |
| 184 | func (recoverySnapshotImage) excludeFromSnapshot(m *Module) bool { |
| 185 | return m.ExcludeFromRecoverySnapshot() |
| 186 | } |
| 187 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 188 | func (recoverySnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool { |
| 189 | recoverySnapshotVersion := cfg.RecoverySnapshotVersion() |
| 190 | return recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" |
| 191 | } |
| 192 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 193 | func (recoverySnapshotImage) targetSnapshotVersion(cfg android.DeviceConfig) string { |
| 194 | return cfg.RecoverySnapshotVersion() |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 197 | func (recoverySnapshotImage) excludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool { |
| 198 | // directed recovery snapshot is not implemented yet |
| 199 | return false |
| 200 | } |
| 201 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 202 | func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string { |
| 203 | return android.RecoveryVariation |
| 204 | } |
| 205 | |
| 206 | func (recoverySnapshotImage) moduleNameSuffix() string { |
| 207 | return recoverySuffix |
| 208 | } |
| 209 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 210 | var vendorSnapshotImageSingleton vendorSnapshotImage |
| 211 | var recoverySnapshotImageSingleton recoverySnapshotImage |
| 212 | |
| 213 | func init() { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 214 | vendorSnapshotImageSingleton.init(android.InitRegistrationContext) |
| 215 | recoverySnapshotImageSingleton.init(android.InitRegistrationContext) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | const ( |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 219 | snapshotHeaderSuffix = "_header." |
| 220 | snapshotSharedSuffix = "_shared." |
| 221 | snapshotStaticSuffix = "_static." |
| 222 | snapshotBinarySuffix = "_binary." |
| 223 | snapshotObjectSuffix = "_object." |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 224 | ) |
| 225 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 226 | type SnapshotProperties struct { |
| 227 | Header_libs []string `android:"arch_variant"` |
| 228 | Static_libs []string `android:"arch_variant"` |
| 229 | Shared_libs []string `android:"arch_variant"` |
| 230 | Vndk_libs []string `android:"arch_variant"` |
| 231 | Binaries []string `android:"arch_variant"` |
| 232 | Objects []string `android:"arch_variant"` |
| 233 | } |
| 234 | |
| 235 | type snapshot struct { |
| 236 | android.ModuleBase |
| 237 | |
| 238 | properties SnapshotProperties |
| 239 | |
| 240 | baseSnapshot baseSnapshotDecorator |
| 241 | |
| 242 | image snapshotImage |
| 243 | } |
| 244 | |
| 245 | func (s *snapshot) ImageMutatorBegin(ctx android.BaseModuleContext) { |
| 246 | cfg := ctx.DeviceConfig() |
| 247 | if !s.image.isUsingSnapshot(cfg) || s.image.targetSnapshotVersion(cfg) != s.baseSnapshot.version() { |
| 248 | s.Disable() |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | func (s *snapshot) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 253 | return false |
| 254 | } |
| 255 | |
| 256 | func (s *snapshot) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 257 | return false |
| 258 | } |
| 259 | |
| 260 | func (s *snapshot) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 261 | return false |
| 262 | } |
| 263 | |
| 264 | func (s *snapshot) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 265 | return false |
| 266 | } |
| 267 | |
| 268 | func (s *snapshot) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
| 269 | return []string{s.image.imageVariantName(ctx.DeviceConfig())} |
| 270 | } |
| 271 | |
| 272 | func (s *snapshot) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
| 273 | } |
| 274 | |
| 275 | func (s *snapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 276 | // Nothing, the snapshot module is only used to forward dependency information in DepsMutator. |
| 277 | } |
| 278 | |
| 279 | func (s *snapshot) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 280 | collectSnapshotMap := func(variations []blueprint.Variation, depTag blueprint.DependencyTag, |
| 281 | names []string, snapshotSuffix, moduleSuffix string) map[string]string { |
| 282 | |
| 283 | decoratedNames := make([]string, 0, len(names)) |
| 284 | for _, name := range names { |
| 285 | decoratedNames = append(decoratedNames, name+ |
| 286 | snapshotSuffix+moduleSuffix+ |
| 287 | s.baseSnapshot.version()+ |
| 288 | "."+ctx.Arch().ArchType.Name) |
| 289 | } |
| 290 | |
| 291 | deps := ctx.AddVariationDependencies(variations, depTag, decoratedNames...) |
| 292 | snapshotMap := make(map[string]string) |
| 293 | for _, dep := range deps { |
| 294 | if dep == nil { |
| 295 | continue |
| 296 | } |
| 297 | |
| 298 | snapshotMap[dep.(*Module).BaseModuleName()] = ctx.OtherModuleName(dep) |
| 299 | } |
| 300 | return snapshotMap |
| 301 | } |
| 302 | |
| 303 | snapshotSuffix := s.image.moduleNameSuffix() |
| 304 | headers := collectSnapshotMap(nil, HeaderDepTag(), s.properties.Header_libs, snapshotSuffix, snapshotHeaderSuffix) |
| 305 | binaries := collectSnapshotMap(nil, nil, s.properties.Binaries, snapshotSuffix, snapshotBinarySuffix) |
| 306 | objects := collectSnapshotMap(nil, nil, s.properties.Objects, snapshotSuffix, snapshotObjectSuffix) |
| 307 | |
| 308 | staticLibs := collectSnapshotMap([]blueprint.Variation{ |
| 309 | {Mutator: "link", Variation: "static"}, |
| 310 | }, StaticDepTag(), s.properties.Static_libs, snapshotSuffix, snapshotStaticSuffix) |
| 311 | |
| 312 | sharedLibs := collectSnapshotMap([]blueprint.Variation{ |
| 313 | {Mutator: "link", Variation: "shared"}, |
| 314 | }, SharedDepTag(), s.properties.Shared_libs, snapshotSuffix, snapshotSharedSuffix) |
| 315 | |
| 316 | vndkLibs := collectSnapshotMap([]blueprint.Variation{ |
| 317 | {Mutator: "link", Variation: "shared"}, |
| 318 | }, SharedDepTag(), s.properties.Vndk_libs, "", vndkSuffix) |
| 319 | |
| 320 | for k, v := range vndkLibs { |
| 321 | sharedLibs[k] = v |
| 322 | } |
| 323 | ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{ |
| 324 | HeaderLibs: headers, |
| 325 | Binaries: binaries, |
| 326 | Objects: objects, |
| 327 | StaticLibs: staticLibs, |
| 328 | SharedLibs: sharedLibs, |
| 329 | }) |
| 330 | } |
| 331 | |
| 332 | type SnapshotInfo struct { |
| 333 | HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs map[string]string |
| 334 | } |
| 335 | |
| 336 | var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") |
| 337 | |
| 338 | var _ android.ImageInterface = (*snapshot)(nil) |
| 339 | |
| 340 | func vendorSnapshotFactory() android.Module { |
| 341 | return snapshotFactory(vendorSnapshotImageSingleton) |
| 342 | } |
| 343 | |
| 344 | func recoverySnapshotFactory() android.Module { |
| 345 | return snapshotFactory(recoverySnapshotImageSingleton) |
| 346 | } |
| 347 | |
| 348 | func snapshotFactory(image snapshotImage) android.Module { |
| 349 | snapshot := &snapshot{} |
| 350 | snapshot.image = image |
| 351 | snapshot.AddProperties( |
| 352 | &snapshot.properties, |
| 353 | &snapshot.baseSnapshot.baseProperties) |
| 354 | android.InitAndroidArchModule(snapshot, android.DeviceSupported, android.MultilibBoth) |
| 355 | return snapshot |
| 356 | } |
| 357 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 358 | type baseSnapshotDecoratorProperties struct { |
| 359 | // snapshot version. |
| 360 | Version string |
| 361 | |
| 362 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') |
| 363 | Target_arch string |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 364 | |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 365 | // Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor". |
| 366 | Androidmk_suffix string |
| 367 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 368 | // Suffix to be added to the module name, e.g., vendor_shared, |
| 369 | // recovery_shared, etc. |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 370 | ModuleSuffix string `blueprint:"mutated"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | // baseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot |
| 374 | // version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't |
| 375 | // collide with source modules. e.g. the following example module, |
| 376 | // |
| 377 | // vendor_snapshot_static { |
| 378 | // name: "libbase", |
| 379 | // arch: "arm64", |
| 380 | // version: 30, |
| 381 | // ... |
| 382 | // } |
| 383 | // |
| 384 | // will be seen as "libbase.vendor_static.30.arm64" by Soong. |
| 385 | type baseSnapshotDecorator struct { |
| 386 | baseProperties baseSnapshotDecoratorProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | func (p *baseSnapshotDecorator) Name(name string) string { |
| 390 | return name + p.NameSuffix() |
| 391 | } |
| 392 | |
| 393 | func (p *baseSnapshotDecorator) NameSuffix() string { |
| 394 | versionSuffix := p.version() |
| 395 | if p.arch() != "" { |
| 396 | versionSuffix += "." + p.arch() |
| 397 | } |
| 398 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 399 | return p.baseProperties.ModuleSuffix + versionSuffix |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | func (p *baseSnapshotDecorator) version() string { |
| 403 | return p.baseProperties.Version |
| 404 | } |
| 405 | |
| 406 | func (p *baseSnapshotDecorator) arch() string { |
| 407 | return p.baseProperties.Target_arch |
| 408 | } |
| 409 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 410 | func (p *baseSnapshotDecorator) moduleSuffix() string { |
| 411 | return p.baseProperties.ModuleSuffix |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 412 | } |
| 413 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 414 | func (p *baseSnapshotDecorator) isSnapshotPrebuilt() bool { |
| 415 | return true |
| 416 | } |
| 417 | |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 418 | func (p *baseSnapshotDecorator) snapshotAndroidMkSuffix() string { |
| 419 | return p.baseProperties.Androidmk_suffix |
| 420 | } |
| 421 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 422 | // Call this with a module suffix after creating a snapshot module, such as |
| 423 | // vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc. |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 424 | func (p *baseSnapshotDecorator) init(m *Module, snapshotSuffix, moduleSuffix string) { |
| 425 | p.baseProperties.ModuleSuffix = snapshotSuffix + moduleSuffix |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 426 | m.AddProperties(&p.baseProperties) |
| 427 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
| 428 | vendorSnapshotLoadHook(ctx, p) |
| 429 | }) |
| 430 | } |
| 431 | |
| 432 | // vendorSnapshotLoadHook disables snapshots if it's not BOARD_VNDK_VERSION. |
| 433 | // As vendor snapshot is only for vendor, such modules won't be used at all. |
| 434 | func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *baseSnapshotDecorator) { |
| 435 | if p.version() != ctx.DeviceConfig().VndkVersion() { |
| 436 | ctx.Module().Disable() |
| 437 | return |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | // |
| 442 | // Module definitions for snapshots of libraries (shared, static, header). |
| 443 | // |
| 444 | // Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and |
| 445 | // static libraries have their prebuilt library files (.so for shared, .a for static) as their src, |
| 446 | // which can be installed or linked against. Also they export flags needed when linked, such as |
| 447 | // include directories, c flags, sanitize dependency information, etc. |
| 448 | // |
| 449 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 450 | type snapshotLibraryProperties struct { |
| 451 | // Prebuilt file for each arch. |
| 452 | Src *string `android:"arch_variant"` |
| 453 | |
| 454 | // list of directories that will be added to the include path (using -I). |
| 455 | Export_include_dirs []string `android:"arch_variant"` |
| 456 | |
| 457 | // list of directories that will be added to the system path (using -isystem). |
| 458 | Export_system_include_dirs []string `android:"arch_variant"` |
| 459 | |
| 460 | // list of flags that will be used for any module that links against this module. |
| 461 | Export_flags []string `android:"arch_variant"` |
| 462 | |
| 463 | // Whether this prebuilt needs to depend on sanitize ubsan runtime or not. |
| 464 | Sanitize_ubsan_dep *bool `android:"arch_variant"` |
| 465 | |
| 466 | // Whether this prebuilt needs to depend on sanitize minimal runtime or not. |
| 467 | Sanitize_minimal_dep *bool `android:"arch_variant"` |
| 468 | } |
| 469 | |
| 470 | type snapshotSanitizer interface { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 471 | isSanitizerEnabled(t SanitizerType) bool |
| 472 | setSanitizerVariation(t SanitizerType, enabled bool) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | type snapshotLibraryDecorator struct { |
| 476 | baseSnapshotDecorator |
| 477 | *libraryDecorator |
| 478 | properties snapshotLibraryProperties |
| 479 | sanitizerProperties struct { |
| 480 | CfiEnabled bool `blueprint:"mutated"` |
| 481 | |
| 482 | // Library flags for cfi variant. |
| 483 | Cfi snapshotLibraryProperties `android:"arch_variant"` |
| 484 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 488 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
| 489 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 490 | } |
| 491 | |
| 492 | func (p *snapshotLibraryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 493 | arches := config.Arches() |
| 494 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 495 | return false |
| 496 | } |
| 497 | if !p.header() && p.properties.Src == nil { |
| 498 | return false |
| 499 | } |
| 500 | return true |
| 501 | } |
| 502 | |
| 503 | // cc modules' link functions are to link compiled objects into final binaries. |
| 504 | // As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are |
| 505 | // done by normal library decorator, e.g. exporting flags. |
| 506 | func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 507 | if p.header() { |
| 508 | return p.libraryDecorator.link(ctx, flags, deps, objs) |
| 509 | } |
| 510 | |
| 511 | if p.sanitizerProperties.CfiEnabled { |
| 512 | p.properties = p.sanitizerProperties.Cfi |
| 513 | } |
| 514 | |
| 515 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 516 | return nil |
| 517 | } |
| 518 | |
| 519 | p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...) |
| 520 | p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...) |
| 521 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
| 522 | |
| 523 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 524 | p.unstrippedOutputFile = in |
| 525 | |
| 526 | if p.shared() { |
| 527 | libName := in.Base() |
| 528 | builderFlags := flagsToBuilderFlags(flags) |
| 529 | |
| 530 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 531 | // depending on a table of contents file instead of the library itself. |
| 532 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 533 | p.tocFile = android.OptionalPathForPath(tocFile) |
| 534 | transformSharedObjectToToc(ctx, in, tocFile, builderFlags) |
| 535 | |
| 536 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
| 537 | SharedLibrary: in, |
| 538 | UnstrippedSharedLibrary: p.unstrippedOutputFile, |
| 539 | |
| 540 | TableOfContents: p.tocFile, |
| 541 | }) |
| 542 | } |
| 543 | |
| 544 | if p.static() { |
| 545 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() |
| 546 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ |
| 547 | StaticLibrary: in, |
| 548 | |
| 549 | TransitiveStaticLibrariesForOrdering: depSet, |
| 550 | }) |
| 551 | } |
| 552 | |
| 553 | p.libraryDecorator.flagExporter.setProvider(ctx) |
| 554 | |
| 555 | return in |
| 556 | } |
| 557 | |
| 558 | func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
| 559 | if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) { |
| 560 | p.baseInstaller.install(ctx, file) |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | func (p *snapshotLibraryDecorator) nativeCoverage() bool { |
| 565 | return false |
| 566 | } |
| 567 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 568 | func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 569 | switch t { |
| 570 | case cfi: |
| 571 | return p.sanitizerProperties.Cfi.Src != nil |
| 572 | default: |
| 573 | return false |
| 574 | } |
| 575 | } |
| 576 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 577 | func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 578 | if !enabled { |
| 579 | return |
| 580 | } |
| 581 | switch t { |
| 582 | case cfi: |
| 583 | p.sanitizerProperties.CfiEnabled = true |
| 584 | default: |
| 585 | return |
| 586 | } |
| 587 | } |
| 588 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 589 | func snapshotLibraryFactory(snapshotSuffix, moduleSuffix string) (*Module, *snapshotLibraryDecorator) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 590 | module, library := NewLibrary(android.DeviceSupported) |
| 591 | |
| 592 | module.stl = nil |
| 593 | module.sanitize = nil |
| 594 | library.disableStripping() |
| 595 | |
| 596 | prebuilt := &snapshotLibraryDecorator{ |
| 597 | libraryDecorator: library, |
| 598 | } |
| 599 | |
| 600 | prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 601 | prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 602 | |
| 603 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 604 | if prebuilt.baseLinker.Properties.System_shared_libs == nil { |
| 605 | prebuilt.baseLinker.Properties.System_shared_libs = []string{} |
| 606 | } |
| 607 | |
| 608 | module.compiler = nil |
| 609 | module.linker = prebuilt |
| 610 | module.installer = prebuilt |
| 611 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 612 | prebuilt.init(module, snapshotSuffix, moduleSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 613 | module.AddProperties( |
| 614 | &prebuilt.properties, |
| 615 | &prebuilt.sanitizerProperties, |
| 616 | ) |
| 617 | |
| 618 | return module, prebuilt |
| 619 | } |
| 620 | |
| 621 | // vendor_snapshot_shared is a special prebuilt shared library which is auto-generated by |
| 622 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_shared |
| 623 | // overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION |
| 624 | // is set. |
| 625 | func VendorSnapshotSharedFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 626 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotSharedSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 627 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 628 | return module.Init() |
| 629 | } |
| 630 | |
| 631 | // recovery_snapshot_shared is a special prebuilt shared library which is auto-generated by |
| 632 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_shared |
| 633 | // overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION |
| 634 | // is set. |
| 635 | func RecoverySnapshotSharedFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 636 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotSharedSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 637 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 638 | return module.Init() |
| 639 | } |
| 640 | |
| 641 | // vendor_snapshot_static is a special prebuilt static library which is auto-generated by |
| 642 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_static |
| 643 | // overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION |
| 644 | // is set. |
| 645 | func VendorSnapshotStaticFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 646 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotStaticSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 647 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 648 | return module.Init() |
| 649 | } |
| 650 | |
| 651 | // recovery_snapshot_static is a special prebuilt static library which is auto-generated by |
| 652 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_static |
| 653 | // overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION |
| 654 | // is set. |
| 655 | func RecoverySnapshotStaticFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 656 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotStaticSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 657 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 658 | return module.Init() |
| 659 | } |
| 660 | |
| 661 | // vendor_snapshot_header is a special header library which is auto-generated by |
| 662 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_header |
| 663 | // overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION |
| 664 | // is set. |
| 665 | func VendorSnapshotHeaderFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 666 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotHeaderSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 667 | prebuilt.libraryDecorator.HeaderOnly() |
| 668 | return module.Init() |
| 669 | } |
| 670 | |
| 671 | // recovery_snapshot_header is a special header library which is auto-generated by |
| 672 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_header |
| 673 | // overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION |
| 674 | // is set. |
| 675 | func RecoverySnapshotHeaderFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 676 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotHeaderSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 677 | prebuilt.libraryDecorator.HeaderOnly() |
| 678 | return module.Init() |
| 679 | } |
| 680 | |
| 681 | var _ snapshotSanitizer = (*snapshotLibraryDecorator)(nil) |
| 682 | |
| 683 | // |
| 684 | // Module definitions for snapshots of executable binaries. |
| 685 | // |
| 686 | // Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable |
| 687 | // binaries (e.g. toybox, sh) as their src, which can be installed. |
| 688 | // |
| 689 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 690 | type snapshotBinaryProperties struct { |
| 691 | // Prebuilt file for each arch. |
| 692 | Src *string `android:"arch_variant"` |
| 693 | } |
| 694 | |
| 695 | type snapshotBinaryDecorator struct { |
| 696 | baseSnapshotDecorator |
| 697 | *binaryDecorator |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 698 | properties snapshotBinaryProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | func (p *snapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 702 | if config.DeviceArch() != p.arch() { |
| 703 | return false |
| 704 | } |
| 705 | if p.properties.Src == nil { |
| 706 | return false |
| 707 | } |
| 708 | return true |
| 709 | } |
| 710 | |
| 711 | // cc modules' link functions are to link compiled objects into final binaries. |
| 712 | // As snapshots are prebuilts, this just returns the prebuilt binary |
| 713 | func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
| 714 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 715 | return nil |
| 716 | } |
| 717 | |
| 718 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 719 | p.unstrippedOutputFile = in |
| 720 | binName := in.Base() |
| 721 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 722 | // use cpExecutable to make it executable |
| 723 | outputFile := android.PathForModuleOut(ctx, binName) |
| 724 | ctx.Build(pctx, android.BuildParams{ |
| 725 | Rule: android.CpExecutable, |
| 726 | Description: "prebuilt", |
| 727 | Output: outputFile, |
| 728 | Input: in, |
| 729 | }) |
| 730 | |
| 731 | return outputFile |
| 732 | } |
| 733 | |
| 734 | func (p *snapshotBinaryDecorator) nativeCoverage() bool { |
| 735 | return false |
| 736 | } |
| 737 | |
| 738 | // vendor_snapshot_binary is a special prebuilt executable binary which is auto-generated by |
| 739 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary |
| 740 | // overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. |
| 741 | func VendorSnapshotBinaryFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 742 | return snapshotBinaryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotBinarySuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | // recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by |
| 746 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary |
| 747 | // overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. |
| 748 | func RecoverySnapshotBinaryFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 749 | return snapshotBinaryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotBinarySuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 750 | } |
| 751 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 752 | func snapshotBinaryFactory(snapshotSuffix, moduleSuffix string) android.Module { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 753 | module, binary := NewBinary(android.DeviceSupported) |
| 754 | binary.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 755 | binary.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 756 | |
| 757 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 758 | if binary.baseLinker.Properties.System_shared_libs == nil { |
| 759 | binary.baseLinker.Properties.System_shared_libs = []string{} |
| 760 | } |
| 761 | |
| 762 | prebuilt := &snapshotBinaryDecorator{ |
| 763 | binaryDecorator: binary, |
| 764 | } |
| 765 | |
| 766 | module.compiler = nil |
| 767 | module.sanitize = nil |
| 768 | module.stl = nil |
| 769 | module.linker = prebuilt |
| 770 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 771 | prebuilt.init(module, snapshotSuffix, moduleSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 772 | module.AddProperties(&prebuilt.properties) |
| 773 | return module.Init() |
| 774 | } |
| 775 | |
| 776 | // |
| 777 | // Module definitions for snapshots of object files (*.o). |
| 778 | // |
| 779 | // Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object |
| 780 | // files (*.o) as their src. |
| 781 | // |
| 782 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 783 | type vendorSnapshotObjectProperties struct { |
| 784 | // Prebuilt file for each arch. |
| 785 | Src *string `android:"arch_variant"` |
| 786 | } |
| 787 | |
| 788 | type snapshotObjectLinker struct { |
| 789 | baseSnapshotDecorator |
| 790 | objectLinker |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 791 | properties vendorSnapshotObjectProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | func (p *snapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool { |
| 795 | if config.DeviceArch() != p.arch() { |
| 796 | return false |
| 797 | } |
| 798 | if p.properties.Src == nil { |
| 799 | return false |
| 800 | } |
| 801 | return true |
| 802 | } |
| 803 | |
| 804 | // cc modules' link functions are to link compiled objects into final binaries. |
| 805 | // As snapshots are prebuilts, this just returns the prebuilt binary |
| 806 | func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
| 807 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 808 | return nil |
| 809 | } |
| 810 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 811 | return android.PathForModuleSrc(ctx, *p.properties.Src) |
| 812 | } |
| 813 | |
| 814 | func (p *snapshotObjectLinker) nativeCoverage() bool { |
| 815 | return false |
| 816 | } |
| 817 | |
| 818 | // vendor_snapshot_object is a special prebuilt compiled object file which is auto-generated by |
| 819 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_object |
| 820 | // overrides the vendor variant of the cc object with the same name, if BOARD_VNDK_VERSION is set. |
| 821 | func VendorSnapshotObjectFactory() android.Module { |
| 822 | module := newObject() |
| 823 | |
| 824 | prebuilt := &snapshotObjectLinker{ |
| 825 | objectLinker: objectLinker{ |
| 826 | baseLinker: NewBaseLinker(nil), |
| 827 | }, |
| 828 | } |
| 829 | module.linker = prebuilt |
| 830 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 831 | prebuilt.init(module, vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotObjectSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 832 | module.AddProperties(&prebuilt.properties) |
| 833 | return module.Init() |
| 834 | } |
| 835 | |
| 836 | // recovery_snapshot_object is a special prebuilt compiled object file which is auto-generated by |
| 837 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_object |
| 838 | // overrides the recovery variant of the cc object with the same name, if BOARD_VNDK_VERSION is set. |
| 839 | func RecoverySnapshotObjectFactory() android.Module { |
| 840 | module := newObject() |
| 841 | |
| 842 | prebuilt := &snapshotObjectLinker{ |
| 843 | objectLinker: objectLinker{ |
| 844 | baseLinker: NewBaseLinker(nil), |
| 845 | }, |
| 846 | } |
| 847 | module.linker = prebuilt |
| 848 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 849 | prebuilt.init(module, recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotObjectSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 850 | module.AddProperties(&prebuilt.properties) |
| 851 | return module.Init() |
| 852 | } |
| 853 | |
| 854 | type snapshotInterface interface { |
| 855 | matchesWithDevice(config android.DeviceConfig) bool |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 856 | isSnapshotPrebuilt() bool |
| 857 | version() string |
| 858 | snapshotAndroidMkSuffix() string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) |
| 862 | var _ snapshotInterface = (*snapshotLibraryDecorator)(nil) |
| 863 | var _ snapshotInterface = (*snapshotBinaryDecorator)(nil) |
| 864 | var _ snapshotInterface = (*snapshotObjectLinker)(nil) |