blob: f531af369f952201dab2ec243efd97769c35d205 [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,
45 vndkUsingCoreVariantLibrariesTxt,
46 }
47 }
48 // Snapshot vndks have their own *.libraries.VER.txt files.
49 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
50 return []string{
51 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
52 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
53 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
54 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
55 }
56}
57
Justin Yun8effde42017-06-23 19:24:43 +090058type VndkProperties struct {
59 Vndk struct {
60 // declared as a VNDK or VNDK-SP module. The vendor variant
61 // will be installed in /system instead of /vendor partition.
62 //
Roland Levillaindfe75b32019-07-23 16:53:32 +010063 // `vendor_available` must be explicitly set to either true or
Jiyong Park82e2bf32017-08-16 14:05:54 +090064 // false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090065 Enabled *bool
66
67 // declared as a VNDK-SP module, which is a subset of VNDK.
68 //
69 // `vndk: { enabled: true }` must set together.
70 //
71 // All these modules are allowed to link to VNDK-SP or LL-NDK
72 // modules only. Other dependency will cause link-type errors.
73 //
74 // If `support_system_process` is not set or set to false,
75 // the module is VNDK-core and can link to other VNDK-core,
76 // VNDK-SP or LL-NDK modules only.
77 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080078
79 // Extending another module
80 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090081 }
82}
83
84type vndkdep struct {
85 Properties VndkProperties
86}
87
88func (vndk *vndkdep) props() []interface{} {
89 return []interface{}{&vndk.Properties}
90}
91
92func (vndk *vndkdep) begin(ctx BaseModuleContext) {}
93
94func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps {
95 return deps
96}
97
98func (vndk *vndkdep) isVndk() bool {
99 return Bool(vndk.Properties.Vndk.Enabled)
100}
101
102func (vndk *vndkdep) isVndkSp() bool {
103 return Bool(vndk.Properties.Vndk.Support_system_process)
104}
105
Logan Chienf3511742017-10-31 18:04:35 +0800106func (vndk *vndkdep) isVndkExt() bool {
107 return vndk.Properties.Vndk.Extends != nil
108}
109
110func (vndk *vndkdep) getVndkExtendsModuleName() string {
111 return String(vndk.Properties.Vndk.Extends)
112}
113
Justin Yun8effde42017-06-23 19:24:43 +0900114func (vndk *vndkdep) typeName() string {
115 if !vndk.isVndk() {
116 return "native:vendor"
117 }
Logan Chienf3511742017-10-31 18:04:35 +0800118 if !vndk.isVndkExt() {
119 if !vndk.isVndkSp() {
120 return "native:vendor:vndk"
121 }
122 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900123 }
Logan Chienf3511742017-10-31 18:04:35 +0800124 if !vndk.isVndkSp() {
125 return "native:vendor:vndkext"
126 }
127 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900128}
129
Ivan Lozano183a3212019-10-18 14:18:45 -0700130func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900131 if to.linker == nil {
132 return
133 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900134 if !vndk.isVndk() {
135 // Non-VNDK modules (those installed to /vendor) can't depend on modules marked with
136 // vendor_available: false.
137 violation := false
Nan Zhang0007d812017-11-07 10:57:05 -0800138 if lib, ok := to.linker.(*llndkStubDecorator); ok && !Bool(lib.Properties.Vendor_available) {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900139 violation = true
140 } else {
141 if _, ok := to.linker.(libraryInterface); ok && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) {
142 // Vendor_available == nil && !Bool(Vendor_available) should be okay since
143 // it means a vendor-only library which is a valid dependency for non-VNDK
144 // modules.
145 violation = true
146 }
147 }
148 if violation {
149 ctx.ModuleErrorf("Vendor module that is not VNDK should not link to %q which is marked as `vendor_available: false`", to.Name())
150 }
151 }
Justin Yun8effde42017-06-23 19:24:43 +0900152 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
153 // Check only shared libraries.
154 // Other (static and LL-NDK) libraries are allowed to link.
155 return
156 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700157 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900158 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
159 vndk.typeName(), to.Name())
160 return
161 }
Logan Chienf3511742017-10-31 18:04:35 +0800162 if tag == vndkExtDepTag {
163 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
164 // and has identical vndk properties.
165 if to.vndkdep == nil || !to.vndkdep.isVndk() {
166 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
167 return
168 }
169 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
170 ctx.ModuleErrorf(
171 "`extends` refers a module %q with mismatched support_system_process",
172 to.Name())
173 return
174 }
175 if !Bool(to.VendorProperties.Vendor_available) {
176 ctx.ModuleErrorf(
177 "`extends` refers module %q which does not have `vendor_available: true`",
178 to.Name())
179 return
180 }
181 }
Justin Yun8effde42017-06-23 19:24:43 +0900182 if to.vndkdep == nil {
183 return
184 }
Logan Chienf3511742017-10-31 18:04:35 +0800185
Logan Chiend3c59a22018-03-29 14:08:15 +0800186 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100187 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
188 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
189 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800190 return
191 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800192}
Logan Chienf3511742017-10-31 18:04:35 +0800193
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100194func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800195 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
196 if from.isVndkExt() {
197 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100198 if to.isVndk() && !to.isVndkSp() {
199 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
200 }
201 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800202 }
203 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100204 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900205 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800206 if from.isVndk() {
207 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100208 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800209 }
210 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100211 if !to.isVndkSp() {
212 return errors.New("VNDK-SP must only depend on VNDK-SP")
213 }
214 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800215 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100216 if !to.isVndk() {
217 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
218 }
219 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800220 }
221 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100222 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900223}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900224
225var (
Jooyung Hana463f722019-11-01 08:45:59 +0900226 vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires")
227 vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires")
228 llndkLibrariesKey = android.NewOnceKey("llndkLibrarires")
229 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires")
230 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibrarires")
Jooyung Hana463f722019-11-01 08:45:59 +0900231 vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
232 vndkLibrariesLock sync.Mutex
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900233
Inseob Kimae553032019-05-14 18:52:49 +0900234 headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
235)
Inseob Kim1f086e22019-05-09 13:29:15 +0900236
Jooyung Han0302a842019-10-30 18:43:49 +0900237func vndkCoreLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900238 return config.Once(vndkCoreLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900239 return make(map[string]string)
240 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900241}
242
Jooyung Han0302a842019-10-30 18:43:49 +0900243func vndkSpLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900244 return config.Once(vndkSpLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900245 return make(map[string]string)
246 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900247}
248
Jooyung Han0302a842019-10-30 18:43:49 +0900249func isLlndkLibrary(baseModuleName string, config android.Config) bool {
250 _, ok := llndkLibraries(config)[baseModuleName]
251 return ok
252}
253
254func llndkLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900255 return config.Once(llndkLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900256 return make(map[string]string)
257 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900258}
259
Jooyung Han0302a842019-10-30 18:43:49 +0900260func isVndkPrivateLibrary(baseModuleName string, config android.Config) bool {
261 _, ok := vndkPrivateLibraries(config)[baseModuleName]
262 return ok
263}
264
265func vndkPrivateLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900266 return config.Once(vndkPrivateLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900267 return make(map[string]string)
268 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900269}
270
Jooyung Han0302a842019-10-30 18:43:49 +0900271func vndkUsingCoreVariantLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900272 return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900273 return make(map[string]string)
274 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900275}
276
Jooyung Han097087b2019-10-22 19:32:18 +0900277func vndkMustUseVendorVariantList(cfg android.Config) []string {
278 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900279 return config.VndkMustUseVendorVariantList
280 }).([]string)
281}
282
283// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
284// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
285func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900286 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900287 return mustUseVendorVariantList
288 })
289}
290
Inseob Kim1f086e22019-05-09 13:29:15 +0900291func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
292 lib := m.linker.(*llndkStubDecorator)
Jooyung Han0302a842019-10-30 18:43:49 +0900293 name := m.BaseModuleName()
294 filename := m.BaseModuleName() + ".so"
Inseob Kim9516ee92019-05-09 10:56:13 +0900295
Inseob Kim1f086e22019-05-09 13:29:15 +0900296 vndkLibrariesLock.Lock()
297 defer vndkLibrariesLock.Unlock()
Inseob Kim9516ee92019-05-09 10:56:13 +0900298
Jooyung Han0302a842019-10-30 18:43:49 +0900299 llndkLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900300 if !Bool(lib.Properties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900301 vndkPrivateLibraries(mctx.Config())[name] = filename
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900302 }
303}
Inseob Kim1f086e22019-05-09 13:29:15 +0900304
305func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Jooyung Han0302a842019-10-30 18:43:49 +0900306 name := m.BaseModuleName()
307 filename, err := getVndkFileName(m)
308 if err != nil {
309 panic(err)
310 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900311
312 vndkLibrariesLock.Lock()
313 defer vndkLibrariesLock.Unlock()
314
Jooyung Han097087b2019-10-22 19:32:18 +0900315 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
316 m.Properties.MustUseVendorVariant = true
317 }
Jooyung Han0302a842019-10-30 18:43:49 +0900318 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
319 vndkUsingCoreVariantLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900320 }
Jooyung Han0302a842019-10-30 18:43:49 +0900321
Inseob Kim1f086e22019-05-09 13:29:15 +0900322 if m.vndkdep.isVndkSp() {
Jooyung Han0302a842019-10-30 18:43:49 +0900323 vndkSpLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900324 } else {
Jooyung Han0302a842019-10-30 18:43:49 +0900325 vndkCoreLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900326 }
327 if !Bool(m.VendorProperties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900328 vndkPrivateLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900329 }
330}
331
Jooyung Han31c470b2019-10-18 16:26:59 +0900332func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
333 if !m.Enabled() {
334 return false
335 }
336
Jooyung Han87a7f302019-10-29 05:18:21 +0900337 if !mctx.Device() {
338 return false
339 }
340
Jooyung Han31c470b2019-10-18 16:26:59 +0900341 if m.Target().NativeBridge == android.NativeBridgeEnabled {
342 return false
343 }
344
345 // prebuilt vndk modules should match with device
346 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
347 // When b/142675459 is landed, remove following check
348 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) {
349 return false
350 }
351
352 if lib, ok := m.linker.(libraryInterface); ok {
353 useCoreVariant := m.vndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900354 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozano52767be2019-10-18 14:49:46 -0700355 return lib.shared() && m.UseVndk() && m.IsVndk() && !m.isVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900356 }
357 return false
358}
359
Inseob Kim1f086e22019-05-09 13:29:15 +0900360// gather list of vndk-core, vndk-sp, and ll-ndk libs
361func VndkMutator(mctx android.BottomUpMutatorContext) {
362 m, ok := mctx.Module().(*Module)
363 if !ok {
364 return
365 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900366 if !m.Enabled() {
367 return
368 }
Justin Yun7390ea32019-09-08 11:34:06 +0900369 if m.Target().NativeBridge == android.NativeBridgeEnabled {
370 // Skip native_bridge modules
371 return
372 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900373
374 if _, ok := m.linker.(*llndkStubDecorator); ok {
375 processLlndkLibrary(mctx, m)
376 return
377 }
378
379 lib, is_lib := m.linker.(*libraryDecorator)
380 prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker)
381
Inseob Kim64c43952019-08-26 16:52:35 +0900382 if (is_lib && lib.buildShared()) || (is_prebuilt_lib && prebuilt_lib.buildShared()) {
383 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900384 processVndkLibrary(mctx, m)
385 return
386 }
387 }
388}
389
390func init() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900391 android.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Inseob Kim1f086e22019-05-09 13:29:15 +0900392 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900393}
394
Jooyung Han2216fb12019-11-06 16:46:15 +0900395type vndkLibrariesTxt struct {
396 android.ModuleBase
397 outputFile android.OutputPath
398}
399
Jooyung Han39edb6c2019-11-06 16:53:07 +0900400var _ android.PrebuiltEtcModule = &vndkLibrariesTxt{}
401var _ android.OutputFileProducer = &vndkLibrariesTxt{}
402
Jooyung Han2216fb12019-11-06 16:46:15 +0900403// vndk_libraries_txt is a special kind of module type in that it name is one of
404// - llndk.libraries.txt
405// - vndkcore.libraries.txt
406// - vndksp.libraries.txt
407// - vndkprivate.libraries.txt
408// - vndkcorevariant.libraries.txt
409// A module behaves like a prebuilt_etc but its content is generated by soong.
410// By being a soong module, these files can be referenced by other soong modules.
411// For example, apex_vndk can depend on these files as prebuilt.
Jooyung Han39edb6c2019-11-06 16:53:07 +0900412func VndkLibrariesTxtFactory() android.Module {
Jooyung Han2216fb12019-11-06 16:46:15 +0900413 m := &vndkLibrariesTxt{}
414 android.InitAndroidModule(m)
415 return m
416}
417
418func insertVndkVersion(filename string, vndkVersion string) string {
419 if index := strings.LastIndex(filename, "."); index != -1 {
420 return filename[:index] + "." + vndkVersion + filename[index:]
421 }
422 return filename
423}
424
425func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
426 var list []string
427 switch txt.Name() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900428 case llndkLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900429 for _, filename := range android.SortedStringMapValues(llndkLibraries(ctx.Config())) {
430 if strings.HasPrefix(filename, "libclang_rt.hwasan-") {
431 continue
432 }
433 list = append(list, filename)
434 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900435 case vndkCoreLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900436 list = android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900437 case vndkSpLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900438 list = android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900439 case vndkPrivateLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900440 list = android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900441 case vndkUsingCoreVariantLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900442 list = android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config()))
443 default:
444 ctx.ModuleErrorf("name(%s) is unknown.", txt.Name())
445 return
446 }
447
448 filename := insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
449 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
450 ctx.Build(pctx, android.BuildParams{
451 Rule: android.WriteFile,
452 Output: txt.outputFile,
453 Description: "Writing " + txt.outputFile.String(),
454 Args: map[string]string{
455 "content": strings.Join(list, "\\n"),
456 },
457 })
458
459 installPath := android.PathForModuleInstall(ctx, "etc")
460 ctx.InstallFile(installPath, filename, txt.outputFile)
461}
462
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900463func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
464 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900465 Class: "ETC",
466 OutputFile: android.OptionalPathForPath(txt.outputFile),
467 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
468 func(entries *android.AndroidMkEntries) {
469 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
470 },
471 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900472 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900473}
474
Jooyung Han39edb6c2019-11-06 16:53:07 +0900475func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
476 return txt.outputFile
477}
478
479func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
480 return android.Paths{txt.outputFile}, nil
481}
482
483func (txt *vndkLibrariesTxt) SubDir() string {
484 return ""
485}
486
Inseob Kim1f086e22019-05-09 13:29:15 +0900487func VndkSnapshotSingleton() android.Singleton {
488 return &vndkSnapshotSingleton{}
489}
490
Jooyung Han0302a842019-10-30 18:43:49 +0900491type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900492 vndkLibrariesFile android.OutputPath
493 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900494}
Inseob Kim1f086e22019-05-09 13:29:15 +0900495
Inseob Kim1f086e22019-05-09 13:29:15 +0900496func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900497 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
498 c.buildVndkLibrariesTxtFiles(ctx)
499
Inseob Kim1f086e22019-05-09 13:29:15 +0900500 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
501 if ctx.DeviceConfig().VndkVersion() != "current" {
502 return
503 }
504
505 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
506 return
507 }
508
509 if ctx.DeviceConfig().BoardVndkRuntimeDisable() {
510 return
511 }
512
Inseob Kim242ef0c2019-10-22 20:15:20 +0900513 var snapshotOutputs android.Paths
514
515 /*
516 VNDK snapshot zipped artifacts directory structure:
517 {SNAPSHOT_ARCH}/
518 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
519 shared/
520 vndk-core/
521 (VNDK-core libraries, e.g. libbinder.so)
522 vndk-sp/
523 (VNDK-SP libraries, e.g. libc++.so)
524 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
525 shared/
526 vndk-core/
527 (VNDK-core libraries, e.g. libbinder.so)
528 vndk-sp/
529 (VNDK-SP libraries, e.g. libc++.so)
530 binder32/
531 (This directory is newly introduced in v28 (Android P) to hold
532 prebuilts built for 32-bit binder interface.)
533 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
534 ...
535 configs/
536 (various *.txt configuration files)
537 include/
538 (header files of same directory structure with source tree)
539 NOTICE_FILES/
540 (notice files of libraries, e.g. libcutils.so.txt)
541 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900542
543 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900544 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900545
Inseob Kim242ef0c2019-10-22 20:15:20 +0900546 targetArchDirMap := make(map[android.ArchType]string)
Inseob Kimae553032019-05-14 18:52:49 +0900547 for _, target := range ctx.Config().Targets[android.Android] {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900548 dir := snapshotArchDir
Inseob Kimae553032019-05-14 18:52:49 +0900549 if ctx.DeviceConfig().BinderBitness() == "32" {
550 dir = filepath.Join(dir, "binder32")
551 }
552 arch := "arch-" + target.Arch.ArchType.String()
553 if target.Arch.ArchVariant != "" {
554 arch += "-" + target.Arch.ArchVariant
555 }
556 dir = filepath.Join(dir, arch)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900557 targetArchDirMap[target.Arch.ArchType] = dir
Inseob Kim1f086e22019-05-09 13:29:15 +0900558 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900559 configsDir := filepath.Join(snapshotArchDir, "configs")
560 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
561 includeDir := filepath.Join(snapshotArchDir, "include")
562
563 // set of include paths exported by VNDK libraries
564 exportedIncludes := make(map[string]bool)
565
566 // generated header files among exported headers.
567 var generatedHeaders android.Paths
568
569 // set of notice files copied.
Inseob Kim1f086e22019-05-09 13:29:15 +0900570 noticeBuilt := make(map[string]bool)
571
Inseob Kim242ef0c2019-10-22 20:15:20 +0900572 // paths of VNDK modules for GPL license checking
573 modulePaths := make(map[string]string)
574
575 // actual module names of .so files
576 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
577 moduleNames := make(map[string]string)
578
579 installSnapshotFileFromPath := func(path android.Path, out string) android.OutputPath {
580 outPath := android.PathForOutput(ctx, out)
Inseob Kimae553032019-05-14 18:52:49 +0900581 ctx.Build(pctx, android.BuildParams{
582 Rule: android.Cp,
583 Input: path,
Inseob Kim242ef0c2019-10-22 20:15:20 +0900584 Output: outPath,
Inseob Kimae553032019-05-14 18:52:49 +0900585 Description: "vndk snapshot " + out,
586 Args: map[string]string{
587 "cpFlags": "-f -L",
588 },
589 })
Inseob Kim242ef0c2019-10-22 20:15:20 +0900590 return outPath
Inseob Kimae553032019-05-14 18:52:49 +0900591 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900592
593 installSnapshotFileFromContent := func(content, out string) android.OutputPath {
594 outPath := android.PathForOutput(ctx, out)
Inseob Kimae553032019-05-14 18:52:49 +0900595 ctx.Build(pctx, android.BuildParams{
596 Rule: android.WriteFile,
Inseob Kim242ef0c2019-10-22 20:15:20 +0900597 Output: outPath,
Inseob Kimae553032019-05-14 18:52:49 +0900598 Description: "vndk snapshot " + out,
599 Args: map[string]string{
600 "content": content,
601 },
602 })
Inseob Kim242ef0c2019-10-22 20:15:20 +0900603 return outPath
Inseob Kimae553032019-05-14 18:52:49 +0900604 }
605
Inseob Kimae553032019-05-14 18:52:49 +0900606 type vndkSnapshotLibraryInterface interface {
607 exportedFlagsProducer
608 libraryInterface
609 }
610
611 var _ vndkSnapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
612 var _ vndkSnapshotLibraryInterface = (*libraryDecorator)(nil)
613
Inseob Kim242ef0c2019-10-22 20:15:20 +0900614 installVndkSnapshotLib := func(m *Module, l vndkSnapshotLibraryInterface, vndkType string) (android.Paths, bool) {
615 targetArchDir, ok := targetArchDirMap[m.Target().Arch.ArchType]
616 if !ok {
617 return nil, false
618 }
Inseob Kimae553032019-05-14 18:52:49 +0900619
Inseob Kim242ef0c2019-10-22 20:15:20 +0900620 var ret android.Paths
621
622 libPath := m.outputFile.Path()
623 stem := libPath.Base()
624 snapshotLibOut := filepath.Join(targetArchDir, "shared", vndkType, stem)
625 ret = append(ret, installSnapshotFileFromPath(libPath, snapshotLibOut))
626
627 moduleNames[stem] = ctx.ModuleName(m)
628 modulePaths[stem] = ctx.ModuleDir(m)
629
630 if m.NoticeFile().Valid() {
631 noticeName := stem + ".txt"
632 // skip already copied notice file
633 if _, ok := noticeBuilt[noticeName]; !ok {
634 noticeBuilt[noticeName] = true
635 ret = append(ret, installSnapshotFileFromPath(
636 m.NoticeFile().Path(), filepath.Join(noticeDir, noticeName)))
637 }
638 }
Inseob Kimae553032019-05-14 18:52:49 +0900639
640 if ctx.Config().VndkSnapshotBuildArtifacts() {
641 prop := struct {
642 ExportedDirs []string `json:",omitempty"`
643 ExportedSystemDirs []string `json:",omitempty"`
644 ExportedFlags []string `json:",omitempty"`
645 RelativeInstallPath string `json:",omitempty"`
646 }{}
647 prop.ExportedFlags = l.exportedFlags()
Jiyong Park74955042019-10-22 20:19:51 +0900648 prop.ExportedDirs = l.exportedDirs().Strings()
649 prop.ExportedSystemDirs = l.exportedSystemDirs().Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900650 prop.RelativeInstallPath = m.RelativeInstallPath()
651
Inseob Kim242ef0c2019-10-22 20:15:20 +0900652 propOut := snapshotLibOut + ".json"
Inseob Kimae553032019-05-14 18:52:49 +0900653
654 j, err := json.Marshal(prop)
655 if err != nil {
656 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900657 return nil, false
Inseob Kimae553032019-05-14 18:52:49 +0900658 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900659 ret = append(ret, installSnapshotFileFromContent(string(j), propOut))
Inseob Kimae553032019-05-14 18:52:49 +0900660 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900661 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900662 }
663
Inseob Kim242ef0c2019-10-22 20:15:20 +0900664 isVndkSnapshotLibrary := func(m *Module) (i vndkSnapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
Inseob Kimae553032019-05-14 18:52:49 +0900665 if m.Target().NativeBridge == android.NativeBridgeEnabled {
666 return nil, "", false
667 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700668 if !m.UseVndk() || !m.IsForPlatform() || !m.installable() {
Inseob Kimae553032019-05-14 18:52:49 +0900669 return nil, "", false
670 }
671 l, ok := m.linker.(vndkSnapshotLibraryInterface)
672 if !ok || !l.shared() {
673 return nil, "", false
674 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900675 if m.vndkVersion() == ctx.DeviceConfig().PlatformVndkVersion() && m.IsVndk() && !m.isVndkExt() {
676 if m.isVndkSp() {
677 return l, "vndk-sp", true
678 } else {
679 return l, "vndk-core", true
680 }
Inseob Kimae553032019-05-14 18:52:49 +0900681 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900682
683 return nil, "", false
Inseob Kimae553032019-05-14 18:52:49 +0900684 }
685
Inseob Kim1f086e22019-05-09 13:29:15 +0900686 ctx.VisitAllModules(func(module android.Module) {
687 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900688 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900689 return
690 }
691
Inseob Kim242ef0c2019-10-22 20:15:20 +0900692 l, vndkType, ok := isVndkSnapshotLibrary(m)
Inseob Kimae553032019-05-14 18:52:49 +0900693 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200694 return
695 }
696
Inseob Kim242ef0c2019-10-22 20:15:20 +0900697 libs, ok := installVndkSnapshotLib(m, l, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900698 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900699 return
700 }
701
Inseob Kim242ef0c2019-10-22 20:15:20 +0900702 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900703
Inseob Kim242ef0c2019-10-22 20:15:20 +0900704 // We glob headers from include directories inside source tree. So we first gather
705 // all include directories inside our source tree. On the contrast, we manually
706 // collect generated headers from dependencies as they can't globbed.
Inseob Kimd110f872019-12-06 13:15:38 +0900707 generatedHeaders = append(generatedHeaders, l.exportedGeneratedHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900708 for _, dir := range append(l.exportedDirs(), l.exportedSystemDirs()...) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900709 exportedIncludes[dir.String()] = true
Inseob Kimae553032019-05-14 18:52:49 +0900710 }
711 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900712
Inseob Kimae553032019-05-14 18:52:49 +0900713 if ctx.Config().VndkSnapshotBuildArtifacts() {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900714 globbedHeaders := make(map[string]bool)
Inseob Kimae553032019-05-14 18:52:49 +0900715
Inseob Kim242ef0c2019-10-22 20:15:20 +0900716 for _, dir := range android.SortedStringKeys(exportedIncludes) {
717 // Skip if dir is for generated headers
Inseob Kimae553032019-05-14 18:52:49 +0900718 if strings.HasPrefix(dir, android.PathForOutput(ctx).String()) {
719 continue
Inseob Kim1f086e22019-05-09 13:29:15 +0900720 }
Inseob Kimae553032019-05-14 18:52:49 +0900721 exts := headerExts
722 // Glob all files under this special directory, because of C++ headers.
723 if strings.HasPrefix(dir, "external/libcxx/include") {
724 exts = []string{""}
Inseob Kim1f086e22019-05-09 13:29:15 +0900725 }
Inseob Kimae553032019-05-14 18:52:49 +0900726 for _, ext := range exts {
727 glob, err := ctx.GlobWithDeps(dir+"/**/*"+ext, nil)
728 if err != nil {
729 ctx.Errorf("%#v\n", err)
730 return
731 }
732 for _, header := range glob {
733 if strings.HasSuffix(header, "/") {
734 continue
735 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900736 globbedHeaders[header] = true
Inseob Kimae553032019-05-14 18:52:49 +0900737 }
738 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900739 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900740
Inseob Kim242ef0c2019-10-22 20:15:20 +0900741 for _, header := range android.SortedStringKeys(globbedHeaders) {
742 snapshotOutputs = append(snapshotOutputs, installSnapshotFileFromPath(
743 android.PathForSource(ctx, header), filepath.Join(includeDir, header)))
Inseob Kimae553032019-05-14 18:52:49 +0900744 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900745
Inseob Kimae553032019-05-14 18:52:49 +0900746 isHeader := func(path string) bool {
747 for _, ext := range headerExts {
748 if strings.HasSuffix(path, ext) {
749 return true
750 }
751 }
752 return false
753 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900754
Inseob Kim242ef0c2019-10-22 20:15:20 +0900755 // For generated headers, manually install one by one, rather than glob
Inseob Kimae553032019-05-14 18:52:49 +0900756 for _, path := range android.PathsToDirectorySortedPaths(android.FirstUniquePaths(generatedHeaders)) {
757 header := path.String()
758
759 if !isHeader(header) {
760 continue
761 }
762
Inseob Kim242ef0c2019-10-22 20:15:20 +0900763 snapshotOutputs = append(snapshotOutputs, installSnapshotFileFromPath(
764 path, filepath.Join(includeDir, header)))
Inseob Kimae553032019-05-14 18:52:49 +0900765 }
766 }
767
Jooyung Han39edb6c2019-11-06 16:53:07 +0900768 // install *.libraries.txt except vndkcorevariant.libraries.txt
769 ctx.VisitAllModules(func(module android.Module) {
770 m, ok := module.(*vndkLibrariesTxt)
771 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
772 return
773 }
774 snapshotOutputs = append(snapshotOutputs, installSnapshotFileFromPath(m.OutputFile(), filepath.Join(configsDir, m.Name())))
775 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900776
Inseob Kim242ef0c2019-10-22 20:15:20 +0900777 /*
778 Dump a map to a list file as:
Inseob Kim1f086e22019-05-09 13:29:15 +0900779
Inseob Kim242ef0c2019-10-22 20:15:20 +0900780 {key1} {value1}
781 {key2} {value2}
782 ...
783 */
784 installMapListFile := func(m map[string]string, path string) android.OutputPath {
785 var txtBuilder strings.Builder
786 for idx, k := range android.SortedStringKeys(m) {
787 if idx > 0 {
788 txtBuilder.WriteString("\\n")
789 }
790 txtBuilder.WriteString(k)
791 txtBuilder.WriteString(" ")
792 txtBuilder.WriteString(m[k])
Inseob Kim1f086e22019-05-09 13:29:15 +0900793 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900794 return installSnapshotFileFromContent(txtBuilder.String(), path)
Inseob Kim1f086e22019-05-09 13:29:15 +0900795 }
796
Inseob Kim242ef0c2019-10-22 20:15:20 +0900797 /*
798 module_paths.txt contains paths on which VNDK modules are defined.
799 e.g.,
800 libbase.so system/core/base
801 libc.so bionic/libc
802 ...
803 */
804 snapshotOutputs = append(snapshotOutputs, installMapListFile(modulePaths, filepath.Join(configsDir, "module_paths.txt")))
805
806 /*
807 module_names.txt contains names as which VNDK modules are defined,
808 because output filename and module name can be different with stem and suffix properties.
809
810 e.g.,
811 libcutils.so libcutils
812 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
813 ...
814 */
815 snapshotOutputs = append(snapshotOutputs, installMapListFile(moduleNames, filepath.Join(configsDir, "module_names.txt")))
816
817 // All artifacts are ready. Sort them to normalize ninja and then zip.
818 sort.Slice(snapshotOutputs, func(i, j int) bool {
819 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
820 })
821
822 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
823 zipRule := android.NewRuleBuilder()
824
825 // If output files are too many, soong_zip command can exceed ARG_MAX.
826 // So first dump file lists into a single list file, and then feed it to Soong
827 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
828 zipRule.Command().
829 Text("( xargs").
830 FlagWithRspFileInputList("-n1 echo < ", snapshotOutputs).
831 FlagWithOutput("| tr -d \\' > ", snapshotOutputList).
832 Text(")")
833
834 zipRule.Temporary(snapshotOutputList)
835
836 zipRule.Command().
837 BuiltTool(ctx, "soong_zip").
838 FlagWithOutput("-o ", zipPath).
839 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
840 FlagWithInput("-l ", snapshotOutputList)
841
842 zipRule.Build(pctx, ctx, zipPath.String(), "vndk snapshot "+zipPath.String())
843 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900844}
Jooyung Han097087b2019-10-22 19:32:18 +0900845
Jooyung Han0302a842019-10-30 18:43:49 +0900846func getVndkFileName(m *Module) (string, error) {
847 if library, ok := m.linker.(*libraryDecorator); ok {
848 return library.getLibNameHelper(m.BaseModuleName(), true) + ".so", nil
849 }
850 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
851 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true) + ".so", nil
852 }
853 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900854}
855
856func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900857 llndk := android.SortedStringMapValues(llndkLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900858 vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
859 vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
860 vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900861
Jooyung Han2216fb12019-11-06 16:46:15 +0900862 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900863 // Since each target have different set of libclang_rt.* files,
864 // keep the common set of files in vndk.libraries.txt
865 var merged []string
Jooyung Han097087b2019-10-22 19:32:18 +0900866 filterOutLibClangRt := func(libList []string) (filtered []string) {
867 for _, lib := range libList {
868 if !strings.HasPrefix(lib, "libclang_rt.") {
869 filtered = append(filtered, lib)
870 }
871 }
872 return
873 }
874 merged = append(merged, addPrefix(filterOutLibClangRt(llndk), "LLNDK: ")...)
875 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
876 merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...)
877 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900878 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
879 ctx.Build(pctx, android.BuildParams{
880 Rule: android.WriteFile,
881 Output: c.vndkLibrariesFile,
882 Description: "Writing " + c.vndkLibrariesFile.String(),
883 Args: map[string]string{
884 "content": strings.Join(merged, "\\n"),
885 },
886 })
Jooyung Han0302a842019-10-30 18:43:49 +0900887}
Jooyung Han097087b2019-10-22 19:32:18 +0900888
Jooyung Han0302a842019-10-30 18:43:49 +0900889func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
890 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
891 // they been moved to an apex.
892 movedToApexLlndkLibraries := []string{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900893 for lib := range llndkLibraries(ctx.Config()) {
Jooyung Han0302a842019-10-30 18:43:49 +0900894 // Skip bionic libs, they are handled in different manner
895 if android.DirectlyInAnyApex(&notOnHostContext{}, lib) && !isBionic(lib) {
896 movedToApexLlndkLibraries = append(movedToApexLlndkLibraries, lib)
897 }
898 }
899 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", strings.Join(movedToApexLlndkLibraries, " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900900
901 // Make uses LLNDK_LIBRARIES to determine which libraries to install.
902 // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
903 // Therefore, by removing the library here, we cause it to only be installed if libc
904 // depends on it.
905 installedLlndkLibraries := []string{}
906 for lib := range llndkLibraries(ctx.Config()) {
907 if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
908 continue
909 }
910 installedLlndkLibraries = append(installedLlndkLibraries, lib)
911 }
912 sort.Strings(installedLlndkLibraries)
913 ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
914
Jooyung Han0302a842019-10-30 18:43:49 +0900915 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkCoreLibraries(ctx.Config())), " "))
916 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(android.SortedStringKeys(vndkSpLibraries(ctx.Config())), " "))
917 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())), " "))
918 ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(android.SortedStringKeys(vndkUsingCoreVariantLibraries(ctx.Config())), " "))
919
Jooyung Han0302a842019-10-30 18:43:49 +0900920 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900921 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900922}