blob: 1708841c61f7bceda1f582cc57bfb8210f7538a5 [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
81 // Extending another module
82 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090083 }
84}
85
86type vndkdep struct {
87 Properties VndkProperties
88}
89
90func (vndk *vndkdep) props() []interface{} {
91 return []interface{}{&vndk.Properties}
92}
93
94func (vndk *vndkdep) begin(ctx BaseModuleContext) {}
95
96func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps {
97 return deps
98}
99
100func (vndk *vndkdep) isVndk() bool {
101 return Bool(vndk.Properties.Vndk.Enabled)
102}
103
104func (vndk *vndkdep) isVndkSp() bool {
105 return Bool(vndk.Properties.Vndk.Support_system_process)
106}
107
Logan Chienf3511742017-10-31 18:04:35 +0800108func (vndk *vndkdep) isVndkExt() bool {
109 return vndk.Properties.Vndk.Extends != nil
110}
111
112func (vndk *vndkdep) getVndkExtendsModuleName() string {
113 return String(vndk.Properties.Vndk.Extends)
114}
115
Justin Yun8effde42017-06-23 19:24:43 +0900116func (vndk *vndkdep) typeName() string {
117 if !vndk.isVndk() {
118 return "native:vendor"
119 }
Logan Chienf3511742017-10-31 18:04:35 +0800120 if !vndk.isVndkExt() {
121 if !vndk.isVndkSp() {
122 return "native:vendor:vndk"
123 }
124 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900125 }
Logan Chienf3511742017-10-31 18:04:35 +0800126 if !vndk.isVndkSp() {
127 return "native:vendor:vndkext"
128 }
129 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900130}
131
Justin Yun63e9ec72020-10-29 16:49:43 +0900132// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900133func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900134 if to.linker == nil {
135 return
136 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900137 if !vndk.isVndk() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900138 // Non-VNDK modules those installed to /vendor or /system/vendor
139 // can't depend on modules marked with vendor_available: false;
140 // or those installed to /product or /system/product can't depend
141 // on modules marked with product_available: false.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900142 violation := false
Justin Yun6977e8a2020-10-29 18:24:11 +0900143 variant := "vendor"
Nan Zhang0007d812017-11-07 10:57:05 -0800144 if lib, ok := to.linker.(*llndkStubDecorator); ok && !Bool(lib.Properties.Vendor_available) {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900145 violation = true
Justin Yun6977e8a2020-10-29 18:24:11 +0900146 if to.InProduct() {
147 variant = "product"
148 }
149 } else if _, ok := to.linker.(libraryInterface); ok {
150 if to.inVendor() && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) {
151 // A vendor module with Vendor_available == nil should be okay since it means a
152 // vendor-only library which is a valid dependency for non-VNDK vendor modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900153 violation = true
Justin Yun6977e8a2020-10-29 18:24:11 +0900154 } else if to.InProduct() && to.VendorProperties.Product_available != nil && !Bool(to.VendorProperties.Product_available) {
155 // A product module with Product_available == nil should be okay since it means a
156 // product-only library which is a valid dependency for non-VNDK product modules.
157 violation = true
158 variant = "product"
Jiyong Park82e2bf32017-08-16 14:05:54 +0900159 }
160 }
161 if violation {
Justin Yun6977e8a2020-10-29 18:24:11 +0900162 ctx.ModuleErrorf("%s module that is not VNDK should not link to %q which is marked as `%s_available: false`", variant, to.Name(), variant)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900163 }
164 }
Justin Yun8effde42017-06-23 19:24:43 +0900165 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
166 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800167 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900168 return
169 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800170
171 if to.IsLlndk() {
172 // LL-NDK libraries are allowed to link
173 return
174 }
175
Ivan Lozano52767be2019-10-18 14:49:46 -0700176 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900177 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
178 vndk.typeName(), to.Name())
179 return
180 }
Logan Chienf3511742017-10-31 18:04:35 +0800181 if tag == vndkExtDepTag {
182 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
183 // and has identical vndk properties.
184 if to.vndkdep == nil || !to.vndkdep.isVndk() {
185 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
186 return
187 }
188 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
189 ctx.ModuleErrorf(
190 "`extends` refers a module %q with mismatched support_system_process",
191 to.Name())
192 return
193 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900194 if to.inVendor() && !Bool(to.VendorProperties.Vendor_available) {
Logan Chienf3511742017-10-31 18:04:35 +0800195 ctx.ModuleErrorf(
196 "`extends` refers module %q which does not have `vendor_available: true`",
197 to.Name())
198 return
199 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900200 if to.InProduct() && !Bool(to.VendorProperties.Product_available) {
201 ctx.ModuleErrorf(
202 "`extends` refers module %q which does not have `product_available: true`",
203 to.Name())
204 return
205 }
Logan Chienf3511742017-10-31 18:04:35 +0800206 }
Justin Yun8effde42017-06-23 19:24:43 +0900207 if to.vndkdep == nil {
208 return
209 }
Logan Chienf3511742017-10-31 18:04:35 +0800210
Logan Chiend3c59a22018-03-29 14:08:15 +0800211 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100212 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
213 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
214 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800215 return
216 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800217}
Logan Chienf3511742017-10-31 18:04:35 +0800218
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100219func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800220 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
221 if from.isVndkExt() {
222 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100223 if to.isVndk() && !to.isVndkSp() {
224 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
225 }
226 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800227 }
228 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100229 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900230 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800231 if from.isVndk() {
232 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100233 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800234 }
235 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100236 if !to.isVndkSp() {
237 return errors.New("VNDK-SP must only depend on VNDK-SP")
238 }
239 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800240 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100241 if !to.isVndk() {
242 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
243 }
244 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800245 }
246 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100247 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900248}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900249
250var (
Jooyung Hana463f722019-11-01 08:45:59 +0900251 vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires")
252 vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires")
253 llndkLibrariesKey = android.NewOnceKey("llndkLibrarires")
254 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900255 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibraries")
Jooyung Hana463f722019-11-01 08:45:59 +0900256 vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
257 vndkLibrariesLock sync.Mutex
Inseob Kimae553032019-05-14 18:52:49 +0900258)
Inseob Kim1f086e22019-05-09 13:29:15 +0900259
Jooyung Han0302a842019-10-30 18:43:49 +0900260func vndkCoreLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900261 return config.Once(vndkCoreLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900262 return make(map[string]string)
263 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900264}
265
Jooyung Han0302a842019-10-30 18:43:49 +0900266func vndkSpLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900267 return config.Once(vndkSpLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900268 return make(map[string]string)
269 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900270}
271
Jooyung Han0302a842019-10-30 18:43:49 +0900272func llndkLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900273 return config.Once(llndkLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900274 return make(map[string]string)
275 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900276}
277
Jooyung Han0302a842019-10-30 18:43:49 +0900278func vndkPrivateLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900279 return config.Once(vndkPrivateLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900280 return make(map[string]string)
281 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900282}
283
Jooyung Han0302a842019-10-30 18:43:49 +0900284func vndkUsingCoreVariantLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900285 return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900286 return make(map[string]string)
287 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900288}
289
Jooyung Han097087b2019-10-22 19:32:18 +0900290func vndkMustUseVendorVariantList(cfg android.Config) []string {
291 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900292 return config.VndkMustUseVendorVariantList
293 }).([]string)
294}
295
296// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
297// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
298func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900299 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900300 return mustUseVendorVariantList
301 })
302}
303
Inseob Kim1f086e22019-05-09 13:29:15 +0900304func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
305 lib := m.linker.(*llndkStubDecorator)
Colin Cross0477b422020-10-13 18:43:54 -0700306 name := m.ImplementationModuleName(mctx)
307 filename := name + ".so"
Inseob Kim9516ee92019-05-09 10:56:13 +0900308
Inseob Kim1f086e22019-05-09 13:29:15 +0900309 vndkLibrariesLock.Lock()
310 defer vndkLibrariesLock.Unlock()
Inseob Kim9516ee92019-05-09 10:56:13 +0900311
Jooyung Han0302a842019-10-30 18:43:49 +0900312 llndkLibraries(mctx.Config())[name] = filename
Colin Cross127bb8b2020-12-16 16:46:01 -0800313 m.VendorProperties.IsLLNDK = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900314 if !Bool(lib.Properties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900315 vndkPrivateLibraries(mctx.Config())[name] = filename
Colin Cross127bb8b2020-12-16 16:46:01 -0800316 m.VendorProperties.IsLLNDKPrivate = true
Jooyung Han61b66e92020-03-21 14:21:46 +0000317 }
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900318}
Inseob Kim1f086e22019-05-09 13:29:15 +0900319
320func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Jooyung Han0302a842019-10-30 18:43:49 +0900321 name := m.BaseModuleName()
322 filename, err := getVndkFileName(m)
323 if err != nil {
324 panic(err)
325 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900326
Colin Cross31076b32020-10-23 17:22:06 -0700327 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000328 // b/155456180 libz is the ONLY exception here. We don't want to make
329 // libz an LLNDK library because we in general can't guarantee that
330 // libz will behave consistently especially about the compression.
331 // i.e. the compressed output might be different across releases.
332 // As the library is an external one, it's risky to keep the compatibility
333 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900334 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
335 }
336
Inseob Kim1f086e22019-05-09 13:29:15 +0900337 vndkLibrariesLock.Lock()
338 defer vndkLibrariesLock.Unlock()
339
Justin Yun6977e8a2020-10-29 18:24:11 +0900340 if m.InProduct() {
341 // We may skip the other steps for the product variants because they
342 // are already covered by the vendor variants.
343 return
344 }
345
Jooyung Han097087b2019-10-22 19:32:18 +0900346 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
347 m.Properties.MustUseVendorVariant = true
348 }
Jooyung Han0302a842019-10-30 18:43:49 +0900349 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
350 vndkUsingCoreVariantLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900351 }
Jooyung Han0302a842019-10-30 18:43:49 +0900352
Inseob Kim1f086e22019-05-09 13:29:15 +0900353 if m.vndkdep.isVndkSp() {
Jooyung Han0302a842019-10-30 18:43:49 +0900354 vndkSpLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900355 } else {
Jooyung Han0302a842019-10-30 18:43:49 +0900356 vndkCoreLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900357 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900358 // As `vendor_available` and `product_available` has the same value for VNDK modules,
359 // we don't need to check both values.
Inseob Kim1f086e22019-05-09 13:29:15 +0900360 if !Bool(m.VendorProperties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900361 vndkPrivateLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900362 }
363}
364
Yo Chiang08fac0c2020-07-29 01:08:20 +0800365// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800366func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900367 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800368 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900369 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800370 if !m.Device() {
371 // Skip non-device modules
372 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900373 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900374 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800375 // Skip native_bridge modules
376 return true
377 }
378 return false
379}
380
381func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
382 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900383 return false
384 }
385
386 // prebuilt vndk modules should match with device
387 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
388 // When b/142675459 is landed, remove following check
389 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) {
390 return false
391 }
392
393 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han73d20d02020-03-27 16:06:55 +0900394 // VNDK APEX for VNDK-Lite devices will have VNDK-SP libraries from core variants
395 if mctx.DeviceConfig().VndkVersion() == "" {
396 // b/73296261: filter out libz.so because it is considered as LLNDK for VNDK-lite devices
397 if mctx.ModuleName() == "libz" {
398 return false
399 }
400 return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.isVndkSp()
401 }
402
Justin Yun5f7f7e82019-11-18 19:52:14 +0900403 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900404 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozanof9e21722020-12-02 09:00:51 -0500405 return lib.shared() && m.inVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900406 }
407 return false
408}
409
Inseob Kim1f086e22019-05-09 13:29:15 +0900410// gather list of vndk-core, vndk-sp, and ll-ndk libs
411func VndkMutator(mctx android.BottomUpMutatorContext) {
412 m, ok := mctx.Module().(*Module)
413 if !ok {
414 return
415 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800416
417 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900418 return
419 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900420
421 if _, ok := m.linker.(*llndkStubDecorator); ok {
422 processLlndkLibrary(mctx, m)
423 return
424 }
425
Colin Cross127bb8b2020-12-16 16:46:01 -0800426 // This is a temporary measure to copy the properties from an llndk_library into the cc_library
427 // that will actually build the stubs. It will be removed once the properties are moved into
428 // the cc_library in the Android.bp files.
429 mergeLLNDKToLib := func(llndk *Module, llndkProperties *llndkLibraryProperties, flagExporter *flagExporter) {
430 if llndkLib := moduleLibraryInterface(llndk); llndkLib != nil {
431 *llndkProperties = llndkLib.(*llndkStubDecorator).Properties
432 flagExporter.Properties = llndkLib.(*llndkStubDecorator).flagExporter.Properties
433
434 m.VendorProperties.IsLLNDK = llndk.VendorProperties.IsLLNDK
435 m.VendorProperties.IsLLNDKPrivate = llndk.VendorProperties.IsLLNDKPrivate
436 }
437 }
438
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800439 lib, isLib := m.linker.(*libraryDecorator)
440 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900441
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800442 if m.UseVndk() && isLib && lib.hasLLNDKStubs() {
Colin Cross127bb8b2020-12-16 16:46:01 -0800443 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(lib.Properties.Llndk_stubs))
444 mergeLLNDKToLib(llndk[0].(*Module), &lib.Properties.Llndk, &lib.flagExporter)
445 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800446 if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
447 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(prebuiltLib.Properties.Llndk_stubs))
448 mergeLLNDKToLib(llndk[0].(*Module), &prebuiltLib.Properties.Llndk, &prebuiltLib.flagExporter)
Colin Cross127bb8b2020-12-16 16:46:01 -0800449 }
450
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800451 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900452 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900453 processVndkLibrary(mctx, m)
454 return
455 }
456 }
457}
458
459func init() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900460 android.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Inseob Kim1f086e22019-05-09 13:29:15 +0900461 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900462}
463
Jooyung Han2216fb12019-11-06 16:46:15 +0900464type vndkLibrariesTxt struct {
465 android.ModuleBase
466 outputFile android.OutputPath
467}
468
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700469var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900470var _ android.OutputFileProducer = &vndkLibrariesTxt{}
471
Jooyung Han2216fb12019-11-06 16:46:15 +0900472// vndk_libraries_txt is a special kind of module type in that it name is one of
473// - llndk.libraries.txt
474// - vndkcore.libraries.txt
475// - vndksp.libraries.txt
476// - vndkprivate.libraries.txt
477// - vndkcorevariant.libraries.txt
478// A module behaves like a prebuilt_etc but its content is generated by soong.
479// By being a soong module, these files can be referenced by other soong modules.
480// For example, apex_vndk can depend on these files as prebuilt.
Jooyung Han39edb6c2019-11-06 16:53:07 +0900481func VndkLibrariesTxtFactory() android.Module {
Jooyung Han2216fb12019-11-06 16:46:15 +0900482 m := &vndkLibrariesTxt{}
483 android.InitAndroidModule(m)
484 return m
485}
486
487func insertVndkVersion(filename string, vndkVersion string) string {
488 if index := strings.LastIndex(filename, "."); index != -1 {
489 return filename[:index] + "." + vndkVersion + filename[index:]
490 }
491 return filename
492}
493
494func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
495 var list []string
496 switch txt.Name() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900497 case llndkLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900498 for _, filename := range android.SortedStringMapValues(llndkLibraries(ctx.Config())) {
499 if strings.HasPrefix(filename, "libclang_rt.hwasan-") {
500 continue
501 }
502 list = append(list, filename)
503 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900504 case vndkCoreLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900505 list = android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900506 case vndkSpLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900507 list = android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900508 case vndkPrivateLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900509 list = android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900510 case vndkUsingCoreVariantLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900511 list = android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config()))
512 default:
513 ctx.ModuleErrorf("name(%s) is unknown.", txt.Name())
514 return
515 }
516
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900517 var filename string
518 if txt.Name() != vndkUsingCoreVariantLibrariesTxt {
519 filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
520 } else {
521 filename = txt.Name()
522 }
523
Jooyung Han2216fb12019-11-06 16:46:15 +0900524 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Colin Crosscf371cc2020-11-13 11:48:42 -0800525 android.WriteFileRule(ctx, txt.outputFile, strings.Join(list, "\n"))
Jooyung Han2216fb12019-11-06 16:46:15 +0900526
527 installPath := android.PathForModuleInstall(ctx, "etc")
528 ctx.InstallFile(installPath, filename, txt.outputFile)
529}
530
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900531func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
532 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900533 Class: "ETC",
534 OutputFile: android.OptionalPathForPath(txt.outputFile),
535 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
536 func(entries *android.AndroidMkEntries) {
537 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
538 },
539 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900540 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900541}
542
Jooyung Han0703fd82020-08-26 22:11:53 +0900543// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900544func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
545 return txt.outputFile
546}
547
Jooyung Han0703fd82020-08-26 22:11:53 +0900548// PrebuiltEtcModule interface
549func (txt *vndkLibrariesTxt) BaseDir() string {
550 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900551}
552
Jooyung Han0703fd82020-08-26 22:11:53 +0900553// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900554func (txt *vndkLibrariesTxt) SubDir() string {
555 return ""
556}
557
Jooyung Han0703fd82020-08-26 22:11:53 +0900558func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
559 return android.Paths{txt.outputFile}, nil
560}
561
Inseob Kim1f086e22019-05-09 13:29:15 +0900562func VndkSnapshotSingleton() android.Singleton {
563 return &vndkSnapshotSingleton{}
564}
565
Jooyung Han0302a842019-10-30 18:43:49 +0900566type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900567 vndkLibrariesFile android.OutputPath
568 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900569}
Inseob Kim1f086e22019-05-09 13:29:15 +0900570
Inseob Kimde5744a2020-12-02 13:14:28 +0900571func isVndkSnapshotAware(config android.DeviceConfig, m *Module,
Colin Cross56a83212020-09-15 18:30:11 -0700572 apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
573
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900574 if m.Target().NativeBridge == android.NativeBridgeEnabled {
575 return nil, "", false
576 }
Jooyung Han261e1582020-10-20 18:54:21 +0900577 // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
578 // !installable: Snapshot only cares about "installable" modules.
579 // isSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
Colin Cross56a83212020-09-15 18:30:11 -0700580 if !m.inVendor() || !m.installable(apexInfo) || m.isSnapshotPrebuilt() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900581 return nil, "", false
582 }
583 l, ok := m.linker.(snapshotLibraryInterface)
584 if !ok || !l.shared() {
585 return nil, "", false
586 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500587 if m.VndkVersion() == config.PlatformVndkVersion() && m.IsVndk() && !m.IsVndkExt() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900588 if m.isVndkSp() {
589 return l, "vndk-sp", true
590 } else {
591 return l, "vndk-core", true
592 }
593 }
594
595 return nil, "", false
596}
597
Inseob Kim1f086e22019-05-09 13:29:15 +0900598func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900599 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
600 c.buildVndkLibrariesTxtFiles(ctx)
601
Inseob Kim1f086e22019-05-09 13:29:15 +0900602 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
603 if ctx.DeviceConfig().VndkVersion() != "current" {
604 return
605 }
606
607 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
608 return
609 }
610
Inseob Kim242ef0c2019-10-22 20:15:20 +0900611 var snapshotOutputs android.Paths
612
613 /*
614 VNDK snapshot zipped artifacts directory structure:
615 {SNAPSHOT_ARCH}/
616 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
617 shared/
618 vndk-core/
619 (VNDK-core libraries, e.g. libbinder.so)
620 vndk-sp/
621 (VNDK-SP libraries, e.g. libc++.so)
622 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
623 shared/
624 vndk-core/
625 (VNDK-core libraries, e.g. libbinder.so)
626 vndk-sp/
627 (VNDK-SP libraries, e.g. libc++.so)
628 binder32/
629 (This directory is newly introduced in v28 (Android P) to hold
630 prebuilts built for 32-bit binder interface.)
631 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
632 ...
633 configs/
634 (various *.txt configuration files)
635 include/
636 (header files of same directory structure with source tree)
637 NOTICE_FILES/
638 (notice files of libraries, e.g. libcutils.so.txt)
639 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900640
641 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900642 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900643
Inseob Kim242ef0c2019-10-22 20:15:20 +0900644 configsDir := filepath.Join(snapshotArchDir, "configs")
645 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
646 includeDir := filepath.Join(snapshotArchDir, "include")
647
Inseob Kim242ef0c2019-10-22 20:15:20 +0900648 // set of notice files copied.
Inseob Kim1f086e22019-05-09 13:29:15 +0900649 noticeBuilt := make(map[string]bool)
650
Inseob Kim242ef0c2019-10-22 20:15:20 +0900651 // paths of VNDK modules for GPL license checking
652 modulePaths := make(map[string]string)
653
654 // actual module names of .so files
655 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
656 moduleNames := make(map[string]string)
657
Inseob Kim8471cda2019-11-15 09:59:12 +0900658 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900659
Inseob Kimde5744a2020-12-02 13:14:28 +0900660 // installVndkSnapshotLib copies built .so file from the module.
661 // Also, if the build artifacts is on, write a json file which contains all exported flags
662 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700663 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900664 var ret android.Paths
665
Inseob Kim8471cda2019-11-15 09:59:12 +0900666 targetArch := "arch-" + m.Target().Arch.ArchType.String()
667 if m.Target().Arch.ArchVariant != "" {
668 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900669 }
Inseob Kimae553032019-05-14 18:52:49 +0900670
Inseob Kim8471cda2019-11-15 09:59:12 +0900671 libPath := m.outputFile.Path()
672 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Inseob Kimde5744a2020-12-02 13:14:28 +0900673 ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900674
Inseob Kimae553032019-05-14 18:52:49 +0900675 if ctx.Config().VndkSnapshotBuildArtifacts() {
676 prop := struct {
677 ExportedDirs []string `json:",omitempty"`
678 ExportedSystemDirs []string `json:",omitempty"`
679 ExportedFlags []string `json:",omitempty"`
680 RelativeInstallPath string `json:",omitempty"`
681 }{}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700682 exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
683 prop.ExportedFlags = exportedInfo.Flags
684 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
685 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900686 prop.RelativeInstallPath = m.RelativeInstallPath()
687
Inseob Kim242ef0c2019-10-22 20:15:20 +0900688 propOut := snapshotLibOut + ".json"
Inseob Kimae553032019-05-14 18:52:49 +0900689
690 j, err := json.Marshal(prop)
691 if err != nil {
692 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900693 return nil, false
Inseob Kimae553032019-05-14 18:52:49 +0900694 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900695 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kimae553032019-05-14 18:52:49 +0900696 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900697 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900698 }
699
Inseob Kim1f086e22019-05-09 13:29:15 +0900700 ctx.VisitAllModules(func(module android.Module) {
701 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900702 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900703 return
704 }
705
Colin Cross56a83212020-09-15 18:30:11 -0700706 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
707
Inseob Kimde5744a2020-12-02 13:14:28 +0900708 l, vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900709 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200710 return
711 }
712
Inseob Kimde5744a2020-12-02 13:14:28 +0900713 // For all snapshot candidates, the followings are captured.
714 // - .so files
715 // - notice files
716 //
717 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
718 // - .json files containing exported flags
719 // - exported headers from collectHeadersForSnapshot()
720 //
721 // Headers are deduplicated after visiting all modules.
722
Inseob Kim8471cda2019-11-15 09:59:12 +0900723 // install .so files for appropriate modules.
724 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700725 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900726 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900727 return
728 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900729 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900730
Inseob Kim8471cda2019-11-15 09:59:12 +0900731 // These are for generating module_names.txt and module_paths.txt
732 stem := m.outputFile.Path().Base()
733 moduleNames[stem] = ctx.ModuleName(m)
734 modulePaths[stem] = ctx.ModuleDir(m)
735
Bob Badoura75b0572020-02-18 20:21:55 -0800736 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900737 noticeName := stem + ".txt"
738 // skip already copied notice file
739 if _, ok := noticeBuilt[noticeName]; !ok {
740 noticeBuilt[noticeName] = true
Inseob Kimde5744a2020-12-02 13:14:28 +0900741 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
Bob Badoura75b0572020-02-18 20:21:55 -0800742 ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName)))
Inseob Kim8471cda2019-11-15 09:59:12 +0900743 }
744 }
745
746 if ctx.Config().VndkSnapshotBuildArtifacts() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900747 headers = append(headers, l.snapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900748 }
749 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900750
Inseob Kim8471cda2019-11-15 09:59:12 +0900751 // install all headers after removing duplicates
752 for _, header := range android.FirstUniquePaths(headers) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900753 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900754 ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900755 }
756
Jooyung Han39edb6c2019-11-06 16:53:07 +0900757 // install *.libraries.txt except vndkcorevariant.libraries.txt
758 ctx.VisitAllModules(func(module android.Module) {
759 m, ok := module.(*vndkLibrariesTxt)
760 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
761 return
762 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900763 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900764 ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900765 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900766
Inseob Kim242ef0c2019-10-22 20:15:20 +0900767 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900768 module_paths.txt contains paths on which VNDK modules are defined.
769 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000770 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900771 libc.so bionic/libc
772 ...
773 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900774 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900775
776 /*
777 module_names.txt contains names as which VNDK modules are defined,
778 because output filename and module name can be different with stem and suffix properties.
779
780 e.g.,
781 libcutils.so libcutils
782 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
783 ...
784 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900785 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900786
787 // All artifacts are ready. Sort them to normalize ninja and then zip.
788 sort.Slice(snapshotOutputs, func(i, j int) bool {
789 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
790 })
791
792 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800793 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900794
Inseob Kimde5744a2020-12-02 13:14:28 +0900795 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900796 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
797 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900798 Text("tr").
799 FlagWithArg("-d ", "\\'").
800 FlagWithRspFileInputList("< ", snapshotOutputs).
801 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900802
803 zipRule.Temporary(snapshotOutputList)
804
805 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800806 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900807 FlagWithOutput("-o ", zipPath).
808 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
809 FlagWithInput("-l ", snapshotOutputList)
810
Colin Crossf1a035e2020-11-16 17:32:30 -0800811 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900812 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900813 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900814}
Jooyung Han097087b2019-10-22 19:32:18 +0900815
Jooyung Han0302a842019-10-30 18:43:49 +0900816func getVndkFileName(m *Module) (string, error) {
817 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900818 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900819 }
820 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900821 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900822 }
823 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900824}
825
826func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900827 llndk := android.SortedStringMapValues(llndkLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900828 vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
829 vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
830 vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900831
Jooyung Han2216fb12019-11-06 16:46:15 +0900832 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900833 // Since each target have different set of libclang_rt.* files,
834 // keep the common set of files in vndk.libraries.txt
835 var merged []string
Jooyung Han097087b2019-10-22 19:32:18 +0900836 filterOutLibClangRt := func(libList []string) (filtered []string) {
837 for _, lib := range libList {
838 if !strings.HasPrefix(lib, "libclang_rt.") {
839 filtered = append(filtered, lib)
840 }
841 }
842 return
843 }
844 merged = append(merged, addPrefix(filterOutLibClangRt(llndk), "LLNDK: ")...)
845 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
846 merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...)
847 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900848 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800849 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900850}
Jooyung Han097087b2019-10-22 19:32:18 +0900851
Jooyung Han0302a842019-10-30 18:43:49 +0900852func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
853 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
854 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700855 movedToApexLlndkLibraries := make(map[string]bool)
856 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800857 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
858 // Skip bionic libs, they are handled in different manner
859 name := library.implementationModuleName(module.(*Module).BaseModuleName())
860 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
861 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700862 }
Jooyung Han0302a842019-10-30 18:43:49 +0900863 }
Colin Cross56a83212020-09-15 18:30:11 -0700864 })
865
866 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
867 strings.Join(android.SortedStringKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900868
869 // Make uses LLNDK_LIBRARIES to determine which libraries to install.
870 // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
871 // Therefore, by removing the library here, we cause it to only be installed if libc
872 // depends on it.
873 installedLlndkLibraries := []string{}
874 for lib := range llndkLibraries(ctx.Config()) {
875 if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
876 continue
877 }
878 installedLlndkLibraries = append(installedLlndkLibraries, lib)
879 }
880 sort.Strings(installedLlndkLibraries)
881 ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
882
Jooyung Han0302a842019-10-30 18:43:49 +0900883 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkCoreLibraries(ctx.Config())), " "))
884 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(android.SortedStringKeys(vndkSpLibraries(ctx.Config())), " "))
885 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())), " "))
886 ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(android.SortedStringKeys(vndkUsingCoreVariantLibraries(ctx.Config())), " "))
887
Jooyung Han0302a842019-10-30 18:43:49 +0900888 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900889 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900890}