blob: c1bce160b4165af3d4d5f9c3007d95be59f86715 [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
Nan Zhang0007d812017-11-07 10:57:05 -0800143 if lib, ok := to.linker.(*llndkStubDecorator); ok && !Bool(lib.Properties.Vendor_available) {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900144 violation = true
145 } else {
146 if _, ok := to.linker.(libraryInterface); ok && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) {
147 // Vendor_available == nil && !Bool(Vendor_available) should be okay since
Justin Yun5f7f7e82019-11-18 19:52:14 +0900148 // it means a vendor-only, or product-only library which is a valid dependency
149 // for non-VNDK modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900150 violation = true
151 }
152 }
153 if violation {
154 ctx.ModuleErrorf("Vendor module that is not VNDK should not link to %q which is marked as `vendor_available: false`", to.Name())
155 }
156 }
Justin Yun8effde42017-06-23 19:24:43 +0900157 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
158 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800159 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900160 return
161 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800162
163 if to.IsLlndk() {
164 // LL-NDK libraries are allowed to link
165 return
166 }
167
Ivan Lozano52767be2019-10-18 14:49:46 -0700168 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900169 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
170 vndk.typeName(), to.Name())
171 return
172 }
Logan Chienf3511742017-10-31 18:04:35 +0800173 if tag == vndkExtDepTag {
174 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
175 // and has identical vndk properties.
176 if to.vndkdep == nil || !to.vndkdep.isVndk() {
177 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
178 return
179 }
180 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
181 ctx.ModuleErrorf(
182 "`extends` refers a module %q with mismatched support_system_process",
183 to.Name())
184 return
185 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900186 // TODO(b/150902910): vndk-ext for product must check product_available.
Logan Chienf3511742017-10-31 18:04:35 +0800187 if !Bool(to.VendorProperties.Vendor_available) {
188 ctx.ModuleErrorf(
189 "`extends` refers module %q which does not have `vendor_available: true`",
190 to.Name())
191 return
192 }
193 }
Justin Yun8effde42017-06-23 19:24:43 +0900194 if to.vndkdep == nil {
195 return
196 }
Logan Chienf3511742017-10-31 18:04:35 +0800197
Logan Chiend3c59a22018-03-29 14:08:15 +0800198 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100199 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
200 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
201 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800202 return
203 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800204}
Logan Chienf3511742017-10-31 18:04:35 +0800205
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100206func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800207 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
208 if from.isVndkExt() {
209 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100210 if to.isVndk() && !to.isVndkSp() {
211 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
212 }
213 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800214 }
215 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100216 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900217 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800218 if from.isVndk() {
219 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100220 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800221 }
222 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100223 if !to.isVndkSp() {
224 return errors.New("VNDK-SP must only depend on VNDK-SP")
225 }
226 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800227 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100228 if !to.isVndk() {
229 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
230 }
231 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800232 }
233 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100234 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900235}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900236
237var (
Jooyung Hana463f722019-11-01 08:45:59 +0900238 vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires")
239 vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires")
240 llndkLibrariesKey = android.NewOnceKey("llndkLibrarires")
241 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900242 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibraries")
Jooyung Hana463f722019-11-01 08:45:59 +0900243 vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
244 vndkLibrariesLock sync.Mutex
Inseob Kimae553032019-05-14 18:52:49 +0900245)
Inseob Kim1f086e22019-05-09 13:29:15 +0900246
Jooyung Han0302a842019-10-30 18:43:49 +0900247func vndkCoreLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900248 return config.Once(vndkCoreLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900249 return make(map[string]string)
250 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900251}
252
Jooyung Han0302a842019-10-30 18:43:49 +0900253func vndkSpLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900254 return config.Once(vndkSpLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900255 return make(map[string]string)
256 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900257}
258
Jooyung Han0302a842019-10-30 18:43:49 +0900259func llndkLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900260 return config.Once(llndkLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900261 return make(map[string]string)
262 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900263}
264
Jooyung Han0302a842019-10-30 18:43:49 +0900265func vndkPrivateLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900266 return config.Once(vndkPrivateLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900267 return make(map[string]string)
268 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900269}
270
Jooyung Han0302a842019-10-30 18:43:49 +0900271func vndkUsingCoreVariantLibraries(config android.Config) map[string]string {
Inseob Kim9516ee92019-05-09 10:56:13 +0900272 return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} {
Jooyung Han0302a842019-10-30 18:43:49 +0900273 return make(map[string]string)
274 }).(map[string]string)
Inseob Kim9516ee92019-05-09 10:56:13 +0900275}
276
Jooyung Han097087b2019-10-22 19:32:18 +0900277func vndkMustUseVendorVariantList(cfg android.Config) []string {
278 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900279 return config.VndkMustUseVendorVariantList
280 }).([]string)
281}
282
283// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
284// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
285func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900286 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900287 return mustUseVendorVariantList
288 })
289}
290
Inseob Kim1f086e22019-05-09 13:29:15 +0900291func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
292 lib := m.linker.(*llndkStubDecorator)
Colin Cross0477b422020-10-13 18:43:54 -0700293 name := m.ImplementationModuleName(mctx)
294 filename := name + ".so"
Inseob Kim9516ee92019-05-09 10:56:13 +0900295
Inseob Kim1f086e22019-05-09 13:29:15 +0900296 vndkLibrariesLock.Lock()
297 defer vndkLibrariesLock.Unlock()
Inseob Kim9516ee92019-05-09 10:56:13 +0900298
Jooyung Han0302a842019-10-30 18:43:49 +0900299 llndkLibraries(mctx.Config())[name] = filename
Colin Cross127bb8b2020-12-16 16:46:01 -0800300 m.VendorProperties.IsLLNDK = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900301 if !Bool(lib.Properties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900302 vndkPrivateLibraries(mctx.Config())[name] = filename
Colin Cross127bb8b2020-12-16 16:46:01 -0800303 m.VendorProperties.IsLLNDKPrivate = true
Jooyung Han61b66e92020-03-21 14:21:46 +0000304 }
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900305}
Inseob Kim1f086e22019-05-09 13:29:15 +0900306
307func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Jooyung Han0302a842019-10-30 18:43:49 +0900308 name := m.BaseModuleName()
309 filename, err := getVndkFileName(m)
310 if err != nil {
311 panic(err)
312 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900313
Colin Cross31076b32020-10-23 17:22:06 -0700314 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000315 // b/155456180 libz is the ONLY exception here. We don't want to make
316 // libz an LLNDK library because we in general can't guarantee that
317 // libz will behave consistently especially about the compression.
318 // i.e. the compressed output might be different across releases.
319 // As the library is an external one, it's risky to keep the compatibility
320 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900321 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
322 }
323
Inseob Kim1f086e22019-05-09 13:29:15 +0900324 vndkLibrariesLock.Lock()
325 defer vndkLibrariesLock.Unlock()
326
Jooyung Han097087b2019-10-22 19:32:18 +0900327 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
328 m.Properties.MustUseVendorVariant = true
329 }
Jooyung Han0302a842019-10-30 18:43:49 +0900330 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
331 vndkUsingCoreVariantLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900332 }
Jooyung Han0302a842019-10-30 18:43:49 +0900333
Inseob Kim1f086e22019-05-09 13:29:15 +0900334 if m.vndkdep.isVndkSp() {
Jooyung Han0302a842019-10-30 18:43:49 +0900335 vndkSpLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900336 } else {
Jooyung Han0302a842019-10-30 18:43:49 +0900337 vndkCoreLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900338 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900339 // As `vendor_available` and `product_available` has the same value for VNDK modules,
340 // we don't need to check both values.
Inseob Kim1f086e22019-05-09 13:29:15 +0900341 if !Bool(m.VendorProperties.Vendor_available) {
Jooyung Han0302a842019-10-30 18:43:49 +0900342 vndkPrivateLibraries(mctx.Config())[name] = filename
Inseob Kim1f086e22019-05-09 13:29:15 +0900343 }
344}
345
Yo Chiang08fac0c2020-07-29 01:08:20 +0800346// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800347func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900348 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800349 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900350 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800351 if !m.Device() {
352 // Skip non-device modules
353 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900354 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900355 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800356 // Skip native_bridge modules
357 return true
358 }
359 return false
360}
361
362func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
363 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900364 return false
365 }
366
367 // prebuilt vndk modules should match with device
368 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
369 // When b/142675459 is landed, remove following check
370 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) {
371 return false
372 }
373
374 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han73d20d02020-03-27 16:06:55 +0900375 // VNDK APEX for VNDK-Lite devices will have VNDK-SP libraries from core variants
376 if mctx.DeviceConfig().VndkVersion() == "" {
377 // b/73296261: filter out libz.so because it is considered as LLNDK for VNDK-lite devices
378 if mctx.ModuleName() == "libz" {
379 return false
380 }
381 return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.isVndkSp()
382 }
383
Justin Yun5f7f7e82019-11-18 19:52:14 +0900384 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900385 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozanof9e21722020-12-02 09:00:51 -0500386 return lib.shared() && m.inVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900387 }
388 return false
389}
390
Inseob Kim1f086e22019-05-09 13:29:15 +0900391// gather list of vndk-core, vndk-sp, and ll-ndk libs
392func VndkMutator(mctx android.BottomUpMutatorContext) {
393 m, ok := mctx.Module().(*Module)
394 if !ok {
395 return
396 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800397
398 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900399 return
400 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900401
402 if _, ok := m.linker.(*llndkStubDecorator); ok {
403 processLlndkLibrary(mctx, m)
404 return
405 }
406
Colin Cross127bb8b2020-12-16 16:46:01 -0800407 // This is a temporary measure to copy the properties from an llndk_library into the cc_library
408 // that will actually build the stubs. It will be removed once the properties are moved into
409 // the cc_library in the Android.bp files.
410 mergeLLNDKToLib := func(llndk *Module, llndkProperties *llndkLibraryProperties, flagExporter *flagExporter) {
411 if llndkLib := moduleLibraryInterface(llndk); llndkLib != nil {
412 *llndkProperties = llndkLib.(*llndkStubDecorator).Properties
413 flagExporter.Properties = llndkLib.(*llndkStubDecorator).flagExporter.Properties
414
415 m.VendorProperties.IsLLNDK = llndk.VendorProperties.IsLLNDK
416 m.VendorProperties.IsLLNDKPrivate = llndk.VendorProperties.IsLLNDKPrivate
417 }
418 }
419
Inseob Kim1f086e22019-05-09 13:29:15 +0900420 lib, is_lib := m.linker.(*libraryDecorator)
421 prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker)
422
Colin Cross127bb8b2020-12-16 16:46:01 -0800423 if m.UseVndk() && is_lib && lib.hasLLNDKStubs() {
424 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(lib.Properties.Llndk_stubs))
425 mergeLLNDKToLib(llndk[0].(*Module), &lib.Properties.Llndk, &lib.flagExporter)
426 }
427 if m.UseVndk() && is_prebuilt_lib && prebuilt_lib.hasLLNDKStubs() {
428 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(prebuilt_lib.Properties.Llndk_stubs))
429 mergeLLNDKToLib(llndk[0].(*Module), &prebuilt_lib.Properties.Llndk, &prebuilt_lib.flagExporter)
430 }
431
Inseob Kim64c43952019-08-26 16:52:35 +0900432 if (is_lib && lib.buildShared()) || (is_prebuilt_lib && prebuilt_lib.buildShared()) {
433 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900434 processVndkLibrary(mctx, m)
435 return
436 }
437 }
438}
439
440func init() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900441 android.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
Inseob Kim1f086e22019-05-09 13:29:15 +0900442 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900443}
444
Jooyung Han2216fb12019-11-06 16:46:15 +0900445type vndkLibrariesTxt struct {
446 android.ModuleBase
447 outputFile android.OutputPath
448}
449
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700450var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900451var _ android.OutputFileProducer = &vndkLibrariesTxt{}
452
Jooyung Han2216fb12019-11-06 16:46:15 +0900453// vndk_libraries_txt is a special kind of module type in that it name is one of
454// - llndk.libraries.txt
455// - vndkcore.libraries.txt
456// - vndksp.libraries.txt
457// - vndkprivate.libraries.txt
458// - vndkcorevariant.libraries.txt
459// A module behaves like a prebuilt_etc but its content is generated by soong.
460// By being a soong module, these files can be referenced by other soong modules.
461// For example, apex_vndk can depend on these files as prebuilt.
Jooyung Han39edb6c2019-11-06 16:53:07 +0900462func VndkLibrariesTxtFactory() android.Module {
Jooyung Han2216fb12019-11-06 16:46:15 +0900463 m := &vndkLibrariesTxt{}
464 android.InitAndroidModule(m)
465 return m
466}
467
468func insertVndkVersion(filename string, vndkVersion string) string {
469 if index := strings.LastIndex(filename, "."); index != -1 {
470 return filename[:index] + "." + vndkVersion + filename[index:]
471 }
472 return filename
473}
474
475func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
476 var list []string
477 switch txt.Name() {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900478 case llndkLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900479 for _, filename := range android.SortedStringMapValues(llndkLibraries(ctx.Config())) {
480 if strings.HasPrefix(filename, "libclang_rt.hwasan-") {
481 continue
482 }
483 list = append(list, filename)
484 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900485 case vndkCoreLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900486 list = android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900487 case vndkSpLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900488 list = android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900489 case vndkPrivateLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900490 list = android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900491 case vndkUsingCoreVariantLibrariesTxt:
Jooyung Han2216fb12019-11-06 16:46:15 +0900492 list = android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config()))
493 default:
494 ctx.ModuleErrorf("name(%s) is unknown.", txt.Name())
495 return
496 }
497
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900498 var filename string
499 if txt.Name() != vndkUsingCoreVariantLibrariesTxt {
500 filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
501 } else {
502 filename = txt.Name()
503 }
504
Jooyung Han2216fb12019-11-06 16:46:15 +0900505 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Colin Crosscf371cc2020-11-13 11:48:42 -0800506 android.WriteFileRule(ctx, txt.outputFile, strings.Join(list, "\n"))
Jooyung Han2216fb12019-11-06 16:46:15 +0900507
508 installPath := android.PathForModuleInstall(ctx, "etc")
509 ctx.InstallFile(installPath, filename, txt.outputFile)
510}
511
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900512func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
513 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900514 Class: "ETC",
515 OutputFile: android.OptionalPathForPath(txt.outputFile),
516 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
517 func(entries *android.AndroidMkEntries) {
518 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
519 },
520 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900521 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900522}
523
Jooyung Han0703fd82020-08-26 22:11:53 +0900524// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900525func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
526 return txt.outputFile
527}
528
Jooyung Han0703fd82020-08-26 22:11:53 +0900529// PrebuiltEtcModule interface
530func (txt *vndkLibrariesTxt) BaseDir() string {
531 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900532}
533
Jooyung Han0703fd82020-08-26 22:11:53 +0900534// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900535func (txt *vndkLibrariesTxt) SubDir() string {
536 return ""
537}
538
Jooyung Han0703fd82020-08-26 22:11:53 +0900539func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
540 return android.Paths{txt.outputFile}, nil
541}
542
Inseob Kim1f086e22019-05-09 13:29:15 +0900543func VndkSnapshotSingleton() android.Singleton {
544 return &vndkSnapshotSingleton{}
545}
546
Jooyung Han0302a842019-10-30 18:43:49 +0900547type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900548 vndkLibrariesFile android.OutputPath
549 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900550}
Inseob Kim1f086e22019-05-09 13:29:15 +0900551
Inseob Kimde5744a2020-12-02 13:14:28 +0900552func isVndkSnapshotAware(config android.DeviceConfig, m *Module,
Colin Cross56a83212020-09-15 18:30:11 -0700553 apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
554
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900555 if m.Target().NativeBridge == android.NativeBridgeEnabled {
556 return nil, "", false
557 }
Jooyung Han261e1582020-10-20 18:54:21 +0900558 // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
559 // !installable: Snapshot only cares about "installable" modules.
560 // isSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
Colin Cross56a83212020-09-15 18:30:11 -0700561 if !m.inVendor() || !m.installable(apexInfo) || m.isSnapshotPrebuilt() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900562 return nil, "", false
563 }
564 l, ok := m.linker.(snapshotLibraryInterface)
565 if !ok || !l.shared() {
566 return nil, "", false
567 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500568 if m.VndkVersion() == config.PlatformVndkVersion() && m.IsVndk() && !m.IsVndkExt() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900569 if m.isVndkSp() {
570 return l, "vndk-sp", true
571 } else {
572 return l, "vndk-core", true
573 }
574 }
575
576 return nil, "", false
577}
578
Inseob Kim1f086e22019-05-09 13:29:15 +0900579func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900580 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
581 c.buildVndkLibrariesTxtFiles(ctx)
582
Inseob Kim1f086e22019-05-09 13:29:15 +0900583 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
584 if ctx.DeviceConfig().VndkVersion() != "current" {
585 return
586 }
587
588 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
589 return
590 }
591
Inseob Kim242ef0c2019-10-22 20:15:20 +0900592 var snapshotOutputs android.Paths
593
594 /*
595 VNDK snapshot zipped artifacts directory structure:
596 {SNAPSHOT_ARCH}/
597 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
598 shared/
599 vndk-core/
600 (VNDK-core libraries, e.g. libbinder.so)
601 vndk-sp/
602 (VNDK-SP libraries, e.g. libc++.so)
603 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
604 shared/
605 vndk-core/
606 (VNDK-core libraries, e.g. libbinder.so)
607 vndk-sp/
608 (VNDK-SP libraries, e.g. libc++.so)
609 binder32/
610 (This directory is newly introduced in v28 (Android P) to hold
611 prebuilts built for 32-bit binder interface.)
612 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
613 ...
614 configs/
615 (various *.txt configuration files)
616 include/
617 (header files of same directory structure with source tree)
618 NOTICE_FILES/
619 (notice files of libraries, e.g. libcutils.so.txt)
620 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900621
622 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900623 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900624
Inseob Kim242ef0c2019-10-22 20:15:20 +0900625 configsDir := filepath.Join(snapshotArchDir, "configs")
626 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
627 includeDir := filepath.Join(snapshotArchDir, "include")
628
Inseob Kim242ef0c2019-10-22 20:15:20 +0900629 // set of notice files copied.
Inseob Kim1f086e22019-05-09 13:29:15 +0900630 noticeBuilt := make(map[string]bool)
631
Inseob Kim242ef0c2019-10-22 20:15:20 +0900632 // paths of VNDK modules for GPL license checking
633 modulePaths := make(map[string]string)
634
635 // actual module names of .so files
636 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
637 moduleNames := make(map[string]string)
638
Inseob Kim8471cda2019-11-15 09:59:12 +0900639 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900640
Inseob Kimde5744a2020-12-02 13:14:28 +0900641 // installVndkSnapshotLib copies built .so file from the module.
642 // Also, if the build artifacts is on, write a json file which contains all exported flags
643 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700644 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900645 var ret android.Paths
646
Inseob Kim8471cda2019-11-15 09:59:12 +0900647 targetArch := "arch-" + m.Target().Arch.ArchType.String()
648 if m.Target().Arch.ArchVariant != "" {
649 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900650 }
Inseob Kimae553032019-05-14 18:52:49 +0900651
Inseob Kim8471cda2019-11-15 09:59:12 +0900652 libPath := m.outputFile.Path()
653 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Inseob Kimde5744a2020-12-02 13:14:28 +0900654 ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900655
Inseob Kimae553032019-05-14 18:52:49 +0900656 if ctx.Config().VndkSnapshotBuildArtifacts() {
657 prop := struct {
658 ExportedDirs []string `json:",omitempty"`
659 ExportedSystemDirs []string `json:",omitempty"`
660 ExportedFlags []string `json:",omitempty"`
661 RelativeInstallPath string `json:",omitempty"`
662 }{}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700663 exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
664 prop.ExportedFlags = exportedInfo.Flags
665 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
666 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900667 prop.RelativeInstallPath = m.RelativeInstallPath()
668
Inseob Kim242ef0c2019-10-22 20:15:20 +0900669 propOut := snapshotLibOut + ".json"
Inseob Kimae553032019-05-14 18:52:49 +0900670
671 j, err := json.Marshal(prop)
672 if err != nil {
673 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900674 return nil, false
Inseob Kimae553032019-05-14 18:52:49 +0900675 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900676 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kimae553032019-05-14 18:52:49 +0900677 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900678 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900679 }
680
Inseob Kim1f086e22019-05-09 13:29:15 +0900681 ctx.VisitAllModules(func(module android.Module) {
682 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900683 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900684 return
685 }
686
Colin Cross56a83212020-09-15 18:30:11 -0700687 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
688
Inseob Kimde5744a2020-12-02 13:14:28 +0900689 l, vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900690 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200691 return
692 }
693
Inseob Kimde5744a2020-12-02 13:14:28 +0900694 // For all snapshot candidates, the followings are captured.
695 // - .so files
696 // - notice files
697 //
698 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
699 // - .json files containing exported flags
700 // - exported headers from collectHeadersForSnapshot()
701 //
702 // Headers are deduplicated after visiting all modules.
703
Inseob Kim8471cda2019-11-15 09:59:12 +0900704 // install .so files for appropriate modules.
705 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700706 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900707 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900708 return
709 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900710 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900711
Inseob Kim8471cda2019-11-15 09:59:12 +0900712 // These are for generating module_names.txt and module_paths.txt
713 stem := m.outputFile.Path().Base()
714 moduleNames[stem] = ctx.ModuleName(m)
715 modulePaths[stem] = ctx.ModuleDir(m)
716
Bob Badoura75b0572020-02-18 20:21:55 -0800717 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900718 noticeName := stem + ".txt"
719 // skip already copied notice file
720 if _, ok := noticeBuilt[noticeName]; !ok {
721 noticeBuilt[noticeName] = true
Inseob Kimde5744a2020-12-02 13:14:28 +0900722 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
Bob Badoura75b0572020-02-18 20:21:55 -0800723 ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName)))
Inseob Kim8471cda2019-11-15 09:59:12 +0900724 }
725 }
726
727 if ctx.Config().VndkSnapshotBuildArtifacts() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900728 headers = append(headers, l.snapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900729 }
730 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900731
Inseob Kim8471cda2019-11-15 09:59:12 +0900732 // install all headers after removing duplicates
733 for _, header := range android.FirstUniquePaths(headers) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900734 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900735 ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900736 }
737
Jooyung Han39edb6c2019-11-06 16:53:07 +0900738 // install *.libraries.txt except vndkcorevariant.libraries.txt
739 ctx.VisitAllModules(func(module android.Module) {
740 m, ok := module.(*vndkLibrariesTxt)
741 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
742 return
743 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900744 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900745 ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900746 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900747
Inseob Kim242ef0c2019-10-22 20:15:20 +0900748 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900749 module_paths.txt contains paths on which VNDK modules are defined.
750 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000751 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900752 libc.so bionic/libc
753 ...
754 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900755 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900756
757 /*
758 module_names.txt contains names as which VNDK modules are defined,
759 because output filename and module name can be different with stem and suffix properties.
760
761 e.g.,
762 libcutils.so libcutils
763 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
764 ...
765 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900766 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900767
768 // All artifacts are ready. Sort them to normalize ninja and then zip.
769 sort.Slice(snapshotOutputs, func(i, j int) bool {
770 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
771 })
772
773 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800774 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900775
Inseob Kimde5744a2020-12-02 13:14:28 +0900776 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900777 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
778 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900779 Text("tr").
780 FlagWithArg("-d ", "\\'").
781 FlagWithRspFileInputList("< ", snapshotOutputs).
782 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900783
784 zipRule.Temporary(snapshotOutputList)
785
786 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800787 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900788 FlagWithOutput("-o ", zipPath).
789 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
790 FlagWithInput("-l ", snapshotOutputList)
791
Colin Crossf1a035e2020-11-16 17:32:30 -0800792 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900793 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900794 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900795}
Jooyung Han097087b2019-10-22 19:32:18 +0900796
Jooyung Han0302a842019-10-30 18:43:49 +0900797func getVndkFileName(m *Module) (string, error) {
798 if library, ok := m.linker.(*libraryDecorator); ok {
799 return library.getLibNameHelper(m.BaseModuleName(), true) + ".so", nil
800 }
801 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
802 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true) + ".so", nil
803 }
804 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900805}
806
807func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900808 llndk := android.SortedStringMapValues(llndkLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900809 vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
810 vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
811 vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
Jooyung Han0302a842019-10-30 18:43:49 +0900812
Jooyung Han2216fb12019-11-06 16:46:15 +0900813 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900814 // Since each target have different set of libclang_rt.* files,
815 // keep the common set of files in vndk.libraries.txt
816 var merged []string
Jooyung Han097087b2019-10-22 19:32:18 +0900817 filterOutLibClangRt := func(libList []string) (filtered []string) {
818 for _, lib := range libList {
819 if !strings.HasPrefix(lib, "libclang_rt.") {
820 filtered = append(filtered, lib)
821 }
822 }
823 return
824 }
825 merged = append(merged, addPrefix(filterOutLibClangRt(llndk), "LLNDK: ")...)
826 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
827 merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...)
828 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900829 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800830 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900831}
Jooyung Han097087b2019-10-22 19:32:18 +0900832
Jooyung Han0302a842019-10-30 18:43:49 +0900833func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
834 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
835 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700836 movedToApexLlndkLibraries := make(map[string]bool)
837 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800838 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
839 // Skip bionic libs, they are handled in different manner
840 name := library.implementationModuleName(module.(*Module).BaseModuleName())
841 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
842 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700843 }
Jooyung Han0302a842019-10-30 18:43:49 +0900844 }
Colin Cross56a83212020-09-15 18:30:11 -0700845 })
846
847 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
848 strings.Join(android.SortedStringKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900849
850 // Make uses LLNDK_LIBRARIES to determine which libraries to install.
851 // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
852 // Therefore, by removing the library here, we cause it to only be installed if libc
853 // depends on it.
854 installedLlndkLibraries := []string{}
855 for lib := range llndkLibraries(ctx.Config()) {
856 if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
857 continue
858 }
859 installedLlndkLibraries = append(installedLlndkLibraries, lib)
860 }
861 sort.Strings(installedLlndkLibraries)
862 ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
863
Jooyung Han0302a842019-10-30 18:43:49 +0900864 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkCoreLibraries(ctx.Config())), " "))
865 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(android.SortedStringKeys(vndkSpLibraries(ctx.Config())), " "))
866 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())), " "))
867 ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(android.SortedStringKeys(vndkUsingCoreVariantLibraries(ctx.Config())), " "))
868
Jooyung Han0302a842019-10-30 18:43:49 +0900869 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900870 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900871}