blob: 78bde381678a21b8fcef6f3260623b4058a2ee65 [file] [log] [blame]
Inseob Kim8471cda2019-11-15 09:59:12 +09001// 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.
14package cc
15
16import (
17 "encoding/json"
18 "path/filepath"
19 "sort"
20 "strings"
Inseob Kimeec88e12020-01-22 11:11:29 +090021 "sync"
Inseob Kim8471cda2019-11-15 09:59:12 +090022
23 "github.com/google/blueprint/proptools"
24
25 "android/soong/android"
26)
27
Inseob Kimeec88e12020-01-22 11:11:29 +090028const (
29 vendorSnapshotHeaderSuffix = ".vendor_header."
30 vendorSnapshotSharedSuffix = ".vendor_shared."
31 vendorSnapshotStaticSuffix = ".vendor_static."
32 vendorSnapshotBinarySuffix = ".vendor_binary."
Inseob Kim1042d292020-06-01 23:23:05 +090033 vendorSnapshotObjectSuffix = ".vendor_object."
Inseob Kimeec88e12020-01-22 11:11:29 +090034)
35
36var (
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 Kim1042d292020-06-01 23:23:05 +090043 vendorSnapshotObjectsKey = android.NewOnceKey("vendorSnapshotObjects")
Inseob Kimeec88e12020-01-22 11:11:29 +090044)
45
Inseob Kim5f64aec2020-02-18 17:27:19 +090046// vendor snapshot maps hold names of vendor snapshot modules per arch
Inseob Kimeec88e12020-01-22 11:11:29 +090047func 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
53func vendorSnapshotHeaderLibs(config android.Config) *snapshotMap {
54 return config.Once(vendorSnapshotHeaderLibsKey, func() interface{} {
55 return newSnapshotMap()
56 }).(*snapshotMap)
57}
58
59func vendorSnapshotSharedLibs(config android.Config) *snapshotMap {
60 return config.Once(vendorSnapshotSharedLibsKey, func() interface{} {
61 return newSnapshotMap()
62 }).(*snapshotMap)
63}
64
65func vendorSnapshotStaticLibs(config android.Config) *snapshotMap {
66 return config.Once(vendorSnapshotStaticLibsKey, func() interface{} {
67 return newSnapshotMap()
68 }).(*snapshotMap)
69}
70
71func vendorSnapshotBinaries(config android.Config) *snapshotMap {
72 return config.Once(vendorSnapshotBinariesKey, func() interface{} {
73 return newSnapshotMap()
74 }).(*snapshotMap)
75}
76
Inseob Kim1042d292020-06-01 23:23:05 +090077func vendorSnapshotObjects(config android.Config) *snapshotMap {
78 return config.Once(vendorSnapshotObjectsKey, func() interface{} {
79 return newSnapshotMap()
80 }).(*snapshotMap)
81}
82
Inseob Kim2d34ad92020-07-30 21:04:09 +090083type vendorSnapshotBaseProperties struct {
Inseob Kimeec88e12020-01-22 11:11:29 +090084 // snapshot version.
85 Version string
86
87 // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64')
88 Target_arch string
Inseob Kim2d34ad92020-07-30 21:04:09 +090089}
Inseob Kimeec88e12020-01-22 11:11:29 +090090
Inseob Kim2d34ad92020-07-30 21:04:09 +090091// vendorSnapshotModuleBase provides common basic functions for all snapshot modules.
92type vendorSnapshotModuleBase struct {
93 baseProperties vendorSnapshotBaseProperties
94 moduleSuffix string
95}
96
97func (p *vendorSnapshotModuleBase) Name(name string) string {
98 return name + p.NameSuffix()
99}
100
101func (p *vendorSnapshotModuleBase) NameSuffix() string {
102 versionSuffix := p.version()
103 if p.arch() != "" {
104 versionSuffix += "." + p.arch()
105 }
106
107 return p.moduleSuffix + versionSuffix
108}
109
110func (p *vendorSnapshotModuleBase) version() string {
111 return p.baseProperties.Version
112}
113
114func (p *vendorSnapshotModuleBase) arch() string {
115 return p.baseProperties.Target_arch
116}
117
118func (p *vendorSnapshotModuleBase) isSnapshotPrebuilt() bool {
119 return true
120}
121
122// Call this after creating a snapshot module with module suffix
123// such as vendorSnapshotSharedSuffix
124func (p *vendorSnapshotModuleBase) init(m *Module, suffix string) {
125 p.moduleSuffix = suffix
126 m.AddProperties(&p.baseProperties)
127 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
128 vendorSnapshotLoadHook(ctx, p)
129 })
130}
131
132func vendorSnapshotLoadHook(ctx android.LoadHookContext, p *vendorSnapshotModuleBase) {
133 if p.version() != ctx.DeviceConfig().VndkVersion() {
134 ctx.Module().Disable()
135 return
136 }
137}
138
139type vendorSnapshotLibraryProperties struct {
Inseob Kimeec88e12020-01-22 11:11:29 +0900140 // Prebuilt file for each arch.
141 Src *string `android:"arch_variant"`
142
Inseob Kimc42f2f22020-07-29 20:32:10 +0900143 // list of directories that will be added to the include path (using -I).
144 Export_include_dirs []string `android:"arch_variant"`
145
146 // list of directories that will be added to the system path (using -isystem).
147 Export_system_include_dirs []string `android:"arch_variant"`
148
Inseob Kimeec88e12020-01-22 11:11:29 +0900149 // list of flags that will be used for any module that links against this module.
150 Export_flags []string `android:"arch_variant"`
151
Inseob Kimeec88e12020-01-22 11:11:29 +0900152 // Whether this prebuilt needs to depend on sanitize ubsan runtime or not.
153 Sanitize_ubsan_dep *bool `android:"arch_variant"`
154
155 // Whether this prebuilt needs to depend on sanitize minimal runtime or not.
156 Sanitize_minimal_dep *bool `android:"arch_variant"`
157}
158
Inseob Kimc42f2f22020-07-29 20:32:10 +0900159type snapshotSanitizer interface {
160 isSanitizerEnabled(t sanitizerType) bool
161 setSanitizerVariation(t sanitizerType, enabled bool)
162}
163
Inseob Kimeec88e12020-01-22 11:11:29 +0900164type vendorSnapshotLibraryDecorator struct {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900165 vendorSnapshotModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900166 *libraryDecorator
Inseob Kimc42f2f22020-07-29 20:32:10 +0900167 properties vendorSnapshotLibraryProperties
168 sanitizerProperties struct {
169 CfiEnabled bool `blueprint:"mutated"`
170
171 // Library flags for cfi variant.
172 Cfi vendorSnapshotLibraryProperties `android:"arch_variant"`
173 }
Inseob Kimeec88e12020-01-22 11:11:29 +0900174 androidMkVendorSuffix bool
175}
176
Inseob Kimeec88e12020-01-22 11:11:29 +0900177func (p *vendorSnapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
178 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
179 return p.libraryDecorator.linkerFlags(ctx, flags)
180}
181
182func (p *vendorSnapshotLibraryDecorator) matchesWithDevice(config android.DeviceConfig) bool {
183 arches := config.Arches()
184 if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
185 return false
186 }
187 if !p.header() && p.properties.Src == nil {
188 return false
189 }
190 return true
191}
192
193func (p *vendorSnapshotLibraryDecorator) link(ctx ModuleContext,
194 flags Flags, deps PathDeps, objs Objects) android.Path {
195 m := ctx.Module().(*Module)
196 p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()]
197
198 if p.header() {
199 return p.libraryDecorator.link(ctx, flags, deps, objs)
200 }
201
Inseob Kimc42f2f22020-07-29 20:32:10 +0900202 if p.sanitizerProperties.CfiEnabled {
203 p.properties = p.sanitizerProperties.Cfi
204 }
205
Inseob Kimeec88e12020-01-22 11:11:29 +0900206 if !p.matchesWithDevice(ctx.DeviceConfig()) {
207 return nil
208 }
209
Inseob Kimc42f2f22020-07-29 20:32:10 +0900210 p.libraryDecorator.reexportDirs(android.PathsForModuleSrc(ctx, p.properties.Export_include_dirs)...)
211 p.libraryDecorator.reexportSystemDirs(android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...)
Inseob Kimeec88e12020-01-22 11:11:29 +0900212 p.libraryDecorator.reexportFlags(p.properties.Export_flags...)
213
214 in := android.PathForModuleSrc(ctx, *p.properties.Src)
215 p.unstrippedOutputFile = in
216
217 if p.shared() {
218 libName := in.Base()
219 builderFlags := flagsToBuilderFlags(flags)
220
221 // Optimize out relinking against shared libraries whose interface hasn't changed by
222 // depending on a table of contents file instead of the library itself.
223 tocFile := android.PathForModuleOut(ctx, libName+".toc")
224 p.tocFile = android.OptionalPathForPath(tocFile)
225 TransformSharedObjectToToc(ctx, in, tocFile, builderFlags)
Colin Cross0de8a1e2020-09-18 14:15:30 -0700226
227 ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
228 SharedLibrary: in,
229 UnstrippedSharedLibrary: p.unstrippedOutputFile,
230
231 TableOfContents: p.tocFile,
232 })
233 }
234
235 if p.static() {
236 depSet := android.NewDepSetBuilder(android.TOPOLOGICAL).Direct(in).Build()
237 ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
238 StaticLibrary: in,
239
240 TransitiveStaticLibrariesForOrdering: depSet,
241 })
Inseob Kimeec88e12020-01-22 11:11:29 +0900242 }
243
Inseob Kim67be7322020-10-19 10:15:28 +0900244 p.libraryDecorator.flagExporter.setProvider(ctx)
245
Inseob Kimeec88e12020-01-22 11:11:29 +0900246 return in
247}
248
Inseob Kimeec88e12020-01-22 11:11:29 +0900249func (p *vendorSnapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) {
250 if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) {
251 p.baseInstaller.install(ctx, file)
252 }
253}
254
Inseob Kim2d34ad92020-07-30 21:04:09 +0900255func (p *vendorSnapshotLibraryDecorator) nativeCoverage() bool {
256 return false
Inseob Kimeec88e12020-01-22 11:11:29 +0900257}
258
Inseob Kimc42f2f22020-07-29 20:32:10 +0900259func (p *vendorSnapshotLibraryDecorator) isSanitizerEnabled(t sanitizerType) bool {
260 switch t {
261 case cfi:
262 return p.sanitizerProperties.Cfi.Src != nil
263 default:
264 return false
265 }
266}
267
268func (p *vendorSnapshotLibraryDecorator) setSanitizerVariation(t sanitizerType, enabled bool) {
269 if !enabled {
270 return
271 }
272 switch t {
273 case cfi:
274 p.sanitizerProperties.CfiEnabled = true
275 default:
276 return
277 }
278}
279
Inseob Kim2d34ad92020-07-30 21:04:09 +0900280func vendorSnapshotLibrary(suffix string) (*Module, *vendorSnapshotLibraryDecorator) {
Inseob Kimeec88e12020-01-22 11:11:29 +0900281 module, library := NewLibrary(android.DeviceSupported)
282
283 module.stl = nil
284 module.sanitize = nil
Thiébaud Weksteend4587452020-08-19 14:53:01 +0200285 library.disableStripping()
Inseob Kimeec88e12020-01-22 11:11:29 +0900286
287 prebuilt := &vendorSnapshotLibraryDecorator{
288 libraryDecorator: library,
289 }
290
291 prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true)
292 prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true)
293
294 // Prevent default system libs (libc, libm, and libdl) from being linked
295 if prebuilt.baseLinker.Properties.System_shared_libs == nil {
296 prebuilt.baseLinker.Properties.System_shared_libs = []string{}
297 }
298
299 module.compiler = nil
300 module.linker = prebuilt
301 module.installer = prebuilt
302
Inseob Kim2d34ad92020-07-30 21:04:09 +0900303 prebuilt.init(module, suffix)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900304 module.AddProperties(
305 &prebuilt.properties,
306 &prebuilt.sanitizerProperties,
307 )
Inseob Kimeec88e12020-01-22 11:11:29 +0900308
309 return module, prebuilt
310}
311
312func VendorSnapshotSharedFactory() android.Module {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900313 module, prebuilt := vendorSnapshotLibrary(vendorSnapshotSharedSuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +0900314 prebuilt.libraryDecorator.BuildOnlyShared()
Inseob Kimeec88e12020-01-22 11:11:29 +0900315 return module.Init()
316}
317
318func VendorSnapshotStaticFactory() android.Module {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900319 module, prebuilt := vendorSnapshotLibrary(vendorSnapshotStaticSuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +0900320 prebuilt.libraryDecorator.BuildOnlyStatic()
Inseob Kimeec88e12020-01-22 11:11:29 +0900321 return module.Init()
322}
323
324func VendorSnapshotHeaderFactory() android.Module {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900325 module, prebuilt := vendorSnapshotLibrary(vendorSnapshotHeaderSuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +0900326 prebuilt.libraryDecorator.HeaderOnly()
Inseob Kimeec88e12020-01-22 11:11:29 +0900327 return module.Init()
328}
329
Inseob Kimc42f2f22020-07-29 20:32:10 +0900330var _ snapshotSanitizer = (*vendorSnapshotLibraryDecorator)(nil)
331
Inseob Kimeec88e12020-01-22 11:11:29 +0900332type vendorSnapshotBinaryProperties struct {
Inseob Kimeec88e12020-01-22 11:11:29 +0900333 // Prebuilt file for each arch.
334 Src *string `android:"arch_variant"`
335}
336
337type vendorSnapshotBinaryDecorator struct {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900338 vendorSnapshotModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900339 *binaryDecorator
340 properties vendorSnapshotBinaryProperties
341 androidMkVendorSuffix bool
342}
343
Inseob Kimeec88e12020-01-22 11:11:29 +0900344func (p *vendorSnapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool {
345 if config.DeviceArch() != p.arch() {
346 return false
347 }
348 if p.properties.Src == nil {
349 return false
350 }
351 return true
352}
353
354func (p *vendorSnapshotBinaryDecorator) link(ctx ModuleContext,
355 flags Flags, deps PathDeps, objs Objects) android.Path {
356 if !p.matchesWithDevice(ctx.DeviceConfig()) {
357 return nil
358 }
359
360 in := android.PathForModuleSrc(ctx, *p.properties.Src)
Thiébaud Weksteend4587452020-08-19 14:53:01 +0200361 stripFlags := flagsToStripFlags(flags)
Inseob Kimeec88e12020-01-22 11:11:29 +0900362 p.unstrippedOutputFile = in
363 binName := in.Base()
Thiébaud Weksteend4587452020-08-19 14:53:01 +0200364 if p.stripper.NeedsStrip(ctx) {
Inseob Kimeec88e12020-01-22 11:11:29 +0900365 stripped := android.PathForModuleOut(ctx, "stripped", binName)
Thiébaud Weksteend4587452020-08-19 14:53:01 +0200366 p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags)
Inseob Kimeec88e12020-01-22 11:11:29 +0900367 in = stripped
368 }
369
370 m := ctx.Module().(*Module)
371 p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()]
372
373 // use cpExecutable to make it executable
374 outputFile := android.PathForModuleOut(ctx, binName)
375 ctx.Build(pctx, android.BuildParams{
376 Rule: android.CpExecutable,
377 Description: "prebuilt",
378 Output: outputFile,
379 Input: in,
380 })
381
382 return outputFile
383}
384
Inseob Kim2d34ad92020-07-30 21:04:09 +0900385func (p *vendorSnapshotBinaryDecorator) nativeCoverage() bool {
386 return false
Inseob Kim1042d292020-06-01 23:23:05 +0900387}
388
Inseob Kimeec88e12020-01-22 11:11:29 +0900389func VendorSnapshotBinaryFactory() android.Module {
390 module, binary := NewBinary(android.DeviceSupported)
391 binary.baseLinker.Properties.No_libcrt = BoolPtr(true)
392 binary.baseLinker.Properties.Nocrt = BoolPtr(true)
393
394 // Prevent default system libs (libc, libm, and libdl) from being linked
395 if binary.baseLinker.Properties.System_shared_libs == nil {
396 binary.baseLinker.Properties.System_shared_libs = []string{}
397 }
398
399 prebuilt := &vendorSnapshotBinaryDecorator{
400 binaryDecorator: binary,
401 }
402
403 module.compiler = nil
404 module.sanitize = nil
405 module.stl = nil
406 module.linker = prebuilt
407
Inseob Kim2d34ad92020-07-30 21:04:09 +0900408 prebuilt.init(module, vendorSnapshotBinarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +0900409 module.AddProperties(&prebuilt.properties)
410 return module.Init()
411}
412
Inseob Kim1042d292020-06-01 23:23:05 +0900413type vendorSnapshotObjectProperties struct {
Inseob Kim1042d292020-06-01 23:23:05 +0900414 // Prebuilt file for each arch.
415 Src *string `android:"arch_variant"`
416}
417
418type vendorSnapshotObjectLinker struct {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900419 vendorSnapshotModuleBase
Inseob Kim1042d292020-06-01 23:23:05 +0900420 objectLinker
421 properties vendorSnapshotObjectProperties
422 androidMkVendorSuffix bool
423}
424
Inseob Kim1042d292020-06-01 23:23:05 +0900425func (p *vendorSnapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool {
426 if config.DeviceArch() != p.arch() {
427 return false
428 }
429 if p.properties.Src == nil {
430 return false
431 }
432 return true
433}
434
435func (p *vendorSnapshotObjectLinker) link(ctx ModuleContext,
436 flags Flags, deps PathDeps, objs Objects) android.Path {
437 if !p.matchesWithDevice(ctx.DeviceConfig()) {
438 return nil
439 }
440
441 m := ctx.Module().(*Module)
442 p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()]
443
444 return android.PathForModuleSrc(ctx, *p.properties.Src)
445}
446
447func (p *vendorSnapshotObjectLinker) nativeCoverage() bool {
448 return false
449}
450
Inseob Kim1042d292020-06-01 23:23:05 +0900451func VendorSnapshotObjectFactory() android.Module {
452 module := newObject()
453
454 prebuilt := &vendorSnapshotObjectLinker{
455 objectLinker: objectLinker{
456 baseLinker: NewBaseLinker(nil),
457 },
458 }
459 module.linker = prebuilt
460
Inseob Kim2d34ad92020-07-30 21:04:09 +0900461 prebuilt.init(module, vendorSnapshotObjectSuffix)
Inseob Kim1042d292020-06-01 23:23:05 +0900462 module.AddProperties(&prebuilt.properties)
463 return module.Init()
464}
465
Inseob Kim8471cda2019-11-15 09:59:12 +0900466func init() {
467 android.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Inseob Kimeec88e12020-01-22 11:11:29 +0900468 android.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
469 android.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
470 android.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory)
471 android.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
Inseob Kim1042d292020-06-01 23:23:05 +0900472 android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory)
Inseob Kim8471cda2019-11-15 09:59:12 +0900473}
474
475func VendorSnapshotSingleton() android.Singleton {
476 return &vendorSnapshotSingleton{}
477}
478
479type vendorSnapshotSingleton struct {
480 vendorSnapshotZipFile android.OptionalPath
481}
482
483var (
484 // Modules under following directories are ignored. They are OEM's and vendor's
Daniel Norman713387d2020-07-28 16:04:38 -0700485 // proprietary modules(device/, kernel/, vendor/, and hardware/).
Inseob Kim8471cda2019-11-15 09:59:12 +0900486 // TODO(b/65377115): Clean up these with more maintainable way
487 vendorProprietaryDirs = []string{
488 "device",
Daniel Norman713387d2020-07-28 16:04:38 -0700489 "kernel",
Inseob Kim8471cda2019-11-15 09:59:12 +0900490 "vendor",
491 "hardware",
492 }
493
494 // Modules under following directories are included as they are in AOSP,
Daniel Norman713387d2020-07-28 16:04:38 -0700495 // although hardware/ and kernel/ are normally for vendor's own.
Inseob Kim8471cda2019-11-15 09:59:12 +0900496 // TODO(b/65377115): Clean up these with more maintainable way
497 aospDirsUnderProprietary = []string{
Daniel Norman713387d2020-07-28 16:04:38 -0700498 "kernel/configs",
499 "kernel/prebuilts",
500 "kernel/tests",
Inseob Kim8471cda2019-11-15 09:59:12 +0900501 "hardware/interfaces",
502 "hardware/libhardware",
503 "hardware/libhardware_legacy",
504 "hardware/ril",
505 }
506)
507
508// Determine if a dir under source tree is an SoC-owned proprietary directory, such as
509// device/, vendor/, etc.
510func isVendorProprietaryPath(dir string) bool {
511 for _, p := range vendorProprietaryDirs {
512 if strings.HasPrefix(dir, p) {
513 // filter out AOSP defined directories, e.g. hardware/interfaces/
514 aosp := false
515 for _, p := range aospDirsUnderProprietary {
516 if strings.HasPrefix(dir, p) {
517 aosp = true
518 break
519 }
520 }
521 if !aosp {
522 return true
523 }
524 }
525 }
526 return false
527}
528
Bill Peckham945441c2020-08-31 16:07:58 -0700529func isVendorProprietaryModule(ctx android.BaseModuleContext) bool {
530
531 // Any module in a vendor proprietary path is a vendor proprietary
532 // module.
533
534 if isVendorProprietaryPath(ctx.ModuleDir()) {
535 return true
536 }
537
538 // However if the module is not in a vendor proprietary path, it may
539 // still be a vendor proprietary module. This happens for cc modules
540 // that are excluded from the vendor snapshot, and it means that the
541 // vendor has assumed control of the framework-provided module.
542
543 if c, ok := ctx.Module().(*Module); ok {
544 if c.ExcludeFromVendorSnapshot() {
545 return true
546 }
547 }
548
549 return false
550}
551
Inseob Kim8471cda2019-11-15 09:59:12 +0900552// Determine if a module is going to be included in vendor snapshot or not.
553//
554// Targets of vendor snapshot are "vendor: true" or "vendor_available: true" modules in
555// AOSP. They are not guaranteed to be compatible with older vendor images. (e.g. might
556// depend on newer VNDK) So they are captured as vendor snapshot To build older vendor
557// image and newer system image altogether.
Colin Cross56a83212020-09-15 18:30:11 -0700558func isVendorSnapshotModule(m *Module, inVendorProprietaryPath bool, apexInfo android.ApexInfo) bool {
Inseob Kim7f283f42020-06-01 21:53:49 +0900559 if !m.Enabled() || m.Properties.HideFromMake {
Inseob Kim8471cda2019-11-15 09:59:12 +0900560 return false
561 }
Martin Stjernholm809d5182020-09-10 01:46:05 +0100562 // When android/prebuilt.go selects between source and prebuilt, it sets
563 // SkipInstall on the other one to avoid duplicate install rules in make.
564 if m.IsSkipInstall() {
565 return false
566 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900567 // skip proprietary modules, but include all VNDK (static)
Bill Peckham945441c2020-08-31 16:07:58 -0700568 if inVendorProprietaryPath && !m.IsVndk() {
569 return false
570 }
571 // If the module would be included based on its path, check to see if
572 // the module is marked to be excluded. If so, skip it.
573 if m.ExcludeFromVendorSnapshot() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900574 return false
575 }
576 if m.Target().Os.Class != android.Device {
577 return false
578 }
579 if m.Target().NativeBridge == android.NativeBridgeEnabled {
580 return false
581 }
582 // the module must be installed in /vendor
Colin Cross56a83212020-09-15 18:30:11 -0700583 if !apexInfo.IsForPlatform() || m.isSnapshotPrebuilt() || !m.inVendor() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900584 return false
585 }
Inseob Kim65ca36a2020-06-11 13:55:45 +0900586 // skip kernel_headers which always depend on vendor
587 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
588 return false
589 }
Justin Yunf2664c62020-07-30 18:57:54 +0900590 // skip llndk_library and llndk_headers which are backward compatible
591 if _, ok := m.linker.(*llndkStubDecorator); ok {
592 return false
593 }
594 if _, ok := m.linker.(*llndkHeadersDecorator); ok {
595 return false
596 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900597
598 // Libraries
599 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Inseob Kim7f283f42020-06-01 21:53:49 +0900600 // TODO(b/65377115): add full support for sanitizer
601 if m.sanitize != nil {
Inseob Kimc42f2f22020-07-29 20:32:10 +0900602 // scs and hwasan export both sanitized and unsanitized variants for static and header
Inseob Kim7f283f42020-06-01 21:53:49 +0900603 // Always use unsanitized variants of them.
Inseob Kimc42f2f22020-07-29 20:32:10 +0900604 for _, t := range []sanitizerType{scs, hwasan} {
Inseob Kim7f283f42020-06-01 21:53:49 +0900605 if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
606 return false
607 }
608 }
Inseob Kimc42f2f22020-07-29 20:32:10 +0900609 // cfi also exports both variants. But for static, we capture both.
610 if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) {
611 return false
612 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900613 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900614 if l.static() {
Inseob Kim7f283f42020-06-01 21:53:49 +0900615 return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true)
Inseob Kim8471cda2019-11-15 09:59:12 +0900616 }
617 if l.shared() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700618 if !m.outputFile.Valid() {
619 return false
620 }
621 if !m.IsVndk() {
622 return true
623 }
624 return m.isVndkExt()
Inseob Kim8471cda2019-11-15 09:59:12 +0900625 }
626 return true
627 }
628
Inseob Kim1042d292020-06-01 23:23:05 +0900629 // Binaries and Objects
630 if m.binary() || m.object() {
Inseob Kim7f283f42020-06-01 21:53:49 +0900631 return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true)
Inseob Kim8471cda2019-11-15 09:59:12 +0900632 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900633
634 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900635}
636
637func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
638 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a vendor snapshot.
639 if ctx.DeviceConfig().VndkVersion() != "current" {
640 return
641 }
642
643 var snapshotOutputs android.Paths
644
645 /*
646 Vendor snapshot zipped artifacts directory structure:
647 {SNAPSHOT_ARCH}/
648 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
649 shared/
650 (.so shared libraries)
651 static/
652 (.a static libraries)
653 header/
654 (header only libraries)
655 binary/
656 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900657 object/
658 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900659 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
660 shared/
661 (.so shared libraries)
662 static/
663 (.a static libraries)
664 header/
665 (header only libraries)
666 binary/
667 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900668 object/
669 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900670 NOTICE_FILES/
671 (notice files, e.g. libbase.txt)
672 configs/
673 (config files, e.g. init.rc files, vintf_fragments.xml files, etc.)
674 include/
675 (header files of same directory structure with source tree)
676 */
677
678 snapshotDir := "vendor-snapshot"
679 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
680
681 includeDir := filepath.Join(snapshotArchDir, "include")
682 configsDir := filepath.Join(snapshotArchDir, "configs")
683 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
684
685 installedNotices := make(map[string]bool)
686 installedConfigs := make(map[string]bool)
687
688 var headers android.Paths
689
Inseob Kim8471cda2019-11-15 09:59:12 +0900690 installSnapshot := func(m *Module) android.Paths {
691 targetArch := "arch-" + m.Target().Arch.ArchType.String()
692 if m.Target().Arch.ArchVariant != "" {
693 targetArch += "-" + m.Target().Arch.ArchVariant
694 }
695
696 var ret android.Paths
697
698 prop := struct {
699 ModuleName string `json:",omitempty"`
700 RelativeInstallPath string `json:",omitempty"`
701
702 // library flags
703 ExportedDirs []string `json:",omitempty"`
704 ExportedSystemDirs []string `json:",omitempty"`
705 ExportedFlags []string `json:",omitempty"`
Inseob Kimc42f2f22020-07-29 20:32:10 +0900706 Sanitize string `json:",omitempty"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900707 SanitizeMinimalDep bool `json:",omitempty"`
708 SanitizeUbsanDep bool `json:",omitempty"`
709
710 // binary flags
711 Symlinks []string `json:",omitempty"`
712
713 // dependencies
714 SharedLibs []string `json:",omitempty"`
715 RuntimeLibs []string `json:",omitempty"`
716 Required []string `json:",omitempty"`
717
718 // extra config files
719 InitRc []string `json:",omitempty"`
720 VintfFragments []string `json:",omitempty"`
721 }{}
722
723 // Common properties among snapshots.
724 prop.ModuleName = ctx.ModuleName(m)
Bill Peckham7d3f0962020-06-29 16:49:15 -0700725 if m.isVndkExt() {
726 // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
727 if m.isVndkSp() {
728 prop.RelativeInstallPath = "vndk-sp"
729 } else {
730 prop.RelativeInstallPath = "vndk"
731 }
732 } else {
733 prop.RelativeInstallPath = m.RelativeInstallPath()
734 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900735 prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs
736 prop.Required = m.RequiredModuleNames()
737 for _, path := range m.InitRc() {
738 prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base()))
739 }
740 for _, path := range m.VintfFragments() {
741 prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base()))
742 }
743
744 // install config files. ignores any duplicates.
745 for _, path := range append(m.InitRc(), m.VintfFragments()...) {
746 out := filepath.Join(configsDir, path.Base())
747 if !installedConfigs[out] {
748 installedConfigs[out] = true
749 ret = append(ret, copyFile(ctx, path, out))
750 }
751 }
752
753 var propOut string
754
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900755 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700756 exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900757
Inseob Kim8471cda2019-11-15 09:59:12 +0900758 // library flags
Colin Cross0de8a1e2020-09-18 14:15:30 -0700759 prop.ExportedFlags = exporterInfo.Flags
760 for _, dir := range exporterInfo.IncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900761 prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String()))
762 }
Colin Cross0de8a1e2020-09-18 14:15:30 -0700763 for _, dir := range exporterInfo.SystemIncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900764 prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String()))
765 }
766 // shared libs dependencies aren't meaningful on static or header libs
767 if l.shared() {
768 prop.SharedLibs = m.Properties.SnapshotSharedLibs
769 }
770 if l.static() && m.sanitize != nil {
771 prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize)
772 prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize)
773 }
774
775 var libType string
776 if l.static() {
777 libType = "static"
778 } else if l.shared() {
779 libType = "shared"
780 } else {
781 libType = "header"
782 }
783
784 var stem string
785
786 // install .a or .so
787 if libType != "header" {
788 libPath := m.outputFile.Path()
789 stem = libPath.Base()
Inseob Kimc42f2f22020-07-29 20:32:10 +0900790 if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) {
791 // both cfi and non-cfi variant for static libraries can exist.
792 // attach .cfi to distinguish between cfi and non-cfi.
793 // e.g. libbase.a -> libbase.cfi.a
794 ext := filepath.Ext(stem)
795 stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
796 prop.Sanitize = "cfi"
797 prop.ModuleName += ".cfi"
798 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900799 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
800 ret = append(ret, copyFile(ctx, libPath, snapshotLibOut))
801 } else {
802 stem = ctx.ModuleName(m)
803 }
804
805 propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
Inseob Kim7f283f42020-06-01 21:53:49 +0900806 } else if m.binary() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900807 // binary flags
808 prop.Symlinks = m.Symlinks()
809 prop.SharedLibs = m.Properties.SnapshotSharedLibs
810
811 // install bin
812 binPath := m.outputFile.Path()
813 snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
814 ret = append(ret, copyFile(ctx, binPath, snapshotBinOut))
815 propOut = snapshotBinOut + ".json"
Inseob Kim1042d292020-06-01 23:23:05 +0900816 } else if m.object() {
817 // object files aren't installed to the device, so their names can conflict.
818 // Use module name as stem.
819 objPath := m.outputFile.Path()
820 snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
821 ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
822 ret = append(ret, copyFile(ctx, objPath, snapshotObjOut))
823 propOut = snapshotObjOut + ".json"
Inseob Kim7f283f42020-06-01 21:53:49 +0900824 } else {
825 ctx.Errorf("unknown module %q in vendor snapshot", m.String())
826 return nil
Inseob Kim8471cda2019-11-15 09:59:12 +0900827 }
828
829 j, err := json.Marshal(prop)
830 if err != nil {
831 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
832 return nil
833 }
834 ret = append(ret, writeStringToFile(ctx, string(j), propOut))
835
836 return ret
837 }
838
839 ctx.VisitAllModules(func(module android.Module) {
840 m, ok := module.(*Module)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900841 if !ok {
842 return
843 }
844
845 moduleDir := ctx.ModuleDir(module)
Bill Peckham945441c2020-08-31 16:07:58 -0700846 inVendorProprietaryPath := isVendorProprietaryPath(moduleDir)
Colin Cross56a83212020-09-15 18:30:11 -0700847 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
Bill Peckham945441c2020-08-31 16:07:58 -0700848
849 if m.ExcludeFromVendorSnapshot() {
850 if inVendorProprietaryPath {
851 // Error: exclude_from_vendor_snapshot applies
852 // to framework-path modules only.
853 ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir)
854 return
855 }
856 if Bool(m.VendorProperties.Vendor_available) {
857 // Error: may not combine "vendor_available:
858 // true" with "exclude_from_vendor_snapshot:
859 // true".
860 ctx.Errorf("module %q may not use both \"vendor_available: true\" and \"exclude_from_vendor_snapshot: true\"", m.String())
861 return
862 }
863 }
864
Colin Cross56a83212020-09-15 18:30:11 -0700865 if !isVendorSnapshotModule(m, inVendorProprietaryPath, apexInfo) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900866 return
867 }
868
869 snapshotOutputs = append(snapshotOutputs, installSnapshot(m)...)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900870 if l, ok := m.linker.(snapshotLibraryInterface); ok {
871 headers = append(headers, l.snapshotHeaders()...)
Inseob Kim8471cda2019-11-15 09:59:12 +0900872 }
873
Bob Badoura75b0572020-02-18 20:21:55 -0800874 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900875 noticeName := ctx.ModuleName(m) + ".txt"
876 noticeOut := filepath.Join(noticeDir, noticeName)
877 // skip already copied notice file
878 if !installedNotices[noticeOut] {
879 installedNotices[noticeOut] = true
Bob Badoura75b0572020-02-18 20:21:55 -0800880 snapshotOutputs = append(snapshotOutputs, combineNotices(
881 ctx, m.NoticeFiles(), noticeOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900882 }
883 }
884 })
885
886 // install all headers after removing duplicates
887 for _, header := range android.FirstUniquePaths(headers) {
888 snapshotOutputs = append(snapshotOutputs, copyFile(
889 ctx, header, filepath.Join(includeDir, header.String())))
890 }
891
892 // All artifacts are ready. Sort them to normalize ninja and then zip.
893 sort.Slice(snapshotOutputs, func(i, j int) bool {
894 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
895 })
896
897 zipPath := android.PathForOutput(ctx, snapshotDir, "vendor-"+ctx.Config().DeviceName()+".zip")
898 zipRule := android.NewRuleBuilder()
899
900 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
901 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "vendor-"+ctx.Config().DeviceName()+"_list")
902 zipRule.Command().
903 Text("tr").
904 FlagWithArg("-d ", "\\'").
905 FlagWithRspFileInputList("< ", snapshotOutputs).
906 FlagWithOutput("> ", snapshotOutputList)
907
908 zipRule.Temporary(snapshotOutputList)
909
910 zipRule.Command().
911 BuiltTool(ctx, "soong_zip").
912 FlagWithOutput("-o ", zipPath).
913 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
914 FlagWithInput("-l ", snapshotOutputList)
915
916 zipRule.Build(pctx, ctx, zipPath.String(), "vendor snapshot "+zipPath.String())
917 zipRule.DeleteTemporaryFiles()
918 c.vendorSnapshotZipFile = android.OptionalPathForPath(zipPath)
919}
920
921func (c *vendorSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
922 ctx.Strict("SOONG_VENDOR_SNAPSHOT_ZIP", c.vendorSnapshotZipFile.String())
923}
Inseob Kimeec88e12020-01-22 11:11:29 +0900924
925type snapshotInterface interface {
926 matchesWithDevice(config android.DeviceConfig) bool
927}
928
929var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
930var _ snapshotInterface = (*vendorSnapshotLibraryDecorator)(nil)
931var _ snapshotInterface = (*vendorSnapshotBinaryDecorator)(nil)
Inseob Kim1042d292020-06-01 23:23:05 +0900932var _ snapshotInterface = (*vendorSnapshotObjectLinker)(nil)
Inseob Kimeec88e12020-01-22 11:11:29 +0900933
934// gathers all snapshot modules for vendor, and disable unnecessary snapshots
935// TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules
936func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) {
937 vndkVersion := ctx.DeviceConfig().VndkVersion()
938 // don't need snapshot if current
939 if vndkVersion == "current" || vndkVersion == "" {
940 return
941 }
942
943 module, ok := ctx.Module().(*Module)
944 if !ok || !module.Enabled() || module.VndkVersion() != vndkVersion {
945 return
946 }
947
Inseob Kim1042d292020-06-01 23:23:05 +0900948 if !module.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +0900949 return
950 }
951
Inseob Kim1042d292020-06-01 23:23:05 +0900952 // isSnapshotPrebuilt ensures snapshotInterface
953 if !module.linker.(snapshotInterface).matchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimeec88e12020-01-22 11:11:29 +0900954 // Disable unnecessary snapshot module, but do not disable
955 // vndk_prebuilt_shared because they might be packed into vndk APEX
956 if !module.IsVndk() {
957 module.Disable()
958 }
959 return
960 }
961
962 var snapshotMap *snapshotMap
963
964 if lib, ok := module.linker.(libraryInterface); ok {
965 if lib.static() {
966 snapshotMap = vendorSnapshotStaticLibs(ctx.Config())
967 } else if lib.shared() {
968 snapshotMap = vendorSnapshotSharedLibs(ctx.Config())
969 } else {
970 // header
971 snapshotMap = vendorSnapshotHeaderLibs(ctx.Config())
972 }
973 } else if _, ok := module.linker.(*vendorSnapshotBinaryDecorator); ok {
974 snapshotMap = vendorSnapshotBinaries(ctx.Config())
Inseob Kim1042d292020-06-01 23:23:05 +0900975 } else if _, ok := module.linker.(*vendorSnapshotObjectLinker); ok {
976 snapshotMap = vendorSnapshotObjects(ctx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +0900977 } else {
978 return
979 }
980
981 vendorSnapshotsLock.Lock()
982 defer vendorSnapshotsLock.Unlock()
983 snapshotMap.add(module.BaseModuleName(), ctx.Arch().ArchType, ctx.ModuleName())
984}
985
986// Disables source modules which have snapshots
987func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) {
Inseob Kim5f64aec2020-02-18 17:27:19 +0900988 if !ctx.Device() {
989 return
990 }
991
Inseob Kimeec88e12020-01-22 11:11:29 +0900992 vndkVersion := ctx.DeviceConfig().VndkVersion()
993 // don't need snapshot if current
994 if vndkVersion == "current" || vndkVersion == "" {
995 return
996 }
997
998 module, ok := ctx.Module().(*Module)
999 if !ok {
1000 return
1001 }
1002
Inseob Kim5f64aec2020-02-18 17:27:19 +09001003 // vendor suffix should be added to snapshots if the source module isn't vendor: true.
1004 if !module.SocSpecific() {
1005 // But we can't just check SocSpecific() since we already passed the image mutator.
1006 // Check ramdisk and recovery to see if we are real "vendor: true" module.
1007 ramdisk_available := module.InRamdisk() && !module.OnlyInRamdisk()
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001008 vendor_ramdisk_available := module.InVendorRamdisk() && !module.OnlyInVendorRamdisk()
Inseob Kim5f64aec2020-02-18 17:27:19 +09001009 recovery_available := module.InRecovery() && !module.OnlyInRecovery()
Inseob Kimeec88e12020-01-22 11:11:29 +09001010
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001011 if !ramdisk_available && !recovery_available && !vendor_ramdisk_available {
Inseob Kim5f64aec2020-02-18 17:27:19 +09001012 vendorSnapshotsLock.Lock()
1013 defer vendorSnapshotsLock.Unlock()
1014
1015 vendorSuffixModules(ctx.Config())[ctx.ModuleName()] = true
1016 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001017 }
1018
1019 if module.isSnapshotPrebuilt() || module.VndkVersion() != ctx.DeviceConfig().VndkVersion() {
1020 // only non-snapshot modules with BOARD_VNDK_VERSION
1021 return
1022 }
1023
Inseob Kim206665c2020-06-02 23:48:32 +09001024 // .. and also filter out llndk library
1025 if module.isLlndk(ctx.Config()) {
1026 return
1027 }
1028
Inseob Kimeec88e12020-01-22 11:11:29 +09001029 var snapshotMap *snapshotMap
1030
1031 if lib, ok := module.linker.(libraryInterface); ok {
1032 if lib.static() {
1033 snapshotMap = vendorSnapshotStaticLibs(ctx.Config())
1034 } else if lib.shared() {
1035 snapshotMap = vendorSnapshotSharedLibs(ctx.Config())
1036 } else {
1037 // header
1038 snapshotMap = vendorSnapshotHeaderLibs(ctx.Config())
1039 }
Inseob Kim7f283f42020-06-01 21:53:49 +09001040 } else if module.binary() {
Inseob Kimeec88e12020-01-22 11:11:29 +09001041 snapshotMap = vendorSnapshotBinaries(ctx.Config())
Inseob Kim1042d292020-06-01 23:23:05 +09001042 } else if module.object() {
1043 snapshotMap = vendorSnapshotObjects(ctx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001044 } else {
1045 return
1046 }
1047
1048 if _, ok := snapshotMap.get(ctx.ModuleName(), ctx.Arch().ArchType); !ok {
1049 // Corresponding snapshot doesn't exist
1050 return
1051 }
1052
1053 // Disables source modules if corresponding snapshot exists.
1054 if lib, ok := module.linker.(libraryInterface); ok && lib.buildStatic() && lib.buildShared() {
1055 // But do not disable because the shared variant depends on the static variant.
1056 module.SkipInstall()
1057 module.Properties.HideFromMake = true
1058 } else {
1059 module.Disable()
1060 }
1061}