blob: 6bc7131355dfcc166f0ff592c0a7a603affc9a0c [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"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028 "android/soong/etc"
Colin Cross6e511a92020-07-27 21:26:48 -070029
30 "github.com/google/blueprint"
Justin Yun8effde42017-06-23 19:24:43 +090031)
32
Jooyung Han39edb6c2019-11-06 16:53:07 +090033const (
34 llndkLibrariesTxt = "llndk.libraries.txt"
35 vndkCoreLibrariesTxt = "vndkcore.libraries.txt"
36 vndkSpLibrariesTxt = "vndksp.libraries.txt"
37 vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt"
38 vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt"
39)
40
41func VndkLibrariesTxtModules(vndkVersion string) []string {
42 if vndkVersion == "current" {
43 return []string{
44 llndkLibrariesTxt,
45 vndkCoreLibrariesTxt,
46 vndkSpLibrariesTxt,
47 vndkPrivateLibrariesTxt,
Jooyung Han39edb6c2019-11-06 16:53:07 +090048 }
49 }
50 // Snapshot vndks have their own *.libraries.VER.txt files.
51 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
52 return []string{
53 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
54 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
55 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
56 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
57 }
58}
59
Justin Yun8effde42017-06-23 19:24:43 +090060type VndkProperties struct {
61 Vndk struct {
62 // declared as a VNDK or VNDK-SP module. The vendor variant
63 // will be installed in /system instead of /vendor partition.
64 //
Justin Yun63e9ec72020-10-29 16:49:43 +090065 // `vendor_available` and `product_available` must be explicitly
66 // set to either true or false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090067 Enabled *bool
68
69 // declared as a VNDK-SP module, which is a subset of VNDK.
70 //
71 // `vndk: { enabled: true }` must set together.
72 //
73 // All these modules are allowed to link to VNDK-SP or LL-NDK
74 // modules only. Other dependency will cause link-type errors.
75 //
76 // If `support_system_process` is not set or set to false,
77 // the module is VNDK-core and can link to other VNDK-core,
78 // VNDK-SP or LL-NDK modules only.
79 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080080
Justin Yunfd9e8042020-12-23 18:23:14 +090081 // declared as a VNDK-private module.
82 // This module still creates the vendor and product variants refering
83 // to the `vendor_available: true` and `product_available: true`
84 // properties. However, it is only available to the other VNDK modules
85 // but not to the non-VNDK vendor or product modules.
86 Private *bool
87
Logan Chienf3511742017-10-31 18:04:35 +080088 // Extending another module
89 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090090 }
91}
92
93type vndkdep struct {
94 Properties VndkProperties
95}
96
97func (vndk *vndkdep) props() []interface{} {
98 return []interface{}{&vndk.Properties}
99}
100
101func (vndk *vndkdep) begin(ctx BaseModuleContext) {}
102
103func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps {
104 return deps
105}
106
107func (vndk *vndkdep) isVndk() bool {
108 return Bool(vndk.Properties.Vndk.Enabled)
109}
110
111func (vndk *vndkdep) isVndkSp() bool {
112 return Bool(vndk.Properties.Vndk.Support_system_process)
113}
114
Logan Chienf3511742017-10-31 18:04:35 +0800115func (vndk *vndkdep) isVndkExt() bool {
116 return vndk.Properties.Vndk.Extends != nil
117}
118
119func (vndk *vndkdep) getVndkExtendsModuleName() string {
120 return String(vndk.Properties.Vndk.Extends)
121}
122
Justin Yun8effde42017-06-23 19:24:43 +0900123func (vndk *vndkdep) typeName() string {
124 if !vndk.isVndk() {
125 return "native:vendor"
126 }
Logan Chienf3511742017-10-31 18:04:35 +0800127 if !vndk.isVndkExt() {
128 if !vndk.isVndkSp() {
129 return "native:vendor:vndk"
130 }
131 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900132 }
Logan Chienf3511742017-10-31 18:04:35 +0800133 if !vndk.isVndkSp() {
134 return "native:vendor:vndkext"
135 }
136 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900137}
138
Justin Yun63e9ec72020-10-29 16:49:43 +0900139// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900140func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900141 if to.linker == nil {
142 return
143 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900144 if !vndk.isVndk() {
Justin Yunfd9e8042020-12-23 18:23:14 +0900145 // Non-VNDK modules those installed to /vendor, /system/vendor,
146 // /product or /system/product cannot depend on VNDK-private modules
147 // that include VNDK-core-private, VNDK-SP-private and LLNDK-private.
148 if to.IsVndkPrivate() {
149 ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name())
Jiyong Park82e2bf32017-08-16 14:05:54 +0900150 }
151 }
Justin Yun8effde42017-06-23 19:24:43 +0900152 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
153 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800154 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900155 return
156 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800157
158 if to.IsLlndk() {
159 // LL-NDK libraries are allowed to link
160 return
161 }
162
Ivan Lozano52767be2019-10-18 14:49:46 -0700163 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900164 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
165 vndk.typeName(), to.Name())
166 return
167 }
Logan Chienf3511742017-10-31 18:04:35 +0800168 if tag == vndkExtDepTag {
169 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
170 // and has identical vndk properties.
171 if to.vndkdep == nil || !to.vndkdep.isVndk() {
172 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
173 return
174 }
175 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
176 ctx.ModuleErrorf(
177 "`extends` refers a module %q with mismatched support_system_process",
178 to.Name())
179 return
180 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900181 if to.IsVndkPrivate() {
Logan Chienf3511742017-10-31 18:04:35 +0800182 ctx.ModuleErrorf(
Justin Yunfd9e8042020-12-23 18:23:14 +0900183 "`extends` refers module %q which has `private: true`",
Justin Yun6977e8a2020-10-29 18:24:11 +0900184 to.Name())
185 return
186 }
Logan Chienf3511742017-10-31 18:04:35 +0800187 }
Justin Yun8effde42017-06-23 19:24:43 +0900188 if to.vndkdep == nil {
189 return
190 }
Logan Chienf3511742017-10-31 18:04:35 +0800191
Logan Chiend3c59a22018-03-29 14:08:15 +0800192 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100193 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
194 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
195 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800196 return
197 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800198}
Logan Chienf3511742017-10-31 18:04:35 +0800199
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100200func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800201 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
202 if from.isVndkExt() {
203 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100204 if to.isVndk() && !to.isVndkSp() {
205 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
206 }
207 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800208 }
209 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100210 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900211 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800212 if from.isVndk() {
213 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100214 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800215 }
216 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100217 if !to.isVndkSp() {
218 return errors.New("VNDK-SP must only depend on VNDK-SP")
219 }
220 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800221 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100222 if !to.isVndk() {
223 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
224 }
225 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800226 }
227 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100228 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900229}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900230
231var (
Jooyung Hana463f722019-11-01 08:45:59 +0900232 vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires")
233 vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires")
234 llndkLibrariesKey = android.NewOnceKey("llndkLibrarires")
235 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900236 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibraries")
Jooyung Hana463f722019-11-01 08:45:59 +0900237 vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
238 vndkLibrariesLock sync.Mutex
Inseob Kimae553032019-05-14 18:52:49 +0900239)
Inseob Kim1f086e22019-05-09 13:29:15 +0900240
Jooyung Han0302a842019-10-30 18:43:49 +0900241func vndkCoreLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900242 return config.Once(vndkCoreLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900243 return make(map[string]string)
244 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900245}
246
Jooyung Han0302a842019-10-30 18:43:49 +0900247func vndkSpLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900248 return config.Once(vndkSpLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900249 return make(map[string]string)
250 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900251}
252
Jooyung Han0302a842019-10-30 18:43:49 +0900253func 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 vndkPrivateLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900260 return config.Once(vndkPrivateLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900261 return make(map[string]string)
262 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900263}
264
Jooyung Han0302a842019-10-30 18:43:49 +0900265func vndkUsingCoreVariantLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900266 return config.Once(vndkUsingCoreVariantLibrariesKey, 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 Han097087b2019-10-22 19:32:18 +0900271func vndkMustUseVendorVariantList(cfg android.Config) []string {
272 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900273 return config.VndkMustUseVendorVariantList
274 }).([]string)
275}
276
277// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
278// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
279func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900280 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900281 return mustUseVendorVariantList
282 })
283}
284
Inseob Kim1f086e22019-05-09 13:29:15 +0900285func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
286 lib := m.linker.(*llndkStubDecorator)
Colin Cross0477b422020-10-13 18:43:54 -0700287 name := m.ImplementationModuleName(mctx)
288 filename := name + ".so"
Inseob Kim9516ee92019-05-09 10:56:13 +0900289
Inseob Kim1f086e22019-05-09 13:29:15 +0900290 vndkLibrariesLock.Lock()
291 defer vndkLibrariesLock.Unlock()
Inseob Kim9516ee92019-05-09 10:56:13 +0900292
Jooyung Han0302a842019-10-30 18:43:49 +0900293 llndkLibraries(mctx.Config())[name] = filename
Colin Cross127bb8b2020-12-16 16:46:01 -0800294 m.VendorProperties.IsLLNDK = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900295 if !Bool(lib.Properties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900296 vndkPrivateLibraries(mctx.Config())[name] = filename
Colin Cross127bb8b2020-12-16 16:46:01 -0800297 m.VendorProperties.IsLLNDKPrivate = true
Jooyung Han61b66e92020-03-21 14:21:46 +0000298 }
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900299}
Inseob Kim1f086e22019-05-09 13:29:15 +0900300
301func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Jooyung Han0302a842019-10-30 18:43:49 +0900302 name := m.BaseModuleName()
303 filename, err := getVndkFileName(m)
304 if err != nil {
305 panic(err)
306 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900307
Colin Cross31076b32020-10-23 17:22:06 -0700308 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000309 // b/155456180 libz is the ONLY exception here. We don't want to make
310 // libz an LLNDK library because we in general can't guarantee that
311 // libz will behave consistently especially about the compression.
312 // i.e. the compressed output might be different across releases.
313 // As the library is an external one, it's risky to keep the compatibility
314 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900315 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
316 }
317
Inseob Kim1f086e22019-05-09 13:29:15 +0900318 vndkLibrariesLock.Lock()
319 defer vndkLibrariesLock.Unlock()
320
Justin Yun6977e8a2020-10-29 18:24:11 +0900321 if m.InProduct() {
322 // We may skip the other steps for the product variants because they
323 // are already covered by the vendor variants.
324 return
325 }
326
Jooyung Han097087b2019-10-22 19:32:18 +0900327 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
328 m.Properties.MustUseVendorVariant = true
329 }
Jooyung Han0302a842019-10-30 18:43:49 +0900330 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
331 vndkUsingCoreVariantLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900332 }
Jooyung Han0302a842019-10-30 18:43:49 +0900333
Inseob Kim1f086e22019-05-09 13:29:15 +0900334 if m.vndkdep.isVndkSp() {
Jooyung Han0302a842019-10-30 18:43:49 +0900335 vndkSpLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900336 } else {
Jooyung Han0302a842019-10-30 18:43:49 +0900337 vndkCoreLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900338 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900339 if m.IsVndkPrivate() {
Jooyung Han0302a842019-10-30 18:43:49 +0900340 vndkPrivateLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900341 }
342}
343
Yo Chiang08fac0c2020-07-29 01:08:20 +0800344// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800345func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900346 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800347 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900348 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800349 if !m.Device() {
350 // Skip non-device modules
351 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900352 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900353 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800354 // Skip native_bridge modules
355 return true
356 }
357 return false
358}
359
360func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
361 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900362 return false
363 }
364
365 // prebuilt vndk modules should match with device
366 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
367 // When b/142675459 is landed, remove following check
368 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) {
369 return false
370 }
371
372 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han73d20d02020-03-27 16:06:55 +0900373 // VNDK APEX for VNDK-Lite devices will have VNDK-SP libraries from core variants
374 if mctx.DeviceConfig().VndkVersion() == "" {
375 // b/73296261: filter out libz.so because it is considered as LLNDK for VNDK-lite devices
376 if mctx.ModuleName() == "libz" {
377 return false
378 }
379 return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.isVndkSp()
380 }
381
Justin Yun5f7f7e82019-11-18 19:52:14 +0900382 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900383 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozanof9e21722020-12-02 09:00:51 -0500384 return lib.shared() && m.inVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900385 }
386 return false
387}
388
Inseob Kim1f086e22019-05-09 13:29:15 +0900389// gather list of vndk-core, vndk-sp, and ll-ndk libs
390func VndkMutator(mctx android.BottomUpMutatorContext) {
391 m, ok := mctx.Module().(*Module)
392 if !ok {
393 return
394 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800395
396 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900397 return
398 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900399
400 if _, ok := m.linker.(*llndkStubDecorator); ok {
401 processLlndkLibrary(mctx, m)
402 return
403 }
404
Colin Cross127bb8b2020-12-16 16:46:01 -0800405 // This is a temporary measure to copy the properties from an llndk_library into the cc_library
406 // that will actually build the stubs. It will be removed once the properties are moved into
407 // the cc_library in the Android.bp files.
408 mergeLLNDKToLib := func(llndk *Module, llndkProperties *llndkLibraryProperties, flagExporter *flagExporter) {
409 if llndkLib := moduleLibraryInterface(llndk); llndkLib != nil {
410 *llndkProperties = llndkLib.(*llndkStubDecorator).Properties
411 flagExporter.Properties = llndkLib.(*llndkStubDecorator).flagExporter.Properties
412
413 m.VendorProperties.IsLLNDK = llndk.VendorProperties.IsLLNDK
414 m.VendorProperties.IsLLNDKPrivate = llndk.VendorProperties.IsLLNDKPrivate
415 }
416 }
417
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800418 lib, isLib := m.linker.(*libraryDecorator)
419 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900420
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800421 if m.UseVndk() && isLib && lib.hasLLNDKStubs() {
Colin Cross127bb8b2020-12-16 16:46:01 -0800422 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(lib.Properties.Llndk_stubs))
423 mergeLLNDKToLib(llndk[0].(*Module), &lib.Properties.Llndk, &lib.flagExporter)
424 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800425 if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
426 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(prebuiltLib.Properties.Llndk_stubs))
427 mergeLLNDKToLib(llndk[0].(*Module), &prebuiltLib.Properties.Llndk, &prebuiltLib.flagExporter)
Colin Cross127bb8b2020-12-16 16:46:01 -0800428 }
429
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800430 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900431 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900432 processVndkLibrary(mctx, m)
433 return
434 }
435 }
436}
437
438func init() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900439 android.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Inseob Kim1f086e22019-05-09 13:29:15 +0900440 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900441}
442
Jooyung Han2216fb12019-11-06 16:46:15 +0900443type vndkLibrariesTxt struct {
444 android.ModuleBase
445 outputFile android.OutputPath
446}
447
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700448var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900449var _ android.OutputFileProducer = &vndkLibrariesTxt{}
450
Jooyung Han2216fb12019-11-06 16:46:15 +0900451// vndk_libraries_txt is a special kind of module type in that it name is one of
452// - llndk.libraries.txt
453// - vndkcore.libraries.txt
454// - vndksp.libraries.txt
455// - vndkprivate.libraries.txt
456// - vndkcorevariant.libraries.txt
457// A module behaves like a prebuilt_etc but its content is generated by soong.
458// By being a soong module, these files can be referenced by other soong modules.
459// For example, apex_vndk can depend on these files as prebuilt.
Jooyung Han39edb6c2019-11-06 16:53:07 +0900460func VndkLibrariesTxtFactory() android.Module {
Jooyung Han2216fb12019-11-06 16:46:15 +0900461 m := &vndkLibrariesTxt{}
462 android.InitAndroidModule(m)
463 return m
464}
465
466func insertVndkVersion(filename string, vndkVersion string) string {
467 if index := strings.LastIndex(filename, "."); index != -1 {
468 return filename[:index] + "." + vndkVersion + filename[index:]
469 }
470 return filename
471}
472
473func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
474 var list []string
475 switch txt.Name() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900476 case llndkLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900477 for _, filename := range android.SortedStringMapValues(llndkLibraries(ctx.Config())) {
478 if strings.HasPrefix(filename, "libclang_rt.hwasan-") {
479 continue
480 }
481 list = append(list, filename)
482 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900483 case vndkCoreLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900484 list = android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900485 case vndkSpLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900486 list = android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900487 case vndkPrivateLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900488 list = android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900489 case vndkUsingCoreVariantLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900490 list = android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config()))
491 default:
492 ctx.ModuleErrorf("name(%s) is unknown.", txt.Name())
493 return
494 }
495
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900496 var filename string
497 if txt.Name() != vndkUsingCoreVariantLibrariesTxt {
498 filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
499 } else {
500 filename = txt.Name()
501 }
502
Jooyung Han2216fb12019-11-06 16:46:15 +0900503 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Colin Crosscf371cc2020-11-13 11:48:42 -0800504 android.WriteFileRule(ctx, txt.outputFile, strings.Join(list, "\n"))
Jooyung Han2216fb12019-11-06 16:46:15 +0900505
506 installPath := android.PathForModuleInstall(ctx, "etc")
507 ctx.InstallFile(installPath, filename, txt.outputFile)
508}
509
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900510func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
511 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900512 Class: "ETC",
513 OutputFile: android.OptionalPathForPath(txt.outputFile),
514 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
515 func(entries *android.AndroidMkEntries) {
516 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
517 },
518 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900519 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900520}
521
Jooyung Han0703fd82020-08-26 22:11:53 +0900522// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900523func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
524 return txt.outputFile
525}
526
Jooyung Han0703fd82020-08-26 22:11:53 +0900527// PrebuiltEtcModule interface
528func (txt *vndkLibrariesTxt) BaseDir() string {
529 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900530}
531
Jooyung Han0703fd82020-08-26 22:11:53 +0900532// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900533func (txt *vndkLibrariesTxt) SubDir() string {
534 return ""
535}
536
Jooyung Han0703fd82020-08-26 22:11:53 +0900537func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
538 return android.Paths{txt.outputFile}, nil
539}
540
Inseob Kim1f086e22019-05-09 13:29:15 +0900541func VndkSnapshotSingleton() android.Singleton {
542 return &vndkSnapshotSingleton{}
543}
544
Jooyung Han0302a842019-10-30 18:43:49 +0900545type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900546 vndkLibrariesFile android.OutputPath
547 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900548}
Inseob Kim1f086e22019-05-09 13:29:15 +0900549
Inseob Kimde5744a2020-12-02 13:14:28 +0900550func isVndkSnapshotAware(config android.DeviceConfig, m *Module,
Colin Cross56a83212020-09-15 18:30:11 -0700551 apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
552
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900553 if m.Target().NativeBridge == android.NativeBridgeEnabled {
554 return nil, "", false
555 }
Jooyung Han261e1582020-10-20 18:54:21 +0900556 // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
557 // !installable: Snapshot only cares about "installable" modules.
558 // isSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
Colin Cross56a83212020-09-15 18:30:11 -0700559 if !m.inVendor() || !m.installable(apexInfo) || m.isSnapshotPrebuilt() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900560 return nil, "", false
561 }
562 l, ok := m.linker.(snapshotLibraryInterface)
563 if !ok || !l.shared() {
564 return nil, "", false
565 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500566 if m.VndkVersion() == config.PlatformVndkVersion() && m.IsVndk() && !m.IsVndkExt() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900567 if m.isVndkSp() {
568 return l, "vndk-sp", true
569 } else {
570 return l, "vndk-core", true
571 }
572 }
573
574 return nil, "", false
575}
576
Inseob Kim1f086e22019-05-09 13:29:15 +0900577func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900578 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
579 c.buildVndkLibrariesTxtFiles(ctx)
580
Inseob Kim1f086e22019-05-09 13:29:15 +0900581 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
582 if ctx.DeviceConfig().VndkVersion() != "current" {
583 return
584 }
585
586 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
587 return
588 }
589
Inseob Kim242ef0c2019-10-22 20:15:20 +0900590 var snapshotOutputs android.Paths
591
592 /*
593 VNDK snapshot zipped artifacts directory structure:
594 {SNAPSHOT_ARCH}/
595 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
596 shared/
597 vndk-core/
598 (VNDK-core libraries, e.g. libbinder.so)
599 vndk-sp/
600 (VNDK-SP libraries, e.g. libc++.so)
601 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
602 shared/
603 vndk-core/
604 (VNDK-core libraries, e.g. libbinder.so)
605 vndk-sp/
606 (VNDK-SP libraries, e.g. libc++.so)
607 binder32/
608 (This directory is newly introduced in v28 (Android P) to hold
609 prebuilts built for 32-bit binder interface.)
610 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
611 ...
612 configs/
613 (various *.txt configuration files)
614 include/
615 (header files of same directory structure with source tree)
616 NOTICE_FILES/
617 (notice files of libraries, e.g. libcutils.so.txt)
618 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900619
620 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900621 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900622
Inseob Kim242ef0c2019-10-22 20:15:20 +0900623 configsDir := filepath.Join(snapshotArchDir, "configs")
624 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
625 includeDir := filepath.Join(snapshotArchDir, "include")
626
Inseob Kim242ef0c2019-10-22 20:15:20 +0900627 // set of notice files copied.
Inseob Kim1f086e22019-05-09 13:29:15 +0900628 noticeBuilt := make(map[string]bool)
629
Inseob Kim242ef0c2019-10-22 20:15:20 +0900630 // paths of VNDK modules for GPL license checking
631 modulePaths := make(map[string]string)
632
633 // actual module names of .so files
634 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
635 moduleNames := make(map[string]string)
636
Inseob Kim8471cda2019-11-15 09:59:12 +0900637 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900638
Inseob Kimde5744a2020-12-02 13:14:28 +0900639 // installVndkSnapshotLib copies built .so file from the module.
640 // Also, if the build artifacts is on, write a json file which contains all exported flags
641 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700642 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900643 var ret android.Paths
644
Inseob Kim8471cda2019-11-15 09:59:12 +0900645 targetArch := "arch-" + m.Target().Arch.ArchType.String()
646 if m.Target().Arch.ArchVariant != "" {
647 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900648 }
Inseob Kimae553032019-05-14 18:52:49 +0900649
Inseob Kim8471cda2019-11-15 09:59:12 +0900650 libPath := m.outputFile.Path()
651 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Inseob Kimde5744a2020-12-02 13:14:28 +0900652 ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900653
Inseob Kimae553032019-05-14 18:52:49 +0900654 if ctx.Config().VndkSnapshotBuildArtifacts() {
655 prop := struct {
656 ExportedDirs []string `json:",omitempty"`
657 ExportedSystemDirs []string `json:",omitempty"`
658 ExportedFlags []string `json:",omitempty"`
659 RelativeInstallPath string `json:",omitempty"`
660 }{}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700661 exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
662 prop.ExportedFlags = exportedInfo.Flags
663 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
664 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900665 prop.RelativeInstallPath = m.RelativeInstallPath()
666
Inseob Kim242ef0c2019-10-22 20:15:20 +0900667 propOut := snapshotLibOut + ".json"
Inseob Kimae553032019-05-14 18:52:49 +0900668
669 j, err := json.Marshal(prop)
670 if err != nil {
671 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900672 return nil, false
Inseob Kimae553032019-05-14 18:52:49 +0900673 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900674 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kimae553032019-05-14 18:52:49 +0900675 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900676 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900677 }
678
Inseob Kim1f086e22019-05-09 13:29:15 +0900679 ctx.VisitAllModules(func(module android.Module) {
680 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900681 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900682 return
683 }
684
Colin Cross56a83212020-09-15 18:30:11 -0700685 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
686
Inseob Kimde5744a2020-12-02 13:14:28 +0900687 l, vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900688 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200689 return
690 }
691
Inseob Kimde5744a2020-12-02 13:14:28 +0900692 // For all snapshot candidates, the followings are captured.
693 // - .so files
694 // - notice files
695 //
696 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
697 // - .json files containing exported flags
698 // - exported headers from collectHeadersForSnapshot()
699 //
700 // Headers are deduplicated after visiting all modules.
701
Inseob Kim8471cda2019-11-15 09:59:12 +0900702 // install .so files for appropriate modules.
703 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700704 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900705 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900706 return
707 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900708 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900709
Inseob Kim8471cda2019-11-15 09:59:12 +0900710 // These are for generating module_names.txt and module_paths.txt
711 stem := m.outputFile.Path().Base()
712 moduleNames[stem] = ctx.ModuleName(m)
713 modulePaths[stem] = ctx.ModuleDir(m)
714
Bob Badoura75b0572020-02-18 20:21:55 -0800715 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900716 noticeName := stem + ".txt"
717 // skip already copied notice file
718 if _, ok := noticeBuilt[noticeName]; !ok {
719 noticeBuilt[noticeName] = true
Inseob Kimde5744a2020-12-02 13:14:28 +0900720 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
Bob Badoura75b0572020-02-18 20:21:55 -0800721 ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName)))
Inseob Kim8471cda2019-11-15 09:59:12 +0900722 }
723 }
724
725 if ctx.Config().VndkSnapshotBuildArtifacts() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900726 headers = append(headers, l.snapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900727 }
728 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900729
Inseob Kim8471cda2019-11-15 09:59:12 +0900730 // install all headers after removing duplicates
731 for _, header := range android.FirstUniquePaths(headers) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900732 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900733 ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900734 }
735
Jooyung Han39edb6c2019-11-06 16:53:07 +0900736 // install *.libraries.txt except vndkcorevariant.libraries.txt
737 ctx.VisitAllModules(func(module android.Module) {
738 m, ok := module.(*vndkLibrariesTxt)
739 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
740 return
741 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900742 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900743 ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900744 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900745
Inseob Kim242ef0c2019-10-22 20:15:20 +0900746 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900747 module_paths.txt contains paths on which VNDK modules are defined.
748 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000749 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900750 libc.so bionic/libc
751 ...
752 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900753 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900754
755 /*
756 module_names.txt contains names as which VNDK modules are defined,
757 because output filename and module name can be different with stem and suffix properties.
758
759 e.g.,
760 libcutils.so libcutils
761 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
762 ...
763 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900764 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900765
766 // All artifacts are ready. Sort them to normalize ninja and then zip.
767 sort.Slice(snapshotOutputs, func(i, j int) bool {
768 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
769 })
770
771 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800772 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900773
Inseob Kimde5744a2020-12-02 13:14:28 +0900774 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900775 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
776 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900777 Text("tr").
778 FlagWithArg("-d ", "\\'").
779 FlagWithRspFileInputList("< ", snapshotOutputs).
780 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900781
782 zipRule.Temporary(snapshotOutputList)
783
784 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800785 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900786 FlagWithOutput("-o ", zipPath).
787 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
788 FlagWithInput("-l ", snapshotOutputList)
789
Colin Crossf1a035e2020-11-16 17:32:30 -0800790 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900791 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900792 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900793}
Jooyung Han097087b2019-10-22 19:32:18 +0900794
Jooyung Han0302a842019-10-30 18:43:49 +0900795func getVndkFileName(m *Module) (string, error) {
796 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900797 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900798 }
799 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900800 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900801 }
802 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900803}
804
805func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900806 llndk := android.SortedStringMapValues(llndkLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900807 vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
808 vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
809 vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900810
Jooyung Han2216fb12019-11-06 16:46:15 +0900811 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900812 // Since each target have different set of libclang_rt.* files,
813 // keep the common set of files in vndk.libraries.txt
814 var merged []string
Jooyung Han097087b2019-10-22 19:32:18 +0900815 filterOutLibClangRt := func(libList []string) (filtered []string) {
816 for _, lib := range libList {
817 if !strings.HasPrefix(lib, "libclang_rt.") {
818 filtered = append(filtered, lib)
819 }
820 }
821 return
822 }
823 merged = append(merged, addPrefix(filterOutLibClangRt(llndk), "LLNDK: ")...)
824 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
825 merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...)
826 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900827 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800828 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900829}
Jooyung Han097087b2019-10-22 19:32:18 +0900830
Jooyung Han0302a842019-10-30 18:43:49 +0900831func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
832 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
833 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700834 movedToApexLlndkLibraries := make(map[string]bool)
835 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800836 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
837 // Skip bionic libs, they are handled in different manner
838 name := library.implementationModuleName(module.(*Module).BaseModuleName())
839 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
840 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700841 }
Jooyung Han0302a842019-10-30 18:43:49 +0900842 }
Colin Cross56a83212020-09-15 18:30:11 -0700843 })
844
845 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
846 strings.Join(android.SortedStringKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900847
848 // Make uses LLNDK_LIBRARIES to determine which libraries to install.
849 // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
850 // Therefore, by removing the library here, we cause it to only be installed if libc
851 // depends on it.
852 installedLlndkLibraries := []string{}
853 for lib := range llndkLibraries(ctx.Config()) {
854 if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
855 continue
856 }
857 installedLlndkLibraries = append(installedLlndkLibraries, lib)
858 }
859 sort.Strings(installedLlndkLibraries)
860 ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
861
Jooyung Han0302a842019-10-30 18:43:49 +0900862 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkCoreLibraries(ctx.Config())), " "))
863 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(android.SortedStringKeys(vndkSpLibraries(ctx.Config())), " "))
864 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())), " "))
865 ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(android.SortedStringKeys(vndkUsingCoreVariantLibraries(ctx.Config())), " "))
866
Jooyung Han0302a842019-10-30 18:43:49 +0900867 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900868 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900869}