Inseob Kim | 8471cda | 2019-11-15 09:59:12 +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 | import ( |
| 17 | "encoding/json" |
| 18 | "path/filepath" |
| 19 | "sort" |
| 20 | "strings" |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 21 | "sync" |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | ) |
| 27 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 28 | const ( |
| 29 | vendorSnapshotHeaderSuffix = ".vendor_header." |
| 30 | vendorSnapshotSharedSuffix = ".vendor_shared." |
| 31 | vendorSnapshotStaticSuffix = ".vendor_static." |
| 32 | vendorSnapshotBinarySuffix = ".vendor_binary." |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 33 | vendorSnapshotObjectSuffix = ".vendor_object." |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | var ( |
| 37 | vendorSnapshotsLock sync.Mutex |
| 38 | vendorSuffixModulesKey = android.NewOnceKey("vendorSuffixModules") |
| 39 | vendorSnapshotHeaderLibsKey = android.NewOnceKey("vendorSnapshotHeaderLibs") |
| 40 | vendorSnapshotStaticLibsKey = android.NewOnceKey("vendorSnapshotStaticLibs") |
| 41 | vendorSnapshotSharedLibsKey = android.NewOnceKey("vendorSnapshotSharedLibs") |
| 42 | vendorSnapshotBinariesKey = android.NewOnceKey("vendorSnapshotBinaries") |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 43 | vendorSnapshotObjectsKey = android.NewOnceKey("vendorSnapshotObjects") |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 44 | ) |
| 45 | |
Inseob Kim | 5f64aec | 2020-02-18 17:27:19 +0900 | [diff] [blame] | 46 | // vendor snapshot maps hold names of vendor snapshot modules per arch |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 47 | func vendorSuffixModules(config android.Config) map[string]bool { |
| 48 | return config.Once(vendorSuffixModulesKey, func() interface{} { |
| 49 | return make(map[string]bool) |
| 50 | }).(map[string]bool) |
| 51 | } |
| 52 | |
| 53 | func vendorSnapshotHeaderLibs(config android.Config) *snapshotMap { |
| 54 | return config.Once(vendorSnapshotHeaderLibsKey, func() interface{} { |
| 55 | return newSnapshotMap() |
| 56 | }).(*snapshotMap) |
| 57 | } |
| 58 | |
| 59 | func vendorSnapshotSharedLibs(config android.Config) *snapshotMap { |
| 60 | return config.Once(vendorSnapshotSharedLibsKey, func() interface{} { |
| 61 | return newSnapshotMap() |
| 62 | }).(*snapshotMap) |
| 63 | } |
| 64 | |
| 65 | func vendorSnapshotStaticLibs(config android.Config) *snapshotMap { |
| 66 | return config.Once(vendorSnapshotStaticLibsKey, func() interface{} { |
| 67 | return newSnapshotMap() |
| 68 | }).(*snapshotMap) |
| 69 | } |
| 70 | |
| 71 | func vendorSnapshotBinaries(config android.Config) *snapshotMap { |
| 72 | return config.Once(vendorSnapshotBinariesKey, func() interface{} { |
| 73 | return newSnapshotMap() |
| 74 | }).(*snapshotMap) |
| 75 | } |
| 76 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 77 | func vendorSnapshotObjects(config android.Config) *snapshotMap { |
| 78 | return config.Once(vendorSnapshotObjectsKey, func() interface{} { |
| 79 | return newSnapshotMap() |
| 80 | }).(*snapshotMap) |
| 81 | } |
| 82 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 83 | type vendorSnapshotLibraryProperties struct { |
| 84 | // snapshot version. |
| 85 | Version string |
| 86 | |
| 87 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') |
| 88 | Target_arch string |
| 89 | |
| 90 | // Prebuilt file for each arch. |
| 91 | Src *string `android:"arch_variant"` |
| 92 | |
| 93 | // list of flags that will be used for any module that links against this module. |
| 94 | Export_flags []string `android:"arch_variant"` |
| 95 | |
| 96 | // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined symbols, |
| 97 | // etc). |
| 98 | Check_elf_files *bool |
| 99 | |
| 100 | // Whether this prebuilt needs to depend on sanitize ubsan runtime or not. |
| 101 | Sanitize_ubsan_dep *bool `android:"arch_variant"` |
| 102 | |
| 103 | // Whether this prebuilt needs to depend on sanitize minimal runtime or not. |
| 104 | Sanitize_minimal_dep *bool `android:"arch_variant"` |
| 105 | } |
| 106 | |
| 107 | type vendorSnapshotLibraryDecorator struct { |
| 108 | *libraryDecorator |
| 109 | properties vendorSnapshotLibraryProperties |
| 110 | androidMkVendorSuffix bool |
| 111 | } |
| 112 | |
| 113 | func (p *vendorSnapshotLibraryDecorator) Name(name string) string { |
| 114 | return name + p.NameSuffix() |
| 115 | } |
| 116 | |
| 117 | func (p *vendorSnapshotLibraryDecorator) NameSuffix() string { |
| 118 | versionSuffix := p.version() |
| 119 | if p.arch() != "" { |
| 120 | versionSuffix += "." + p.arch() |
| 121 | } |
| 122 | |
| 123 | var linkageSuffix string |
| 124 | if p.buildShared() { |
| 125 | linkageSuffix = vendorSnapshotSharedSuffix |
| 126 | } else if p.buildStatic() { |
| 127 | linkageSuffix = vendorSnapshotStaticSuffix |
| 128 | } else { |
| 129 | linkageSuffix = vendorSnapshotHeaderSuffix |
| 130 | } |
| 131 | |
| 132 | return linkageSuffix + versionSuffix |
| 133 | } |
| 134 | |
| 135 | func (p *vendorSnapshotLibraryDecorator) version() string { |
| 136 | return p.properties.Version |
| 137 | } |
| 138 | |
| 139 | func (p *vendorSnapshotLibraryDecorator) arch() string { |
| 140 | return p.properties.Target_arch |
| 141 | } |
| 142 | |
| 143 | func (p *vendorSnapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 144 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
| 145 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 146 | } |
| 147 | |
| 148 | func (p *vendorSnapshotLibraryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 149 | arches := config.Arches() |
| 150 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 151 | return false |
| 152 | } |
| 153 | if !p.header() && p.properties.Src == nil { |
| 154 | return false |
| 155 | } |
| 156 | return true |
| 157 | } |
| 158 | |
| 159 | func (p *vendorSnapshotLibraryDecorator) link(ctx ModuleContext, |
| 160 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 161 | m := ctx.Module().(*Module) |
| 162 | p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] |
| 163 | |
| 164 | if p.header() { |
| 165 | return p.libraryDecorator.link(ctx, flags, deps, objs) |
| 166 | } |
| 167 | |
| 168 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 169 | return nil |
| 170 | } |
| 171 | |
| 172 | p.libraryDecorator.exportIncludes(ctx) |
| 173 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
| 174 | |
| 175 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 176 | p.unstrippedOutputFile = in |
| 177 | |
| 178 | if p.shared() { |
| 179 | libName := in.Base() |
| 180 | builderFlags := flagsToBuilderFlags(flags) |
| 181 | |
| 182 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 183 | // depending on a table of contents file instead of the library itself. |
| 184 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 185 | p.tocFile = android.OptionalPathForPath(tocFile) |
| 186 | TransformSharedObjectToToc(ctx, in, tocFile, builderFlags) |
| 187 | } |
| 188 | |
| 189 | return in |
| 190 | } |
| 191 | |
| 192 | func (p *vendorSnapshotLibraryDecorator) nativeCoverage() bool { |
| 193 | return false |
| 194 | } |
| 195 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 196 | func (p *vendorSnapshotLibraryDecorator) isSnapshotPrebuilt() bool { |
| 197 | return true |
| 198 | } |
| 199 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 200 | func (p *vendorSnapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
| 201 | if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) { |
| 202 | p.baseInstaller.install(ctx, file) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | type vendorSnapshotInterface interface { |
| 207 | version() string |
| 208 | } |
| 209 | |
| 210 | func vendorSnapshotLoadHook(ctx android.LoadHookContext, p vendorSnapshotInterface) { |
| 211 | if p.version() != ctx.DeviceConfig().VndkVersion() { |
| 212 | ctx.Module().Disable() |
| 213 | return |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | func vendorSnapshotLibrary() (*Module, *vendorSnapshotLibraryDecorator) { |
| 218 | module, library := NewLibrary(android.DeviceSupported) |
| 219 | |
| 220 | module.stl = nil |
| 221 | module.sanitize = nil |
| 222 | library.StripProperties.Strip.None = BoolPtr(true) |
| 223 | |
| 224 | prebuilt := &vendorSnapshotLibraryDecorator{ |
| 225 | libraryDecorator: library, |
| 226 | } |
| 227 | |
| 228 | prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 229 | prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 230 | |
| 231 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 232 | if prebuilt.baseLinker.Properties.System_shared_libs == nil { |
| 233 | prebuilt.baseLinker.Properties.System_shared_libs = []string{} |
| 234 | } |
| 235 | |
| 236 | module.compiler = nil |
| 237 | module.linker = prebuilt |
| 238 | module.installer = prebuilt |
| 239 | |
| 240 | module.AddProperties( |
| 241 | &prebuilt.properties, |
| 242 | ) |
| 243 | |
| 244 | return module, prebuilt |
| 245 | } |
| 246 | |
| 247 | func VendorSnapshotSharedFactory() android.Module { |
| 248 | module, prebuilt := vendorSnapshotLibrary() |
| 249 | prebuilt.libraryDecorator.BuildOnlyShared() |
| 250 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 251 | vendorSnapshotLoadHook(ctx, prebuilt) |
| 252 | }) |
| 253 | return module.Init() |
| 254 | } |
| 255 | |
| 256 | func VendorSnapshotStaticFactory() android.Module { |
| 257 | module, prebuilt := vendorSnapshotLibrary() |
| 258 | prebuilt.libraryDecorator.BuildOnlyStatic() |
| 259 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 260 | vendorSnapshotLoadHook(ctx, prebuilt) |
| 261 | }) |
| 262 | return module.Init() |
| 263 | } |
| 264 | |
| 265 | func VendorSnapshotHeaderFactory() android.Module { |
| 266 | module, prebuilt := vendorSnapshotLibrary() |
| 267 | prebuilt.libraryDecorator.HeaderOnly() |
| 268 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 269 | vendorSnapshotLoadHook(ctx, prebuilt) |
| 270 | }) |
| 271 | return module.Init() |
| 272 | } |
| 273 | |
| 274 | type vendorSnapshotBinaryProperties struct { |
| 275 | // snapshot version. |
| 276 | Version string |
| 277 | |
| 278 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64_ab') |
| 279 | Target_arch string |
| 280 | |
| 281 | // Prebuilt file for each arch. |
| 282 | Src *string `android:"arch_variant"` |
| 283 | } |
| 284 | |
| 285 | type vendorSnapshotBinaryDecorator struct { |
| 286 | *binaryDecorator |
| 287 | properties vendorSnapshotBinaryProperties |
| 288 | androidMkVendorSuffix bool |
| 289 | } |
| 290 | |
| 291 | func (p *vendorSnapshotBinaryDecorator) Name(name string) string { |
| 292 | return name + p.NameSuffix() |
| 293 | } |
| 294 | |
| 295 | func (p *vendorSnapshotBinaryDecorator) NameSuffix() string { |
| 296 | versionSuffix := p.version() |
| 297 | if p.arch() != "" { |
| 298 | versionSuffix += "." + p.arch() |
| 299 | } |
| 300 | return vendorSnapshotBinarySuffix + versionSuffix |
| 301 | } |
| 302 | |
| 303 | func (p *vendorSnapshotBinaryDecorator) version() string { |
| 304 | return p.properties.Version |
| 305 | } |
| 306 | |
| 307 | func (p *vendorSnapshotBinaryDecorator) arch() string { |
| 308 | return p.properties.Target_arch |
| 309 | } |
| 310 | |
| 311 | func (p *vendorSnapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 312 | if config.DeviceArch() != p.arch() { |
| 313 | return false |
| 314 | } |
| 315 | if p.properties.Src == nil { |
| 316 | return false |
| 317 | } |
| 318 | return true |
| 319 | } |
| 320 | |
| 321 | func (p *vendorSnapshotBinaryDecorator) link(ctx ModuleContext, |
| 322 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 323 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 324 | return nil |
| 325 | } |
| 326 | |
| 327 | in := android.PathForModuleSrc(ctx, *p.properties.Src) |
| 328 | builderFlags := flagsToBuilderFlags(flags) |
| 329 | p.unstrippedOutputFile = in |
| 330 | binName := in.Base() |
| 331 | if p.needsStrip(ctx) { |
| 332 | stripped := android.PathForModuleOut(ctx, "stripped", binName) |
| 333 | p.stripExecutableOrSharedLib(ctx, in, stripped, builderFlags) |
| 334 | in = stripped |
| 335 | } |
| 336 | |
| 337 | m := ctx.Module().(*Module) |
| 338 | p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] |
| 339 | |
| 340 | // use cpExecutable to make it executable |
| 341 | outputFile := android.PathForModuleOut(ctx, binName) |
| 342 | ctx.Build(pctx, android.BuildParams{ |
| 343 | Rule: android.CpExecutable, |
| 344 | Description: "prebuilt", |
| 345 | Output: outputFile, |
| 346 | Input: in, |
| 347 | }) |
| 348 | |
| 349 | return outputFile |
| 350 | } |
| 351 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 352 | func (p *vendorSnapshotBinaryDecorator) isSnapshotPrebuilt() bool { |
| 353 | return true |
| 354 | } |
| 355 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 356 | func VendorSnapshotBinaryFactory() android.Module { |
| 357 | module, binary := NewBinary(android.DeviceSupported) |
| 358 | binary.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 359 | binary.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 360 | |
| 361 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 362 | if binary.baseLinker.Properties.System_shared_libs == nil { |
| 363 | binary.baseLinker.Properties.System_shared_libs = []string{} |
| 364 | } |
| 365 | |
| 366 | prebuilt := &vendorSnapshotBinaryDecorator{ |
| 367 | binaryDecorator: binary, |
| 368 | } |
| 369 | |
| 370 | module.compiler = nil |
| 371 | module.sanitize = nil |
| 372 | module.stl = nil |
| 373 | module.linker = prebuilt |
| 374 | |
| 375 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 376 | vendorSnapshotLoadHook(ctx, prebuilt) |
| 377 | }) |
| 378 | |
| 379 | module.AddProperties(&prebuilt.properties) |
| 380 | return module.Init() |
| 381 | } |
| 382 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 383 | type vendorSnapshotObjectProperties struct { |
| 384 | // snapshot version. |
| 385 | Version string |
| 386 | |
| 387 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64_ab') |
| 388 | Target_arch string |
| 389 | |
| 390 | // Prebuilt file for each arch. |
| 391 | Src *string `android:"arch_variant"` |
| 392 | } |
| 393 | |
| 394 | type vendorSnapshotObjectLinker struct { |
| 395 | objectLinker |
| 396 | properties vendorSnapshotObjectProperties |
| 397 | androidMkVendorSuffix bool |
| 398 | } |
| 399 | |
| 400 | func (p *vendorSnapshotObjectLinker) Name(name string) string { |
| 401 | return name + p.NameSuffix() |
| 402 | } |
| 403 | |
| 404 | func (p *vendorSnapshotObjectLinker) NameSuffix() string { |
| 405 | versionSuffix := p.version() |
| 406 | if p.arch() != "" { |
| 407 | versionSuffix += "." + p.arch() |
| 408 | } |
| 409 | return vendorSnapshotObjectSuffix + versionSuffix |
| 410 | } |
| 411 | |
| 412 | func (p *vendorSnapshotObjectLinker) version() string { |
| 413 | return p.properties.Version |
| 414 | } |
| 415 | |
| 416 | func (p *vendorSnapshotObjectLinker) arch() string { |
| 417 | return p.properties.Target_arch |
| 418 | } |
| 419 | |
| 420 | func (p *vendorSnapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool { |
| 421 | if config.DeviceArch() != p.arch() { |
| 422 | return false |
| 423 | } |
| 424 | if p.properties.Src == nil { |
| 425 | return false |
| 426 | } |
| 427 | return true |
| 428 | } |
| 429 | |
| 430 | func (p *vendorSnapshotObjectLinker) link(ctx ModuleContext, |
| 431 | flags Flags, deps PathDeps, objs Objects) android.Path { |
| 432 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
| 433 | return nil |
| 434 | } |
| 435 | |
| 436 | m := ctx.Module().(*Module) |
| 437 | p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()] |
| 438 | |
| 439 | return android.PathForModuleSrc(ctx, *p.properties.Src) |
| 440 | } |
| 441 | |
| 442 | func (p *vendorSnapshotObjectLinker) nativeCoverage() bool { |
| 443 | return false |
| 444 | } |
| 445 | |
| 446 | func (p *vendorSnapshotObjectLinker) isSnapshotPrebuilt() bool { |
| 447 | return true |
| 448 | } |
| 449 | |
| 450 | func VendorSnapshotObjectFactory() android.Module { |
| 451 | module := newObject() |
| 452 | |
| 453 | prebuilt := &vendorSnapshotObjectLinker{ |
| 454 | objectLinker: objectLinker{ |
| 455 | baseLinker: NewBaseLinker(nil), |
| 456 | }, |
| 457 | } |
| 458 | module.linker = prebuilt |
| 459 | |
| 460 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 461 | vendorSnapshotLoadHook(ctx, prebuilt) |
| 462 | }) |
| 463 | |
| 464 | module.AddProperties(&prebuilt.properties) |
| 465 | return module.Init() |
| 466 | } |
| 467 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 468 | func init() { |
| 469 | android.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 470 | android.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory) |
| 471 | android.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory) |
| 472 | android.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory) |
| 473 | android.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 474 | android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | func VendorSnapshotSingleton() android.Singleton { |
| 478 | return &vendorSnapshotSingleton{} |
| 479 | } |
| 480 | |
| 481 | type vendorSnapshotSingleton struct { |
| 482 | vendorSnapshotZipFile android.OptionalPath |
| 483 | } |
| 484 | |
| 485 | var ( |
| 486 | // Modules under following directories are ignored. They are OEM's and vendor's |
| 487 | // proprietary modules(device/, vendor/, and hardware/). |
| 488 | // TODO(b/65377115): Clean up these with more maintainable way |
| 489 | vendorProprietaryDirs = []string{ |
| 490 | "device", |
| 491 | "vendor", |
| 492 | "hardware", |
| 493 | } |
| 494 | |
| 495 | // Modules under following directories are included as they are in AOSP, |
| 496 | // although hardware/ is normally for vendor's own. |
| 497 | // TODO(b/65377115): Clean up these with more maintainable way |
| 498 | aospDirsUnderProprietary = []string{ |
| 499 | "hardware/interfaces", |
| 500 | "hardware/libhardware", |
| 501 | "hardware/libhardware_legacy", |
| 502 | "hardware/ril", |
| 503 | } |
| 504 | ) |
| 505 | |
| 506 | // Determine if a dir under source tree is an SoC-owned proprietary directory, such as |
| 507 | // device/, vendor/, etc. |
| 508 | func isVendorProprietaryPath(dir string) bool { |
| 509 | for _, p := range vendorProprietaryDirs { |
| 510 | if strings.HasPrefix(dir, p) { |
| 511 | // filter out AOSP defined directories, e.g. hardware/interfaces/ |
| 512 | aosp := false |
| 513 | for _, p := range aospDirsUnderProprietary { |
| 514 | if strings.HasPrefix(dir, p) { |
| 515 | aosp = true |
| 516 | break |
| 517 | } |
| 518 | } |
| 519 | if !aosp { |
| 520 | return true |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | return false |
| 525 | } |
| 526 | |
| 527 | // Determine if a module is going to be included in vendor snapshot or not. |
| 528 | // |
| 529 | // Targets of vendor snapshot are "vendor: true" or "vendor_available: true" modules in |
| 530 | // AOSP. They are not guaranteed to be compatible with older vendor images. (e.g. might |
| 531 | // depend on newer VNDK) So they are captured as vendor snapshot To build older vendor |
| 532 | // image and newer system image altogether. |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 533 | func isVendorSnapshotModule(m *Module, moduleDir string) bool { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 534 | if !m.Enabled() || m.Properties.HideFromMake { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 535 | return false |
| 536 | } |
| 537 | // skip proprietary modules, but include all VNDK (static) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 538 | if isVendorProprietaryPath(moduleDir) && !m.IsVndk() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 539 | return false |
| 540 | } |
| 541 | if m.Target().Os.Class != android.Device { |
| 542 | return false |
| 543 | } |
| 544 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 545 | return false |
| 546 | } |
| 547 | // the module must be installed in /vendor |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 548 | if !m.IsForPlatform() || m.isSnapshotPrebuilt() || !m.inVendor() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 549 | return false |
| 550 | } |
| 551 | |
| 552 | // Libraries |
| 553 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 554 | // TODO(b/65377115): add full support for sanitizer |
| 555 | if m.sanitize != nil { |
| 556 | // cfi, scs and hwasan export both sanitized and unsanitized variants for static and header |
| 557 | // Always use unsanitized variants of them. |
| 558 | for _, t := range []sanitizerType{cfi, scs, hwasan} { |
| 559 | if !l.shared() && m.sanitize.isSanitizerEnabled(t) { |
| 560 | return false |
| 561 | } |
| 562 | } |
| 563 | } |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 564 | if l.static() { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 565 | return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 566 | } |
| 567 | if l.shared() { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 568 | return m.outputFile.Valid() && !m.IsVndk() |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 569 | } |
| 570 | return true |
| 571 | } |
| 572 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 573 | // Binaries and Objects |
| 574 | if m.binary() || m.object() { |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 575 | return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 576 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 577 | |
| 578 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 582 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a vendor snapshot. |
| 583 | if ctx.DeviceConfig().VndkVersion() != "current" { |
| 584 | return |
| 585 | } |
| 586 | |
| 587 | var snapshotOutputs android.Paths |
| 588 | |
| 589 | /* |
| 590 | Vendor snapshot zipped artifacts directory structure: |
| 591 | {SNAPSHOT_ARCH}/ |
| 592 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 593 | shared/ |
| 594 | (.so shared libraries) |
| 595 | static/ |
| 596 | (.a static libraries) |
| 597 | header/ |
| 598 | (header only libraries) |
| 599 | binary/ |
| 600 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 601 | object/ |
| 602 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 603 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 604 | shared/ |
| 605 | (.so shared libraries) |
| 606 | static/ |
| 607 | (.a static libraries) |
| 608 | header/ |
| 609 | (header only libraries) |
| 610 | binary/ |
| 611 | (executable binaries) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 612 | object/ |
| 613 | (.o object files) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 614 | NOTICE_FILES/ |
| 615 | (notice files, e.g. libbase.txt) |
| 616 | configs/ |
| 617 | (config files, e.g. init.rc files, vintf_fragments.xml files, etc.) |
| 618 | include/ |
| 619 | (header files of same directory structure with source tree) |
| 620 | */ |
| 621 | |
| 622 | snapshotDir := "vendor-snapshot" |
| 623 | snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) |
| 624 | |
| 625 | includeDir := filepath.Join(snapshotArchDir, "include") |
| 626 | configsDir := filepath.Join(snapshotArchDir, "configs") |
| 627 | noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") |
| 628 | |
| 629 | installedNotices := make(map[string]bool) |
| 630 | installedConfigs := make(map[string]bool) |
| 631 | |
| 632 | var headers android.Paths |
| 633 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 634 | installSnapshot := func(m *Module) android.Paths { |
| 635 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 636 | if m.Target().Arch.ArchVariant != "" { |
| 637 | targetArch += "-" + m.Target().Arch.ArchVariant |
| 638 | } |
| 639 | |
| 640 | var ret android.Paths |
| 641 | |
| 642 | prop := struct { |
| 643 | ModuleName string `json:",omitempty"` |
| 644 | RelativeInstallPath string `json:",omitempty"` |
| 645 | |
| 646 | // library flags |
| 647 | ExportedDirs []string `json:",omitempty"` |
| 648 | ExportedSystemDirs []string `json:",omitempty"` |
| 649 | ExportedFlags []string `json:",omitempty"` |
| 650 | SanitizeMinimalDep bool `json:",omitempty"` |
| 651 | SanitizeUbsanDep bool `json:",omitempty"` |
| 652 | |
| 653 | // binary flags |
| 654 | Symlinks []string `json:",omitempty"` |
| 655 | |
| 656 | // dependencies |
| 657 | SharedLibs []string `json:",omitempty"` |
| 658 | RuntimeLibs []string `json:",omitempty"` |
| 659 | Required []string `json:",omitempty"` |
| 660 | |
| 661 | // extra config files |
| 662 | InitRc []string `json:",omitempty"` |
| 663 | VintfFragments []string `json:",omitempty"` |
| 664 | }{} |
| 665 | |
| 666 | // Common properties among snapshots. |
| 667 | prop.ModuleName = ctx.ModuleName(m) |
| 668 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 669 | prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs |
| 670 | prop.Required = m.RequiredModuleNames() |
| 671 | for _, path := range m.InitRc() { |
| 672 | prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base())) |
| 673 | } |
| 674 | for _, path := range m.VintfFragments() { |
| 675 | prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base())) |
| 676 | } |
| 677 | |
| 678 | // install config files. ignores any duplicates. |
| 679 | for _, path := range append(m.InitRc(), m.VintfFragments()...) { |
| 680 | out := filepath.Join(configsDir, path.Base()) |
| 681 | if !installedConfigs[out] { |
| 682 | installedConfigs[out] = true |
| 683 | ret = append(ret, copyFile(ctx, path, out)) |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | var propOut string |
| 688 | |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 689 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 690 | // library flags |
| 691 | prop.ExportedFlags = l.exportedFlags() |
| 692 | for _, dir := range l.exportedDirs() { |
| 693 | prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String())) |
| 694 | } |
| 695 | for _, dir := range l.exportedSystemDirs() { |
| 696 | prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String())) |
| 697 | } |
| 698 | // shared libs dependencies aren't meaningful on static or header libs |
| 699 | if l.shared() { |
| 700 | prop.SharedLibs = m.Properties.SnapshotSharedLibs |
| 701 | } |
| 702 | if l.static() && m.sanitize != nil { |
| 703 | prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize) |
| 704 | prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize) |
| 705 | } |
| 706 | |
| 707 | var libType string |
| 708 | if l.static() { |
| 709 | libType = "static" |
| 710 | } else if l.shared() { |
| 711 | libType = "shared" |
| 712 | } else { |
| 713 | libType = "header" |
| 714 | } |
| 715 | |
| 716 | var stem string |
| 717 | |
| 718 | // install .a or .so |
| 719 | if libType != "header" { |
| 720 | libPath := m.outputFile.Path() |
| 721 | stem = libPath.Base() |
| 722 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem) |
| 723 | ret = append(ret, copyFile(ctx, libPath, snapshotLibOut)) |
| 724 | } else { |
| 725 | stem = ctx.ModuleName(m) |
| 726 | } |
| 727 | |
| 728 | propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json") |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 729 | } else if m.binary() { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 730 | // binary flags |
| 731 | prop.Symlinks = m.Symlinks() |
| 732 | prop.SharedLibs = m.Properties.SnapshotSharedLibs |
| 733 | |
| 734 | // install bin |
| 735 | binPath := m.outputFile.Path() |
| 736 | snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) |
| 737 | ret = append(ret, copyFile(ctx, binPath, snapshotBinOut)) |
| 738 | propOut = snapshotBinOut + ".json" |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 739 | } else if m.object() { |
| 740 | // object files aren't installed to the device, so their names can conflict. |
| 741 | // Use module name as stem. |
| 742 | objPath := m.outputFile.Path() |
| 743 | snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object", |
| 744 | ctx.ModuleName(m)+filepath.Ext(objPath.Base())) |
| 745 | ret = append(ret, copyFile(ctx, objPath, snapshotObjOut)) |
| 746 | propOut = snapshotObjOut + ".json" |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 747 | } else { |
| 748 | ctx.Errorf("unknown module %q in vendor snapshot", m.String()) |
| 749 | return nil |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | j, err := json.Marshal(prop) |
| 753 | if err != nil { |
| 754 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 755 | return nil |
| 756 | } |
| 757 | ret = append(ret, writeStringToFile(ctx, string(j), propOut)) |
| 758 | |
| 759 | return ret |
| 760 | } |
| 761 | |
| 762 | ctx.VisitAllModules(func(module android.Module) { |
| 763 | m, ok := module.(*Module) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 764 | if !ok { |
| 765 | return |
| 766 | } |
| 767 | |
| 768 | moduleDir := ctx.ModuleDir(module) |
| 769 | if !isVendorSnapshotModule(m, moduleDir) { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 770 | return |
| 771 | } |
| 772 | |
| 773 | snapshotOutputs = append(snapshotOutputs, installSnapshot(m)...) |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 774 | if l, ok := m.linker.(snapshotLibraryInterface); ok { |
| 775 | headers = append(headers, l.snapshotHeaders()...) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 776 | } |
| 777 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 778 | if len(m.NoticeFiles()) > 0 { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 779 | noticeName := ctx.ModuleName(m) + ".txt" |
| 780 | noticeOut := filepath.Join(noticeDir, noticeName) |
| 781 | // skip already copied notice file |
| 782 | if !installedNotices[noticeOut] { |
| 783 | installedNotices[noticeOut] = true |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 784 | snapshotOutputs = append(snapshotOutputs, combineNotices( |
| 785 | ctx, m.NoticeFiles(), noticeOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | }) |
| 789 | |
| 790 | // install all headers after removing duplicates |
| 791 | for _, header := range android.FirstUniquePaths(headers) { |
| 792 | snapshotOutputs = append(snapshotOutputs, copyFile( |
| 793 | ctx, header, filepath.Join(includeDir, header.String()))) |
| 794 | } |
| 795 | |
| 796 | // All artifacts are ready. Sort them to normalize ninja and then zip. |
| 797 | sort.Slice(snapshotOutputs, func(i, j int) bool { |
| 798 | return snapshotOutputs[i].String() < snapshotOutputs[j].String() |
| 799 | }) |
| 800 | |
| 801 | zipPath := android.PathForOutput(ctx, snapshotDir, "vendor-"+ctx.Config().DeviceName()+".zip") |
| 802 | zipRule := android.NewRuleBuilder() |
| 803 | |
| 804 | // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr |
| 805 | snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "vendor-"+ctx.Config().DeviceName()+"_list") |
| 806 | zipRule.Command(). |
| 807 | Text("tr"). |
| 808 | FlagWithArg("-d ", "\\'"). |
| 809 | FlagWithRspFileInputList("< ", snapshotOutputs). |
| 810 | FlagWithOutput("> ", snapshotOutputList) |
| 811 | |
| 812 | zipRule.Temporary(snapshotOutputList) |
| 813 | |
| 814 | zipRule.Command(). |
| 815 | BuiltTool(ctx, "soong_zip"). |
| 816 | FlagWithOutput("-o ", zipPath). |
| 817 | FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()). |
| 818 | FlagWithInput("-l ", snapshotOutputList) |
| 819 | |
| 820 | zipRule.Build(pctx, ctx, zipPath.String(), "vendor snapshot "+zipPath.String()) |
| 821 | zipRule.DeleteTemporaryFiles() |
| 822 | c.vendorSnapshotZipFile = android.OptionalPathForPath(zipPath) |
| 823 | } |
| 824 | |
| 825 | func (c *vendorSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 826 | ctx.Strict("SOONG_VENDOR_SNAPSHOT_ZIP", c.vendorSnapshotZipFile.String()) |
| 827 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 828 | |
| 829 | type snapshotInterface interface { |
| 830 | matchesWithDevice(config android.DeviceConfig) bool |
| 831 | } |
| 832 | |
| 833 | var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil) |
| 834 | var _ snapshotInterface = (*vendorSnapshotLibraryDecorator)(nil) |
| 835 | var _ snapshotInterface = (*vendorSnapshotBinaryDecorator)(nil) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 836 | var _ snapshotInterface = (*vendorSnapshotObjectLinker)(nil) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 837 | |
| 838 | // gathers all snapshot modules for vendor, and disable unnecessary snapshots |
| 839 | // TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules |
| 840 | func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) { |
| 841 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 842 | // don't need snapshot if current |
| 843 | if vndkVersion == "current" || vndkVersion == "" { |
| 844 | return |
| 845 | } |
| 846 | |
| 847 | module, ok := ctx.Module().(*Module) |
| 848 | if !ok || !module.Enabled() || module.VndkVersion() != vndkVersion { |
| 849 | return |
| 850 | } |
| 851 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 852 | if !module.isSnapshotPrebuilt() { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 853 | return |
| 854 | } |
| 855 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 856 | // isSnapshotPrebuilt ensures snapshotInterface |
| 857 | if !module.linker.(snapshotInterface).matchesWithDevice(ctx.DeviceConfig()) { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 858 | // Disable unnecessary snapshot module, but do not disable |
| 859 | // vndk_prebuilt_shared because they might be packed into vndk APEX |
| 860 | if !module.IsVndk() { |
| 861 | module.Disable() |
| 862 | } |
| 863 | return |
| 864 | } |
| 865 | |
| 866 | var snapshotMap *snapshotMap |
| 867 | |
| 868 | if lib, ok := module.linker.(libraryInterface); ok { |
| 869 | if lib.static() { |
| 870 | snapshotMap = vendorSnapshotStaticLibs(ctx.Config()) |
| 871 | } else if lib.shared() { |
| 872 | snapshotMap = vendorSnapshotSharedLibs(ctx.Config()) |
| 873 | } else { |
| 874 | // header |
| 875 | snapshotMap = vendorSnapshotHeaderLibs(ctx.Config()) |
| 876 | } |
| 877 | } else if _, ok := module.linker.(*vendorSnapshotBinaryDecorator); ok { |
| 878 | snapshotMap = vendorSnapshotBinaries(ctx.Config()) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 879 | } else if _, ok := module.linker.(*vendorSnapshotObjectLinker); ok { |
| 880 | snapshotMap = vendorSnapshotObjects(ctx.Config()) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 881 | } else { |
| 882 | return |
| 883 | } |
| 884 | |
| 885 | vendorSnapshotsLock.Lock() |
| 886 | defer vendorSnapshotsLock.Unlock() |
| 887 | snapshotMap.add(module.BaseModuleName(), ctx.Arch().ArchType, ctx.ModuleName()) |
| 888 | } |
| 889 | |
| 890 | // Disables source modules which have snapshots |
| 891 | func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) { |
Inseob Kim | 5f64aec | 2020-02-18 17:27:19 +0900 | [diff] [blame] | 892 | if !ctx.Device() { |
| 893 | return |
| 894 | } |
| 895 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 896 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 897 | // don't need snapshot if current |
| 898 | if vndkVersion == "current" || vndkVersion == "" { |
| 899 | return |
| 900 | } |
| 901 | |
| 902 | module, ok := ctx.Module().(*Module) |
| 903 | if !ok { |
| 904 | return |
| 905 | } |
| 906 | |
Inseob Kim | 5f64aec | 2020-02-18 17:27:19 +0900 | [diff] [blame] | 907 | // vendor suffix should be added to snapshots if the source module isn't vendor: true. |
| 908 | if !module.SocSpecific() { |
| 909 | // But we can't just check SocSpecific() since we already passed the image mutator. |
| 910 | // Check ramdisk and recovery to see if we are real "vendor: true" module. |
| 911 | ramdisk_available := module.InRamdisk() && !module.OnlyInRamdisk() |
| 912 | recovery_available := module.InRecovery() && !module.OnlyInRecovery() |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 913 | |
Inseob Kim | 5f64aec | 2020-02-18 17:27:19 +0900 | [diff] [blame] | 914 | if !ramdisk_available && !recovery_available { |
| 915 | vendorSnapshotsLock.Lock() |
| 916 | defer vendorSnapshotsLock.Unlock() |
| 917 | |
| 918 | vendorSuffixModules(ctx.Config())[ctx.ModuleName()] = true |
| 919 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | if module.isSnapshotPrebuilt() || module.VndkVersion() != ctx.DeviceConfig().VndkVersion() { |
| 923 | // only non-snapshot modules with BOARD_VNDK_VERSION |
| 924 | return |
| 925 | } |
| 926 | |
| 927 | var snapshotMap *snapshotMap |
| 928 | |
| 929 | if lib, ok := module.linker.(libraryInterface); ok { |
| 930 | if lib.static() { |
| 931 | snapshotMap = vendorSnapshotStaticLibs(ctx.Config()) |
| 932 | } else if lib.shared() { |
| 933 | snapshotMap = vendorSnapshotSharedLibs(ctx.Config()) |
| 934 | } else { |
| 935 | // header |
| 936 | snapshotMap = vendorSnapshotHeaderLibs(ctx.Config()) |
| 937 | } |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 938 | } else if module.binary() { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 939 | snapshotMap = vendorSnapshotBinaries(ctx.Config()) |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame^] | 940 | } else if module.object() { |
| 941 | snapshotMap = vendorSnapshotObjects(ctx.Config()) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 942 | } else { |
| 943 | return |
| 944 | } |
| 945 | |
| 946 | if _, ok := snapshotMap.get(ctx.ModuleName(), ctx.Arch().ArchType); !ok { |
| 947 | // Corresponding snapshot doesn't exist |
| 948 | return |
| 949 | } |
| 950 | |
| 951 | // Disables source modules if corresponding snapshot exists. |
| 952 | if lib, ok := module.linker.(libraryInterface); ok && lib.buildStatic() && lib.buildShared() { |
| 953 | // But do not disable because the shared variant depends on the static variant. |
| 954 | module.SkipInstall() |
| 955 | module.Properties.HideFromMake = true |
| 956 | } else { |
| 957 | module.Disable() |
| 958 | } |
| 959 | } |