blob: 2071a03021400545ddd1941d2d565129e7d65fb2 [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"
Justin Yun8a2600c2020-12-07 12:44:03 +090038 vndkProductLibrariesTxt = "vndkproduct.libraries.txt"
Jooyung Han39edb6c2019-11-06 16:53:07 +090039 vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt"
40)
41
42func VndkLibrariesTxtModules(vndkVersion string) []string {
43 if vndkVersion == "current" {
44 return []string{
45 llndkLibrariesTxt,
46 vndkCoreLibrariesTxt,
47 vndkSpLibrariesTxt,
48 vndkPrivateLibrariesTxt,
Justin Yun8a2600c2020-12-07 12:44:03 +090049 vndkProductLibrariesTxt,
Jooyung Han39edb6c2019-11-06 16:53:07 +090050 }
51 }
52 // Snapshot vndks have their own *.libraries.VER.txt files.
53 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
54 return []string{
55 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
56 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
57 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
58 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
Justin Yun8a2600c2020-12-07 12:44:03 +090059 insertVndkVersion(vndkProductLibrariesTxt, vndkVersion),
Jooyung Han39edb6c2019-11-06 16:53:07 +090060 }
61}
62
Justin Yun8effde42017-06-23 19:24:43 +090063type VndkProperties struct {
64 Vndk struct {
65 // declared as a VNDK or VNDK-SP module. The vendor variant
66 // will be installed in /system instead of /vendor partition.
67 //
Justin Yun63e9ec72020-10-29 16:49:43 +090068 // `vendor_available` and `product_available` must be explicitly
69 // set to either true or false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090070 Enabled *bool
71
72 // declared as a VNDK-SP module, which is a subset of VNDK.
73 //
74 // `vndk: { enabled: true }` must set together.
75 //
76 // All these modules are allowed to link to VNDK-SP or LL-NDK
77 // modules only. Other dependency will cause link-type errors.
78 //
79 // If `support_system_process` is not set or set to false,
80 // the module is VNDK-core and can link to other VNDK-core,
81 // VNDK-SP or LL-NDK modules only.
82 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080083
Justin Yunfd9e8042020-12-23 18:23:14 +090084 // declared as a VNDK-private module.
85 // This module still creates the vendor and product variants refering
86 // to the `vendor_available: true` and `product_available: true`
87 // properties. However, it is only available to the other VNDK modules
88 // but not to the non-VNDK vendor or product modules.
89 Private *bool
90
Logan Chienf3511742017-10-31 18:04:35 +080091 // Extending another module
92 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090093 }
94}
95
96type vndkdep struct {
97 Properties VndkProperties
98}
99
100func (vndk *vndkdep) props() []interface{} {
101 return []interface{}{&vndk.Properties}
102}
103
104func (vndk *vndkdep) begin(ctx BaseModuleContext) {}
105
106func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps {
107 return deps
108}
109
110func (vndk *vndkdep) isVndk() bool {
111 return Bool(vndk.Properties.Vndk.Enabled)
112}
113
114func (vndk *vndkdep) isVndkSp() bool {
115 return Bool(vndk.Properties.Vndk.Support_system_process)
116}
117
Logan Chienf3511742017-10-31 18:04:35 +0800118func (vndk *vndkdep) isVndkExt() bool {
119 return vndk.Properties.Vndk.Extends != nil
120}
121
122func (vndk *vndkdep) getVndkExtendsModuleName() string {
123 return String(vndk.Properties.Vndk.Extends)
124}
125
Justin Yun8effde42017-06-23 19:24:43 +0900126func (vndk *vndkdep) typeName() string {
127 if !vndk.isVndk() {
128 return "native:vendor"
129 }
Logan Chienf3511742017-10-31 18:04:35 +0800130 if !vndk.isVndkExt() {
131 if !vndk.isVndkSp() {
132 return "native:vendor:vndk"
133 }
134 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900135 }
Logan Chienf3511742017-10-31 18:04:35 +0800136 if !vndk.isVndkSp() {
137 return "native:vendor:vndkext"
138 }
139 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900140}
141
Justin Yun63e9ec72020-10-29 16:49:43 +0900142// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900143func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900144 if to.linker == nil {
145 return
146 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900147 if !vndk.isVndk() {
Justin Yunfd9e8042020-12-23 18:23:14 +0900148 // Non-VNDK modules those installed to /vendor, /system/vendor,
149 // /product or /system/product cannot depend on VNDK-private modules
150 // that include VNDK-core-private, VNDK-SP-private and LLNDK-private.
151 if to.IsVndkPrivate() {
152 ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name())
Jiyong Park82e2bf32017-08-16 14:05:54 +0900153 }
154 }
Justin Yun8effde42017-06-23 19:24:43 +0900155 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
156 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800157 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900158 return
159 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800160
161 if to.IsLlndk() {
162 // LL-NDK libraries are allowed to link
163 return
164 }
165
Ivan Lozano52767be2019-10-18 14:49:46 -0700166 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900167 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
168 vndk.typeName(), to.Name())
169 return
170 }
Logan Chienf3511742017-10-31 18:04:35 +0800171 if tag == vndkExtDepTag {
172 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
173 // and has identical vndk properties.
174 if to.vndkdep == nil || !to.vndkdep.isVndk() {
175 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
176 return
177 }
178 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
179 ctx.ModuleErrorf(
180 "`extends` refers a module %q with mismatched support_system_process",
181 to.Name())
182 return
183 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900184 if to.IsVndkPrivate() {
Logan Chienf3511742017-10-31 18:04:35 +0800185 ctx.ModuleErrorf(
Justin Yunfd9e8042020-12-23 18:23:14 +0900186 "`extends` refers module %q which has `private: true`",
Justin Yun6977e8a2020-10-29 18:24:11 +0900187 to.Name())
188 return
189 }
Logan Chienf3511742017-10-31 18:04:35 +0800190 }
Justin Yun8effde42017-06-23 19:24:43 +0900191 if to.vndkdep == nil {
192 return
193 }
Logan Chienf3511742017-10-31 18:04:35 +0800194
Logan Chiend3c59a22018-03-29 14:08:15 +0800195 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100196 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
197 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
198 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800199 return
200 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800201}
Logan Chienf3511742017-10-31 18:04:35 +0800202
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100203func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800204 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
205 if from.isVndkExt() {
206 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100207 if to.isVndk() && !to.isVndkSp() {
208 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
209 }
210 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800211 }
212 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100213 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900214 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800215 if from.isVndk() {
216 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100217 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800218 }
219 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100220 if !to.isVndkSp() {
221 return errors.New("VNDK-SP must only depend on VNDK-SP")
222 }
223 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800224 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100225 if !to.isVndk() {
226 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
227 }
228 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800229 }
230 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100231 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900232}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900233
234var (
Justin Yun8a2600c2020-12-07 12:44:03 +0900235 vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibraries")
236 vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibraries")
237 llndkLibrariesKey = android.NewOnceKey("llndkLibraries")
238 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibraries")
239 vndkProductLibrariesKey = android.NewOnceKey("vndkProductLibraries")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900240 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibraries")
Jooyung Hana463f722019-11-01 08:45:59 +0900241 vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
242 vndkLibrariesLock sync.Mutex
Inseob Kimae553032019-05-14 18:52:49 +0900243)
Inseob Kim1f086e22019-05-09 13:29:15 +0900244
Jooyung Han0302a842019-10-30 18:43:49 +0900245func vndkCoreLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900246 return config.Once(vndkCoreLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900247 return make(map[string]string)
248 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900249}
250
Jooyung Han0302a842019-10-30 18:43:49 +0900251func vndkSpLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900252 return config.Once(vndkSpLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900253 return make(map[string]string)
254 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900255}
256
Jooyung Han0302a842019-10-30 18:43:49 +0900257func llndkLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900258 return config.Once(llndkLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900259 return make(map[string]string)
260 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900261}
262
Jooyung Han0302a842019-10-30 18:43:49 +0900263func vndkPrivateLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900264 return config.Once(vndkPrivateLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900265 return make(map[string]string)
266 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900267}
268
Justin Yun8a2600c2020-12-07 12:44:03 +0900269func vndkProductLibraries(config android.Config) map[string]string {
270 return config.Once(vndkProductLibrariesKey, func() interface{} {
271 return make(map[string]string)
272 }).(map[string]string)
273}
274
Jooyung Han0302a842019-10-30 18:43:49 +0900275func vndkUsingCoreVariantLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900276 return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900277 return make(map[string]string)
278 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900279}
280
Jooyung Han097087b2019-10-22 19:32:18 +0900281func vndkMustUseVendorVariantList(cfg android.Config) []string {
282 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900283 return config.VndkMustUseVendorVariantList
284 }).([]string)
285}
286
287// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
288// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
289func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900290 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900291 return mustUseVendorVariantList
292 })
293}
294
Inseob Kim1f086e22019-05-09 13:29:15 +0900295func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
296 lib := m.linker.(*llndkStubDecorator)
Colin Cross0477b422020-10-13 18:43:54 -0700297 name := m.ImplementationModuleName(mctx)
298 filename := name + ".so"
Inseob Kim9516ee92019-05-09 10:56:13 +0900299
Inseob Kim1f086e22019-05-09 13:29:15 +0900300 vndkLibrariesLock.Lock()
301 defer vndkLibrariesLock.Unlock()
Inseob Kim9516ee92019-05-09 10:56:13 +0900302
Jooyung Han0302a842019-10-30 18:43:49 +0900303 llndkLibraries(mctx.Config())[name] = filename
Colin Cross127bb8b2020-12-16 16:46:01 -0800304 m.VendorProperties.IsLLNDK = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900305 if !Bool(lib.Properties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900306 vndkPrivateLibraries(mctx.Config())[name] = filename
Colin Cross127bb8b2020-12-16 16:46:01 -0800307 m.VendorProperties.IsLLNDKPrivate = true
Jooyung Han61b66e92020-03-21 14:21:46 +0000308 }
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900309}
Inseob Kim1f086e22019-05-09 13:29:15 +0900310
311func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Justin Yun8a2600c2020-12-07 12:44:03 +0900312 if m.InProduct() {
313 // We may skip the steps for the product variants because they
314 // are already covered by the vendor variants.
315 return
316 }
317
Jooyung Han0302a842019-10-30 18:43:49 +0900318 name := m.BaseModuleName()
319 filename, err := getVndkFileName(m)
320 if err != nil {
321 panic(err)
322 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900323
Colin Cross31076b32020-10-23 17:22:06 -0700324 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000325 // b/155456180 libz is the ONLY exception here. We don't want to make
326 // libz an LLNDK library because we in general can't guarantee that
327 // libz will behave consistently especially about the compression.
328 // i.e. the compressed output might be different across releases.
329 // As the library is an external one, it's risky to keep the compatibility
330 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900331 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
332 }
333
Inseob Kim1f086e22019-05-09 13:29:15 +0900334 vndkLibrariesLock.Lock()
335 defer vndkLibrariesLock.Unlock()
336
Jooyung Han097087b2019-10-22 19:32:18 +0900337 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
338 m.Properties.MustUseVendorVariant = true
339 }
Jooyung Han0302a842019-10-30 18:43:49 +0900340 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
341 vndkUsingCoreVariantLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900342 }
Jooyung Han0302a842019-10-30 18:43:49 +0900343
Inseob Kim1f086e22019-05-09 13:29:15 +0900344 if m.vndkdep.isVndkSp() {
Jooyung Han0302a842019-10-30 18:43:49 +0900345 vndkSpLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900346 } else {
Jooyung Han0302a842019-10-30 18:43:49 +0900347 vndkCoreLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900348 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900349 if m.IsVndkPrivate() {
Jooyung Han0302a842019-10-30 18:43:49 +0900350 vndkPrivateLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900351 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900352 if m.VendorProperties.Product_available != nil {
353 vndkProductLibraries(mctx.Config())[name] = filename
354 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900355}
356
Yo Chiang08fac0c2020-07-29 01:08:20 +0800357// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800358func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900359 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800360 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900361 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800362 if !m.Device() {
363 // Skip non-device modules
364 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900365 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900366 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800367 // Skip native_bridge modules
368 return true
369 }
370 return false
371}
372
373func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
374 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900375 return false
376 }
377
378 // prebuilt vndk modules should match with device
379 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
380 // When b/142675459 is landed, remove following check
381 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) {
382 return false
383 }
384
385 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han73d20d02020-03-27 16:06:55 +0900386 // VNDK APEX for VNDK-Lite devices will have VNDK-SP libraries from core variants
387 if mctx.DeviceConfig().VndkVersion() == "" {
388 // b/73296261: filter out libz.so because it is considered as LLNDK for VNDK-lite devices
389 if mctx.ModuleName() == "libz" {
390 return false
391 }
392 return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.isVndkSp()
393 }
394
Justin Yun5f7f7e82019-11-18 19:52:14 +0900395 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900396 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozanof9e21722020-12-02 09:00:51 -0500397 return lib.shared() && m.inVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900398 }
399 return false
400}
401
Inseob Kim1f086e22019-05-09 13:29:15 +0900402// gather list of vndk-core, vndk-sp, and ll-ndk libs
403func VndkMutator(mctx android.BottomUpMutatorContext) {
404 m, ok := mctx.Module().(*Module)
405 if !ok {
406 return
407 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800408
409 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900410 return
411 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900412
413 if _, ok := m.linker.(*llndkStubDecorator); ok {
414 processLlndkLibrary(mctx, m)
415 return
416 }
417
Colin Cross127bb8b2020-12-16 16:46:01 -0800418 // This is a temporary measure to copy the properties from an llndk_library into the cc_library
419 // that will actually build the stubs. It will be removed once the properties are moved into
420 // the cc_library in the Android.bp files.
421 mergeLLNDKToLib := func(llndk *Module, llndkProperties *llndkLibraryProperties, flagExporter *flagExporter) {
422 if llndkLib := moduleLibraryInterface(llndk); llndkLib != nil {
423 *llndkProperties = llndkLib.(*llndkStubDecorator).Properties
424 flagExporter.Properties = llndkLib.(*llndkStubDecorator).flagExporter.Properties
425
426 m.VendorProperties.IsLLNDK = llndk.VendorProperties.IsLLNDK
427 m.VendorProperties.IsLLNDKPrivate = llndk.VendorProperties.IsLLNDKPrivate
428 }
429 }
430
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800431 lib, isLib := m.linker.(*libraryDecorator)
432 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900433
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800434 if m.UseVndk() && isLib && lib.hasLLNDKStubs() {
Colin Cross127bb8b2020-12-16 16:46:01 -0800435 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(lib.Properties.Llndk_stubs))
436 mergeLLNDKToLib(llndk[0].(*Module), &lib.Properties.Llndk, &lib.flagExporter)
437 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800438 if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
439 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(prebuiltLib.Properties.Llndk_stubs))
440 mergeLLNDKToLib(llndk[0].(*Module), &prebuiltLib.Properties.Llndk, &prebuiltLib.flagExporter)
Colin Cross127bb8b2020-12-16 16:46:01 -0800441 }
442
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800443 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900444 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900445 processVndkLibrary(mctx, m)
446 return
447 }
448 }
449}
450
451func init() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900452 android.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Inseob Kim1f086e22019-05-09 13:29:15 +0900453 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900454}
455
Jooyung Han2216fb12019-11-06 16:46:15 +0900456type vndkLibrariesTxt struct {
457 android.ModuleBase
458 outputFile android.OutputPath
459}
460
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700461var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900462var _ android.OutputFileProducer = &vndkLibrariesTxt{}
463
Jooyung Han2216fb12019-11-06 16:46:15 +0900464// vndk_libraries_txt is a special kind of module type in that it name is one of
465// - llndk.libraries.txt
466// - vndkcore.libraries.txt
467// - vndksp.libraries.txt
468// - vndkprivate.libraries.txt
Justin Yun8a2600c2020-12-07 12:44:03 +0900469// - vndkproduct.libraries.txt
Jooyung Han2216fb12019-11-06 16:46:15 +0900470// - vndkcorevariant.libraries.txt
471// A module behaves like a prebuilt_etc but its content is generated by soong.
472// By being a soong module, these files can be referenced by other soong modules.
473// For example, apex_vndk can depend on these files as prebuilt.
Jooyung Han39edb6c2019-11-06 16:53:07 +0900474func VndkLibrariesTxtFactory() android.Module {
Jooyung Han2216fb12019-11-06 16:46:15 +0900475 m := &vndkLibrariesTxt{}
476 android.InitAndroidModule(m)
477 return m
478}
479
480func insertVndkVersion(filename string, vndkVersion string) string {
481 if index := strings.LastIndex(filename, "."); index != -1 {
482 return filename[:index] + "." + vndkVersion + filename[index:]
483 }
484 return filename
485}
486
487func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
488 var list []string
489 switch txt.Name() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900490 case llndkLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900491 for _, filename := range android.SortedStringMapValues(llndkLibraries(ctx.Config())) {
492 if strings.HasPrefix(filename, "libclang_rt.hwasan-") {
493 continue
494 }
495 list = append(list, filename)
496 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900497 case vndkCoreLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900498 list = android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900499 case vndkSpLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900500 list = android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900501 case vndkPrivateLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900502 list = android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Justin Yun8a2600c2020-12-07 12:44:03 +0900503 case vndkProductLibrariesTxt:
504 list = android.SortedStringMapValues(vndkProductLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900505 case vndkUsingCoreVariantLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900506 list = android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config()))
507 default:
508 ctx.ModuleErrorf("name(%s) is unknown.", txt.Name())
509 return
510 }
511
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900512 var filename string
513 if txt.Name() != vndkUsingCoreVariantLibrariesTxt {
514 filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
515 } else {
516 filename = txt.Name()
517 }
518
Jooyung Han2216fb12019-11-06 16:46:15 +0900519 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Colin Crosscf371cc2020-11-13 11:48:42 -0800520 android.WriteFileRule(ctx, txt.outputFile, strings.Join(list, "\n"))
Jooyung Han2216fb12019-11-06 16:46:15 +0900521
522 installPath := android.PathForModuleInstall(ctx, "etc")
523 ctx.InstallFile(installPath, filename, txt.outputFile)
524}
525
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900526func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
527 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900528 Class: "ETC",
529 OutputFile: android.OptionalPathForPath(txt.outputFile),
530 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
531 func(entries *android.AndroidMkEntries) {
532 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
533 },
534 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900535 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900536}
537
Jooyung Han0703fd82020-08-26 22:11:53 +0900538// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900539func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
540 return txt.outputFile
541}
542
Jooyung Han0703fd82020-08-26 22:11:53 +0900543// PrebuiltEtcModule interface
544func (txt *vndkLibrariesTxt) BaseDir() string {
545 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900546}
547
Jooyung Han0703fd82020-08-26 22:11:53 +0900548// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900549func (txt *vndkLibrariesTxt) SubDir() string {
550 return ""
551}
552
Jooyung Han0703fd82020-08-26 22:11:53 +0900553func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
554 return android.Paths{txt.outputFile}, nil
555}
556
Inseob Kim1f086e22019-05-09 13:29:15 +0900557func VndkSnapshotSingleton() android.Singleton {
558 return &vndkSnapshotSingleton{}
559}
560
Jooyung Han0302a842019-10-30 18:43:49 +0900561type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900562 vndkLibrariesFile android.OutputPath
563 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900564}
Inseob Kim1f086e22019-05-09 13:29:15 +0900565
Inseob Kimde5744a2020-12-02 13:14:28 +0900566func isVndkSnapshotAware(config android.DeviceConfig, m *Module,
Colin Cross56a83212020-09-15 18:30:11 -0700567 apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
568
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900569 if m.Target().NativeBridge == android.NativeBridgeEnabled {
570 return nil, "", false
571 }
Jooyung Han261e1582020-10-20 18:54:21 +0900572 // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
573 // !installable: Snapshot only cares about "installable" modules.
574 // isSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
Colin Cross56a83212020-09-15 18:30:11 -0700575 if !m.inVendor() || !m.installable(apexInfo) || m.isSnapshotPrebuilt() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900576 return nil, "", false
577 }
578 l, ok := m.linker.(snapshotLibraryInterface)
579 if !ok || !l.shared() {
580 return nil, "", false
581 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500582 if m.VndkVersion() == config.PlatformVndkVersion() && m.IsVndk() && !m.IsVndkExt() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900583 if m.isVndkSp() {
584 return l, "vndk-sp", true
585 } else {
586 return l, "vndk-core", true
587 }
588 }
589
590 return nil, "", false
591}
592
Inseob Kim1f086e22019-05-09 13:29:15 +0900593func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900594 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
595 c.buildVndkLibrariesTxtFiles(ctx)
596
Inseob Kim1f086e22019-05-09 13:29:15 +0900597 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
598 if ctx.DeviceConfig().VndkVersion() != "current" {
599 return
600 }
601
602 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
603 return
604 }
605
Inseob Kim242ef0c2019-10-22 20:15:20 +0900606 var snapshotOutputs android.Paths
607
608 /*
609 VNDK snapshot zipped artifacts directory structure:
610 {SNAPSHOT_ARCH}/
611 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
612 shared/
613 vndk-core/
614 (VNDK-core libraries, e.g. libbinder.so)
615 vndk-sp/
616 (VNDK-SP libraries, e.g. libc++.so)
617 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
618 shared/
619 vndk-core/
620 (VNDK-core libraries, e.g. libbinder.so)
621 vndk-sp/
622 (VNDK-SP libraries, e.g. libc++.so)
623 binder32/
624 (This directory is newly introduced in v28 (Android P) to hold
625 prebuilts built for 32-bit binder interface.)
626 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
627 ...
628 configs/
629 (various *.txt configuration files)
630 include/
631 (header files of same directory structure with source tree)
632 NOTICE_FILES/
633 (notice files of libraries, e.g. libcutils.so.txt)
634 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900635
636 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900637 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900638
Inseob Kim242ef0c2019-10-22 20:15:20 +0900639 configsDir := filepath.Join(snapshotArchDir, "configs")
640 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
641 includeDir := filepath.Join(snapshotArchDir, "include")
642
Inseob Kim242ef0c2019-10-22 20:15:20 +0900643 // set of notice files copied.
Inseob Kim1f086e22019-05-09 13:29:15 +0900644 noticeBuilt := make(map[string]bool)
645
Inseob Kim242ef0c2019-10-22 20:15:20 +0900646 // paths of VNDK modules for GPL license checking
647 modulePaths := make(map[string]string)
648
649 // actual module names of .so files
650 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
651 moduleNames := make(map[string]string)
652
Inseob Kim8471cda2019-11-15 09:59:12 +0900653 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900654
Inseob Kimde5744a2020-12-02 13:14:28 +0900655 // installVndkSnapshotLib copies built .so file from the module.
656 // Also, if the build artifacts is on, write a json file which contains all exported flags
657 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700658 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900659 var ret android.Paths
660
Inseob Kim8471cda2019-11-15 09:59:12 +0900661 targetArch := "arch-" + m.Target().Arch.ArchType.String()
662 if m.Target().Arch.ArchVariant != "" {
663 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900664 }
Inseob Kimae553032019-05-14 18:52:49 +0900665
Inseob Kim8471cda2019-11-15 09:59:12 +0900666 libPath := m.outputFile.Path()
667 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Inseob Kimde5744a2020-12-02 13:14:28 +0900668 ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900669
Inseob Kimae553032019-05-14 18:52:49 +0900670 if ctx.Config().VndkSnapshotBuildArtifacts() {
671 prop := struct {
672 ExportedDirs []string `json:",omitempty"`
673 ExportedSystemDirs []string `json:",omitempty"`
674 ExportedFlags []string `json:",omitempty"`
675 RelativeInstallPath string `json:",omitempty"`
676 }{}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700677 exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
678 prop.ExportedFlags = exportedInfo.Flags
679 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
680 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900681 prop.RelativeInstallPath = m.RelativeInstallPath()
682
Inseob Kim242ef0c2019-10-22 20:15:20 +0900683 propOut := snapshotLibOut + ".json"
Inseob Kimae553032019-05-14 18:52:49 +0900684
685 j, err := json.Marshal(prop)
686 if err != nil {
687 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900688 return nil, false
Inseob Kimae553032019-05-14 18:52:49 +0900689 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900690 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kimae553032019-05-14 18:52:49 +0900691 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900692 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900693 }
694
Inseob Kim1f086e22019-05-09 13:29:15 +0900695 ctx.VisitAllModules(func(module android.Module) {
696 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900697 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900698 return
699 }
700
Colin Cross56a83212020-09-15 18:30:11 -0700701 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
702
Inseob Kimde5744a2020-12-02 13:14:28 +0900703 l, vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900704 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200705 return
706 }
707
Inseob Kimde5744a2020-12-02 13:14:28 +0900708 // For all snapshot candidates, the followings are captured.
709 // - .so files
710 // - notice files
711 //
712 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
713 // - .json files containing exported flags
714 // - exported headers from collectHeadersForSnapshot()
715 //
716 // Headers are deduplicated after visiting all modules.
717
Inseob Kim8471cda2019-11-15 09:59:12 +0900718 // install .so files for appropriate modules.
719 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700720 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900721 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900722 return
723 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900724 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900725
Inseob Kim8471cda2019-11-15 09:59:12 +0900726 // These are for generating module_names.txt and module_paths.txt
727 stem := m.outputFile.Path().Base()
728 moduleNames[stem] = ctx.ModuleName(m)
729 modulePaths[stem] = ctx.ModuleDir(m)
730
Bob Badoura75b0572020-02-18 20:21:55 -0800731 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900732 noticeName := stem + ".txt"
733 // skip already copied notice file
734 if _, ok := noticeBuilt[noticeName]; !ok {
735 noticeBuilt[noticeName] = true
Inseob Kimde5744a2020-12-02 13:14:28 +0900736 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
Bob Badoura75b0572020-02-18 20:21:55 -0800737 ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName)))
Inseob Kim8471cda2019-11-15 09:59:12 +0900738 }
739 }
740
741 if ctx.Config().VndkSnapshotBuildArtifacts() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900742 headers = append(headers, l.snapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900743 }
744 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900745
Inseob Kim8471cda2019-11-15 09:59:12 +0900746 // install all headers after removing duplicates
747 for _, header := range android.FirstUniquePaths(headers) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900748 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900749 ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900750 }
751
Jooyung Han39edb6c2019-11-06 16:53:07 +0900752 // install *.libraries.txt except vndkcorevariant.libraries.txt
753 ctx.VisitAllModules(func(module android.Module) {
754 m, ok := module.(*vndkLibrariesTxt)
755 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
756 return
757 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900758 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900759 ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900760 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900761
Inseob Kim242ef0c2019-10-22 20:15:20 +0900762 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900763 module_paths.txt contains paths on which VNDK modules are defined.
764 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000765 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900766 libc.so bionic/libc
767 ...
768 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900769 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900770
771 /*
772 module_names.txt contains names as which VNDK modules are defined,
773 because output filename and module name can be different with stem and suffix properties.
774
775 e.g.,
776 libcutils.so libcutils
777 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
778 ...
779 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900780 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900781
782 // All artifacts are ready. Sort them to normalize ninja and then zip.
783 sort.Slice(snapshotOutputs, func(i, j int) bool {
784 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
785 })
786
787 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800788 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900789
Inseob Kimde5744a2020-12-02 13:14:28 +0900790 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900791 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
792 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900793 Text("tr").
794 FlagWithArg("-d ", "\\'").
795 FlagWithRspFileInputList("< ", snapshotOutputs).
796 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900797
798 zipRule.Temporary(snapshotOutputList)
799
800 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800801 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900802 FlagWithOutput("-o ", zipPath).
803 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
804 FlagWithInput("-l ", snapshotOutputList)
805
Colin Crossf1a035e2020-11-16 17:32:30 -0800806 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900807 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900808 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900809}
Jooyung Han097087b2019-10-22 19:32:18 +0900810
Jooyung Han0302a842019-10-30 18:43:49 +0900811func getVndkFileName(m *Module) (string, error) {
812 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900813 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900814 }
815 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900816 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900817 }
818 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900819}
820
821func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900822 llndk := android.SortedStringMapValues(llndkLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900823 vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
824 vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
825 vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Justin Yun8a2600c2020-12-07 12:44:03 +0900826 vndkproduct := android.SortedStringMapValues(vndkProductLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900827
Jooyung Han2216fb12019-11-06 16:46:15 +0900828 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900829 // Since each target have different set of libclang_rt.* files,
830 // keep the common set of files in vndk.libraries.txt
831 var merged []string
Jooyung Han097087b2019-10-22 19:32:18 +0900832 filterOutLibClangRt := func(libList []string) (filtered []string) {
833 for _, lib := range libList {
834 if !strings.HasPrefix(lib, "libclang_rt.") {
835 filtered = append(filtered, lib)
836 }
837 }
838 return
839 }
840 merged = append(merged, addPrefix(filterOutLibClangRt(llndk), "LLNDK: ")...)
841 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
842 merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...)
843 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Justin Yun8a2600c2020-12-07 12:44:03 +0900844 merged = append(merged, addPrefix(filterOutLibClangRt(vndkproduct), "VNDK-product: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900845 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800846 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900847}
Jooyung Han097087b2019-10-22 19:32:18 +0900848
Jooyung Han0302a842019-10-30 18:43:49 +0900849func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
850 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
851 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700852 movedToApexLlndkLibraries := make(map[string]bool)
853 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800854 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
855 // Skip bionic libs, they are handled in different manner
856 name := library.implementationModuleName(module.(*Module).BaseModuleName())
857 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
858 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700859 }
Jooyung Han0302a842019-10-30 18:43:49 +0900860 }
Colin Cross56a83212020-09-15 18:30:11 -0700861 })
862
863 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
864 strings.Join(android.SortedStringKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900865
866 // Make uses LLNDK_LIBRARIES to determine which libraries to install.
867 // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
868 // Therefore, by removing the library here, we cause it to only be installed if libc
869 // depends on it.
870 installedLlndkLibraries := []string{}
871 for lib := range llndkLibraries(ctx.Config()) {
872 if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
873 continue
874 }
875 installedLlndkLibraries = append(installedLlndkLibraries, lib)
876 }
877 sort.Strings(installedLlndkLibraries)
878 ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
879
Jooyung Han0302a842019-10-30 18:43:49 +0900880 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkCoreLibraries(ctx.Config())), " "))
881 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(android.SortedStringKeys(vndkSpLibraries(ctx.Config())), " "))
882 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())), " "))
883 ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(android.SortedStringKeys(vndkUsingCoreVariantLibraries(ctx.Config())), " "))
884
Jooyung Han0302a842019-10-30 18:43:49 +0900885 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900886 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900887}