blob: 4c206e6d286774565b67f3eb378287fa4dc375e2 [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
244 return in
245}
246
Inseob Kimeec88e12020-01-22 11:11:29 +0900247func (p *vendorSnapshotLibraryDecorator) install(ctx ModuleContext, file android.Path) {
248 if p.matchesWithDevice(ctx.DeviceConfig()) && (p.shared() || p.static()) {
249 p.baseInstaller.install(ctx, file)
250 }
251}
252
Inseob Kim2d34ad92020-07-30 21:04:09 +0900253func (p *vendorSnapshotLibraryDecorator) nativeCoverage() bool {
254 return false
Inseob Kimeec88e12020-01-22 11:11:29 +0900255}
256
Inseob Kimc42f2f22020-07-29 20:32:10 +0900257func (p *vendorSnapshotLibraryDecorator) isSanitizerEnabled(t sanitizerType) bool {
258 switch t {
259 case cfi:
260 return p.sanitizerProperties.Cfi.Src != nil
261 default:
262 return false
263 }
264}
265
266func (p *vendorSnapshotLibraryDecorator) setSanitizerVariation(t sanitizerType, enabled bool) {
267 if !enabled {
268 return
269 }
270 switch t {
271 case cfi:
272 p.sanitizerProperties.CfiEnabled = true
273 default:
274 return
275 }
276}
277
Inseob Kim2d34ad92020-07-30 21:04:09 +0900278func vendorSnapshotLibrary(suffix string) (*Module, *vendorSnapshotLibraryDecorator) {
Inseob Kimeec88e12020-01-22 11:11:29 +0900279 module, library := NewLibrary(android.DeviceSupported)
280
281 module.stl = nil
282 module.sanitize = nil
Thiébaud Weksteend4587452020-08-19 14:53:01 +0200283 library.disableStripping()
Inseob Kimeec88e12020-01-22 11:11:29 +0900284
285 prebuilt := &vendorSnapshotLibraryDecorator{
286 libraryDecorator: library,
287 }
288
289 prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true)
290 prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true)
291
292 // Prevent default system libs (libc, libm, and libdl) from being linked
293 if prebuilt.baseLinker.Properties.System_shared_libs == nil {
294 prebuilt.baseLinker.Properties.System_shared_libs = []string{}
295 }
296
297 module.compiler = nil
298 module.linker = prebuilt
299 module.installer = prebuilt
300
Inseob Kim2d34ad92020-07-30 21:04:09 +0900301 prebuilt.init(module, suffix)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900302 module.AddProperties(
303 &prebuilt.properties,
304 &prebuilt.sanitizerProperties,
305 )
Inseob Kimeec88e12020-01-22 11:11:29 +0900306
307 return module, prebuilt
308}
309
310func VendorSnapshotSharedFactory() android.Module {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900311 module, prebuilt := vendorSnapshotLibrary(vendorSnapshotSharedSuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +0900312 prebuilt.libraryDecorator.BuildOnlyShared()
Inseob Kimeec88e12020-01-22 11:11:29 +0900313 return module.Init()
314}
315
316func VendorSnapshotStaticFactory() android.Module {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900317 module, prebuilt := vendorSnapshotLibrary(vendorSnapshotStaticSuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +0900318 prebuilt.libraryDecorator.BuildOnlyStatic()
Inseob Kimeec88e12020-01-22 11:11:29 +0900319 return module.Init()
320}
321
322func VendorSnapshotHeaderFactory() android.Module {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900323 module, prebuilt := vendorSnapshotLibrary(vendorSnapshotHeaderSuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +0900324 prebuilt.libraryDecorator.HeaderOnly()
Inseob Kimeec88e12020-01-22 11:11:29 +0900325 return module.Init()
326}
327
Inseob Kimc42f2f22020-07-29 20:32:10 +0900328var _ snapshotSanitizer = (*vendorSnapshotLibraryDecorator)(nil)
329
Inseob Kimeec88e12020-01-22 11:11:29 +0900330type vendorSnapshotBinaryProperties struct {
Inseob Kimeec88e12020-01-22 11:11:29 +0900331 // Prebuilt file for each arch.
332 Src *string `android:"arch_variant"`
333}
334
335type vendorSnapshotBinaryDecorator struct {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900336 vendorSnapshotModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900337 *binaryDecorator
338 properties vendorSnapshotBinaryProperties
339 androidMkVendorSuffix bool
340}
341
Inseob Kimeec88e12020-01-22 11:11:29 +0900342func (p *vendorSnapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool {
343 if config.DeviceArch() != p.arch() {
344 return false
345 }
346 if p.properties.Src == nil {
347 return false
348 }
349 return true
350}
351
352func (p *vendorSnapshotBinaryDecorator) link(ctx ModuleContext,
353 flags Flags, deps PathDeps, objs Objects) android.Path {
354 if !p.matchesWithDevice(ctx.DeviceConfig()) {
355 return nil
356 }
357
358 in := android.PathForModuleSrc(ctx, *p.properties.Src)
Thiébaud Weksteend4587452020-08-19 14:53:01 +0200359 stripFlags := flagsToStripFlags(flags)
Inseob Kimeec88e12020-01-22 11:11:29 +0900360 p.unstrippedOutputFile = in
361 binName := in.Base()
Thiébaud Weksteend4587452020-08-19 14:53:01 +0200362 if p.stripper.NeedsStrip(ctx) {
Inseob Kimeec88e12020-01-22 11:11:29 +0900363 stripped := android.PathForModuleOut(ctx, "stripped", binName)
Thiébaud Weksteend4587452020-08-19 14:53:01 +0200364 p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags)
Inseob Kimeec88e12020-01-22 11:11:29 +0900365 in = stripped
366 }
367
368 m := ctx.Module().(*Module)
369 p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()]
370
371 // use cpExecutable to make it executable
372 outputFile := android.PathForModuleOut(ctx, binName)
373 ctx.Build(pctx, android.BuildParams{
374 Rule: android.CpExecutable,
375 Description: "prebuilt",
376 Output: outputFile,
377 Input: in,
378 })
379
380 return outputFile
381}
382
Inseob Kim2d34ad92020-07-30 21:04:09 +0900383func (p *vendorSnapshotBinaryDecorator) nativeCoverage() bool {
384 return false
Inseob Kim1042d292020-06-01 23:23:05 +0900385}
386
Inseob Kimeec88e12020-01-22 11:11:29 +0900387func VendorSnapshotBinaryFactory() android.Module {
388 module, binary := NewBinary(android.DeviceSupported)
389 binary.baseLinker.Properties.No_libcrt = BoolPtr(true)
390 binary.baseLinker.Properties.Nocrt = BoolPtr(true)
391
392 // Prevent default system libs (libc, libm, and libdl) from being linked
393 if binary.baseLinker.Properties.System_shared_libs == nil {
394 binary.baseLinker.Properties.System_shared_libs = []string{}
395 }
396
397 prebuilt := &vendorSnapshotBinaryDecorator{
398 binaryDecorator: binary,
399 }
400
401 module.compiler = nil
402 module.sanitize = nil
403 module.stl = nil
404 module.linker = prebuilt
405
Inseob Kim2d34ad92020-07-30 21:04:09 +0900406 prebuilt.init(module, vendorSnapshotBinarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +0900407 module.AddProperties(&prebuilt.properties)
408 return module.Init()
409}
410
Inseob Kim1042d292020-06-01 23:23:05 +0900411type vendorSnapshotObjectProperties struct {
Inseob Kim1042d292020-06-01 23:23:05 +0900412 // Prebuilt file for each arch.
413 Src *string `android:"arch_variant"`
414}
415
416type vendorSnapshotObjectLinker struct {
Inseob Kim2d34ad92020-07-30 21:04:09 +0900417 vendorSnapshotModuleBase
Inseob Kim1042d292020-06-01 23:23:05 +0900418 objectLinker
419 properties vendorSnapshotObjectProperties
420 androidMkVendorSuffix bool
421}
422
Inseob Kim1042d292020-06-01 23:23:05 +0900423func (p *vendorSnapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool {
424 if config.DeviceArch() != p.arch() {
425 return false
426 }
427 if p.properties.Src == nil {
428 return false
429 }
430 return true
431}
432
433func (p *vendorSnapshotObjectLinker) link(ctx ModuleContext,
434 flags Flags, deps PathDeps, objs Objects) android.Path {
435 if !p.matchesWithDevice(ctx.DeviceConfig()) {
436 return nil
437 }
438
439 m := ctx.Module().(*Module)
440 p.androidMkVendorSuffix = vendorSuffixModules(ctx.Config())[m.BaseModuleName()]
441
442 return android.PathForModuleSrc(ctx, *p.properties.Src)
443}
444
445func (p *vendorSnapshotObjectLinker) nativeCoverage() bool {
446 return false
447}
448
Inseob Kim1042d292020-06-01 23:23:05 +0900449func VendorSnapshotObjectFactory() android.Module {
450 module := newObject()
451
452 prebuilt := &vendorSnapshotObjectLinker{
453 objectLinker: objectLinker{
454 baseLinker: NewBaseLinker(nil),
455 },
456 }
457 module.linker = prebuilt
458
Inseob Kim2d34ad92020-07-30 21:04:09 +0900459 prebuilt.init(module, vendorSnapshotObjectSuffix)
Inseob Kim1042d292020-06-01 23:23:05 +0900460 module.AddProperties(&prebuilt.properties)
461 return module.Init()
462}
463
Inseob Kim8471cda2019-11-15 09:59:12 +0900464func init() {
465 android.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
Inseob Kimeec88e12020-01-22 11:11:29 +0900466 android.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
467 android.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
468 android.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory)
469 android.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
Inseob Kim1042d292020-06-01 23:23:05 +0900470 android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory)
Inseob Kim8471cda2019-11-15 09:59:12 +0900471}
472
473func VendorSnapshotSingleton() android.Singleton {
474 return &vendorSnapshotSingleton{}
475}
476
477type vendorSnapshotSingleton struct {
478 vendorSnapshotZipFile android.OptionalPath
479}
480
481var (
482 // Modules under following directories are ignored. They are OEM's and vendor's
Daniel Norman713387d2020-07-28 16:04:38 -0700483 // proprietary modules(device/, kernel/, vendor/, and hardware/).
Inseob Kim8471cda2019-11-15 09:59:12 +0900484 // TODO(b/65377115): Clean up these with more maintainable way
485 vendorProprietaryDirs = []string{
486 "device",
Daniel Norman713387d2020-07-28 16:04:38 -0700487 "kernel",
Inseob Kim8471cda2019-11-15 09:59:12 +0900488 "vendor",
489 "hardware",
490 }
491
492 // Modules under following directories are included as they are in AOSP,
Daniel Norman713387d2020-07-28 16:04:38 -0700493 // although hardware/ and kernel/ are normally for vendor's own.
Inseob Kim8471cda2019-11-15 09:59:12 +0900494 // TODO(b/65377115): Clean up these with more maintainable way
495 aospDirsUnderProprietary = []string{
Daniel Norman713387d2020-07-28 16:04:38 -0700496 "kernel/configs",
497 "kernel/prebuilts",
498 "kernel/tests",
Inseob Kim8471cda2019-11-15 09:59:12 +0900499 "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.
508func 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
Bill Peckham945441c2020-08-31 16:07:58 -0700527func isVendorProprietaryModule(ctx android.BaseModuleContext) bool {
528
529 // Any module in a vendor proprietary path is a vendor proprietary
530 // module.
531
532 if isVendorProprietaryPath(ctx.ModuleDir()) {
533 return true
534 }
535
536 // However if the module is not in a vendor proprietary path, it may
537 // still be a vendor proprietary module. This happens for cc modules
538 // that are excluded from the vendor snapshot, and it means that the
539 // vendor has assumed control of the framework-provided module.
540
541 if c, ok := ctx.Module().(*Module); ok {
542 if c.ExcludeFromVendorSnapshot() {
543 return true
544 }
545 }
546
547 return false
548}
549
Inseob Kim8471cda2019-11-15 09:59:12 +0900550// Determine if a module is going to be included in vendor snapshot or not.
551//
552// Targets of vendor snapshot are "vendor: true" or "vendor_available: true" modules in
553// AOSP. They are not guaranteed to be compatible with older vendor images. (e.g. might
554// depend on newer VNDK) So they are captured as vendor snapshot To build older vendor
555// image and newer system image altogether.
Colin Cross56a83212020-09-15 18:30:11 -0700556func isVendorSnapshotModule(m *Module, inVendorProprietaryPath bool, apexInfo android.ApexInfo) bool {
Inseob Kim7f283f42020-06-01 21:53:49 +0900557 if !m.Enabled() || m.Properties.HideFromMake {
Inseob Kim8471cda2019-11-15 09:59:12 +0900558 return false
559 }
Martin Stjernholm809d5182020-09-10 01:46:05 +0100560 // When android/prebuilt.go selects between source and prebuilt, it sets
561 // SkipInstall on the other one to avoid duplicate install rules in make.
562 if m.IsSkipInstall() {
563 return false
564 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900565 // skip proprietary modules, but include all VNDK (static)
Bill Peckham945441c2020-08-31 16:07:58 -0700566 if inVendorProprietaryPath && !m.IsVndk() {
567 return false
568 }
569 // If the module would be included based on its path, check to see if
570 // the module is marked to be excluded. If so, skip it.
571 if m.ExcludeFromVendorSnapshot() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900572 return false
573 }
574 if m.Target().Os.Class != android.Device {
575 return false
576 }
577 if m.Target().NativeBridge == android.NativeBridgeEnabled {
578 return false
579 }
580 // the module must be installed in /vendor
Colin Cross56a83212020-09-15 18:30:11 -0700581 if !apexInfo.IsForPlatform() || m.isSnapshotPrebuilt() || !m.inVendor() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900582 return false
583 }
Inseob Kim65ca36a2020-06-11 13:55:45 +0900584 // skip kernel_headers which always depend on vendor
585 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
586 return false
587 }
Justin Yunf2664c62020-07-30 18:57:54 +0900588 // skip llndk_library and llndk_headers which are backward compatible
589 if _, ok := m.linker.(*llndkStubDecorator); ok {
590 return false
591 }
592 if _, ok := m.linker.(*llndkHeadersDecorator); ok {
593 return false
594 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900595
596 // Libraries
597 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Inseob Kim7f283f42020-06-01 21:53:49 +0900598 // TODO(b/65377115): add full support for sanitizer
599 if m.sanitize != nil {
Inseob Kimc42f2f22020-07-29 20:32:10 +0900600 // scs and hwasan export both sanitized and unsanitized variants for static and header
Inseob Kim7f283f42020-06-01 21:53:49 +0900601 // Always use unsanitized variants of them.
Inseob Kimc42f2f22020-07-29 20:32:10 +0900602 for _, t := range []sanitizerType{scs, hwasan} {
Inseob Kim7f283f42020-06-01 21:53:49 +0900603 if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
604 return false
605 }
606 }
Inseob Kimc42f2f22020-07-29 20:32:10 +0900607 // cfi also exports both variants. But for static, we capture both.
608 if !l.static() && !l.shared() && m.sanitize.isSanitizerEnabled(cfi) {
609 return false
610 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900611 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900612 if l.static() {
Inseob Kim7f283f42020-06-01 21:53:49 +0900613 return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true)
Inseob Kim8471cda2019-11-15 09:59:12 +0900614 }
615 if l.shared() {
Bill Peckham7d3f0962020-06-29 16:49:15 -0700616 if !m.outputFile.Valid() {
617 return false
618 }
619 if !m.IsVndk() {
620 return true
621 }
622 return m.isVndkExt()
Inseob Kim8471cda2019-11-15 09:59:12 +0900623 }
624 return true
625 }
626
Inseob Kim1042d292020-06-01 23:23:05 +0900627 // Binaries and Objects
628 if m.binary() || m.object() {
Inseob Kim7f283f42020-06-01 21:53:49 +0900629 return m.outputFile.Valid() && proptools.BoolDefault(m.VendorProperties.Vendor_available, true)
Inseob Kim8471cda2019-11-15 09:59:12 +0900630 }
Inseob Kim7f283f42020-06-01 21:53:49 +0900631
632 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900633}
634
635func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
636 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a vendor snapshot.
637 if ctx.DeviceConfig().VndkVersion() != "current" {
638 return
639 }
640
641 var snapshotOutputs android.Paths
642
643 /*
644 Vendor snapshot zipped artifacts directory structure:
645 {SNAPSHOT_ARCH}/
646 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
647 shared/
648 (.so shared libraries)
649 static/
650 (.a static libraries)
651 header/
652 (header only libraries)
653 binary/
654 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900655 object/
656 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900657 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
658 shared/
659 (.so shared libraries)
660 static/
661 (.a static libraries)
662 header/
663 (header only libraries)
664 binary/
665 (executable binaries)
Inseob Kim1042d292020-06-01 23:23:05 +0900666 object/
667 (.o object files)
Inseob Kim8471cda2019-11-15 09:59:12 +0900668 NOTICE_FILES/
669 (notice files, e.g. libbase.txt)
670 configs/
671 (config files, e.g. init.rc files, vintf_fragments.xml files, etc.)
672 include/
673 (header files of same directory structure with source tree)
674 */
675
676 snapshotDir := "vendor-snapshot"
677 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
678
679 includeDir := filepath.Join(snapshotArchDir, "include")
680 configsDir := filepath.Join(snapshotArchDir, "configs")
681 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
682
683 installedNotices := make(map[string]bool)
684 installedConfigs := make(map[string]bool)
685
686 var headers android.Paths
687
Inseob Kim8471cda2019-11-15 09:59:12 +0900688 installSnapshot := func(m *Module) android.Paths {
689 targetArch := "arch-" + m.Target().Arch.ArchType.String()
690 if m.Target().Arch.ArchVariant != "" {
691 targetArch += "-" + m.Target().Arch.ArchVariant
692 }
693
694 var ret android.Paths
695
696 prop := struct {
697 ModuleName string `json:",omitempty"`
698 RelativeInstallPath string `json:",omitempty"`
699
700 // library flags
701 ExportedDirs []string `json:",omitempty"`
702 ExportedSystemDirs []string `json:",omitempty"`
703 ExportedFlags []string `json:",omitempty"`
Inseob Kimc42f2f22020-07-29 20:32:10 +0900704 Sanitize string `json:",omitempty"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900705 SanitizeMinimalDep bool `json:",omitempty"`
706 SanitizeUbsanDep bool `json:",omitempty"`
707
708 // binary flags
709 Symlinks []string `json:",omitempty"`
710
711 // dependencies
712 SharedLibs []string `json:",omitempty"`
713 RuntimeLibs []string `json:",omitempty"`
714 Required []string `json:",omitempty"`
715
716 // extra config files
717 InitRc []string `json:",omitempty"`
718 VintfFragments []string `json:",omitempty"`
719 }{}
720
721 // Common properties among snapshots.
722 prop.ModuleName = ctx.ModuleName(m)
Bill Peckham7d3f0962020-06-29 16:49:15 -0700723 if m.isVndkExt() {
724 // vndk exts are installed to /vendor/lib(64)?/vndk(-sp)?
725 if m.isVndkSp() {
726 prop.RelativeInstallPath = "vndk-sp"
727 } else {
728 prop.RelativeInstallPath = "vndk"
729 }
730 } else {
731 prop.RelativeInstallPath = m.RelativeInstallPath()
732 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900733 prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs
734 prop.Required = m.RequiredModuleNames()
735 for _, path := range m.InitRc() {
736 prop.InitRc = append(prop.InitRc, filepath.Join("configs", path.Base()))
737 }
738 for _, path := range m.VintfFragments() {
739 prop.VintfFragments = append(prop.VintfFragments, filepath.Join("configs", path.Base()))
740 }
741
742 // install config files. ignores any duplicates.
743 for _, path := range append(m.InitRc(), m.VintfFragments()...) {
744 out := filepath.Join(configsDir, path.Base())
745 if !installedConfigs[out] {
746 installedConfigs[out] = true
747 ret = append(ret, copyFile(ctx, path, out))
748 }
749 }
750
751 var propOut string
752
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900753 if l, ok := m.linker.(snapshotLibraryInterface); ok {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700754 exporterInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
Inseob Kimc42f2f22020-07-29 20:32:10 +0900755
Inseob Kim8471cda2019-11-15 09:59:12 +0900756 // library flags
Colin Cross0de8a1e2020-09-18 14:15:30 -0700757 prop.ExportedFlags = exporterInfo.Flags
758 for _, dir := range exporterInfo.IncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900759 prop.ExportedDirs = append(prop.ExportedDirs, filepath.Join("include", dir.String()))
760 }
Colin Cross0de8a1e2020-09-18 14:15:30 -0700761 for _, dir := range exporterInfo.SystemIncludeDirs {
Inseob Kim8471cda2019-11-15 09:59:12 +0900762 prop.ExportedSystemDirs = append(prop.ExportedSystemDirs, filepath.Join("include", dir.String()))
763 }
764 // shared libs dependencies aren't meaningful on static or header libs
765 if l.shared() {
766 prop.SharedLibs = m.Properties.SnapshotSharedLibs
767 }
768 if l.static() && m.sanitize != nil {
769 prop.SanitizeMinimalDep = m.sanitize.Properties.MinimalRuntimeDep || enableMinimalRuntime(m.sanitize)
770 prop.SanitizeUbsanDep = m.sanitize.Properties.UbsanRuntimeDep || enableUbsanRuntime(m.sanitize)
771 }
772
773 var libType string
774 if l.static() {
775 libType = "static"
776 } else if l.shared() {
777 libType = "shared"
778 } else {
779 libType = "header"
780 }
781
782 var stem string
783
784 // install .a or .so
785 if libType != "header" {
786 libPath := m.outputFile.Path()
787 stem = libPath.Base()
Inseob Kimc42f2f22020-07-29 20:32:10 +0900788 if l.static() && m.sanitize != nil && m.sanitize.isSanitizerEnabled(cfi) {
789 // both cfi and non-cfi variant for static libraries can exist.
790 // attach .cfi to distinguish between cfi and non-cfi.
791 // e.g. libbase.a -> libbase.cfi.a
792 ext := filepath.Ext(stem)
793 stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
794 prop.Sanitize = "cfi"
795 prop.ModuleName += ".cfi"
796 }
Inseob Kim8471cda2019-11-15 09:59:12 +0900797 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
798 ret = append(ret, copyFile(ctx, libPath, snapshotLibOut))
799 } else {
800 stem = ctx.ModuleName(m)
801 }
802
803 propOut = filepath.Join(snapshotArchDir, targetArch, libType, stem+".json")
Inseob Kim7f283f42020-06-01 21:53:49 +0900804 } else if m.binary() {
Inseob Kim8471cda2019-11-15 09:59:12 +0900805 // binary flags
806 prop.Symlinks = m.Symlinks()
807 prop.SharedLibs = m.Properties.SnapshotSharedLibs
808
809 // install bin
810 binPath := m.outputFile.Path()
811 snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())
812 ret = append(ret, copyFile(ctx, binPath, snapshotBinOut))
813 propOut = snapshotBinOut + ".json"
Inseob Kim1042d292020-06-01 23:23:05 +0900814 } else if m.object() {
815 // object files aren't installed to the device, so their names can conflict.
816 // Use module name as stem.
817 objPath := m.outputFile.Path()
818 snapshotObjOut := filepath.Join(snapshotArchDir, targetArch, "object",
819 ctx.ModuleName(m)+filepath.Ext(objPath.Base()))
820 ret = append(ret, copyFile(ctx, objPath, snapshotObjOut))
821 propOut = snapshotObjOut + ".json"
Inseob Kim7f283f42020-06-01 21:53:49 +0900822 } else {
823 ctx.Errorf("unknown module %q in vendor snapshot", m.String())
824 return nil
Inseob Kim8471cda2019-11-15 09:59:12 +0900825 }
826
827 j, err := json.Marshal(prop)
828 if err != nil {
829 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
830 return nil
831 }
832 ret = append(ret, writeStringToFile(ctx, string(j), propOut))
833
834 return ret
835 }
836
837 ctx.VisitAllModules(func(module android.Module) {
838 m, ok := module.(*Module)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900839 if !ok {
840 return
841 }
842
843 moduleDir := ctx.ModuleDir(module)
Bill Peckham945441c2020-08-31 16:07:58 -0700844 inVendorProprietaryPath := isVendorProprietaryPath(moduleDir)
Colin Cross56a83212020-09-15 18:30:11 -0700845 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
Bill Peckham945441c2020-08-31 16:07:58 -0700846
847 if m.ExcludeFromVendorSnapshot() {
848 if inVendorProprietaryPath {
849 // Error: exclude_from_vendor_snapshot applies
850 // to framework-path modules only.
851 ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir)
852 return
853 }
854 if Bool(m.VendorProperties.Vendor_available) {
855 // Error: may not combine "vendor_available:
856 // true" with "exclude_from_vendor_snapshot:
857 // true".
858 ctx.Errorf("module %q may not use both \"vendor_available: true\" and \"exclude_from_vendor_snapshot: true\"", m.String())
859 return
860 }
861 }
862
Colin Cross56a83212020-09-15 18:30:11 -0700863 if !isVendorSnapshotModule(m, inVendorProprietaryPath, apexInfo) {
Inseob Kim8471cda2019-11-15 09:59:12 +0900864 return
865 }
866
867 snapshotOutputs = append(snapshotOutputs, installSnapshot(m)...)
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900868 if l, ok := m.linker.(snapshotLibraryInterface); ok {
869 headers = append(headers, l.snapshotHeaders()...)
Inseob Kim8471cda2019-11-15 09:59:12 +0900870 }
871
Bob Badoura75b0572020-02-18 20:21:55 -0800872 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900873 noticeName := ctx.ModuleName(m) + ".txt"
874 noticeOut := filepath.Join(noticeDir, noticeName)
875 // skip already copied notice file
876 if !installedNotices[noticeOut] {
877 installedNotices[noticeOut] = true
Bob Badoura75b0572020-02-18 20:21:55 -0800878 snapshotOutputs = append(snapshotOutputs, combineNotices(
879 ctx, m.NoticeFiles(), noticeOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900880 }
881 }
882 })
883
884 // install all headers after removing duplicates
885 for _, header := range android.FirstUniquePaths(headers) {
886 snapshotOutputs = append(snapshotOutputs, copyFile(
887 ctx, header, filepath.Join(includeDir, header.String())))
888 }
889
890 // All artifacts are ready. Sort them to normalize ninja and then zip.
891 sort.Slice(snapshotOutputs, func(i, j int) bool {
892 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
893 })
894
895 zipPath := android.PathForOutput(ctx, snapshotDir, "vendor-"+ctx.Config().DeviceName()+".zip")
896 zipRule := android.NewRuleBuilder()
897
898 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
899 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "vendor-"+ctx.Config().DeviceName()+"_list")
900 zipRule.Command().
901 Text("tr").
902 FlagWithArg("-d ", "\\'").
903 FlagWithRspFileInputList("< ", snapshotOutputs).
904 FlagWithOutput("> ", snapshotOutputList)
905
906 zipRule.Temporary(snapshotOutputList)
907
908 zipRule.Command().
909 BuiltTool(ctx, "soong_zip").
910 FlagWithOutput("-o ", zipPath).
911 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
912 FlagWithInput("-l ", snapshotOutputList)
913
914 zipRule.Build(pctx, ctx, zipPath.String(), "vendor snapshot "+zipPath.String())
915 zipRule.DeleteTemporaryFiles()
916 c.vendorSnapshotZipFile = android.OptionalPathForPath(zipPath)
917}
918
919func (c *vendorSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
920 ctx.Strict("SOONG_VENDOR_SNAPSHOT_ZIP", c.vendorSnapshotZipFile.String())
921}
Inseob Kimeec88e12020-01-22 11:11:29 +0900922
923type snapshotInterface interface {
924 matchesWithDevice(config android.DeviceConfig) bool
925}
926
927var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
928var _ snapshotInterface = (*vendorSnapshotLibraryDecorator)(nil)
929var _ snapshotInterface = (*vendorSnapshotBinaryDecorator)(nil)
Inseob Kim1042d292020-06-01 23:23:05 +0900930var _ snapshotInterface = (*vendorSnapshotObjectLinker)(nil)
Inseob Kimeec88e12020-01-22 11:11:29 +0900931
932// gathers all snapshot modules for vendor, and disable unnecessary snapshots
933// TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules
934func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) {
935 vndkVersion := ctx.DeviceConfig().VndkVersion()
936 // don't need snapshot if current
937 if vndkVersion == "current" || vndkVersion == "" {
938 return
939 }
940
941 module, ok := ctx.Module().(*Module)
942 if !ok || !module.Enabled() || module.VndkVersion() != vndkVersion {
943 return
944 }
945
Inseob Kim1042d292020-06-01 23:23:05 +0900946 if !module.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +0900947 return
948 }
949
Inseob Kim1042d292020-06-01 23:23:05 +0900950 // isSnapshotPrebuilt ensures snapshotInterface
951 if !module.linker.(snapshotInterface).matchesWithDevice(ctx.DeviceConfig()) {
Inseob Kimeec88e12020-01-22 11:11:29 +0900952 // Disable unnecessary snapshot module, but do not disable
953 // vndk_prebuilt_shared because they might be packed into vndk APEX
954 if !module.IsVndk() {
955 module.Disable()
956 }
957 return
958 }
959
960 var snapshotMap *snapshotMap
961
962 if lib, ok := module.linker.(libraryInterface); ok {
963 if lib.static() {
964 snapshotMap = vendorSnapshotStaticLibs(ctx.Config())
965 } else if lib.shared() {
966 snapshotMap = vendorSnapshotSharedLibs(ctx.Config())
967 } else {
968 // header
969 snapshotMap = vendorSnapshotHeaderLibs(ctx.Config())
970 }
971 } else if _, ok := module.linker.(*vendorSnapshotBinaryDecorator); ok {
972 snapshotMap = vendorSnapshotBinaries(ctx.Config())
Inseob Kim1042d292020-06-01 23:23:05 +0900973 } else if _, ok := module.linker.(*vendorSnapshotObjectLinker); ok {
974 snapshotMap = vendorSnapshotObjects(ctx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +0900975 } else {
976 return
977 }
978
979 vendorSnapshotsLock.Lock()
980 defer vendorSnapshotsLock.Unlock()
981 snapshotMap.add(module.BaseModuleName(), ctx.Arch().ArchType, ctx.ModuleName())
982}
983
984// Disables source modules which have snapshots
985func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) {
Inseob Kim5f64aec2020-02-18 17:27:19 +0900986 if !ctx.Device() {
987 return
988 }
989
Inseob Kimeec88e12020-01-22 11:11:29 +0900990 vndkVersion := ctx.DeviceConfig().VndkVersion()
991 // don't need snapshot if current
992 if vndkVersion == "current" || vndkVersion == "" {
993 return
994 }
995
996 module, ok := ctx.Module().(*Module)
997 if !ok {
998 return
999 }
1000
Inseob Kim5f64aec2020-02-18 17:27:19 +09001001 // vendor suffix should be added to snapshots if the source module isn't vendor: true.
1002 if !module.SocSpecific() {
1003 // But we can't just check SocSpecific() since we already passed the image mutator.
1004 // Check ramdisk and recovery to see if we are real "vendor: true" module.
1005 ramdisk_available := module.InRamdisk() && !module.OnlyInRamdisk()
1006 recovery_available := module.InRecovery() && !module.OnlyInRecovery()
Inseob Kimeec88e12020-01-22 11:11:29 +09001007
Inseob Kim5f64aec2020-02-18 17:27:19 +09001008 if !ramdisk_available && !recovery_available {
1009 vendorSnapshotsLock.Lock()
1010 defer vendorSnapshotsLock.Unlock()
1011
1012 vendorSuffixModules(ctx.Config())[ctx.ModuleName()] = true
1013 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001014 }
1015
1016 if module.isSnapshotPrebuilt() || module.VndkVersion() != ctx.DeviceConfig().VndkVersion() {
1017 // only non-snapshot modules with BOARD_VNDK_VERSION
1018 return
1019 }
1020
Inseob Kim206665c2020-06-02 23:48:32 +09001021 // .. and also filter out llndk library
1022 if module.isLlndk(ctx.Config()) {
1023 return
1024 }
1025
Inseob Kimeec88e12020-01-22 11:11:29 +09001026 var snapshotMap *snapshotMap
1027
1028 if lib, ok := module.linker.(libraryInterface); ok {
1029 if lib.static() {
1030 snapshotMap = vendorSnapshotStaticLibs(ctx.Config())
1031 } else if lib.shared() {
1032 snapshotMap = vendorSnapshotSharedLibs(ctx.Config())
1033 } else {
1034 // header
1035 snapshotMap = vendorSnapshotHeaderLibs(ctx.Config())
1036 }
Inseob Kim7f283f42020-06-01 21:53:49 +09001037 } else if module.binary() {
Inseob Kimeec88e12020-01-22 11:11:29 +09001038 snapshotMap = vendorSnapshotBinaries(ctx.Config())
Inseob Kim1042d292020-06-01 23:23:05 +09001039 } else if module.object() {
1040 snapshotMap = vendorSnapshotObjects(ctx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001041 } else {
1042 return
1043 }
1044
1045 if _, ok := snapshotMap.get(ctx.ModuleName(), ctx.Arch().ArchType); !ok {
1046 // Corresponding snapshot doesn't exist
1047 return
1048 }
1049
1050 // Disables source modules if corresponding snapshot exists.
1051 if lib, ok := module.linker.(libraryInterface); ok && lib.buildStatic() && lib.buildShared() {
1052 // But do not disable because the shared variant depends on the static variant.
1053 module.SkipInstall()
1054 module.Properties.HideFromMake = true
1055 } else {
1056 module.Disable()
1057 }
1058}