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