blob: 2c1856e8818bf048c888e5c7e5fc7d10073f39f9 [file] [log] [blame]
Justin Yun8effde42017-06-23 19:24:43 +09001// Copyright 2017 Google Inc. All rights reserved.
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
15package cc
16
17import (
Inseob Kimae553032019-05-14 18:52:49 +090018 "encoding/json"
Martin Stjernholm257eb0c2018-10-15 13:05:27 +010019 "errors"
Inseob Kim1f086e22019-05-09 13:29:15 +090020 "path/filepath"
Colin Cross766efbc2017-08-17 14:55:15 -070021 "sort"
Jiyong Parkd5b18a52017-08-03 21:22:50 +090022 "strings"
23 "sync"
24
Justin Yun8effde42017-06-23 19:24:43 +090025 "android/soong/android"
Vic Yangefd249e2018-11-12 20:19:56 -080026 "android/soong/cc/config"
Justin Yun8effde42017-06-23 19:24:43 +090027)
28
29type VndkProperties struct {
30 Vndk struct {
31 // declared as a VNDK or VNDK-SP module. The vendor variant
32 // will be installed in /system instead of /vendor partition.
33 //
Roland Levillaindfe75b32019-07-23 16:53:32 +010034 // `vendor_available` must be explicitly set to either true or
Jiyong Park82e2bf32017-08-16 14:05:54 +090035 // false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090036 Enabled *bool
37
38 // declared as a VNDK-SP module, which is a subset of VNDK.
39 //
40 // `vndk: { enabled: true }` must set together.
41 //
42 // All these modules are allowed to link to VNDK-SP or LL-NDK
43 // modules only. Other dependency will cause link-type errors.
44 //
45 // If `support_system_process` is not set or set to false,
46 // the module is VNDK-core and can link to other VNDK-core,
47 // VNDK-SP or LL-NDK modules only.
48 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080049
50 // Extending another module
51 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090052 }
53}
54
55type vndkdep struct {
56 Properties VndkProperties
57}
58
59func (vndk *vndkdep) props() []interface{} {
60 return []interface{}{&vndk.Properties}
61}
62
63func (vndk *vndkdep) begin(ctx BaseModuleContext) {}
64
65func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps {
66 return deps
67}
68
69func (vndk *vndkdep) isVndk() bool {
70 return Bool(vndk.Properties.Vndk.Enabled)
71}
72
73func (vndk *vndkdep) isVndkSp() bool {
74 return Bool(vndk.Properties.Vndk.Support_system_process)
75}
76
Logan Chienf3511742017-10-31 18:04:35 +080077func (vndk *vndkdep) isVndkExt() bool {
78 return vndk.Properties.Vndk.Extends != nil
79}
80
81func (vndk *vndkdep) getVndkExtendsModuleName() string {
82 return String(vndk.Properties.Vndk.Extends)
83}
84
Justin Yun8effde42017-06-23 19:24:43 +090085func (vndk *vndkdep) typeName() string {
86 if !vndk.isVndk() {
87 return "native:vendor"
88 }
Logan Chienf3511742017-10-31 18:04:35 +080089 if !vndk.isVndkExt() {
90 if !vndk.isVndkSp() {
91 return "native:vendor:vndk"
92 }
93 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +090094 }
Logan Chienf3511742017-10-31 18:04:35 +080095 if !vndk.isVndkSp() {
96 return "native:vendor:vndkext"
97 }
98 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +090099}
100
Logan Chienf3511742017-10-31 18:04:35 +0800101func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag dependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900102 if to.linker == nil {
103 return
104 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900105 if !vndk.isVndk() {
106 // Non-VNDK modules (those installed to /vendor) can't depend on modules marked with
107 // vendor_available: false.
108 violation := false
Nan Zhang0007d812017-11-07 10:57:05 -0800109 if lib, ok := to.linker.(*llndkStubDecorator); ok && !Bool(lib.Properties.Vendor_available) {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900110 violation = true
111 } else {
112 if _, ok := to.linker.(libraryInterface); ok && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) {
113 // Vendor_available == nil && !Bool(Vendor_available) should be okay since
114 // it means a vendor-only library which is a valid dependency for non-VNDK
115 // modules.
116 violation = true
117 }
118 }
119 if violation {
120 ctx.ModuleErrorf("Vendor module that is not VNDK should not link to %q which is marked as `vendor_available: false`", to.Name())
121 }
122 }
Justin Yun8effde42017-06-23 19:24:43 +0900123 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
124 // Check only shared libraries.
125 // Other (static and LL-NDK) libraries are allowed to link.
126 return
127 }
Inseob Kim64c43952019-08-26 16:52:35 +0900128 if !to.useVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900129 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
130 vndk.typeName(), to.Name())
131 return
132 }
Logan Chienf3511742017-10-31 18:04:35 +0800133 if tag == vndkExtDepTag {
134 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
135 // and has identical vndk properties.
136 if to.vndkdep == nil || !to.vndkdep.isVndk() {
137 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
138 return
139 }
140 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
141 ctx.ModuleErrorf(
142 "`extends` refers a module %q with mismatched support_system_process",
143 to.Name())
144 return
145 }
146 if !Bool(to.VendorProperties.Vendor_available) {
147 ctx.ModuleErrorf(
148 "`extends` refers module %q which does not have `vendor_available: true`",
149 to.Name())
150 return
151 }
152 }
Justin Yun8effde42017-06-23 19:24:43 +0900153 if to.vndkdep == nil {
154 return
155 }
Logan Chienf3511742017-10-31 18:04:35 +0800156
Logan Chiend3c59a22018-03-29 14:08:15 +0800157 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100158 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
159 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
160 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800161 return
162 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800163}
Logan Chienf3511742017-10-31 18:04:35 +0800164
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100165func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800166 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
167 if from.isVndkExt() {
168 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100169 if to.isVndk() && !to.isVndkSp() {
170 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
171 }
172 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800173 }
174 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100175 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900176 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800177 if from.isVndk() {
178 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100179 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800180 }
181 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100182 if !to.isVndkSp() {
183 return errors.New("VNDK-SP must only depend on VNDK-SP")
184 }
185 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800186 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100187 if !to.isVndk() {
188 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
189 }
190 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800191 }
192 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100193 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900194}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900195
196var (
Inseob Kim9516ee92019-05-09 10:56:13 +0900197 vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires")
198 vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires")
199 llndkLibrariesKey = android.NewOnceKey("llndkLibrarires")
200 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires")
201 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibrarires")
Inseob Kim1f086e22019-05-09 13:29:15 +0900202 modulePathsKey = android.NewOnceKey("modulePaths")
203 vndkSnapshotOutputsKey = android.NewOnceKey("vndkSnapshotOutputs")
Inseob Kim9516ee92019-05-09 10:56:13 +0900204 vndkLibrariesLock sync.Mutex
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900205
Inseob Kimae553032019-05-14 18:52:49 +0900206 headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
207)
Inseob Kim1f086e22019-05-09 13:29:15 +0900208
Inseob Kim9516ee92019-05-09 10:56:13 +0900209func vndkCoreLibraries(config android.Config) *[]string {
210 return config.Once(vndkCoreLibrariesKey, func() interface{} {
211 return &[]string{}
212 }).(*[]string)
213}
214
215func vndkSpLibraries(config android.Config) *[]string {
216 return config.Once(vndkSpLibrariesKey, func() interface{} {
217 return &[]string{}
218 }).(*[]string)
219}
220
221func llndkLibraries(config android.Config) *[]string {
222 return config.Once(llndkLibrariesKey, func() interface{} {
223 return &[]string{}
224 }).(*[]string)
225}
226
227func vndkPrivateLibraries(config android.Config) *[]string {
228 return config.Once(vndkPrivateLibrariesKey, func() interface{} {
229 return &[]string{}
230 }).(*[]string)
231}
232
233func vndkUsingCoreVariantLibraries(config android.Config) *[]string {
234 return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} {
235 return &[]string{}
236 }).(*[]string)
237}
238
Inseob Kim1f086e22019-05-09 13:29:15 +0900239func modulePaths(config android.Config) map[string]string {
240 return config.Once(modulePathsKey, func() interface{} {
241 return make(map[string]string)
242 }).(map[string]string)
243}
Inseob Kim9516ee92019-05-09 10:56:13 +0900244
Inseob Kimae553032019-05-14 18:52:49 +0900245func vndkSnapshotOutputs(config android.Config) *android.RuleBuilderInstalls {
Inseob Kim1f086e22019-05-09 13:29:15 +0900246 return config.Once(vndkSnapshotOutputsKey, func() interface{} {
Inseob Kimae553032019-05-14 18:52:49 +0900247 return &android.RuleBuilderInstalls{}
248 }).(*android.RuleBuilderInstalls)
Inseob Kim1f086e22019-05-09 13:29:15 +0900249}
Inseob Kim9516ee92019-05-09 10:56:13 +0900250
Inseob Kim1f086e22019-05-09 13:29:15 +0900251func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
252 lib := m.linker.(*llndkStubDecorator)
253 name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +0900254
Inseob Kim1f086e22019-05-09 13:29:15 +0900255 vndkLibrariesLock.Lock()
256 defer vndkLibrariesLock.Unlock()
Inseob Kim9516ee92019-05-09 10:56:13 +0900257
Inseob Kim1f086e22019-05-09 13:29:15 +0900258 llndkLibraries := llndkLibraries(mctx.Config())
259 if !inList(name, *llndkLibraries) {
260 *llndkLibraries = append(*llndkLibraries, name)
261 sort.Strings(*llndkLibraries)
262 }
263 if !Bool(lib.Properties.Vendor_available) {
264 vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config())
265 if !inList(name, *vndkPrivateLibraries) {
266 *vndkPrivateLibraries = append(*vndkPrivateLibraries, name)
267 sort.Strings(*vndkPrivateLibraries)
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900268 }
269 }
270}
Inseob Kim1f086e22019-05-09 13:29:15 +0900271
272func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
273 name := strings.TrimPrefix(m.Name(), "prebuilt_")
274
275 vndkLibrariesLock.Lock()
276 defer vndkLibrariesLock.Unlock()
277
278 modulePaths := modulePaths(mctx.Config())
279 if mctx.DeviceConfig().VndkUseCoreVariant() && !inList(name, config.VndkMustUseVendorVariantList) {
280 vndkUsingCoreVariantLibraries := vndkUsingCoreVariantLibraries(mctx.Config())
281 if !inList(name, *vndkUsingCoreVariantLibraries) {
282 *vndkUsingCoreVariantLibraries = append(*vndkUsingCoreVariantLibraries, name)
283 sort.Strings(*vndkUsingCoreVariantLibraries)
284 }
285 }
286 if m.vndkdep.isVndkSp() {
287 vndkSpLibraries := vndkSpLibraries(mctx.Config())
288 if !inList(name, *vndkSpLibraries) {
289 *vndkSpLibraries = append(*vndkSpLibraries, name)
290 sort.Strings(*vndkSpLibraries)
291 modulePaths[name] = mctx.ModuleDir()
292 }
293 } else {
294 vndkCoreLibraries := vndkCoreLibraries(mctx.Config())
295 if !inList(name, *vndkCoreLibraries) {
296 *vndkCoreLibraries = append(*vndkCoreLibraries, name)
297 sort.Strings(*vndkCoreLibraries)
298 modulePaths[name] = mctx.ModuleDir()
299 }
300 }
301 if !Bool(m.VendorProperties.Vendor_available) {
302 vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config())
303 if !inList(name, *vndkPrivateLibraries) {
304 *vndkPrivateLibraries = append(*vndkPrivateLibraries, name)
305 sort.Strings(*vndkPrivateLibraries)
306 }
307 }
308}
309
Jooyung Han31c470b2019-10-18 16:26:59 +0900310func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
311 if !m.Enabled() {
312 return false
313 }
314
315 if m.Target().NativeBridge == android.NativeBridgeEnabled {
316 return false
317 }
318
319 // prebuilt vndk modules should match with device
320 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
321 // When b/142675459 is landed, remove following check
322 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) {
323 return false
324 }
325
326 if lib, ok := m.linker.(libraryInterface); ok {
327 useCoreVariant := m.vndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
328 mctx.DeviceConfig().VndkUseCoreVariant() &&
329 !inList(m.BaseModuleName(), config.VndkMustUseVendorVariantList)
330 return lib.shared() && m.useVndk() && m.isVndk() && !m.isVndkExt() && !useCoreVariant
331 }
332 return false
333}
334
Inseob Kim1f086e22019-05-09 13:29:15 +0900335// gather list of vndk-core, vndk-sp, and ll-ndk libs
336func VndkMutator(mctx android.BottomUpMutatorContext) {
337 m, ok := mctx.Module().(*Module)
338 if !ok {
339 return
340 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900341 if !m.Enabled() {
342 return
343 }
Justin Yun7390ea32019-09-08 11:34:06 +0900344 if m.Target().NativeBridge == android.NativeBridgeEnabled {
345 // Skip native_bridge modules
346 return
347 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900348
349 if _, ok := m.linker.(*llndkStubDecorator); ok {
350 processLlndkLibrary(mctx, m)
351 return
352 }
353
354 lib, is_lib := m.linker.(*libraryDecorator)
355 prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker)
356
Inseob Kim64c43952019-08-26 16:52:35 +0900357 if (is_lib && lib.buildShared()) || (is_prebuilt_lib && prebuilt_lib.buildShared()) {
358 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900359 processVndkLibrary(mctx, m)
360 return
361 }
362 }
363}
364
365func init() {
366 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
367 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
368 outputs := vndkSnapshotOutputs(ctx.Config())
Inseob Kimae553032019-05-14 18:52:49 +0900369 ctx.Strict("SOONG_VNDK_SNAPSHOT_FILES", outputs.String())
Inseob Kim1f086e22019-05-09 13:29:15 +0900370 })
371}
372
373func VndkSnapshotSingleton() android.Singleton {
374 return &vndkSnapshotSingleton{}
375}
376
377type vndkSnapshotSingleton struct{}
378
Inseob Kim1f086e22019-05-09 13:29:15 +0900379func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
380 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
381 if ctx.DeviceConfig().VndkVersion() != "current" {
382 return
383 }
384
385 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
386 return
387 }
388
389 if ctx.DeviceConfig().BoardVndkRuntimeDisable() {
390 return
391 }
392
393 outputs := vndkSnapshotOutputs(ctx.Config())
394
395 snapshotDir := "vndk-snapshot"
396
Inseob Kimae553032019-05-14 18:52:49 +0900397 vndkLibDir := make(map[android.ArchType]string)
Inseob Kim1f086e22019-05-09 13:29:15 +0900398
Inseob Kimae553032019-05-14 18:52:49 +0900399 snapshotVariantDir := ctx.DeviceConfig().DeviceArch()
400 for _, target := range ctx.Config().Targets[android.Android] {
401 dir := snapshotVariantDir
402 if ctx.DeviceConfig().BinderBitness() == "32" {
403 dir = filepath.Join(dir, "binder32")
404 }
405 arch := "arch-" + target.Arch.ArchType.String()
406 if target.Arch.ArchVariant != "" {
407 arch += "-" + target.Arch.ArchVariant
408 }
409 dir = filepath.Join(dir, arch)
410 vndkLibDir[target.Arch.ArchType] = dir
Inseob Kim1f086e22019-05-09 13:29:15 +0900411 }
Inseob Kimae553032019-05-14 18:52:49 +0900412 configsDir := filepath.Join(snapshotVariantDir, "configs")
413 noticeDir := filepath.Join(snapshotVariantDir, "NOTICE_FILES")
414 includeDir := filepath.Join(snapshotVariantDir, "include")
Inseob Kim1f086e22019-05-09 13:29:15 +0900415 noticeBuilt := make(map[string]bool)
416
Inseob Kimae553032019-05-14 18:52:49 +0900417 installSnapshotFileFromPath := func(path android.Path, out string) {
418 ctx.Build(pctx, android.BuildParams{
419 Rule: android.Cp,
420 Input: path,
421 Output: android.PathForOutput(ctx, snapshotDir, out),
422 Description: "vndk snapshot " + out,
423 Args: map[string]string{
424 "cpFlags": "-f -L",
425 },
426 })
427 *outputs = append(*outputs, android.RuleBuilderInstall{
428 From: android.PathForOutput(ctx, snapshotDir, out),
429 To: out,
430 })
431 }
432 installSnapshotFileFromContent := func(content, out string) {
433 ctx.Build(pctx, android.BuildParams{
434 Rule: android.WriteFile,
435 Output: android.PathForOutput(ctx, snapshotDir, out),
436 Description: "vndk snapshot " + out,
437 Args: map[string]string{
438 "content": content,
439 },
440 })
441 *outputs = append(*outputs, android.RuleBuilderInstall{
442 From: android.PathForOutput(ctx, snapshotDir, out),
443 To: out,
444 })
445 }
446
Inseob Kim1f086e22019-05-09 13:29:15 +0900447 tryBuildNotice := func(m *Module) {
Inseob Kimae553032019-05-14 18:52:49 +0900448 name := ctx.ModuleName(m) + ".so.txt"
Inseob Kim1f086e22019-05-09 13:29:15 +0900449
450 if _, ok := noticeBuilt[name]; ok {
451 return
452 }
453
454 noticeBuilt[name] = true
455
456 if m.NoticeFile().Valid() {
Inseob Kimae553032019-05-14 18:52:49 +0900457 installSnapshotFileFromPath(m.NoticeFile().Path(), filepath.Join(noticeDir, name))
Inseob Kim1f086e22019-05-09 13:29:15 +0900458 }
459 }
460
461 vndkCoreLibraries := vndkCoreLibraries(ctx.Config())
462 vndkSpLibraries := vndkSpLibraries(ctx.Config())
463 vndkPrivateLibraries := vndkPrivateLibraries(ctx.Config())
464
Inseob Kimae553032019-05-14 18:52:49 +0900465 var generatedHeaders android.Paths
466 includeDirs := make(map[string]bool)
467
468 type vndkSnapshotLibraryInterface interface {
469 exportedFlagsProducer
470 libraryInterface
471 }
472
473 var _ vndkSnapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
474 var _ vndkSnapshotLibraryInterface = (*libraryDecorator)(nil)
475
476 installVndkSnapshotLib := func(m *Module, l vndkSnapshotLibraryInterface, dir string) bool {
477 name := ctx.ModuleName(m)
478 libOut := filepath.Join(dir, name+".so")
479
480 installSnapshotFileFromPath(m.outputFile.Path(), libOut)
481 tryBuildNotice(m)
482
483 if ctx.Config().VndkSnapshotBuildArtifacts() {
484 prop := struct {
485 ExportedDirs []string `json:",omitempty"`
486 ExportedSystemDirs []string `json:",omitempty"`
487 ExportedFlags []string `json:",omitempty"`
488 RelativeInstallPath string `json:",omitempty"`
489 }{}
490 prop.ExportedFlags = l.exportedFlags()
491 prop.ExportedDirs = l.exportedDirs()
492 prop.ExportedSystemDirs = l.exportedSystemDirs()
493 prop.RelativeInstallPath = m.RelativeInstallPath()
494
495 propOut := libOut + ".json"
496
497 j, err := json.Marshal(prop)
498 if err != nil {
499 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
500 return false
501 }
502
503 installSnapshotFileFromContent(string(j), propOut)
504 }
505 return true
506 }
507
508 isVndkSnapshotLibrary := func(m *Module) (i vndkSnapshotLibraryInterface, libDir string, isVndkSnapshotLib bool) {
509 if m.Target().NativeBridge == android.NativeBridgeEnabled {
510 return nil, "", false
511 }
512 if !m.useVndk() || !m.IsForPlatform() || !m.installable() {
513 return nil, "", false
514 }
515 l, ok := m.linker.(vndkSnapshotLibraryInterface)
516 if !ok || !l.shared() {
517 return nil, "", false
518 }
519 name := ctx.ModuleName(m)
520 if inList(name, *vndkCoreLibraries) {
521 return l, filepath.Join("shared", "vndk-core"), true
522 } else if inList(name, *vndkSpLibraries) {
523 return l, filepath.Join("shared", "vndk-sp"), true
524 } else {
525 return nil, "", false
526 }
527 }
528
Inseob Kim1f086e22019-05-09 13:29:15 +0900529 ctx.VisitAllModules(func(module android.Module) {
530 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900531 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900532 return
533 }
534
Inseob Kimae553032019-05-14 18:52:49 +0900535 baseDir, ok := vndkLibDir[m.Target().Arch.ArchType]
536 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200537 return
538 }
539
Inseob Kimae553032019-05-14 18:52:49 +0900540 l, libDir, ok := isVndkSnapshotLibrary(m)
541 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900542 return
543 }
544
Inseob Kimae553032019-05-14 18:52:49 +0900545 if !installVndkSnapshotLib(m, l, filepath.Join(baseDir, libDir)) {
546 return
547 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900548
Inseob Kimae553032019-05-14 18:52:49 +0900549 generatedHeaders = append(generatedHeaders, l.exportedDeps()...)
550 for _, dir := range append(l.exportedDirs(), l.exportedSystemDirs()...) {
551 includeDirs[dir] = true
552 }
553 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900554
Inseob Kimae553032019-05-14 18:52:49 +0900555 if ctx.Config().VndkSnapshotBuildArtifacts() {
556 headers := make(map[string]bool)
557
558 for _, dir := range android.SortedStringKeys(includeDirs) {
559 // workaround to determine if dir is under output directory
560 if strings.HasPrefix(dir, android.PathForOutput(ctx).String()) {
561 continue
Inseob Kim1f086e22019-05-09 13:29:15 +0900562 }
Inseob Kimae553032019-05-14 18:52:49 +0900563 exts := headerExts
564 // Glob all files under this special directory, because of C++ headers.
565 if strings.HasPrefix(dir, "external/libcxx/include") {
566 exts = []string{""}
Inseob Kim1f086e22019-05-09 13:29:15 +0900567 }
Inseob Kimae553032019-05-14 18:52:49 +0900568 for _, ext := range exts {
569 glob, err := ctx.GlobWithDeps(dir+"/**/*"+ext, nil)
570 if err != nil {
571 ctx.Errorf("%#v\n", err)
572 return
573 }
574 for _, header := range glob {
575 if strings.HasSuffix(header, "/") {
576 continue
577 }
578 headers[header] = true
579 }
580 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900581 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900582
Inseob Kimae553032019-05-14 18:52:49 +0900583 for _, header := range android.SortedStringKeys(headers) {
584 installSnapshotFileFromPath(android.PathForSource(ctx, header),
585 filepath.Join(includeDir, header))
586 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900587
Inseob Kimae553032019-05-14 18:52:49 +0900588 isHeader := func(path string) bool {
589 for _, ext := range headerExts {
590 if strings.HasSuffix(path, ext) {
591 return true
592 }
593 }
594 return false
595 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900596
Inseob Kimae553032019-05-14 18:52:49 +0900597 for _, path := range android.PathsToDirectorySortedPaths(android.FirstUniquePaths(generatedHeaders)) {
598 header := path.String()
599
600 if !isHeader(header) {
601 continue
602 }
603
604 installSnapshotFileFromPath(path, filepath.Join(includeDir, header))
605 }
606 }
607
608 installSnapshotFileFromContent(android.JoinWithSuffix(*vndkCoreLibraries, ".so", "\\n"),
609 filepath.Join(configsDir, "vndkcore.libraries.txt"))
610 installSnapshotFileFromContent(android.JoinWithSuffix(*vndkPrivateLibraries, ".so", "\\n"),
611 filepath.Join(configsDir, "vndkprivate.libraries.txt"))
Inseob Kim1f086e22019-05-09 13:29:15 +0900612
613 var modulePathTxtBuilder strings.Builder
614
Colin Cross4c2c46f2019-06-03 15:26:05 -0700615 modulePaths := modulePaths(ctx.Config())
Colin Cross4c2c46f2019-06-03 15:26:05 -0700616
Inseob Kim1f086e22019-05-09 13:29:15 +0900617 first := true
Inseob Kimae553032019-05-14 18:52:49 +0900618 for _, lib := range android.SortedStringKeys(modulePaths) {
Inseob Kim1f086e22019-05-09 13:29:15 +0900619 if first {
620 first = false
621 } else {
622 modulePathTxtBuilder.WriteString("\\n")
623 }
624 modulePathTxtBuilder.WriteString(lib)
625 modulePathTxtBuilder.WriteString(".so ")
Colin Cross4c2c46f2019-06-03 15:26:05 -0700626 modulePathTxtBuilder.WriteString(modulePaths[lib])
Inseob Kim1f086e22019-05-09 13:29:15 +0900627 }
628
Inseob Kimae553032019-05-14 18:52:49 +0900629 installSnapshotFileFromContent(modulePathTxtBuilder.String(),
630 filepath.Join(configsDir, "module_paths.txt"))
Inseob Kim1f086e22019-05-09 13:29:15 +0900631}