Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 1 | // Copyright 2020 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package cc |
| 15 | |
| 16 | // This file defines snapshot prebuilt modules, e.g. vendor snapshot and recovery snapshot. Such |
| 17 | // snapshot modules will override original source modules with setting BOARD_VNDK_VERSION, with |
| 18 | // snapshot mutators and snapshot information maps which are also defined in this file. |
| 19 | |
| 20 | import ( |
| 21 | "strings" |
| 22 | "sync" |
| 23 | |
| 24 | "android/soong/android" |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 25 | |
| 26 | "github.com/google/blueprint/proptools" |
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 { |
| 32 | // Used to register callbacks with the build system. |
| 33 | init() |
| 34 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 35 | // Returns true if a snapshot should be generated for this image. |
| 36 | shouldGenerateSnapshot(ctx android.SingletonContext) bool |
| 37 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 38 | // Function that returns true if the module is included in this image. |
| 39 | // Using a function return instead of a value to prevent early |
| 40 | // evalution of a function that may be not be defined. |
| 41 | inImage(m *Module) func() bool |
| 42 | |
| 43 | // Returns the value of the "available" property for a given module for |
| 44 | // and snapshot, e.g., "vendor_available", "recovery_available", etc. |
| 45 | // or nil if the property is not defined. |
| 46 | available(m *Module) *bool |
| 47 | |
| 48 | // Returns true if a dir under source tree is an SoC-owned proprietary |
| 49 | // directory, such as device/, vendor/, etc. |
| 50 | // |
| 51 | // For a given snapshot (e.g., vendor, recovery, etc.) if |
| 52 | // isProprietaryPath(dir) returns true, then the module in dir will be |
| 53 | // built from sources. |
| 54 | isProprietaryPath(dir string) bool |
| 55 | |
| 56 | // Whether to include VNDK in the snapshot for this image. |
| 57 | includeVndk() bool |
| 58 | |
| 59 | // Whether a given module has been explicitly excluded from the |
| 60 | // snapshot, e.g., using the exclude_from_vendor_snapshot or |
| 61 | // exclude_from_recovery_snapshot properties. |
| 62 | excludeFromSnapshot(m *Module) bool |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 63 | |
| 64 | // Returns the snapshotMap to be used for a given module and config, or nil if the |
| 65 | // module is not included in this image. |
| 66 | getSnapshotMap(m *Module, cfg android.Config) *snapshotMap |
| 67 | |
| 68 | // Returns mutex used for mutual exclusion when updating the snapshot maps. |
| 69 | getMutex() *sync.Mutex |
| 70 | |
| 71 | // For a given arch, a maps of which modules are included in this image. |
| 72 | suffixModules(config android.Config) map[string]bool |
| 73 | |
| 74 | // Whether to add a given module to the suffix map. |
| 75 | shouldBeAddedToSuffixModules(m *Module) bool |
| 76 | |
| 77 | // Returns true if the build is using a snapshot for this image. |
| 78 | isUsingSnapshot(cfg android.DeviceConfig) bool |
| 79 | |
| 80 | // Whether to skip the module mutator for a module in a given context. |
| 81 | skipModuleMutator(ctx android.BottomUpMutatorContext) bool |
| 82 | |
| 83 | // Whether to skip the source mutator for a given module. |
| 84 | skipSourceMutator(ctx android.BottomUpMutatorContext) bool |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | type vendorSnapshotImage struct{} |
| 88 | type recoverySnapshotImage struct{} |
| 89 | |
| 90 | func (vendorSnapshotImage) init() { |
| 91 | android.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton) |
| 92 | android.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) |
| 93 | android.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory) |
| 94 | android.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory) |
| 95 | android.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory) |
| 96 | android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory) |
Inseob Kim | e9aec6a | 2021-01-05 20:03:22 +0900 | [diff] [blame] | 97 | |
| 98 | android.RegisterSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 99 | } |
| 100 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 101 | func (vendorSnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool { |
| 102 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a snapshot. |
| 103 | return ctx.DeviceConfig().VndkVersion() == "current" |
| 104 | } |
| 105 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 106 | func (vendorSnapshotImage) inImage(m *Module) func() bool { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame^] | 107 | return m.InVendor |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | func (vendorSnapshotImage) available(m *Module) *bool { |
| 111 | return m.VendorProperties.Vendor_available |
| 112 | } |
| 113 | |
| 114 | func (vendorSnapshotImage) isProprietaryPath(dir string) bool { |
| 115 | return isVendorProprietaryPath(dir) |
| 116 | } |
| 117 | |
| 118 | // vendor snapshot includes static/header libraries with vndk: {enabled: true}. |
| 119 | func (vendorSnapshotImage) includeVndk() bool { |
| 120 | return true |
| 121 | } |
| 122 | |
| 123 | func (vendorSnapshotImage) excludeFromSnapshot(m *Module) bool { |
| 124 | return m.ExcludeFromVendorSnapshot() |
| 125 | } |
| 126 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 127 | func (vendorSnapshotImage) getSnapshotMap(m *Module, cfg android.Config) *snapshotMap { |
| 128 | if lib, ok := m.linker.(libraryInterface); ok { |
| 129 | if lib.static() { |
| 130 | return vendorSnapshotStaticLibs(cfg) |
| 131 | } else if lib.shared() { |
| 132 | return vendorSnapshotSharedLibs(cfg) |
| 133 | } else { |
| 134 | // header |
| 135 | return vendorSnapshotHeaderLibs(cfg) |
| 136 | } |
| 137 | } else if m.binary() { |
| 138 | return vendorSnapshotBinaries(cfg) |
| 139 | } else if m.object() { |
| 140 | return vendorSnapshotObjects(cfg) |
| 141 | } else { |
| 142 | return nil |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | func (vendorSnapshotImage) getMutex() *sync.Mutex { |
| 147 | return &vendorSnapshotsLock |
| 148 | } |
| 149 | |
| 150 | func (vendorSnapshotImage) suffixModules(config android.Config) map[string]bool { |
| 151 | return vendorSuffixModules(config) |
| 152 | } |
| 153 | |
| 154 | func (vendorSnapshotImage) shouldBeAddedToSuffixModules(module *Module) bool { |
| 155 | // vendor suffix should be added to snapshots if the source module isn't vendor: true. |
| 156 | if module.SocSpecific() { |
| 157 | return false |
| 158 | } |
| 159 | |
| 160 | // But we can't just check SocSpecific() since we already passed the image mutator. |
| 161 | // Check ramdisk and recovery to see if we are real "vendor: true" module. |
| 162 | ramdiskAvailable := module.InRamdisk() && !module.OnlyInRamdisk() |
| 163 | vendorRamdiskAvailable := module.InVendorRamdisk() && !module.OnlyInVendorRamdisk() |
| 164 | recoveryAvailable := module.InRecovery() && !module.OnlyInRecovery() |
| 165 | |
| 166 | return !ramdiskAvailable && !recoveryAvailable && !vendorRamdiskAvailable |
| 167 | } |
| 168 | |
| 169 | func (vendorSnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool { |
| 170 | vndkVersion := cfg.VndkVersion() |
| 171 | return vndkVersion != "current" && vndkVersion != "" |
| 172 | } |
| 173 | |
| 174 | func (vendorSnapshotImage) skipModuleMutator(ctx android.BottomUpMutatorContext) bool { |
| 175 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 176 | module, ok := ctx.Module().(*Module) |
| 177 | return !ok || module.VndkVersion() != vndkVersion |
| 178 | } |
| 179 | |
| 180 | func (vendorSnapshotImage) skipSourceMutator(ctx android.BottomUpMutatorContext) bool { |
| 181 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 182 | module, ok := ctx.Module().(*Module) |
| 183 | if !ok { |
| 184 | return true |
| 185 | } |
| 186 | if module.VndkVersion() != vndkVersion { |
| 187 | return true |
| 188 | } |
| 189 | // .. and also filter out llndk library |
| 190 | if module.IsLlndk() { |
| 191 | return true |
| 192 | } |
| 193 | return false |
| 194 | } |
| 195 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 196 | func (recoverySnapshotImage) init() { |
| 197 | android.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton) |
| 198 | android.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory) |
| 199 | android.RegisterModuleType("recovery_snapshot_static", RecoverySnapshotStaticFactory) |
| 200 | android.RegisterModuleType("recovery_snapshot_header", RecoverySnapshotHeaderFactory) |
| 201 | android.RegisterModuleType("recovery_snapshot_binary", RecoverySnapshotBinaryFactory) |
| 202 | android.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory) |
| 203 | } |
| 204 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 205 | func (recoverySnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool { |
| 206 | // RECOVERY_SNAPSHOT_VERSION must be set to 'current' in order to generate a |
| 207 | // snapshot. |
| 208 | return ctx.DeviceConfig().RecoverySnapshotVersion() == "current" |
| 209 | } |
| 210 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 211 | func (recoverySnapshotImage) inImage(m *Module) func() bool { |
| 212 | return m.InRecovery |
| 213 | } |
| 214 | |
| 215 | func (recoverySnapshotImage) available(m *Module) *bool { |
| 216 | return m.Properties.Recovery_available |
| 217 | } |
| 218 | |
| 219 | func (recoverySnapshotImage) isProprietaryPath(dir string) bool { |
| 220 | return isRecoveryProprietaryPath(dir) |
| 221 | } |
| 222 | |
| 223 | // recovery snapshot does NOT treat vndk specially. |
| 224 | func (recoverySnapshotImage) includeVndk() bool { |
| 225 | return false |
| 226 | } |
| 227 | |
| 228 | func (recoverySnapshotImage) excludeFromSnapshot(m *Module) bool { |
| 229 | return m.ExcludeFromRecoverySnapshot() |
| 230 | } |
| 231 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 232 | func (recoverySnapshotImage) getSnapshotMap(m *Module, cfg android.Config) *snapshotMap { |
| 233 | if lib, ok := m.linker.(libraryInterface); ok { |
| 234 | if lib.static() { |
| 235 | return recoverySnapshotStaticLibs(cfg) |
| 236 | } else if lib.shared() { |
| 237 | return recoverySnapshotSharedLibs(cfg) |
| 238 | } else { |
| 239 | // header |
| 240 | return recoverySnapshotHeaderLibs(cfg) |
| 241 | } |
| 242 | } else if m.binary() { |
| 243 | return recoverySnapshotBinaries(cfg) |
| 244 | } else if m.object() { |
| 245 | return recoverySnapshotObjects(cfg) |
| 246 | } else { |
| 247 | return nil |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | func (recoverySnapshotImage) getMutex() *sync.Mutex { |
| 252 | return &recoverySnapshotsLock |
| 253 | } |
| 254 | |
| 255 | func (recoverySnapshotImage) suffixModules(config android.Config) map[string]bool { |
| 256 | return recoverySuffixModules(config) |
| 257 | } |
| 258 | |
| 259 | func (recoverySnapshotImage) shouldBeAddedToSuffixModules(module *Module) bool { |
| 260 | return proptools.BoolDefault(module.Properties.Recovery_available, false) |
| 261 | } |
| 262 | |
| 263 | func (recoverySnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool { |
| 264 | recoverySnapshotVersion := cfg.RecoverySnapshotVersion() |
| 265 | return recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" |
| 266 | } |
| 267 | |
| 268 | func (recoverySnapshotImage) skipModuleMutator(ctx android.BottomUpMutatorContext) bool { |
| 269 | module, ok := ctx.Module().(*Module) |
| 270 | return !ok || !module.InRecovery() |
| 271 | } |
| 272 | |
| 273 | func (recoverySnapshotImage) skipSourceMutator(ctx android.BottomUpMutatorContext) bool { |
| 274 | module, ok := ctx.Module().(*Module) |
| 275 | return !ok || !module.InRecovery() |
| 276 | } |
| 277 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 278 | var vendorSnapshotImageSingleton vendorSnapshotImage |
| 279 | var recoverySnapshotImageSingleton recoverySnapshotImage |
| 280 | |
| 281 | func init() { |
| 282 | vendorSnapshotImageSingleton.init() |
| 283 | recoverySnapshotImageSingleton.init() |
| 284 | } |
| 285 | |
| 286 | const ( |
| 287 | vendorSnapshotHeaderSuffix = ".vendor_header." |
| 288 | vendorSnapshotSharedSuffix = ".vendor_shared." |
| 289 | vendorSnapshotStaticSuffix = ".vendor_static." |
| 290 | vendorSnapshotBinarySuffix = ".vendor_binary." |
| 291 | vendorSnapshotObjectSuffix = ".vendor_object." |
| 292 | ) |
| 293 | |
| 294 | const ( |
| 295 | recoverySnapshotHeaderSuffix = ".recovery_header." |
| 296 | recoverySnapshotSharedSuffix = ".recovery_shared." |
| 297 | recoverySnapshotStaticSuffix = ".recovery_static." |
| 298 | recoverySnapshotBinarySuffix = ".recovery_binary." |
| 299 | recoverySnapshotObjectSuffix = ".recovery_object." |
| 300 | ) |
| 301 | |
| 302 | var ( |
| 303 | vendorSnapshotsLock sync.Mutex |
| 304 | vendorSuffixModulesKey = android.NewOnceKey("vendorSuffixModules") |
| 305 | vendorSnapshotHeaderLibsKey = android.NewOnceKey("vendorSnapshotHeaderLibs") |
| 306 | vendorSnapshotStaticLibsKey = android.NewOnceKey("vendorSnapshotStaticLibs") |
| 307 | vendorSnapshotSharedLibsKey = android.NewOnceKey("vendorSnapshotSharedLibs") |
| 308 | vendorSnapshotBinariesKey = android.NewOnceKey("vendorSnapshotBinaries") |
| 309 | vendorSnapshotObjectsKey = android.NewOnceKey("vendorSnapshotObjects") |
| 310 | ) |
| 311 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 312 | var ( |
| 313 | recoverySnapshotsLock sync.Mutex |
| 314 | recoverySuffixModulesKey = android.NewOnceKey("recoverySuffixModules") |
| 315 | recoverySnapshotHeaderLibsKey = android.NewOnceKey("recoverySnapshotHeaderLibs") |
| 316 | recoverySnapshotStaticLibsKey = android.NewOnceKey("recoverySnapshotStaticLibs") |
| 317 | recoverySnapshotSharedLibsKey = android.NewOnceKey("recoverySnapshotSharedLibs") |
| 318 | recoverySnapshotBinariesKey = android.NewOnceKey("recoverySnapshotBinaries") |
| 319 | recoverySnapshotObjectsKey = android.NewOnceKey("recoverySnapshotObjects") |
| 320 | ) |
| 321 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 322 | // vendorSuffixModules holds names of modules whose vendor variants should have the vendor suffix. |
| 323 | // This is determined by source modules, and then this will be used when exporting snapshot modules |
| 324 | // to Makefile. |
| 325 | // |
| 326 | // For example, if libbase has "vendor_available: true", the name of core variant will be "libbase" |
| 327 | // while the name of vendor variant will be "libbase.vendor". In such cases, the vendor snapshot of |
| 328 | // "libbase" should be exported with the name "libbase.vendor". |
| 329 | // |
| 330 | // Refer to VendorSnapshotSourceMutator and makeLibName which use this. |
| 331 | func vendorSuffixModules(config android.Config) map[string]bool { |
| 332 | return config.Once(vendorSuffixModulesKey, func() interface{} { |
| 333 | return make(map[string]bool) |
| 334 | }).(map[string]bool) |
| 335 | } |
| 336 | |
| 337 | // these are vendor snapshot maps holding names of vendor snapshot modules |
| 338 | func vendorSnapshotHeaderLibs(config android.Config) *snapshotMap { |
| 339 | return config.Once(vendorSnapshotHeaderLibsKey, func() interface{} { |
| 340 | return newSnapshotMap() |
| 341 | }).(*snapshotMap) |
| 342 | } |
| 343 | |
| 344 | func vendorSnapshotSharedLibs(config android.Config) *snapshotMap { |
| 345 | return config.Once(vendorSnapshotSharedLibsKey, func() interface{} { |
| 346 | return newSnapshotMap() |
| 347 | }).(*snapshotMap) |
| 348 | } |
| 349 | |
| 350 | func vendorSnapshotStaticLibs(config android.Config) *snapshotMap { |
| 351 | return config.Once(vendorSnapshotStaticLibsKey, func() interface{} { |
| 352 | return newSnapshotMap() |
| 353 | }).(*snapshotMap) |
| 354 | } |
| 355 | |
| 356 | func vendorSnapshotBinaries(config android.Config) *snapshotMap { |
| 357 | return config.Once(vendorSnapshotBinariesKey, func() interface{} { |
| 358 | return newSnapshotMap() |
| 359 | }).(*snapshotMap) |
| 360 | } |
| 361 | |
| 362 | func vendorSnapshotObjects(config android.Config) *snapshotMap { |
| 363 | return config.Once(vendorSnapshotObjectsKey, func() interface{} { |
| 364 | return newSnapshotMap() |
| 365 | }).(*snapshotMap) |
| 366 | } |
| 367 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 368 | func recoverySuffixModules(config android.Config) map[string]bool { |
| 369 | return config.Once(recoverySuffixModulesKey, func() interface{} { |
| 370 | return make(map[string]bool) |
| 371 | }).(map[string]bool) |
| 372 | } |
| 373 | |
| 374 | func recoverySnapshotHeaderLibs(config android.Config) *snapshotMap { |
| 375 | return config.Once(recoverySnapshotHeaderLibsKey, func() interface{} { |
| 376 | return newSnapshotMap() |
| 377 | }).(*snapshotMap) |
| 378 | } |
| 379 | |
| 380 | func recoverySnapshotSharedLibs(config android.Config) *snapshotMap { |
| 381 | return config.Once(recoverySnapshotSharedLibsKey, func() interface{} { |
| 382 | return newSnapshotMap() |
| 383 | }).(*snapshotMap) |
| 384 | } |
| 385 | |
| 386 | func recoverySnapshotStaticLibs(config android.Config) *snapshotMap { |
| 387 | return config.Once(recoverySnapshotStaticLibsKey, func() interface{} { |
| 388 | return newSnapshotMap() |
| 389 | }).(*snapshotMap) |
| 390 | } |
| 391 | |
| 392 | func recoverySnapshotBinaries(config android.Config) *snapshotMap { |
| 393 | return config.Once(recoverySnapshotBinariesKey, func() interface{} { |
| 394 | return newSnapshotMap() |
| 395 | }).(*snapshotMap) |
| 396 | } |
| 397 | |
| 398 | func recoverySnapshotObjects(config android.Config) *snapshotMap { |
| 399 | return config.Once(recoverySnapshotObjectsKey, func() interface{} { |
| 400 | return newSnapshotMap() |
| 401 | }).(*snapshotMap) |
| 402 | } |
| 403 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 404 | type baseSnapshotDecoratorProperties struct { |
| 405 | // snapshot version. |
| 406 | Version string |
| 407 | |
| 408 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') |
| 409 | Target_arch string |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 410 | |
| 411 | // Suffix to be added to the module name, e.g., vendor_shared, |
| 412 | // recovery_shared, etc. |
| 413 | Module_suffix string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | // baseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot |
| 417 | // version, snapshot arch, etc. It also adds a special suffix to Soong module name, so it doesn't |
| 418 | // collide with source modules. e.g. the following example module, |
| 419 | // |
| 420 | // vendor_snapshot_static { |
| 421 | // name: "libbase", |
| 422 | // arch: "arm64", |
| 423 | // version: 30, |
| 424 | // ... |
| 425 | // } |
| 426 | // |
| 427 | // will be seen as "libbase.vendor_static.30.arm64" by Soong. |
| 428 | type baseSnapshotDecorator struct { |
| 429 | baseProperties baseSnapshotDecoratorProperties |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | func (p *baseSnapshotDecorator) Name(name string) string { |
| 433 | return name + p.NameSuffix() |
| 434 | } |
| 435 | |
| 436 | func (p *baseSnapshotDecorator) NameSuffix() string { |
| 437 | versionSuffix := p.version() |
| 438 | if p.arch() != "" { |
| 439 | versionSuffix += "." + p.arch() |
| 440 | } |
| 441 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 442 | return p.baseProperties.Module_suffix + versionSuffix |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | func (p *baseSnapshotDecorator) version() string { |
| 446 | return p.baseProperties.Version |
| 447 | } |
| 448 | |
| 449 | func (p *baseSnapshotDecorator) arch() string { |
| 450 | return p.baseProperties.Target_arch |
| 451 | } |
| 452 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 453 | func (p *baseSnapshotDecorator) module_suffix() string { |
| 454 | return p.baseProperties.Module_suffix |
| 455 | } |
| 456 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 457 | func (p *baseSnapshotDecorator) isSnapshotPrebuilt() bool { |
| 458 | return true |
| 459 | } |
| 460 | |
| 461 | // Call this with a module suffix after creating a snapshot module, such as |
| 462 | // vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc. |
| 463 | func (p *baseSnapshotDecorator) init(m *Module, suffix string) { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 464 | p.baseProperties.Module_suffix = suffix |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 465 | m.AddProperties(&p.baseProperties) |
| 466 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { |
| 467 | vendorSnapshotLoadHook(ctx, p) |
| 468 | }) |
| 469 | } |
| 470 | |
| 471 | // vendorSnapshotLoadHook disables snapshots if it's not BOARD_VNDK_VERSION. |
| 472 | // As vendor snapshot is only for vendor, such modules won't be used at all. |
| 473 | func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *baseSnapshotDecorator) { |
| 474 | if p.version() != ctx.DeviceConfig().VndkVersion() { |
| 475 | ctx.Module().Disable() |
| 476 | return |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | // |
| 481 | // Module definitions for snapshots of libraries (shared, static, header). |
| 482 | // |
| 483 | // Modules (vendor|recovery)_snapshot_(shared|static|header) are defined here. Shared libraries and |
| 484 | // static libraries have their prebuilt library files (.so for shared, .a for static) as their src, |
| 485 | // which can be installed or linked against. Also they export flags needed when linked, such as |
| 486 | // include directories, c flags, sanitize dependency information, etc. |
| 487 | // |
| 488 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 489 | type snapshotLibraryProperties struct { |
| 490 | // Prebuilt file for each arch. |
| 491 | Src *string `android:"arch_variant"` |
| 492 | |
| 493 | // list of directories that will be added to the include path (using -I). |
| 494 | Export_include_dirs []string `android:"arch_variant"` |
| 495 | |
| 496 | // list of directories that will be added to the system path (using -isystem). |
| 497 | Export_system_include_dirs []string `android:"arch_variant"` |
| 498 | |
| 499 | // list of flags that will be used for any module that links against this module. |
| 500 | Export_flags []string `android:"arch_variant"` |
| 501 | |
| 502 | // Whether this prebuilt needs to depend on sanitize ubsan runtime or not. |
| 503 | Sanitize_ubsan_dep *bool `android:"arch_variant"` |
| 504 | |
| 505 | // Whether this prebuilt needs to depend on sanitize minimal runtime or not. |
| 506 | Sanitize_minimal_dep *bool `android:"arch_variant"` |
| 507 | } |
| 508 | |
| 509 | type snapshotSanitizer interface { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame^] | 510 | isSanitizerEnabled(t SanitizerType) bool |
| 511 | setSanitizerVariation(t SanitizerType, enabled bool) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | type snapshotLibraryDecorator struct { |
| 515 | baseSnapshotDecorator |
| 516 | *libraryDecorator |
| 517 | properties snapshotLibraryProperties |
| 518 | sanitizerProperties struct { |
| 519 | CfiEnabled bool `blueprint:"mutated"` |
| 520 | |
| 521 | // Library flags for cfi variant. |
| 522 | Cfi snapshotLibraryProperties `android:"arch_variant"` |
| 523 | } |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 524 | androidMkSuffix string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 528 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
| 529 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 530 | } |
| 531 | |
| 532 | func (p *snapshotLibraryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 533 | arches := config.Arches() |
| 534 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 535 | return false |
| 536 | } |
| 537 | if !p.header() && p.properties.Src == nil { |
| 538 | return false |
| 539 | } |
| 540 | return true |
| 541 | } |
| 542 | |
| 543 | // cc modules' link functions are to link compiled objects into final binaries. |
| 544 | // As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are |
| 545 | // done by normal library decorator, e.g. exporting flags. |
| 546 | func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
| 547 | m := ctx.Module().(*Module) |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 548 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame^] | 549 | if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 550 | p.androidMkSuffix = vendorSuffix |
| 551 | } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] { |
| 552 | p.androidMkSuffix = recoverySuffix |
| 553 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 554 | |
| 555 | if p.header() { |
| 556 | return p.libraryDecorator.link(ctx, flags, deps, objs) |
| 557 | } |
| 558 | |
| 559 | if p.sanitizerProperties.CfiEnabled { |
| 560 | p.properties = p.sanitizerProperties.Cfi |
| 561 | } |
| 562 | |
| 563 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 564 | return nil |
| 565 | } |
| 566 | |
| 567 | p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...) |
| 568 | p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...) |
| 569 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
| 570 | |
| 571 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 572 | p.unstrippedOutputFile = in |
| 573 | |
| 574 | if p.shared() { |
| 575 | libName := in.Base() |
| 576 | builderFlags := flagsToBuilderFlags(flags) |
| 577 | |
| 578 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 579 | // depending on a table of contents file instead of the library itself. |
| 580 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 581 | p.tocFile = android.OptionalPathForPath(tocFile) |
| 582 | transformSharedObjectToToc(ctx, in, tocFile, builderFlags) |
| 583 | |
| 584 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
| 585 | SharedLibrary: in, |
| 586 | UnstrippedSharedLibrary: p.unstrippedOutputFile, |
| 587 | |
| 588 | TableOfContents: p.tocFile, |
| 589 | }) |
| 590 | } |
| 591 | |
| 592 | if p.static() { |
| 593 | depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build() |
| 594 | ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ |
| 595 | StaticLibrary: in, |
| 596 | |
| 597 | TransitiveStaticLibrariesForOrdering: depSet, |
| 598 | }) |
| 599 | } |
| 600 | |
| 601 | p.libraryDecorator.flagExporter.setProvider(ctx) |
| 602 | |
| 603 | return in |
| 604 | } |
| 605 | |
| 606 | func (p *snapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
| 607 | if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) { |
| 608 | p.baseInstaller.install(ctx, file) |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | func (p *snapshotLibraryDecorator) nativeCoverage() bool { |
| 613 | return false |
| 614 | } |
| 615 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame^] | 616 | func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 617 | switch t { |
| 618 | case cfi: |
| 619 | return p.sanitizerProperties.Cfi.Src != nil |
| 620 | default: |
| 621 | return false |
| 622 | } |
| 623 | } |
| 624 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame^] | 625 | func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 626 | if !enabled { |
| 627 | return |
| 628 | } |
| 629 | switch t { |
| 630 | case cfi: |
| 631 | p.sanitizerProperties.CfiEnabled = true |
| 632 | default: |
| 633 | return |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | func snapshotLibraryFactory(suffix string) (*Module, *snapshotLibraryDecorator) { |
| 638 | module, library := NewLibrary(android.DeviceSupported) |
| 639 | |
| 640 | module.stl = nil |
| 641 | module.sanitize = nil |
| 642 | library.disableStripping() |
| 643 | |
| 644 | prebuilt := &snapshotLibraryDecorator{ |
| 645 | libraryDecorator: library, |
| 646 | } |
| 647 | |
| 648 | prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 649 | prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 650 | |
| 651 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 652 | if prebuilt.baseLinker.Properties.System_shared_libs == nil { |
| 653 | prebuilt.baseLinker.Properties.System_shared_libs = []string{} |
| 654 | } |
| 655 | |
| 656 | module.compiler = nil |
| 657 | module.linker = prebuilt |
| 658 | module.installer = prebuilt |
| 659 | |
| 660 | prebuilt.init(module, suffix) |
| 661 | module.AddProperties( |
| 662 | &prebuilt.properties, |
| 663 | &prebuilt.sanitizerProperties, |
| 664 | ) |
| 665 | |
| 666 | return module, prebuilt |
| 667 | } |
| 668 | |
| 669 | // vendor_snapshot_shared is a special prebuilt shared library which is auto-generated by |
| 670 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_shared |
| 671 | // overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION |
| 672 | // is set. |
| 673 | func VendorSnapshotSharedFactory() android.Module { |
| 674 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotSharedSuffix) |
| 675 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 676 | return module.Init() |
| 677 | } |
| 678 | |
| 679 | // recovery_snapshot_shared is a special prebuilt shared library which is auto-generated by |
| 680 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_shared |
| 681 | // overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION |
| 682 | // is set. |
| 683 | func RecoverySnapshotSharedFactory() android.Module { |
| 684 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotSharedSuffix) |
| 685 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 686 | return module.Init() |
| 687 | } |
| 688 | |
| 689 | // vendor_snapshot_static is a special prebuilt static library which is auto-generated by |
| 690 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_static |
| 691 | // overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION |
| 692 | // is set. |
| 693 | func VendorSnapshotStaticFactory() android.Module { |
| 694 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotStaticSuffix) |
| 695 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 696 | return module.Init() |
| 697 | } |
| 698 | |
| 699 | // recovery_snapshot_static is a special prebuilt static library which is auto-generated by |
| 700 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_static |
| 701 | // overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION |
| 702 | // is set. |
| 703 | func RecoverySnapshotStaticFactory() android.Module { |
| 704 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotStaticSuffix) |
| 705 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 706 | return module.Init() |
| 707 | } |
| 708 | |
| 709 | // vendor_snapshot_header is a special header library which is auto-generated by |
| 710 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_header |
| 711 | // overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION |
| 712 | // is set. |
| 713 | func VendorSnapshotHeaderFactory() android.Module { |
| 714 | module, prebuilt := snapshotLibraryFactory(vendorSnapshotHeaderSuffix) |
| 715 | prebuilt.libraryDecorator.HeaderOnly() |
| 716 | return module.Init() |
| 717 | } |
| 718 | |
| 719 | // recovery_snapshot_header is a special header library which is auto-generated by |
| 720 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_header |
| 721 | // overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION |
| 722 | // is set. |
| 723 | func RecoverySnapshotHeaderFactory() android.Module { |
| 724 | module, prebuilt := snapshotLibraryFactory(recoverySnapshotHeaderSuffix) |
| 725 | prebuilt.libraryDecorator.HeaderOnly() |
| 726 | return module.Init() |
| 727 | } |
| 728 | |
| 729 | var _ snapshotSanitizer = (*snapshotLibraryDecorator)(nil) |
| 730 | |
| 731 | // |
| 732 | // Module definitions for snapshots of executable binaries. |
| 733 | // |
| 734 | // Modules (vendor|recovery)_snapshot_binary are defined here. They have their prebuilt executable |
| 735 | // binaries (e.g. toybox, sh) as their src, which can be installed. |
| 736 | // |
| 737 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 738 | type snapshotBinaryProperties struct { |
| 739 | // Prebuilt file for each arch. |
| 740 | Src *string `android:"arch_variant"` |
| 741 | } |
| 742 | |
| 743 | type snapshotBinaryDecorator struct { |
| 744 | baseSnapshotDecorator |
| 745 | *binaryDecorator |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 746 | properties snapshotBinaryProperties |
| 747 | androidMkSuffix string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | func (p *snapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 751 | if config.DeviceArch() != p.arch() { |
| 752 | return false |
| 753 | } |
| 754 | if p.properties.Src == nil { |
| 755 | return false |
| 756 | } |
| 757 | return true |
| 758 | } |
| 759 | |
| 760 | // cc modules' link functions are to link compiled objects into final binaries. |
| 761 | // As snapshots are prebuilts, this just returns the prebuilt binary |
| 762 | func (p *snapshotBinaryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
| 763 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 764 | return nil |
| 765 | } |
| 766 | |
| 767 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 768 | p.unstrippedOutputFile = in |
| 769 | binName := in.Base() |
| 770 | |
| 771 | m := ctx.Module().(*Module) |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame^] | 772 | if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 773 | p.androidMkSuffix = vendorSuffix |
| 774 | } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] { |
| 775 | p.androidMkSuffix = recoverySuffix |
| 776 | |
| 777 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 778 | |
| 779 | // use cpExecutable to make it executable |
| 780 | outputFile := android.PathForModuleOut(ctx, binName) |
| 781 | ctx.Build(pctx, android.BuildParams{ |
| 782 | Rule: android.CpExecutable, |
| 783 | Description: "prebuilt", |
| 784 | Output: outputFile, |
| 785 | Input: in, |
| 786 | }) |
| 787 | |
| 788 | return outputFile |
| 789 | } |
| 790 | |
| 791 | func (p *snapshotBinaryDecorator) nativeCoverage() bool { |
| 792 | return false |
| 793 | } |
| 794 | |
| 795 | // vendor_snapshot_binary is a special prebuilt executable binary which is auto-generated by |
| 796 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary |
| 797 | // overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. |
| 798 | func VendorSnapshotBinaryFactory() android.Module { |
| 799 | return snapshotBinaryFactory(vendorSnapshotBinarySuffix) |
| 800 | } |
| 801 | |
| 802 | // recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by |
| 803 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary |
| 804 | // overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set. |
| 805 | func RecoverySnapshotBinaryFactory() android.Module { |
| 806 | return snapshotBinaryFactory(recoverySnapshotBinarySuffix) |
| 807 | } |
| 808 | |
| 809 | func snapshotBinaryFactory(suffix string) android.Module { |
| 810 | module, binary := NewBinary(android.DeviceSupported) |
| 811 | binary.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 812 | binary.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 813 | |
| 814 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 815 | if binary.baseLinker.Properties.System_shared_libs == nil { |
| 816 | binary.baseLinker.Properties.System_shared_libs = []string{} |
| 817 | } |
| 818 | |
| 819 | prebuilt := &snapshotBinaryDecorator{ |
| 820 | binaryDecorator: binary, |
| 821 | } |
| 822 | |
| 823 | module.compiler = nil |
| 824 | module.sanitize = nil |
| 825 | module.stl = nil |
| 826 | module.linker = prebuilt |
| 827 | |
| 828 | prebuilt.init(module, suffix) |
| 829 | module.AddProperties(&prebuilt.properties) |
| 830 | return module.Init() |
| 831 | } |
| 832 | |
| 833 | // |
| 834 | // Module definitions for snapshots of object files (*.o). |
| 835 | // |
| 836 | // Modules (vendor|recovery)_snapshot_object are defined here. They have their prebuilt object |
| 837 | // files (*.o) as their src. |
| 838 | // |
| 839 | // These modules are auto-generated by development/vendor_snapshot/update.py. |
| 840 | type vendorSnapshotObjectProperties struct { |
| 841 | // Prebuilt file for each arch. |
| 842 | Src *string `android:"arch_variant"` |
| 843 | } |
| 844 | |
| 845 | type snapshotObjectLinker struct { |
| 846 | baseSnapshotDecorator |
| 847 | objectLinker |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 848 | properties vendorSnapshotObjectProperties |
| 849 | androidMkSuffix string |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | func (p *snapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool { |
| 853 | if config.DeviceArch() != p.arch() { |
| 854 | return false |
| 855 | } |
| 856 | if p.properties.Src == nil { |
| 857 | return false |
| 858 | } |
| 859 | return true |
| 860 | } |
| 861 | |
| 862 | // cc modules' link functions are to link compiled objects into final binaries. |
| 863 | // As snapshots are prebuilts, this just returns the prebuilt binary |
| 864 | func (p *snapshotObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { |
| 865 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 866 | return nil |
| 867 | } |
| 868 | |
| 869 | m := ctx.Module().(*Module) |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 870 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame^] | 871 | if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 872 | p.androidMkSuffix = vendorSuffix |
| 873 | } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] { |
| 874 | p.androidMkSuffix = recoverySuffix |
| 875 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 876 | |
| 877 | return android.PathForModuleSrc(ctx, *p.properties.Src) |
| 878 | } |
| 879 | |
| 880 | func (p *snapshotObjectLinker) nativeCoverage() bool { |
| 881 | return false |
| 882 | } |
| 883 | |
| 884 | // vendor_snapshot_object is a special prebuilt compiled object file which is auto-generated by |
| 885 | // development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_object |
| 886 | // overrides the vendor variant of the cc object with the same name, if BOARD_VNDK_VERSION is set. |
| 887 | func VendorSnapshotObjectFactory() android.Module { |
| 888 | module := newObject() |
| 889 | |
| 890 | prebuilt := &snapshotObjectLinker{ |
| 891 | objectLinker: objectLinker{ |
| 892 | baseLinker: NewBaseLinker(nil), |
| 893 | }, |
| 894 | } |
| 895 | module.linker = prebuilt |
| 896 | |
| 897 | prebuilt.init(module, vendorSnapshotObjectSuffix) |
| 898 | module.AddProperties(&prebuilt.properties) |
| 899 | return module.Init() |
| 900 | } |
| 901 | |
| 902 | // recovery_snapshot_object is a special prebuilt compiled object file which is auto-generated by |
| 903 | // development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_object |
| 904 | // overrides the recovery variant of the cc object with the same name, if BOARD_VNDK_VERSION is set. |
| 905 | func RecoverySnapshotObjectFactory() android.Module { |
| 906 | module := newObject() |
| 907 | |
| 908 | prebuilt := &snapshotObjectLinker{ |
| 909 | objectLinker: objectLinker{ |
| 910 | baseLinker: NewBaseLinker(nil), |
| 911 | }, |
| 912 | } |
| 913 | module.linker = prebuilt |
| 914 | |
| 915 | prebuilt.init(module, recoverySnapshotObjectSuffix) |
| 916 | module.AddProperties(&prebuilt.properties) |
| 917 | return module.Init() |
| 918 | } |
| 919 | |
| 920 | type snapshotInterface interface { |
| 921 | matchesWithDevice(config android.DeviceConfig) bool |
| 922 | } |
| 923 | |
| 924 | var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) |
| 925 | var _ snapshotInterface = (*snapshotLibraryDecorator)(nil) |
| 926 | var _ snapshotInterface = (*snapshotBinaryDecorator)(nil) |
| 927 | var _ snapshotInterface = (*snapshotObjectLinker)(nil) |
| 928 | |
| 929 | // |
| 930 | // Mutators that helps vendor snapshot modules override source modules. |
| 931 | // |
| 932 | |
| 933 | // VendorSnapshotMutator gathers all snapshots for vendor, and disable all snapshots which don't |
| 934 | // match with device, e.g. |
| 935 | // - snapshot version is different with BOARD_VNDK_VERSION |
| 936 | // - snapshot arch is different with device's arch (e.g. arm vs x86) |
| 937 | // |
| 938 | // This also handles vndk_prebuilt_shared, except for they won't be disabled in any cases, given |
| 939 | // that any versions of VNDK might be packed into vndk APEX. |
| 940 | // |
| 941 | // TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules |
| 942 | func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 943 | snapshotMutator(ctx, vendorSnapshotImageSingleton) |
| 944 | } |
| 945 | |
| 946 | func RecoverySnapshotMutator(ctx android.BottomUpMutatorContext) { |
| 947 | snapshotMutator(ctx, recoverySnapshotImageSingleton) |
| 948 | } |
| 949 | |
| 950 | func snapshotMutator(ctx android.BottomUpMutatorContext, image snapshotImage) { |
| 951 | if !image.isUsingSnapshot(ctx.DeviceConfig()) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 952 | return |
| 953 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 954 | module, ok := ctx.Module().(*Module) |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 955 | if !ok || !module.Enabled() { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 956 | return |
| 957 | } |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 958 | if image.skipModuleMutator(ctx) { |
| 959 | return |
| 960 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 961 | if !module.isSnapshotPrebuilt() { |
| 962 | return |
| 963 | } |
| 964 | |
| 965 | // isSnapshotPrebuilt ensures snapshotInterface |
| 966 | if !module.linker.(snapshotInterface).matchesWithDevice(ctx.DeviceConfig()) { |
| 967 | // Disable unnecessary snapshot module, but do not disable |
| 968 | // vndk_prebuilt_shared because they might be packed into vndk APEX |
| 969 | if !module.IsVndk() { |
| 970 | module.Disable() |
| 971 | } |
| 972 | return |
| 973 | } |
| 974 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 975 | var snapshotMap *snapshotMap = image.getSnapshotMap(module, ctx.Config()) |
| 976 | if snapshotMap == nil { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 977 | return |
| 978 | } |
| 979 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 980 | mutex := image.getMutex() |
| 981 | mutex.Lock() |
| 982 | defer mutex.Unlock() |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 983 | snapshotMap.add(module.BaseModuleName(), ctx.Arch().ArchType, ctx.ModuleName()) |
| 984 | } |
| 985 | |
| 986 | // VendorSnapshotSourceMutator disables source modules which have corresponding snapshots. |
| 987 | func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 988 | snapshotSourceMutator(ctx, vendorSnapshotImageSingleton) |
| 989 | } |
| 990 | |
| 991 | func RecoverySnapshotSourceMutator(ctx android.BottomUpMutatorContext) { |
| 992 | snapshotSourceMutator(ctx, recoverySnapshotImageSingleton) |
| 993 | } |
| 994 | |
| 995 | func snapshotSourceMutator(ctx android.BottomUpMutatorContext, image snapshotImage) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 996 | if !ctx.Device() { |
| 997 | return |
| 998 | } |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 999 | if !image.isUsingSnapshot(ctx.DeviceConfig()) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 1000 | return |
| 1001 | } |
| 1002 | |
| 1003 | module, ok := ctx.Module().(*Module) |
| 1004 | if !ok { |
| 1005 | return |
| 1006 | } |
| 1007 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 1008 | if image.shouldBeAddedToSuffixModules(module) { |
| 1009 | mutex := image.getMutex() |
| 1010 | mutex.Lock() |
| 1011 | defer mutex.Unlock() |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 1012 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 1013 | image.suffixModules(ctx.Config())[ctx.ModuleName()] = true |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 1014 | } |
| 1015 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 1016 | if module.isSnapshotPrebuilt() { |
| 1017 | return |
| 1018 | } |
| 1019 | if image.skipSourceMutator(ctx) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 1020 | return |
| 1021 | } |
| 1022 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 1023 | var snapshotMap *snapshotMap = image.getSnapshotMap(module, ctx.Config()) |
| 1024 | if snapshotMap == nil { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 1025 | return |
| 1026 | } |
| 1027 | |
| 1028 | if _, ok := snapshotMap.get(ctx.ModuleName(), ctx.Arch().ArchType); !ok { |
| 1029 | // Corresponding snapshot doesn't exist |
| 1030 | return |
| 1031 | } |
| 1032 | |
| 1033 | // Disables source modules if corresponding snapshot exists. |
| 1034 | if lib, ok := module.linker.(libraryInterface); ok && lib.buildStatic() && lib.buildShared() { |
| 1035 | // But do not disable because the shared variant depends on the static variant. |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 1036 | module.HideFromMake() |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 1037 | module.Properties.HideFromMake = true |
| 1038 | } else { |
| 1039 | module.Disable() |
| 1040 | } |
| 1041 | } |