blob: 872a473a631d80fec4d5b698fdd2c2174ee150a6 [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"
Jooyung Han0302a842019-10-30 18:43:49 +090020 "fmt"
Inseob Kim1f086e22019-05-09 13:29:15 +090021 "path/filepath"
Inseob Kim242ef0c2019-10-22 20:15:20 +090022 "sort"
Jiyong Parkd5b18a52017-08-03 21:22:50 +090023 "strings"
24 "sync"
25
Justin Yun8effde42017-06-23 19:24:43 +090026 "android/soong/android"
Vic Yangefd249e2018-11-12 20:19:56 -080027 "android/soong/cc/config"
Justin Yun8effde42017-06-23 19:24:43 +090028)
29
Jooyung Han39edb6c2019-11-06 16:53:07 +090030const (
31 llndkLibrariesTxt = "llndk.libraries.txt"
32 vndkCoreLibrariesTxt = "vndkcore.libraries.txt"
33 vndkSpLibrariesTxt = "vndksp.libraries.txt"
34 vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt"
35 vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt"
36)
37
38func VndkLibrariesTxtModules(vndkVersion string) []string {
39 if vndkVersion == "current" {
40 return []string{
41 llndkLibrariesTxt,
42 vndkCoreLibrariesTxt,
43 vndkSpLibrariesTxt,
44 vndkPrivateLibrariesTxt,
Jooyung Han39edb6c2019-11-06 16:53:07 +090045 }
46 }
47 // Snapshot vndks have their own *.libraries.VER.txt files.
48 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
49 return []string{
50 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
51 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
52 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
53 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
54 }
55}
56
Justin Yun8effde42017-06-23 19:24:43 +090057type VndkProperties struct {
58 Vndk struct {
59 // declared as a VNDK or VNDK-SP module. The vendor variant
60 // will be installed in /system instead of /vendor partition.
61 //
Roland Levillaindfe75b32019-07-23 16:53:32 +010062 // `vendor_available` must be explicitly set to either true or
Jiyong Park82e2bf32017-08-16 14:05:54 +090063 // false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090064 Enabled *bool
65
66 // declared as a VNDK-SP module, which is a subset of VNDK.
67 //
68 // `vndk: { enabled: true }` must set together.
69 //
70 // All these modules are allowed to link to VNDK-SP or LL-NDK
71 // modules only. Other dependency will cause link-type errors.
72 //
73 // If `support_system_process` is not set or set to false,
74 // the module is VNDK-core and can link to other VNDK-core,
75 // VNDK-SP or LL-NDK modules only.
76 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080077
78 // Extending another module
79 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090080 }
81}
82
83type vndkdep struct {
84 Properties VndkProperties
85}
86
87func (vndk *vndkdep) props() []interface{} {
88 return []interface{}{&vndk.Properties}
89}
90
91func (vndk *vndkdep) begin(ctx BaseModuleContext) {}
92
93func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps {
94 return deps
95}
96
97func (vndk *vndkdep) isVndk() bool {
98 return Bool(vndk.Properties.Vndk.Enabled)
99}
100
101func (vndk *vndkdep) isVndkSp() bool {
102 return Bool(vndk.Properties.Vndk.Support_system_process)
103}
104
Logan Chienf3511742017-10-31 18:04:35 +0800105func (vndk *vndkdep) isVndkExt() bool {
106 return vndk.Properties.Vndk.Extends != nil
107}
108
109func (vndk *vndkdep) getVndkExtendsModuleName() string {
110 return String(vndk.Properties.Vndk.Extends)
111}
112
Justin Yun8effde42017-06-23 19:24:43 +0900113func (vndk *vndkdep) typeName() string {
114 if !vndk.isVndk() {
115 return "native:vendor"
116 }
Logan Chienf3511742017-10-31 18:04:35 +0800117 if !vndk.isVndkExt() {
118 if !vndk.isVndkSp() {
119 return "native:vendor:vndk"
120 }
121 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900122 }
Logan Chienf3511742017-10-31 18:04:35 +0800123 if !vndk.isVndkSp() {
124 return "native:vendor:vndkext"
125 }
126 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900127}
128
Ivan Lozano183a3212019-10-18 14:18:45 -0700129func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900130 if to.linker == nil {
131 return
132 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900133 if !vndk.isVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900134 // Non-VNDK modules (those installed to /vendor, /product, or /system/product) can't depend
135 // on modules marked with vendor_available: false.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900136 violation := false
Nan Zhang0007d812017-11-07 10:57:05 -0800137 if lib, ok := to.linker.(*llndkStubDecorator); ok && !Bool(lib.Properties.Vendor_available) {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900138 violation = true
139 } else {
140 if _, ok := to.linker.(libraryInterface); ok && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) {
141 // Vendor_available == nil && !Bool(Vendor_available) should be okay since
Justin Yun5f7f7e82019-11-18 19:52:14 +0900142 // it means a vendor-only, or product-only library which is a valid dependency
143 // for non-VNDK modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900144 violation = true
145 }
146 }
147 if violation {
148 ctx.ModuleErrorf("Vendor module that is not VNDK should not link to %q which is marked as `vendor_available: false`", to.Name())
149 }
150 }
Justin Yun8effde42017-06-23 19:24:43 +0900151 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
152 // Check only shared libraries.
153 // Other (static and LL-NDK) libraries are allowed to link.
154 return
155 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700156 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900157 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
158 vndk.typeName(), to.Name())
159 return
160 }
Logan Chienf3511742017-10-31 18:04:35 +0800161 if tag == vndkExtDepTag {
162 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
163 // and has identical vndk properties.
164 if to.vndkdep == nil || !to.vndkdep.isVndk() {
165 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
166 return
167 }
168 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
169 ctx.ModuleErrorf(
170 "`extends` refers a module %q with mismatched support_system_process",
171 to.Name())
172 return
173 }
174 if !Bool(to.VendorProperties.Vendor_available) {
175 ctx.ModuleErrorf(
176 "`extends` refers module %q which does not have `vendor_available: true`",
177 to.Name())
178 return
179 }
180 }
Justin Yun8effde42017-06-23 19:24:43 +0900181 if to.vndkdep == nil {
182 return
183 }
Logan Chienf3511742017-10-31 18:04:35 +0800184
Logan Chiend3c59a22018-03-29 14:08:15 +0800185 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100186 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
187 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
188 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800189 return
190 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800191}
Logan Chienf3511742017-10-31 18:04:35 +0800192
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100193func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800194 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
195 if from.isVndkExt() {
196 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100197 if to.isVndk() && !to.isVndkSp() {
198 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
199 }
200 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800201 }
202 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100203 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900204 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800205 if from.isVndk() {
206 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100207 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800208 }
209 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100210 if !to.isVndkSp() {
211 return errors.New("VNDK-SP must only depend on VNDK-SP")
212 }
213 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800214 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100215 if !to.isVndk() {
216 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
217 }
218 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800219 }
220 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100221 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900222}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900223
224var (
Jooyung Hana463f722019-11-01 08:45:59 +0900225 vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires")
226 vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires")
227 llndkLibrariesKey = android.NewOnceKey("llndkLibrarires")
228 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900229 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibraries")
Jooyung Hana463f722019-11-01 08:45:59 +0900230 vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
231 vndkLibrariesLock sync.Mutex
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900232
Inseob Kimae553032019-05-14 18:52:49 +0900233 headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
234)
Inseob Kim1f086e22019-05-09 13:29:15 +0900235
Jooyung Han0302a842019-10-30 18:43:49 +0900236func vndkCoreLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900237 return config.Once(vndkCoreLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900238 return make(map[string]string)
239 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900240}
241
Jooyung Han0302a842019-10-30 18:43:49 +0900242func vndkSpLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900243 return config.Once(vndkSpLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900244 return make(map[string]string)
245 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900246}
247
Jooyung Han0302a842019-10-30 18:43:49 +0900248func isLlndkLibrary(baseModuleName string, config android.Config) bool {
249 _, ok := llndkLibraries(config)[baseModuleName]
250 return ok
251}
252
253func llndkLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900254 return config.Once(llndkLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900255 return make(map[string]string)
256 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900257}
258
Jooyung Han0302a842019-10-30 18:43:49 +0900259func isVndkPrivateLibrary(baseModuleName string, config android.Config) bool {
260 _, ok := vndkPrivateLibraries(config)[baseModuleName]
261 return ok
262}
263
264func vndkPrivateLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900265 return config.Once(vndkPrivateLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900266 return make(map[string]string)
267 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900268}
269
Jooyung Han0302a842019-10-30 18:43:49 +0900270func vndkUsingCoreVariantLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900271 return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900272 return make(map[string]string)
273 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900274}
275
Jooyung Han097087b2019-10-22 19:32:18 +0900276func vndkMustUseVendorVariantList(cfg android.Config) []string {
277 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900278 return config.VndkMustUseVendorVariantList
279 }).([]string)
280}
281
282// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
283// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
284func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900285 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900286 return mustUseVendorVariantList
287 })
288}
289
Inseob Kim1f086e22019-05-09 13:29:15 +0900290func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
291 lib := m.linker.(*llndkStubDecorator)
Jooyung Han0302a842019-10-30 18:43:49 +0900292 name := m.BaseModuleName()
293 filename := m.BaseModuleName() + ".so"
Inseob Kim9516ee92019-05-09 10:56:13 +0900294
Inseob Kim1f086e22019-05-09 13:29:15 +0900295 vndkLibrariesLock.Lock()
296 defer vndkLibrariesLock.Unlock()
Inseob Kim9516ee92019-05-09 10:56:13 +0900297
Jooyung Han0302a842019-10-30 18:43:49 +0900298 llndkLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900299 if !Bool(lib.Properties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900300 vndkPrivateLibraries(mctx.Config())[name] = filename
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900301 }
302}
Inseob Kim1f086e22019-05-09 13:29:15 +0900303
304func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Jooyung Han0302a842019-10-30 18:43:49 +0900305 name := m.BaseModuleName()
306 filename, err := getVndkFileName(m)
307 if err != nil {
308 panic(err)
309 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900310
311 vndkLibrariesLock.Lock()
312 defer vndkLibrariesLock.Unlock()
313
Jooyung Han097087b2019-10-22 19:32:18 +0900314 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
315 m.Properties.MustUseVendorVariant = true
316 }
Jooyung Han0302a842019-10-30 18:43:49 +0900317 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
318 vndkUsingCoreVariantLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900319 }
Jooyung Han0302a842019-10-30 18:43:49 +0900320
Inseob Kim1f086e22019-05-09 13:29:15 +0900321 if m.vndkdep.isVndkSp() {
Jooyung Han0302a842019-10-30 18:43:49 +0900322 vndkSpLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900323 } else {
Jooyung Han0302a842019-10-30 18:43:49 +0900324 vndkCoreLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900325 }
326 if !Bool(m.VendorProperties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900327 vndkPrivateLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900328 }
329}
330
Jooyung Han31c470b2019-10-18 16:26:59 +0900331func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
332 if !m.Enabled() {
333 return false
334 }
335
Jooyung Han87a7f302019-10-29 05:18:21 +0900336 if !mctx.Device() {
337 return false
338 }
339
Jooyung Han31c470b2019-10-18 16:26:59 +0900340 if m.Target().NativeBridge == android.NativeBridgeEnabled {
341 return false
342 }
343
344 // prebuilt vndk modules should match with device
345 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
346 // When b/142675459 is landed, remove following check
347 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) {
348 return false
349 }
350
351 if lib, ok := m.linker.(libraryInterface); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900352 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900353 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Jooyung Han5df3b112020-01-23 05:10:16 +0000354 return lib.shared() && m.UseVndk() && m.IsVndk() && !m.isVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900355 }
356 return false
357}
358
Inseob Kim1f086e22019-05-09 13:29:15 +0900359// gather list of vndk-core, vndk-sp, and ll-ndk libs
360func VndkMutator(mctx android.BottomUpMutatorContext) {
361 m, ok := mctx.Module().(*Module)
362 if !ok {
363 return
364 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900365 if !m.Enabled() {
366 return
367 }
Justin Yun7390ea32019-09-08 11:34:06 +0900368 if m.Target().NativeBridge == android.NativeBridgeEnabled {
369 // Skip native_bridge modules
370 return
371 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900372
373 if _, ok := m.linker.(*llndkStubDecorator); ok {
374 processLlndkLibrary(mctx, m)
375 return
376 }
377
378 lib, is_lib := m.linker.(*libraryDecorator)
379 prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker)
380
Inseob Kim64c43952019-08-26 16:52:35 +0900381 if (is_lib && lib.buildShared()) || (is_prebuilt_lib && prebuilt_lib.buildShared()) {
382 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900383 processVndkLibrary(mctx, m)
384 return
385 }
386 }
387}
388
389func init() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900390 android.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Inseob Kim1f086e22019-05-09 13:29:15 +0900391 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900392}
393
Jooyung Han2216fb12019-11-06 16:46:15 +0900394type vndkLibrariesTxt struct {
395 android.ModuleBase
396 outputFile android.OutputPath
397}
398
Jooyung Han39edb6c2019-11-06 16:53:07 +0900399var _ android.PrebuiltEtcModule = &vndkLibrariesTxt{}
400var _ android.OutputFileProducer = &vndkLibrariesTxt{}
401
Jooyung Han2216fb12019-11-06 16:46:15 +0900402// vndk_libraries_txt is a special kind of module type in that it name is one of
403// - llndk.libraries.txt
404// - vndkcore.libraries.txt
405// - vndksp.libraries.txt
406// - vndkprivate.libraries.txt
407// - vndkcorevariant.libraries.txt
408// A module behaves like a prebuilt_etc but its content is generated by soong.
409// By being a soong module, these files can be referenced by other soong modules.
410// For example, apex_vndk can depend on these files as prebuilt.
Jooyung Han39edb6c2019-11-06 16:53:07 +0900411func VndkLibrariesTxtFactory() android.Module {
Jooyung Han2216fb12019-11-06 16:46:15 +0900412 m := &vndkLibrariesTxt{}
413 android.InitAndroidModule(m)
414 return m
415}
416
417func insertVndkVersion(filename string, vndkVersion string) string {
418 if index := strings.LastIndex(filename, "."); index != -1 {
419 return filename[:index] + "." + vndkVersion + filename[index:]
420 }
421 return filename
422}
423
424func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
425 var list []string
426 switch txt.Name() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900427 case llndkLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900428 for _, filename := range android.SortedStringMapValues(llndkLibraries(ctx.Config())) {
429 if strings.HasPrefix(filename, "libclang_rt.hwasan-") {
430 continue
431 }
432 list = append(list, filename)
433 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900434 case vndkCoreLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900435 list = android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900436 case vndkSpLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900437 list = android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900438 case vndkPrivateLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900439 list = android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900440 case vndkUsingCoreVariantLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900441 list = android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config()))
442 default:
443 ctx.ModuleErrorf("name(%s) is unknown.", txt.Name())
444 return
445 }
446
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900447 var filename string
448 if txt.Name() != vndkUsingCoreVariantLibrariesTxt {
449 filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
450 } else {
451 filename = txt.Name()
452 }
453
Jooyung Han2216fb12019-11-06 16:46:15 +0900454 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
455 ctx.Build(pctx, android.BuildParams{
456 Rule: android.WriteFile,
457 Output: txt.outputFile,
458 Description: "Writing " + txt.outputFile.String(),
459 Args: map[string]string{
460 "content": strings.Join(list, "\\n"),
461 },
462 })
463
464 installPath := android.PathForModuleInstall(ctx, "etc")
465 ctx.InstallFile(installPath, filename, txt.outputFile)
466}
467
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900468func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
469 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900470 Class: "ETC",
471 OutputFile: android.OptionalPathForPath(txt.outputFile),
472 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
473 func(entries *android.AndroidMkEntries) {
474 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
475 },
476 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900477 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900478}
479
Jooyung Han39edb6c2019-11-06 16:53:07 +0900480func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
481 return txt.outputFile
482}
483
484func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
485 return android.Paths{txt.outputFile}, nil
486}
487
488func (txt *vndkLibrariesTxt) SubDir() string {
489 return ""
490}
491
Inseob Kim1f086e22019-05-09 13:29:15 +0900492func VndkSnapshotSingleton() android.Singleton {
493 return &vndkSnapshotSingleton{}
494}
495
Jooyung Han0302a842019-10-30 18:43:49 +0900496type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900497 vndkLibrariesFile android.OutputPath
498 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900499}
Inseob Kim1f086e22019-05-09 13:29:15 +0900500
Inseob Kim1f086e22019-05-09 13:29:15 +0900501func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900502 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
503 c.buildVndkLibrariesTxtFiles(ctx)
504
Inseob Kim1f086e22019-05-09 13:29:15 +0900505 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
506 if ctx.DeviceConfig().VndkVersion() != "current" {
507 return
508 }
509
510 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
511 return
512 }
513
514 if ctx.DeviceConfig().BoardVndkRuntimeDisable() {
515 return
516 }
517
Inseob Kim242ef0c2019-10-22 20:15:20 +0900518 var snapshotOutputs android.Paths
519
520 /*
521 VNDK snapshot zipped artifacts directory structure:
522 {SNAPSHOT_ARCH}/
523 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
524 shared/
525 vndk-core/
526 (VNDK-core libraries, e.g. libbinder.so)
527 vndk-sp/
528 (VNDK-SP libraries, e.g. libc++.so)
529 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
530 shared/
531 vndk-core/
532 (VNDK-core libraries, e.g. libbinder.so)
533 vndk-sp/
534 (VNDK-SP libraries, e.g. libc++.so)
535 binder32/
536 (This directory is newly introduced in v28 (Android P) to hold
537 prebuilts built for 32-bit binder interface.)
538 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
539 ...
540 configs/
541 (various *.txt configuration files)
542 include/
543 (header files of same directory structure with source tree)
544 NOTICE_FILES/
545 (notice files of libraries, e.g. libcutils.so.txt)
546 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900547
548 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900549 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900550
Inseob Kim242ef0c2019-10-22 20:15:20 +0900551 targetArchDirMap := make(map[android.ArchType]string)
Inseob Kimae553032019-05-14 18:52:49 +0900552 for _, target := range ctx.Config().Targets[android.Android] {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900553 dir := snapshotArchDir
Inseob Kimae553032019-05-14 18:52:49 +0900554 if ctx.DeviceConfig().BinderBitness() == "32" {
555 dir = filepath.Join(dir, "binder32")
556 }
557 arch := "arch-" + target.Arch.ArchType.String()
558 if target.Arch.ArchVariant != "" {
559 arch += "-" + target.Arch.ArchVariant
560 }
561 dir = filepath.Join(dir, arch)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900562 targetArchDirMap[target.Arch.ArchType] = dir
Inseob Kim1f086e22019-05-09 13:29:15 +0900563 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900564 configsDir := filepath.Join(snapshotArchDir, "configs")
565 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
566 includeDir := filepath.Join(snapshotArchDir, "include")
567
568 // set of include paths exported by VNDK libraries
569 exportedIncludes := make(map[string]bool)
570
571 // generated header files among exported headers.
572 var generatedHeaders android.Paths
573
574 // set of notice files copied.
Inseob Kim1f086e22019-05-09 13:29:15 +0900575 noticeBuilt := make(map[string]bool)
576
Inseob Kim242ef0c2019-10-22 20:15:20 +0900577 // paths of VNDK modules for GPL license checking
578 modulePaths := make(map[string]string)
579
580 // actual module names of .so files
581 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
582 moduleNames := make(map[string]string)
583
584 installSnapshotFileFromPath := func(path android.Path, out string) android.OutputPath {
585 outPath := android.PathForOutput(ctx, out)
Inseob Kimae553032019-05-14 18:52:49 +0900586 ctx.Build(pctx, android.BuildParams{
587 Rule: android.Cp,
588 Input: path,
Inseob Kim242ef0c2019-10-22 20:15:20 +0900589 Output: outPath,
Inseob Kimae553032019-05-14 18:52:49 +0900590 Description: "vndk snapshot " + out,
591 Args: map[string]string{
592 "cpFlags": "-f -L",
593 },
594 })
Inseob Kim242ef0c2019-10-22 20:15:20 +0900595 return outPath
Inseob Kimae553032019-05-14 18:52:49 +0900596 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900597
598 installSnapshotFileFromContent := func(content, out string) android.OutputPath {
599 outPath := android.PathForOutput(ctx, out)
Inseob Kimae553032019-05-14 18:52:49 +0900600 ctx.Build(pctx, android.BuildParams{
601 Rule: android.WriteFile,
Inseob Kim242ef0c2019-10-22 20:15:20 +0900602 Output: outPath,
Inseob Kimae553032019-05-14 18:52:49 +0900603 Description: "vndk snapshot " + out,
604 Args: map[string]string{
605 "content": content,
606 },
607 })
Inseob Kim242ef0c2019-10-22 20:15:20 +0900608 return outPath
Inseob Kimae553032019-05-14 18:52:49 +0900609 }
610
Inseob Kimae553032019-05-14 18:52:49 +0900611 type vndkSnapshotLibraryInterface interface {
612 exportedFlagsProducer
613 libraryInterface
614 }
615
616 var _ vndkSnapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
617 var _ vndkSnapshotLibraryInterface = (*libraryDecorator)(nil)
618
Inseob Kim242ef0c2019-10-22 20:15:20 +0900619 installVndkSnapshotLib := func(m *Module, l vndkSnapshotLibraryInterface, vndkType string) (android.Paths, bool) {
620 targetArchDir, ok := targetArchDirMap[m.Target().Arch.ArchType]
621 if !ok {
622 return nil, false
623 }
Inseob Kimae553032019-05-14 18:52:49 +0900624
Inseob Kim242ef0c2019-10-22 20:15:20 +0900625 var ret android.Paths
626
627 libPath := m.outputFile.Path()
628 stem := libPath.Base()
629 snapshotLibOut := filepath.Join(targetArchDir, "shared", vndkType, stem)
630 ret = append(ret, installSnapshotFileFromPath(libPath, snapshotLibOut))
631
632 moduleNames[stem] = ctx.ModuleName(m)
633 modulePaths[stem] = ctx.ModuleDir(m)
634
635 if m.NoticeFile().Valid() {
636 noticeName := stem + ".txt"
637 // skip already copied notice file
638 if _, ok := noticeBuilt[noticeName]; !ok {
639 noticeBuilt[noticeName] = true
640 ret = append(ret, installSnapshotFileFromPath(
641 m.NoticeFile().Path(), filepath.Join(noticeDir, noticeName)))
642 }
643 }
Inseob Kimae553032019-05-14 18:52:49 +0900644
645 if ctx.Config().VndkSnapshotBuildArtifacts() {
646 prop := struct {
647 ExportedDirs []string `json:",omitempty"`
648 ExportedSystemDirs []string `json:",omitempty"`
649 ExportedFlags []string `json:",omitempty"`
650 RelativeInstallPath string `json:",omitempty"`
651 }{}
652 prop.ExportedFlags = l.exportedFlags()
Jiyong Park74955042019-10-22 20:19:51 +0900653 prop.ExportedDirs = l.exportedDirs().Strings()
654 prop.ExportedSystemDirs = l.exportedSystemDirs().Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900655 prop.RelativeInstallPath = m.RelativeInstallPath()
656
Inseob Kim242ef0c2019-10-22 20:15:20 +0900657 propOut := snapshotLibOut + ".json"
Inseob Kimae553032019-05-14 18:52:49 +0900658
659 j, err := json.Marshal(prop)
660 if err != nil {
661 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900662 return nil, false
Inseob Kimae553032019-05-14 18:52:49 +0900663 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900664 ret = append(ret, installSnapshotFileFromContent(string(j), propOut))
Inseob Kimae553032019-05-14 18:52:49 +0900665 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900666 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900667 }
668
Inseob Kim242ef0c2019-10-22 20:15:20 +0900669 isVndkSnapshotLibrary := func(m *Module) (i vndkSnapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
Inseob Kimae553032019-05-14 18:52:49 +0900670 if m.Target().NativeBridge == android.NativeBridgeEnabled {
671 return nil, "", false
672 }
Jooyung Han5df3b112020-01-23 05:10:16 +0000673 if !m.UseVndk() || !m.IsForPlatform() || !m.installable() || !m.inVendor() {
Inseob Kimae553032019-05-14 18:52:49 +0900674 return nil, "", false
675 }
676 l, ok := m.linker.(vndkSnapshotLibraryInterface)
677 if !ok || !l.shared() {
678 return nil, "", false
679 }
Justin Yun5f7f7e82019-11-18 19:52:14 +0900680 if m.VndkVersion() == ctx.DeviceConfig().PlatformVndkVersion() && m.IsVndk() && !m.isVndkExt() {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900681 if m.isVndkSp() {
682 return l, "vndk-sp", true
683 } else {
684 return l, "vndk-core", true
685 }
Inseob Kimae553032019-05-14 18:52:49 +0900686 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900687
688 return nil, "", false
Inseob Kimae553032019-05-14 18:52:49 +0900689 }
690
Inseob Kim1f086e22019-05-09 13:29:15 +0900691 ctx.VisitAllModules(func(module android.Module) {
692 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900693 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900694 return
695 }
696
Inseob Kim242ef0c2019-10-22 20:15:20 +0900697 l, vndkType, ok := isVndkSnapshotLibrary(m)
Inseob Kimae553032019-05-14 18:52:49 +0900698 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200699 return
700 }
701
Inseob Kim242ef0c2019-10-22 20:15:20 +0900702 libs, ok := installVndkSnapshotLib(m, l, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900703 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900704 return
705 }
706
Inseob Kim242ef0c2019-10-22 20:15:20 +0900707 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900708
Inseob Kim242ef0c2019-10-22 20:15:20 +0900709 // We glob headers from include directories inside source tree. So we first gather
710 // all include directories inside our source tree. On the contrast, we manually
711 // collect generated headers from dependencies as they can't globbed.
Inseob Kimd110f872019-12-06 13:15:38 +0900712 generatedHeaders = append(generatedHeaders, l.exportedGeneratedHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900713 for _, dir := range append(l.exportedDirs(), l.exportedSystemDirs()...) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900714 exportedIncludes[dir.String()] = true
Inseob Kimae553032019-05-14 18:52:49 +0900715 }
716 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900717
Inseob Kimae553032019-05-14 18:52:49 +0900718 if ctx.Config().VndkSnapshotBuildArtifacts() {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900719 globbedHeaders := make(map[string]bool)
Inseob Kimae553032019-05-14 18:52:49 +0900720
Inseob Kim242ef0c2019-10-22 20:15:20 +0900721 for _, dir := range android.SortedStringKeys(exportedIncludes) {
722 // Skip if dir is for generated headers
Inseob Kimae553032019-05-14 18:52:49 +0900723 if strings.HasPrefix(dir, android.PathForOutput(ctx).String()) {
724 continue
Inseob Kim1f086e22019-05-09 13:29:15 +0900725 }
Inseob Kimae553032019-05-14 18:52:49 +0900726 exts := headerExts
727 // Glob all files under this special directory, because of C++ headers.
728 if strings.HasPrefix(dir, "external/libcxx/include") {
729 exts = []string{""}
Inseob Kim1f086e22019-05-09 13:29:15 +0900730 }
Inseob Kimae553032019-05-14 18:52:49 +0900731 for _, ext := range exts {
732 glob, err := ctx.GlobWithDeps(dir+"/**/*"+ext, nil)
733 if err != nil {
734 ctx.Errorf("%#v\n", err)
735 return
736 }
737 for _, header := range glob {
738 if strings.HasSuffix(header, "/") {
739 continue
740 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900741 globbedHeaders[header] = true
Inseob Kimae553032019-05-14 18:52:49 +0900742 }
743 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900744 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900745
Inseob Kim242ef0c2019-10-22 20:15:20 +0900746 for _, header := range android.SortedStringKeys(globbedHeaders) {
747 snapshotOutputs = append(snapshotOutputs, installSnapshotFileFromPath(
748 android.PathForSource(ctx, header), filepath.Join(includeDir, header)))
Inseob Kimae553032019-05-14 18:52:49 +0900749 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900750
Inseob Kimae553032019-05-14 18:52:49 +0900751 isHeader := func(path string) bool {
752 for _, ext := range headerExts {
753 if strings.HasSuffix(path, ext) {
754 return true
755 }
756 }
757 return false
758 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900759
Inseob Kim242ef0c2019-10-22 20:15:20 +0900760 // For generated headers, manually install one by one, rather than glob
Inseob Kimae553032019-05-14 18:52:49 +0900761 for _, path := range android.PathsToDirectorySortedPaths(android.FirstUniquePaths(generatedHeaders)) {
762 header := path.String()
763
764 if !isHeader(header) {
765 continue
766 }
767
Inseob Kim242ef0c2019-10-22 20:15:20 +0900768 snapshotOutputs = append(snapshotOutputs, installSnapshotFileFromPath(
769 path, filepath.Join(includeDir, header)))
Inseob Kimae553032019-05-14 18:52:49 +0900770 }
771 }
772
Jooyung Han39edb6c2019-11-06 16:53:07 +0900773 // install *.libraries.txt except vndkcorevariant.libraries.txt
774 ctx.VisitAllModules(func(module android.Module) {
775 m, ok := module.(*vndkLibrariesTxt)
776 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
777 return
778 }
779 snapshotOutputs = append(snapshotOutputs, installSnapshotFileFromPath(m.OutputFile(), filepath.Join(configsDir, m.Name())))
780 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900781
Inseob Kim242ef0c2019-10-22 20:15:20 +0900782 /*
783 Dump a map to a list file as:
Inseob Kim1f086e22019-05-09 13:29:15 +0900784
Inseob Kim242ef0c2019-10-22 20:15:20 +0900785 {key1} {value1}
786 {key2} {value2}
787 ...
788 */
789 installMapListFile := func(m map[string]string, path string) android.OutputPath {
790 var txtBuilder strings.Builder
791 for idx, k := range android.SortedStringKeys(m) {
792 if idx > 0 {
793 txtBuilder.WriteString("\\n")
794 }
795 txtBuilder.WriteString(k)
796 txtBuilder.WriteString(" ")
797 txtBuilder.WriteString(m[k])
Inseob Kim1f086e22019-05-09 13:29:15 +0900798 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900799 return installSnapshotFileFromContent(txtBuilder.String(), path)
Inseob Kim1f086e22019-05-09 13:29:15 +0900800 }
801
Inseob Kim242ef0c2019-10-22 20:15:20 +0900802 /*
803 module_paths.txt contains paths on which VNDK modules are defined.
804 e.g.,
805 libbase.so system/core/base
806 libc.so bionic/libc
807 ...
808 */
809 snapshotOutputs = append(snapshotOutputs, installMapListFile(modulePaths, filepath.Join(configsDir, "module_paths.txt")))
810
811 /*
812 module_names.txt contains names as which VNDK modules are defined,
813 because output filename and module name can be different with stem and suffix properties.
814
815 e.g.,
816 libcutils.so libcutils
817 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
818 ...
819 */
820 snapshotOutputs = append(snapshotOutputs, installMapListFile(moduleNames, filepath.Join(configsDir, "module_names.txt")))
821
822 // All artifacts are ready. Sort them to normalize ninja and then zip.
823 sort.Slice(snapshotOutputs, func(i, j int) bool {
824 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
825 })
826
827 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
828 zipRule := android.NewRuleBuilder()
829
830 // If output files are too many, soong_zip command can exceed ARG_MAX.
831 // So first dump file lists into a single list file, and then feed it to Soong
832 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
833 zipRule.Command().
834 Text("( xargs").
835 FlagWithRspFileInputList("-n1 echo < ", snapshotOutputs).
836 FlagWithOutput("| tr -d \\' > ", snapshotOutputList).
837 Text(")")
838
839 zipRule.Temporary(snapshotOutputList)
840
841 zipRule.Command().
842 BuiltTool(ctx, "soong_zip").
843 FlagWithOutput("-o ", zipPath).
844 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
845 FlagWithInput("-l ", snapshotOutputList)
846
847 zipRule.Build(pctx, ctx, zipPath.String(), "vndk snapshot "+zipPath.String())
848 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900849}
Jooyung Han097087b2019-10-22 19:32:18 +0900850
Jooyung Han0302a842019-10-30 18:43:49 +0900851func getVndkFileName(m *Module) (string, error) {
852 if library, ok := m.linker.(*libraryDecorator); ok {
853 return library.getLibNameHelper(m.BaseModuleName(), true) + ".so", nil
854 }
855 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
856 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true) + ".so", nil
857 }
858 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900859}
860
861func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900862 llndk := android.SortedStringMapValues(llndkLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900863 vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
864 vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
865 vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900866
Jooyung Han2216fb12019-11-06 16:46:15 +0900867 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900868 // Since each target have different set of libclang_rt.* files,
869 // keep the common set of files in vndk.libraries.txt
870 var merged []string
Jooyung Han097087b2019-10-22 19:32:18 +0900871 filterOutLibClangRt := func(libList []string) (filtered []string) {
872 for _, lib := range libList {
873 if !strings.HasPrefix(lib, "libclang_rt.") {
874 filtered = append(filtered, lib)
875 }
876 }
877 return
878 }
879 merged = append(merged, addPrefix(filterOutLibClangRt(llndk), "LLNDK: ")...)
880 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
881 merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...)
882 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900883 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
884 ctx.Build(pctx, android.BuildParams{
885 Rule: android.WriteFile,
886 Output: c.vndkLibrariesFile,
887 Description: "Writing " + c.vndkLibrariesFile.String(),
888 Args: map[string]string{
889 "content": strings.Join(merged, "\\n"),
890 },
891 })
Jooyung Han0302a842019-10-30 18:43:49 +0900892}
Jooyung Han097087b2019-10-22 19:32:18 +0900893
Jooyung Han0302a842019-10-30 18:43:49 +0900894func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
895 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
896 // they been moved to an apex.
897 movedToApexLlndkLibraries := []string{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900898 for lib := range llndkLibraries(ctx.Config()) {
Jooyung Han0302a842019-10-30 18:43:49 +0900899 // Skip bionic libs, they are handled in different manner
900 if android.DirectlyInAnyApex(&notOnHostContext{}, lib) && !isBionic(lib) {
901 movedToApexLlndkLibraries = append(movedToApexLlndkLibraries, lib)
902 }
903 }
904 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", strings.Join(movedToApexLlndkLibraries, " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900905
906 // Make uses LLNDK_LIBRARIES to determine which libraries to install.
907 // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
908 // Therefore, by removing the library here, we cause it to only be installed if libc
909 // depends on it.
910 installedLlndkLibraries := []string{}
911 for lib := range llndkLibraries(ctx.Config()) {
912 if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
913 continue
914 }
915 installedLlndkLibraries = append(installedLlndkLibraries, lib)
916 }
917 sort.Strings(installedLlndkLibraries)
918 ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
919
Jooyung Han0302a842019-10-30 18:43:49 +0900920 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkCoreLibraries(ctx.Config())), " "))
921 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(android.SortedStringKeys(vndkSpLibraries(ctx.Config())), " "))
922 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())), " "))
923 ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(android.SortedStringKeys(vndkUsingCoreVariantLibraries(ctx.Config())), " "))
924
Jooyung Han0302a842019-10-30 18:43:49 +0900925 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900926 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900927}