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