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 { |
Jose Galmes | 4c6895e | 2021-02-09 07:44:30 -0800 | [diff] [blame] | 198 | // If we're using full snapshot, not directed snapshot, capture every module |
| 199 | if !cfg.DirectedRecoverySnapshot() { |
| 200 | return false |
| 201 | } |
| 202 | // Else, checks if name is in RECOVERY_SNAPSHOT_MODULES. |
| 203 | return !cfg.RecoverySnapshotModules()[name] |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 204 | } |
| 205 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 206 | func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string { |
| 207 | return android.RecoveryVariation |
| 208 | } |
| 209 | |
| 210 | func (recoverySnapshotImage) moduleNameSuffix() string { |
| 211 | return recoverySuffix |
| 212 | } |
| 213 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 214 | var vendorSnapshotImageSingleton vendorSnapshotImage |
| 215 | var recoverySnapshotImageSingleton recoverySnapshotImage |
| 216 | |
| 217 | func init() { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 218 | vendorSnapshotImageSingleton.init(android.InitRegistrationContext) |
| 219 | recoverySnapshotImageSingleton.init(android.InitRegistrationContext) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | const ( |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 223 | snapshotHeaderSuffix = "_header." |
| 224 | snapshotSharedSuffix = "_shared." |
| 225 | snapshotStaticSuffix = "_static." |
| 226 | snapshotBinarySuffix = "_binary." |
| 227 | snapshotObjectSuffix = "_object." |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 228 | ) |
| 229 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 230 | type SnapshotProperties struct { |
| 231 | Header_libs []string `android:"arch_variant"` |
| 232 | Static_libs []string `android:"arch_variant"` |
| 233 | Shared_libs []string `android:"arch_variant"` |
| 234 | Vndk_libs []string `android:"arch_variant"` |
| 235 | Binaries []string `android:"arch_variant"` |
| 236 | Objects []string `android:"arch_variant"` |
| 237 | } |
| 238 | |
| 239 | type snapshot struct { |
| 240 | android.ModuleBase |
| 241 | |
| 242 | properties SnapshotProperties |
| 243 | |
| 244 | baseSnapshot baseSnapshotDecorator |
| 245 | |
| 246 | image snapshotImage |
| 247 | } |
| 248 | |
| 249 | func (s *snapshot) ImageMutatorBegin(ctx android.BaseModuleContext) { |
| 250 | cfg := ctx.DeviceConfig() |
| 251 | if !s.image.isUsingSnapshot(cfg) || s.image.targetSnapshotVersion(cfg) != s.baseSnapshot.version() { |
| 252 | s.Disable() |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | func (s *snapshot) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 257 | return false |
| 258 | } |
| 259 | |
| 260 | func (s *snapshot) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 261 | return false |
| 262 | } |
| 263 | |
| 264 | func (s *snapshot) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 265 | return false |
| 266 | } |
| 267 | |
| 268 | func (s *snapshot) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 269 | return false |
| 270 | } |
| 271 | |
| 272 | func (s *snapshot) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
| 273 | return []string{s.image.imageVariantName(ctx.DeviceConfig())} |
| 274 | } |
| 275 | |
| 276 | func (s *snapshot) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
| 277 | } |
| 278 | |
| 279 | func (s *snapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 280 | // Nothing, the snapshot module is only used to forward dependency information in DepsMutator. |
| 281 | } |
| 282 | |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame^] | 283 | func getSnapshotNameSuffix(moduleSuffix, version, arch string) string { |
| 284 | versionSuffix := version |
| 285 | if arch != "" { |
| 286 | versionSuffix += "." + arch |
| 287 | } |
| 288 | return moduleSuffix + versionSuffix |
| 289 | } |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 290 | |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame^] | 291 | func (s *snapshot) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 292 | collectSnapshotMap := func(names []string, snapshotSuffix, moduleSuffix string) map[string]string { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 293 | snapshotMap := make(map[string]string) |
Justin Yun | 4813867 | 2021-02-25 18:21:27 +0900 | [diff] [blame] | 294 | for _, name := range names { |
| 295 | snapshotMap[name] = name + |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame^] | 296 | getSnapshotNameSuffix(snapshotSuffix+moduleSuffix, |
| 297 | s.baseSnapshot.version(), ctx.Arch().ArchType.Name) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 298 | } |
| 299 | return snapshotMap |
| 300 | } |
| 301 | |
| 302 | snapshotSuffix := s.image.moduleNameSuffix() |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame^] | 303 | headers := collectSnapshotMap(s.properties.Header_libs, snapshotSuffix, snapshotHeaderSuffix) |
| 304 | binaries := collectSnapshotMap(s.properties.Binaries, snapshotSuffix, snapshotBinarySuffix) |
| 305 | objects := collectSnapshotMap(s.properties.Objects, snapshotSuffix, snapshotObjectSuffix) |
| 306 | staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, snapshotStaticSuffix) |
| 307 | sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, snapshotSharedSuffix) |
| 308 | vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix) |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 309 | for k, v := range vndkLibs { |
| 310 | sharedLibs[k] = v |
| 311 | } |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame^] | 312 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 313 | ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{ |
| 314 | HeaderLibs: headers, |
| 315 | Binaries: binaries, |
| 316 | Objects: objects, |
| 317 | StaticLibs: staticLibs, |
| 318 | SharedLibs: sharedLibs, |
| 319 | }) |
| 320 | } |
| 321 | |
| 322 | type SnapshotInfo struct { |
| 323 | HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs map[string]string |
| 324 | } |
| 325 | |
| 326 | var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") |
| 327 | |
| 328 | var _ android.ImageInterface = (*snapshot)(nil) |
| 329 | |
| 330 | func vendorSnapshotFactory() android.Module { |
| 331 | return snapshotFactory(vendorSnapshotImageSingleton) |
| 332 | } |
| 333 | |
| 334 | func recoverySnapshotFactory() android.Module { |
| 335 | return snapshotFactory(recoverySnapshotImageSingleton) |
| 336 | } |
| 337 | |
| 338 | func snapshotFactory(image snapshotImage) android.Module { |
| 339 | snapshot := &snapshot{} |
| 340 | snapshot.image = image |
| 341 | snapshot.AddProperties( |
| 342 | &snapshot.properties, |
| 343 | &snapshot.baseSnapshot.baseProperties) |
| 344 | android.InitAndroidArchModule(snapshot, android.DeviceSupported, android.MultilibBoth) |
| 345 | return snapshot |
| 346 | } |
| 347 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 348 | type baseSnapshotDecoratorProperties struct { |
| 349 | // snapshot version. |
| 350 | Version string |
| 351 | |
| 352 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') |
| 353 | Target_arch string |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 354 | |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 355 | // Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor". |
| 356 | Androidmk_suffix string |
| 357 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 358 | // Suffix to be added to the module name, e.g., vendor_shared, |
| 359 | // recovery_shared, etc. |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 360 | ModuleSuffix string `blueprint:"mutated"` |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | // baseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot |
| 364 | // version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't |
| 365 | // collide with source modules. e.g. the following example module, |
| 366 | // |
| 367 | // vendor_snapshot_static { |
| 368 | // name: "libbase", |
| 369 | // arch: "arm64", |
| 370 | // version: 30, |
| 371 | // ... |
| 372 | // } |
| 373 | // |
| 374 | // will be seen as "libbase.vendor_static.30.arm64" by Soong. |
| 375 | type baseSnapshotDecorator struct { |
| 376 | baseProperties baseSnapshotDecoratorProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | func (p *baseSnapshotDecorator) Name(name string) string { |
| 380 | return name + p.NameSuffix() |
| 381 | } |
| 382 | |
| 383 | func (p *baseSnapshotDecorator) NameSuffix() string { |
Justin Yun | 07b9f86 | 2021-02-26 14:00:03 +0900 | [diff] [blame^] | 384 | return getSnapshotNameSuffix(p.moduleSuffix(), p.version(), p.arch()) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | func (p *baseSnapshotDecorator) version() string { |
| 388 | return p.baseProperties.Version |
| 389 | } |
| 390 | |
| 391 | func (p *baseSnapshotDecorator) arch() string { |
| 392 | return p.baseProperties.Target_arch |
| 393 | } |
| 394 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 395 | func (p *baseSnapshotDecorator) moduleSuffix() string { |
| 396 | return p.baseProperties.ModuleSuffix |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 397 | } |
| 398 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 399 | func (p *baseSnapshotDecorator) isSnapshotPrebuilt() bool { |
| 400 | return true |
| 401 | } |
| 402 | |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 403 | func (p *baseSnapshotDecorator) snapshotAndroidMkSuffix() string { |
| 404 | return p.baseProperties.Androidmk_suffix |
| 405 | } |
| 406 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 407 | // Call this with a module suffix after creating a snapshot module, such as |
| 408 | // vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc. |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 409 | func (p *baseSnapshotDecorator) init(m *Module, snapshotSuffix, moduleSuffix string) { |
| 410 | p.baseProperties.ModuleSuffix = snapshotSuffix + moduleSuffix |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 411 | m.AddProperties(&p.baseProperties) |
| 412 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
| 413 | vendorSnapshotLoadHook(ctx, p) |
| 414 | }) |
| 415 | } |
| 416 | |
| 417 | // vendorSnapshotLoadHook disables snapshots if it's not BOARD_VNDK_VERSION. |
| 418 | // As vendor snapshot is only for vendor, such modules won't be used at all. |
| 419 | func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *baseSnapshotDecorator) { |
| 420 | if p.version() != ctx.DeviceConfig().VndkVersion() { |
| 421 | ctx.Module().Disable() |
| 422 | return |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | // |
| 427 | // Module definitions for snapshots of libraries (shared, static, header). |
| 428 | // |
| 429 | // Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and |
| 430 | // static libraries have their prebuilt library files (.so for shared, .a for static) as their src, |
| 431 | // which can be installed or linked against. Also they export flags needed when linked, such as |
| 432 | // include directories, c flags, sanitize dependency information, etc. |
| 433 | // |
| 434 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 435 | type snapshotLibraryProperties struct { |
| 436 | // Prebuilt file for each arch. |
| 437 | Src *string `android:"arch_variant"` |
| 438 | |
| 439 | // list of directories that will be added to the include path (using -I). |
| 440 | Export_include_dirs []string `android:"arch_variant"` |
| 441 | |
| 442 | // list of directories that will be added to the system path (using -isystem). |
| 443 | Export_system_include_dirs []string `android:"arch_variant"` |
| 444 | |
| 445 | // list of flags that will be used for any module that links against this module. |
| 446 | Export_flags []string `android:"arch_variant"` |
| 447 | |
| 448 | // Whether this prebuilt needs to depend on sanitize ubsan runtime or not. |
| 449 | Sanitize_ubsan_dep *bool `android:"arch_variant"` |
| 450 | |
| 451 | // Whether this prebuilt needs to depend on sanitize minimal runtime or not. |
| 452 | Sanitize_minimal_dep *bool `android:"arch_variant"` |
| 453 | } |
| 454 | |
| 455 | type snapshotSanitizer interface { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 456 | isSanitizerEnabled(t SanitizerType) bool |
| 457 | setSanitizerVariation(t SanitizerType, enabled bool) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | type snapshotLibraryDecorator struct { |
| 461 | baseSnapshotDecorator |
| 462 | *libraryDecorator |
| 463 | properties snapshotLibraryProperties |
| 464 | sanitizerProperties struct { |
| 465 | CfiEnabled bool `blueprint:"mutated"` |
| 466 | |
| 467 | // Library flags for cfi variant. |
| 468 | Cfi snapshotLibraryProperties `android:"arch_variant"` |
| 469 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 473 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
| 474 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 475 | } |
| 476 | |
| 477 | func (p *snapshotLibraryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 478 | arches := config.Arches() |
| 479 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 480 | return false |
| 481 | } |
| 482 | if !p.header() && p.properties.Src == nil { |
| 483 | return false |
| 484 | } |
| 485 | return true |
| 486 | } |
| 487 | |
| 488 | // cc modules' link functions are to link compiled objects into final binaries. |
| 489 | // As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are |
| 490 | // done by normal library decorator, e.g. exporting flags. |
| 491 | 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] | 492 | if p.header() { |
| 493 | return p.libraryDecorator.link(ctx, flags, deps, objs) |
| 494 | } |
| 495 | |
| 496 | if p.sanitizerProperties.CfiEnabled { |
| 497 | p.properties = p.sanitizerProperties.Cfi |
| 498 | } |
| 499 | |
| 500 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 501 | return nil |
| 502 | } |
| 503 | |
| 504 | p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...) |
| 505 | p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...) |
| 506 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
| 507 | |
| 508 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 509 | p.unstrippedOutputFile = in |
| 510 | |
| 511 | if p.shared() { |
| 512 | libName := in.Base() |
| 513 | builderFlags := flagsToBuilderFlags(flags) |
| 514 | |
| 515 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 516 | // depending on a table of contents file instead of the library itself. |
| 517 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 518 | p.tocFile = android.OptionalPathForPath(tocFile) |
| 519 | transformSharedObjectToToc(ctx, in, tocFile, builderFlags) |
| 520 | |
| 521 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
| 522 | SharedLibrary: in, |
| 523 | UnstrippedSharedLibrary: p.unstrippedOutputFile, |
| 524 | |
| 525 | TableOfContents: p.tocFile, |
| 526 | }) |
| 527 | } |
| 528 | |
| 529 | if p.static() { |
| 530 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() |
| 531 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ |
| 532 | StaticLibrary: in, |
| 533 | |
| 534 | TransitiveStaticLibrariesForOrdering: depSet, |
| 535 | }) |
| 536 | } |
| 537 | |
| 538 | p.libraryDecorator.flagExporter.setProvider(ctx) |
| 539 | |
| 540 | return in |
| 541 | } |
| 542 | |
| 543 | func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
| 544 | if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) { |
| 545 | p.baseInstaller.install(ctx, file) |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | func (p *snapshotLibraryDecorator) nativeCoverage() bool { |
| 550 | return false |
| 551 | } |
| 552 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 553 | func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 554 | switch t { |
| 555 | case cfi: |
| 556 | return p.sanitizerProperties.Cfi.Src != nil |
| 557 | default: |
| 558 | return false |
| 559 | } |
| 560 | } |
| 561 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 562 | func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 563 | if !enabled { |
| 564 | return |
| 565 | } |
| 566 | switch t { |
| 567 | case cfi: |
| 568 | p.sanitizerProperties.CfiEnabled = true |
| 569 | default: |
| 570 | return |
| 571 | } |
| 572 | } |
| 573 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 574 | func snapshotLibraryFactory(snapshotSuffix, moduleSuffix string) (*Module, *snapshotLibraryDecorator) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 575 | module, library := NewLibrary(android.DeviceSupported) |
| 576 | |
| 577 | module.stl = nil |
| 578 | module.sanitize = nil |
| 579 | library.disableStripping() |
| 580 | |
| 581 | prebuilt := &snapshotLibraryDecorator{ |
| 582 | libraryDecorator: library, |
| 583 | } |
| 584 | |
| 585 | prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 586 | prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 587 | |
| 588 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 589 | if prebuilt.baseLinker.Properties.System_shared_libs == nil { |
| 590 | prebuilt.baseLinker.Properties.System_shared_libs = []string{} |
| 591 | } |
| 592 | |
| 593 | module.compiler = nil |
| 594 | module.linker = prebuilt |
| 595 | module.installer = prebuilt |
| 596 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 597 | prebuilt.init(module, snapshotSuffix, moduleSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 598 | module.AddProperties( |
| 599 | &prebuilt.properties, |
| 600 | &prebuilt.sanitizerProperties, |
| 601 | ) |
| 602 | |
| 603 | return module, prebuilt |
| 604 | } |
| 605 | |
| 606 | // vendor_snapshot_shared is a special prebuilt shared library which is auto-generated by |
| 607 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_shared |
| 608 | // overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION |
| 609 | // is set. |
| 610 | func VendorSnapshotSharedFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 611 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotSharedSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 612 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 613 | return module.Init() |
| 614 | } |
| 615 | |
| 616 | // recovery_snapshot_shared is a special prebuilt shared library which is auto-generated by |
| 617 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_shared |
| 618 | // overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION |
| 619 | // is set. |
| 620 | func RecoverySnapshotSharedFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 621 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotSharedSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 622 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 623 | return module.Init() |
| 624 | } |
| 625 | |
| 626 | // vendor_snapshot_static is a special prebuilt static library which is auto-generated by |
| 627 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_static |
| 628 | // overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION |
| 629 | // is set. |
| 630 | func VendorSnapshotStaticFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 631 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotStaticSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 632 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 633 | return module.Init() |
| 634 | } |
| 635 | |
| 636 | // recovery_snapshot_static is a special prebuilt static library which is auto-generated by |
| 637 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_static |
| 638 | // overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION |
| 639 | // is set. |
| 640 | func RecoverySnapshotStaticFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 641 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotStaticSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 642 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 643 | return module.Init() |
| 644 | } |
| 645 | |
| 646 | // vendor_snapshot_header is a special header library which is auto-generated by |
| 647 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_header |
| 648 | // overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION |
| 649 | // is set. |
| 650 | func VendorSnapshotHeaderFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 651 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotHeaderSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 652 | prebuilt.libraryDecorator.HeaderOnly() |
| 653 | return module.Init() |
| 654 | } |
| 655 | |
| 656 | // recovery_snapshot_header is a special header library which is auto-generated by |
| 657 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_header |
| 658 | // overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION |
| 659 | // is set. |
| 660 | func RecoverySnapshotHeaderFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 661 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotHeaderSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 662 | prebuilt.libraryDecorator.HeaderOnly() |
| 663 | return module.Init() |
| 664 | } |
| 665 | |
| 666 | var _ snapshotSanitizer = (*snapshotLibraryDecorator)(nil) |
| 667 | |
| 668 | // |
| 669 | // Module definitions for snapshots of executable binaries. |
| 670 | // |
| 671 | // Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable |
| 672 | // binaries (e.g. toybox, sh) as their src, which can be installed. |
| 673 | // |
| 674 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 675 | type snapshotBinaryProperties struct { |
| 676 | // Prebuilt file for each arch. |
| 677 | Src *string `android:"arch_variant"` |
| 678 | } |
| 679 | |
| 680 | type snapshotBinaryDecorator struct { |
| 681 | baseSnapshotDecorator |
| 682 | *binaryDecorator |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 683 | properties snapshotBinaryProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | func (p *snapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 687 | if config.DeviceArch() != p.arch() { |
| 688 | return false |
| 689 | } |
| 690 | if p.properties.Src == nil { |
| 691 | return false |
| 692 | } |
| 693 | return true |
| 694 | } |
| 695 | |
| 696 | // cc modules' link functions are to link compiled objects into final binaries. |
| 697 | // As snapshots are prebuilts, this just returns the prebuilt binary |
| 698 | func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
| 699 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 700 | return nil |
| 701 | } |
| 702 | |
| 703 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 704 | p.unstrippedOutputFile = in |
| 705 | binName := in.Base() |
| 706 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 707 | // use cpExecutable to make it executable |
| 708 | outputFile := android.PathForModuleOut(ctx, binName) |
| 709 | ctx.Build(pctx, android.BuildParams{ |
| 710 | Rule: android.CpExecutable, |
| 711 | Description: "prebuilt", |
| 712 | Output: outputFile, |
| 713 | Input: in, |
| 714 | }) |
| 715 | |
| 716 | return outputFile |
| 717 | } |
| 718 | |
| 719 | func (p *snapshotBinaryDecorator) nativeCoverage() bool { |
| 720 | return false |
| 721 | } |
| 722 | |
| 723 | // vendor_snapshot_binary is a special prebuilt executable binary which is auto-generated by |
| 724 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary |
| 725 | // overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. |
| 726 | func VendorSnapshotBinaryFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 727 | return snapshotBinaryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotBinarySuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | // recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by |
| 731 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary |
| 732 | // overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. |
| 733 | func RecoverySnapshotBinaryFactory() android.Module { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 734 | return snapshotBinaryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotBinarySuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 735 | } |
| 736 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 737 | func snapshotBinaryFactory(snapshotSuffix, moduleSuffix string) android.Module { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 738 | module, binary := NewBinary(android.DeviceSupported) |
| 739 | binary.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 740 | binary.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 741 | |
| 742 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 743 | if binary.baseLinker.Properties.System_shared_libs == nil { |
| 744 | binary.baseLinker.Properties.System_shared_libs = []string{} |
| 745 | } |
| 746 | |
| 747 | prebuilt := &snapshotBinaryDecorator{ |
| 748 | binaryDecorator: binary, |
| 749 | } |
| 750 | |
| 751 | module.compiler = nil |
| 752 | module.sanitize = nil |
| 753 | module.stl = nil |
| 754 | module.linker = prebuilt |
| 755 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 756 | prebuilt.init(module, snapshotSuffix, moduleSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 757 | module.AddProperties(&prebuilt.properties) |
| 758 | return module.Init() |
| 759 | } |
| 760 | |
| 761 | // |
| 762 | // Module definitions for snapshots of object files (*.o). |
| 763 | // |
| 764 | // Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object |
| 765 | // files (*.o) as their src. |
| 766 | // |
| 767 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 768 | type vendorSnapshotObjectProperties struct { |
| 769 | // Prebuilt file for each arch. |
| 770 | Src *string `android:"arch_variant"` |
| 771 | } |
| 772 | |
| 773 | type snapshotObjectLinker struct { |
| 774 | baseSnapshotDecorator |
| 775 | objectLinker |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 776 | properties vendorSnapshotObjectProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | func (p *snapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool { |
| 780 | if config.DeviceArch() != p.arch() { |
| 781 | return false |
| 782 | } |
| 783 | if p.properties.Src == nil { |
| 784 | return false |
| 785 | } |
| 786 | return true |
| 787 | } |
| 788 | |
| 789 | // cc modules' link functions are to link compiled objects into final binaries. |
| 790 | // As snapshots are prebuilts, this just returns the prebuilt binary |
| 791 | func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
| 792 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 793 | return nil |
| 794 | } |
| 795 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 796 | return android.PathForModuleSrc(ctx, *p.properties.Src) |
| 797 | } |
| 798 | |
| 799 | func (p *snapshotObjectLinker) nativeCoverage() bool { |
| 800 | return false |
| 801 | } |
| 802 | |
| 803 | // vendor_snapshot_object is a special prebuilt compiled object file which is auto-generated by |
| 804 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_object |
| 805 | // overrides the vendor variant of the cc object with the same name, if BOARD_VNDK_VERSION is set. |
| 806 | func VendorSnapshotObjectFactory() android.Module { |
| 807 | module := newObject() |
| 808 | |
| 809 | prebuilt := &snapshotObjectLinker{ |
| 810 | objectLinker: objectLinker{ |
| 811 | baseLinker: NewBaseLinker(nil), |
| 812 | }, |
| 813 | } |
| 814 | module.linker = prebuilt |
| 815 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 816 | prebuilt.init(module, vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotObjectSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 817 | module.AddProperties(&prebuilt.properties) |
| 818 | return module.Init() |
| 819 | } |
| 820 | |
| 821 | // recovery_snapshot_object is a special prebuilt compiled object file which is auto-generated by |
| 822 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_object |
| 823 | // overrides the recovery variant of the cc object with the same name, if BOARD_VNDK_VERSION is set. |
| 824 | func RecoverySnapshotObjectFactory() android.Module { |
| 825 | module := newObject() |
| 826 | |
| 827 | prebuilt := &snapshotObjectLinker{ |
| 828 | objectLinker: objectLinker{ |
| 829 | baseLinker: NewBaseLinker(nil), |
| 830 | }, |
| 831 | } |
| 832 | module.linker = prebuilt |
| 833 | |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 834 | prebuilt.init(module, recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotObjectSuffix) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 835 | module.AddProperties(&prebuilt.properties) |
| 836 | return module.Init() |
| 837 | } |
| 838 | |
| 839 | type snapshotInterface interface { |
| 840 | matchesWithDevice(config android.DeviceConfig) bool |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 841 | isSnapshotPrebuilt() bool |
| 842 | version() string |
| 843 | snapshotAndroidMkSuffix() string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) |
| 847 | var _ snapshotInterface = (*snapshotLibraryDecorator)(nil) |
| 848 | var _ snapshotInterface = (*snapshotBinaryDecorator)(nil) |
| 849 | var _ snapshotInterface = (*snapshotObjectLinker)(nil) |