blob: 499d4282cf460bc25d560b530cc7c7da9138e006 [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"
Jiyong Parkd5b18a52017-08-03 21:22:50 +090024
Justin Yun8effde42017-06-23 19:24:43 +090025 "android/soong/android"
Vic Yangefd249e2018-11-12 20:19:56 -080026 "android/soong/cc/config"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070027 "android/soong/etc"
Colin Cross6e511a92020-07-27 21:26:48 -070028
29 "github.com/google/blueprint"
Justin Yun8effde42017-06-23 19:24:43 +090030)
31
Jooyung Han39edb6c2019-11-06 16:53:07 +090032const (
33 llndkLibrariesTxt = "llndk.libraries.txt"
34 vndkCoreLibrariesTxt = "vndkcore.libraries.txt"
35 vndkSpLibrariesTxt = "vndksp.libraries.txt"
36 vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt"
Justin Yun8a2600c2020-12-07 12:44:03 +090037 vndkProductLibrariesTxt = "vndkproduct.libraries.txt"
Jooyung Han39edb6c2019-11-06 16:53:07 +090038 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,
Justin Yun8a2600c2020-12-07 12:44:03 +090048 vndkProductLibrariesTxt,
Jooyung Han39edb6c2019-11-06 16:53:07 +090049 }
50 }
51 // Snapshot vndks have their own *.libraries.VER.txt files.
52 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
53 return []string{
54 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
55 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
56 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
57 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
Justin Yun8a2600c2020-12-07 12:44:03 +090058 insertVndkVersion(vndkProductLibrariesTxt, vndkVersion),
Jooyung Han39edb6c2019-11-06 16:53:07 +090059 }
60}
61
Justin Yun8effde42017-06-23 19:24:43 +090062type VndkProperties struct {
63 Vndk struct {
64 // declared as a VNDK or VNDK-SP module. The vendor variant
65 // will be installed in /system instead of /vendor partition.
66 //
Justin Yun63e9ec72020-10-29 16:49:43 +090067 // `vendor_available` and `product_available` must be explicitly
68 // set to either true or false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090069 Enabled *bool
70
71 // declared as a VNDK-SP module, which is a subset of VNDK.
72 //
73 // `vndk: { enabled: true }` must set together.
74 //
75 // All these modules are allowed to link to VNDK-SP or LL-NDK
76 // modules only. Other dependency will cause link-type errors.
77 //
78 // If `support_system_process` is not set or set to false,
79 // the module is VNDK-core and can link to other VNDK-core,
80 // VNDK-SP or LL-NDK modules only.
81 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080082
Justin Yunfd9e8042020-12-23 18:23:14 +090083 // declared as a VNDK-private module.
84 // This module still creates the vendor and product variants refering
85 // to the `vendor_available: true` and `product_available: true`
86 // properties. However, it is only available to the other VNDK modules
87 // but not to the non-VNDK vendor or product modules.
88 Private *bool
89
Logan Chienf3511742017-10-31 18:04:35 +080090 // Extending another module
91 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090092 }
93}
94
95type vndkdep struct {
96 Properties VndkProperties
97}
98
99func (vndk *vndkdep) props() []interface{} {
100 return []interface{}{&vndk.Properties}
101}
102
Justin Yun8effde42017-06-23 19:24:43 +0900103func (vndk *vndkdep) isVndk() bool {
104 return Bool(vndk.Properties.Vndk.Enabled)
105}
106
107func (vndk *vndkdep) isVndkSp() bool {
108 return Bool(vndk.Properties.Vndk.Support_system_process)
109}
110
Logan Chienf3511742017-10-31 18:04:35 +0800111func (vndk *vndkdep) isVndkExt() bool {
112 return vndk.Properties.Vndk.Extends != nil
113}
114
115func (vndk *vndkdep) getVndkExtendsModuleName() string {
116 return String(vndk.Properties.Vndk.Extends)
117}
118
Justin Yun8effde42017-06-23 19:24:43 +0900119func (vndk *vndkdep) typeName() string {
120 if !vndk.isVndk() {
121 return "native:vendor"
122 }
Logan Chienf3511742017-10-31 18:04:35 +0800123 if !vndk.isVndkExt() {
124 if !vndk.isVndkSp() {
125 return "native:vendor:vndk"
126 }
127 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900128 }
Logan Chienf3511742017-10-31 18:04:35 +0800129 if !vndk.isVndkSp() {
130 return "native:vendor:vndkext"
131 }
132 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900133}
134
Justin Yun63e9ec72020-10-29 16:49:43 +0900135// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900136func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900137 if to.linker == nil {
138 return
139 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900140 if !vndk.isVndk() {
Justin Yunfd9e8042020-12-23 18:23:14 +0900141 // Non-VNDK modules those installed to /vendor, /system/vendor,
142 // /product or /system/product cannot depend on VNDK-private modules
143 // that include VNDK-core-private, VNDK-SP-private and LLNDK-private.
144 if to.IsVndkPrivate() {
145 ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name())
Jiyong Park82e2bf32017-08-16 14:05:54 +0900146 }
147 }
Justin Yun8effde42017-06-23 19:24:43 +0900148 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
149 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800150 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900151 return
152 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800153
154 if to.IsLlndk() {
155 // LL-NDK libraries are allowed to link
156 return
157 }
158
Ivan Lozano52767be2019-10-18 14:49:46 -0700159 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900160 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
161 vndk.typeName(), to.Name())
162 return
163 }
Logan Chienf3511742017-10-31 18:04:35 +0800164 if tag == vndkExtDepTag {
165 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
166 // and has identical vndk properties.
167 if to.vndkdep == nil || !to.vndkdep.isVndk() {
168 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
169 return
170 }
171 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
172 ctx.ModuleErrorf(
173 "`extends` refers a module %q with mismatched support_system_process",
174 to.Name())
175 return
176 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900177 if to.IsVndkPrivate() {
Logan Chienf3511742017-10-31 18:04:35 +0800178 ctx.ModuleErrorf(
Justin Yunfd9e8042020-12-23 18:23:14 +0900179 "`extends` refers module %q which has `private: true`",
Justin Yun6977e8a2020-10-29 18:24:11 +0900180 to.Name())
181 return
182 }
Logan Chienf3511742017-10-31 18:04:35 +0800183 }
Justin Yun8effde42017-06-23 19:24:43 +0900184 if to.vndkdep == nil {
185 return
186 }
Logan Chienf3511742017-10-31 18:04:35 +0800187
Logan Chiend3c59a22018-03-29 14:08:15 +0800188 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100189 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
190 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
191 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800192 return
193 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800194}
Logan Chienf3511742017-10-31 18:04:35 +0800195
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100196func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800197 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
198 if from.isVndkExt() {
199 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100200 if to.isVndk() && !to.isVndkSp() {
201 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
202 }
203 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800204 }
205 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100206 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900207 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800208 if from.isVndk() {
209 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100210 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800211 }
212 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100213 if !to.isVndkSp() {
214 return errors.New("VNDK-SP must only depend on VNDK-SP")
215 }
216 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800217 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100218 if !to.isVndk() {
219 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
220 }
221 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800222 }
223 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100224 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900225}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900226
Colin Cross78212242021-01-06 14:51:30 -0800227type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string)
228
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900229var (
Colin Cross203b4212021-04-26 17:19:41 -0700230 llndkLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsLLNDK && !m.Header() })
Colin Cross78212242021-01-06 14:51:30 -0800231 vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP })
232 vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore })
Colin Cross203b4212021-04-26 17:19:41 -0700233 vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate })
Colin Cross78212242021-01-06 14:51:30 -0800234 vndkProductLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKProduct })
235 vndkUsingCoreVariantLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKUsingCoreVariant })
Inseob Kimae553032019-05-14 18:52:49 +0900236)
Inseob Kim1f086e22019-05-09 13:29:15 +0900237
Colin Cross78212242021-01-06 14:51:30 -0800238// vndkModuleLister takes a predicate that operates on a Module and returns a moduleListerFunc
239// that produces a list of module names and output file names for which the predicate returns true.
240func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc {
241 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
242 ctx.VisitAllModules(func(m android.Module) {
243 if c, ok := m.(*Module); ok && predicate(c) {
244 filename, err := getVndkFileName(c)
245 if err != nil {
246 ctx.ModuleErrorf(m, "%s", err)
247 }
248 moduleNames = append(moduleNames, ctx.ModuleName(m))
249 fileNames = append(fileNames, filename)
250 }
251 })
252 moduleNames = android.SortedUniqueStrings(moduleNames)
253 fileNames = android.SortedUniqueStrings(fileNames)
254 return
255 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900256}
257
Colin Cross78212242021-01-06 14:51:30 -0800258// vndkModuleListRemover takes a moduleListerFunc and a prefix and returns a moduleListerFunc
259// that returns the same lists as the input moduleListerFunc, but with modules with the
260// given prefix removed.
261func vndkModuleListRemover(lister moduleListerFunc, prefix string) moduleListerFunc {
262 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
263 moduleNames, fileNames = lister(ctx)
264 filter := func(in []string) []string {
265 out := make([]string, 0, len(in))
266 for _, lib := range in {
267 if strings.HasPrefix(lib, prefix) {
268 continue
269 }
270 out = append(out, lib)
271 }
272 return out
273 }
274 return filter(moduleNames), filter(fileNames)
275 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900276}
277
Colin Cross78212242021-01-06 14:51:30 -0800278var vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
Inseob Kim9516ee92019-05-09 10:56:13 +0900279
Jooyung Han097087b2019-10-22 19:32:18 +0900280func vndkMustUseVendorVariantList(cfg android.Config) []string {
281 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900282 return config.VndkMustUseVendorVariantList
283 }).([]string)
284}
285
286// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
287// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
288func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900289 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900290 return mustUseVendorVariantList
291 })
292}
293
Inseob Kim1f086e22019-05-09 13:29:15 +0900294func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Justin Yun8a2600c2020-12-07 12:44:03 +0900295 if m.InProduct() {
296 // We may skip the steps for the product variants because they
297 // are already covered by the vendor variants.
298 return
299 }
300
Jooyung Han0302a842019-10-30 18:43:49 +0900301 name := m.BaseModuleName()
Inseob Kim1f086e22019-05-09 13:29:15 +0900302
Colin Cross31076b32020-10-23 17:22:06 -0700303 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000304 // b/155456180 libz is the ONLY exception here. We don't want to make
305 // libz an LLNDK library because we in general can't guarantee that
306 // libz will behave consistently especially about the compression.
307 // i.e. the compressed output might be different across releases.
308 // As the library is an external one, it's risky to keep the compatibility
309 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900310 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
311 }
312
Jooyung Han097087b2019-10-22 19:32:18 +0900313 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
314 m.Properties.MustUseVendorVariant = true
315 }
Jooyung Han0302a842019-10-30 18:43:49 +0900316 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
Colin Cross78212242021-01-06 14:51:30 -0800317 m.VendorProperties.IsVNDKUsingCoreVariant = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900318 }
Jooyung Han0302a842019-10-30 18:43:49 +0900319
Inseob Kim1f086e22019-05-09 13:29:15 +0900320 if m.vndkdep.isVndkSp() {
Colin Cross78212242021-01-06 14:51:30 -0800321 m.VendorProperties.IsVNDKSP = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900322 } else {
Colin Cross78212242021-01-06 14:51:30 -0800323 m.VendorProperties.IsVNDKCore = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900324 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900325 if m.IsVndkPrivate() {
Colin Cross78212242021-01-06 14:51:30 -0800326 m.VendorProperties.IsVNDKPrivate = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900327 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900328 if Bool(m.VendorProperties.Product_available) {
Colin Cross78212242021-01-06 14:51:30 -0800329 m.VendorProperties.IsVNDKProduct = true
Justin Yun8a2600c2020-12-07 12:44:03 +0900330 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900331}
332
Yo Chiang08fac0c2020-07-29 01:08:20 +0800333// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800334func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900335 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800336 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900337 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800338 if !m.Device() {
339 // Skip non-device modules
340 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900341 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900342 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800343 // Skip native_bridge modules
344 return true
345 }
346 return false
347}
348
349func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
350 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900351 return false
352 }
353
354 // prebuilt vndk modules should match with device
355 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
356 // When b/142675459 is landed, remove following check
Ivan Lozanod1dec542021-05-26 15:33:11 -0400357 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.MatchesWithDevice(mctx.DeviceConfig()) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900358 return false
359 }
360
361 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han73d20d02020-03-27 16:06:55 +0900362 // VNDK APEX for VNDK-Lite devices will have VNDK-SP libraries from core variants
363 if mctx.DeviceConfig().VndkVersion() == "" {
364 // b/73296261: filter out libz.so because it is considered as LLNDK for VNDK-lite devices
365 if mctx.ModuleName() == "libz" {
366 return false
367 }
Jooyung Han7d6e79b2021-06-24 01:53:43 +0900368 return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.IsVndkSp() && !m.IsVndkExt()
Jooyung Han73d20d02020-03-27 16:06:55 +0900369 }
370
Justin Yun5f7f7e82019-11-18 19:52:14 +0900371 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900372 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500373 return lib.shared() && m.InVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900374 }
375 return false
376}
377
Inseob Kim1f086e22019-05-09 13:29:15 +0900378// gather list of vndk-core, vndk-sp, and ll-ndk libs
379func VndkMutator(mctx android.BottomUpMutatorContext) {
380 m, ok := mctx.Module().(*Module)
381 if !ok {
382 return
383 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800384
385 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900386 return
387 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900388
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800389 lib, isLib := m.linker.(*libraryDecorator)
390 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900391
Colin Cross203b4212021-04-26 17:19:41 -0700392 if m.UseVndk() && isLib && lib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800393 m.VendorProperties.IsLLNDK = true
394 m.VendorProperties.IsVNDKPrivate = Bool(lib.Properties.Llndk.Private)
395 }
Colin Cross203b4212021-04-26 17:19:41 -0700396 if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800397 m.VendorProperties.IsLLNDK = true
398 m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private)
399 }
400
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800401 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900402 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900403 processVndkLibrary(mctx, m)
404 return
405 }
406 }
407}
408
409func init() {
Colin Crosse4e44bc2020-12-28 13:50:21 -0800410 RegisterVndkLibraryTxtTypes(android.InitRegistrationContext)
Inseob Kim1f086e22019-05-09 13:29:15 +0900411 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900412}
413
Colin Crosse4e44bc2020-12-28 13:50:21 -0800414func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) {
Colin Cross78212242021-01-06 14:51:30 -0800415 ctx.RegisterSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory)
416 ctx.RegisterSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory)
417 ctx.RegisterSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory)
418 ctx.RegisterSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory)
419 ctx.RegisterSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory)
420 ctx.RegisterSingletonModuleType("vndkcorevariant_libraries_txt", vndkUsingCoreVariantLibrariesTxtFactory)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800421}
422
Jooyung Han2216fb12019-11-06 16:46:15 +0900423type vndkLibrariesTxt struct {
Colin Cross78212242021-01-06 14:51:30 -0800424 android.SingletonModuleBase
Colin Crosse4e44bc2020-12-28 13:50:21 -0800425
Justin Yun611e8862021-05-24 18:17:33 +0900426 lister moduleListerFunc
427 makeVarName string
428 filterOutFromMakeVar string
Colin Cross78212242021-01-06 14:51:30 -0800429
Colin Crosse4e44bc2020-12-28 13:50:21 -0800430 properties VndkLibrariesTxtProperties
431
Colin Cross78212242021-01-06 14:51:30 -0800432 outputFile android.OutputPath
433 moduleNames []string
434 fileNames []string
Jooyung Han2216fb12019-11-06 16:46:15 +0900435}
436
Colin Crosse4e44bc2020-12-28 13:50:21 -0800437type VndkLibrariesTxtProperties struct {
438 Insert_vndk_version *bool
439}
440
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700441var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900442var _ android.OutputFileProducer = &vndkLibrariesTxt{}
443
Colin Cross78212242021-01-06 14:51:30 -0800444// llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries
445// generated by Soong but can be referenced by other modules.
Jooyung Han2216fb12019-11-06 16:46:15 +0900446// For example, apex_vndk can depend on these files as prebuilt.
Justin Yun611e8862021-05-24 18:17:33 +0900447// Make uses LLNDK_LIBRARIES to determine which libraries to install.
448// HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
449// Therefore, by removing the library here, we cause it to only be installed if libc
450// depends on it.
Colin Cross78212242021-01-06 14:51:30 -0800451func llndkLibrariesTxtFactory() android.SingletonModule {
Justin Yun611e8862021-05-24 18:17:33 +0900452 return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "LLNDK_LIBRARIES", "libclang_rt.hwasan-")
Colin Cross78212242021-01-06 14:51:30 -0800453}
454
455// vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries
456// generated by Soong but can be referenced by other modules.
457// For example, apex_vndk can depend on these files as prebuilt.
458func vndkSPLibrariesTxtFactory() android.SingletonModule {
459 return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES")
460}
461
462// vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries
463// generated by Soong but can be referenced by other modules.
464// For example, apex_vndk can depend on these files as prebuilt.
465func vndkCoreLibrariesTxtFactory() android.SingletonModule {
466 return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES")
467}
468
469// vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries
470// generated by Soong but can be referenced by other modules.
471// For example, apex_vndk can depend on these files as prebuilt.
472func vndkPrivateLibrariesTxtFactory() android.SingletonModule {
473 return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES")
474}
475
476// vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product libraries
477// generated by Soong but can be referenced by other modules.
478// For example, apex_vndk can depend on these files as prebuilt.
479func vndkProductLibrariesTxtFactory() android.SingletonModule {
480 return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES")
481}
482
483// vndkcorevariant_libraries_txt is a singleton module whose content is a list of VNDK libraries
484// that are using the core variant, generated by Soong but can be referenced by other modules.
485// For example, apex_vndk can depend on these files as prebuilt.
486func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule {
487 return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES")
488}
489
Justin Yun611e8862021-05-24 18:17:33 +0900490func newVndkLibrariesWithMakeVarFilter(lister moduleListerFunc, makeVarName string, filter string) android.SingletonModule {
Colin Cross78212242021-01-06 14:51:30 -0800491 m := &vndkLibrariesTxt{
Justin Yun611e8862021-05-24 18:17:33 +0900492 lister: lister,
493 makeVarName: makeVarName,
494 filterOutFromMakeVar: filter,
Colin Crosse4e44bc2020-12-28 13:50:21 -0800495 }
Colin Cross78212242021-01-06 14:51:30 -0800496 m.AddProperties(&m.properties)
497 android.InitAndroidModule(m)
498 return m
Jooyung Han2216fb12019-11-06 16:46:15 +0900499}
500
Justin Yun611e8862021-05-24 18:17:33 +0900501func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule {
502 return newVndkLibrariesWithMakeVarFilter(lister, makeVarName, "")
503}
504
Jooyung Han2216fb12019-11-06 16:46:15 +0900505func insertVndkVersion(filename string, vndkVersion string) string {
506 if index := strings.LastIndex(filename, "."); index != -1 {
507 return filename[:index] + "." + vndkVersion + filename[index:]
508 }
509 return filename
510}
511
Colin Crosse4e44bc2020-12-28 13:50:21 -0800512func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900513 var filename string
Colin Crosse4e44bc2020-12-28 13:50:21 -0800514 if BoolDefault(txt.properties.Insert_vndk_version, true) {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900515 filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
516 } else {
517 filename = txt.Name()
518 }
519
Jooyung Han2216fb12019-11-06 16:46:15 +0900520 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Jooyung Han2216fb12019-11-06 16:46:15 +0900521
522 installPath := android.PathForModuleInstall(ctx, "etc")
523 ctx.InstallFile(installPath, filename, txt.outputFile)
524}
525
Colin Cross78212242021-01-06 14:51:30 -0800526func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) {
527 txt.moduleNames, txt.fileNames = txt.lister(ctx)
528 android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n"))
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{
Colin Crossaa255532020-07-03 13:18:24 -0700536 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900537 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
Colin Cross78212242021-01-06 14:51:30 -0800543func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) {
Justin Yun611e8862021-05-24 18:17:33 +0900544 filter := func(modules []string, prefix string) []string {
545 if prefix == "" {
546 return modules
547 }
548 var result []string
549 for _, module := range modules {
550 if strings.HasPrefix(module, prefix) {
551 continue
552 } else {
553 result = append(result, module)
554 }
555 }
556 return result
557 }
558 ctx.Strict(txt.makeVarName, strings.Join(filter(txt.moduleNames, txt.filterOutFromMakeVar), " "))
Colin Cross78212242021-01-06 14:51:30 -0800559}
560
Jooyung Han0703fd82020-08-26 22:11:53 +0900561// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900562func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
563 return txt.outputFile
564}
565
Jooyung Han0703fd82020-08-26 22:11:53 +0900566// PrebuiltEtcModule interface
567func (txt *vndkLibrariesTxt) BaseDir() string {
568 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900569}
570
Jooyung Han0703fd82020-08-26 22:11:53 +0900571// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900572func (txt *vndkLibrariesTxt) SubDir() string {
573 return ""
574}
575
Jooyung Han0703fd82020-08-26 22:11:53 +0900576func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
577 return android.Paths{txt.outputFile}, nil
578}
579
Inseob Kim1f086e22019-05-09 13:29:15 +0900580func VndkSnapshotSingleton() android.Singleton {
581 return &vndkSnapshotSingleton{}
582}
583
Jooyung Han0302a842019-10-30 18:43:49 +0900584type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900585 vndkLibrariesFile android.OutputPath
586 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900587}
Inseob Kim1f086e22019-05-09 13:29:15 +0900588
Ivan Lozanod7586b62021-04-01 09:49:36 -0400589func isVndkSnapshotAware(config android.DeviceConfig, m LinkableInterface,
590 apexInfo android.ApexInfo) (vndkType string, isVndkSnapshotLib bool) {
Colin Cross56a83212020-09-15 18:30:11 -0700591
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900592 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400593 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900594 }
Jooyung Han261e1582020-10-20 18:54:21 +0900595 // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
596 // !installable: Snapshot only cares about "installable" modules.
Justin Yun450ae722021-04-16 19:58:18 +0900597 // !m.IsLlndk: llndk stubs are required for building against snapshots.
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400598 // IsSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
Justin Yun450ae722021-04-16 19:58:18 +0900599 // !outputFile.Valid: Snapshot requires valid output file.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400600 if !m.InVendor() || (!installable(m, apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.OutputFile().Valid() {
601 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900602 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400603 if !m.IsSnapshotLibrary() || !m.Shared() {
604 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900605 }
Justin Yun450ae722021-04-16 19:58:18 +0900606 if m.VndkVersion() == config.PlatformVndkVersion() {
607 if m.IsVndk() && !m.IsVndkExt() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400608 if m.IsVndkSp() {
609 return "vndk-sp", true
Justin Yun450ae722021-04-16 19:58:18 +0900610 } else {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400611 return "vndk-core", true
Justin Yun450ae722021-04-16 19:58:18 +0900612 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400613 } else if m.HasLlndkStubs() && m.StubsVersion() == "" {
Justin Yun450ae722021-04-16 19:58:18 +0900614 // Use default version for the snapshot.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400615 return "llndk-stub", true
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900616 }
617 }
618
Ivan Lozanod7586b62021-04-01 09:49:36 -0400619 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900620}
621
Inseob Kim1f086e22019-05-09 13:29:15 +0900622func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900623 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
624 c.buildVndkLibrariesTxtFiles(ctx)
625
Inseob Kim1f086e22019-05-09 13:29:15 +0900626 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
627 if ctx.DeviceConfig().VndkVersion() != "current" {
628 return
629 }
630
631 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
632 return
633 }
634
Inseob Kim242ef0c2019-10-22 20:15:20 +0900635 var snapshotOutputs android.Paths
636
637 /*
638 VNDK snapshot zipped artifacts directory structure:
639 {SNAPSHOT_ARCH}/
640 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
641 shared/
642 vndk-core/
643 (VNDK-core libraries, e.g. libbinder.so)
644 vndk-sp/
645 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900646 llndk-stub/
647 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900648 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
649 shared/
650 vndk-core/
651 (VNDK-core libraries, e.g. libbinder.so)
652 vndk-sp/
653 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900654 llndk-stub/
655 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900656 binder32/
657 (This directory is newly introduced in v28 (Android P) to hold
658 prebuilts built for 32-bit binder interface.)
659 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
660 ...
661 configs/
662 (various *.txt configuration files)
663 include/
664 (header files of same directory structure with source tree)
665 NOTICE_FILES/
666 (notice files of libraries, e.g. libcutils.so.txt)
667 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900668
669 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900670 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900671
Inseob Kim242ef0c2019-10-22 20:15:20 +0900672 configsDir := filepath.Join(snapshotArchDir, "configs")
673 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
674 includeDir := filepath.Join(snapshotArchDir, "include")
675
Inseob Kim242ef0c2019-10-22 20:15:20 +0900676 // set of notice files copied.
Inseob Kim1f086e22019-05-09 13:29:15 +0900677 noticeBuilt := make(map[string]bool)
678
Inseob Kim242ef0c2019-10-22 20:15:20 +0900679 // paths of VNDK modules for GPL license checking
680 modulePaths := make(map[string]string)
681
682 // actual module names of .so files
683 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
684 moduleNames := make(map[string]string)
685
Inseob Kim8471cda2019-11-15 09:59:12 +0900686 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900687
Inseob Kimde5744a2020-12-02 13:14:28 +0900688 // installVndkSnapshotLib copies built .so file from the module.
689 // Also, if the build artifacts is on, write a json file which contains all exported flags
690 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700691 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900692 var ret android.Paths
693
Inseob Kim8471cda2019-11-15 09:59:12 +0900694 targetArch := "arch-" + m.Target().Arch.ArchType.String()
695 if m.Target().Arch.ArchVariant != "" {
696 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900697 }
Inseob Kimae553032019-05-14 18:52:49 +0900698
Inseob Kim8471cda2019-11-15 09:59:12 +0900699 libPath := m.outputFile.Path()
700 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Inseob Kimde5744a2020-12-02 13:14:28 +0900701 ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900702
Inseob Kimae553032019-05-14 18:52:49 +0900703 if ctx.Config().VndkSnapshotBuildArtifacts() {
704 prop := struct {
705 ExportedDirs []string `json:",omitempty"`
706 ExportedSystemDirs []string `json:",omitempty"`
707 ExportedFlags []string `json:",omitempty"`
708 RelativeInstallPath string `json:",omitempty"`
709 }{}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700710 exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
711 prop.ExportedFlags = exportedInfo.Flags
712 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
713 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900714 prop.RelativeInstallPath = m.RelativeInstallPath()
715
Inseob Kim242ef0c2019-10-22 20:15:20 +0900716 propOut := snapshotLibOut + ".json"
Inseob Kimae553032019-05-14 18:52:49 +0900717
718 j, err := json.Marshal(prop)
719 if err != nil {
720 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900721 return nil, false
Inseob Kimae553032019-05-14 18:52:49 +0900722 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900723 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kimae553032019-05-14 18:52:49 +0900724 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900725 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900726 }
727
Inseob Kim1f086e22019-05-09 13:29:15 +0900728 ctx.VisitAllModules(func(module android.Module) {
729 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900730 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900731 return
732 }
733
Colin Cross56a83212020-09-15 18:30:11 -0700734 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
735
Ivan Lozanod7586b62021-04-01 09:49:36 -0400736 vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900737 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200738 return
739 }
740
Inseob Kimde5744a2020-12-02 13:14:28 +0900741 // For all snapshot candidates, the followings are captured.
742 // - .so files
743 // - notice files
744 //
745 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
746 // - .json files containing exported flags
747 // - exported headers from collectHeadersForSnapshot()
748 //
749 // Headers are deduplicated after visiting all modules.
750
Inseob Kim8471cda2019-11-15 09:59:12 +0900751 // install .so files for appropriate modules.
752 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700753 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900754 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900755 return
756 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900757 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900758
Inseob Kim8471cda2019-11-15 09:59:12 +0900759 // These are for generating module_names.txt and module_paths.txt
760 stem := m.outputFile.Path().Base()
761 moduleNames[stem] = ctx.ModuleName(m)
762 modulePaths[stem] = ctx.ModuleDir(m)
763
Bob Badoura75b0572020-02-18 20:21:55 -0800764 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900765 noticeName := stem + ".txt"
766 // skip already copied notice file
767 if _, ok := noticeBuilt[noticeName]; !ok {
768 noticeBuilt[noticeName] = true
Inseob Kimde5744a2020-12-02 13:14:28 +0900769 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
Bob Badoura75b0572020-02-18 20:21:55 -0800770 ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName)))
Inseob Kim8471cda2019-11-15 09:59:12 +0900771 }
772 }
773
774 if ctx.Config().VndkSnapshotBuildArtifacts() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400775 headers = append(headers, m.SnapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900776 }
777 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900778
Inseob Kim8471cda2019-11-15 09:59:12 +0900779 // install all headers after removing duplicates
780 for _, header := range android.FirstUniquePaths(headers) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900781 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900782 ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900783 }
784
Jooyung Han39edb6c2019-11-06 16:53:07 +0900785 // install *.libraries.txt except vndkcorevariant.libraries.txt
786 ctx.VisitAllModules(func(module android.Module) {
787 m, ok := module.(*vndkLibrariesTxt)
788 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
789 return
790 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900791 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900792 ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900793 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900794
Inseob Kim242ef0c2019-10-22 20:15:20 +0900795 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900796 module_paths.txt contains paths on which VNDK modules are defined.
797 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000798 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900799 libc.so bionic/libc
800 ...
801 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900802 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900803
804 /*
805 module_names.txt contains names as which VNDK modules are defined,
806 because output filename and module name can be different with stem and suffix properties.
807
808 e.g.,
809 libcutils.so libcutils
810 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
811 ...
812 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900813 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900814
815 // All artifacts are ready. Sort them to normalize ninja and then zip.
816 sort.Slice(snapshotOutputs, func(i, j int) bool {
817 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
818 })
819
820 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800821 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900822
Inseob Kimde5744a2020-12-02 13:14:28 +0900823 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900824 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
Colin Cross70c47412021-03-12 17:48:14 -0800825 rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp")
Inseob Kim242ef0c2019-10-22 20:15:20 +0900826 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900827 Text("tr").
828 FlagWithArg("-d ", "\\'").
Colin Cross70c47412021-03-12 17:48:14 -0800829 FlagWithRspFileInputList("< ", rspFile, snapshotOutputs).
Inseob Kim8471cda2019-11-15 09:59:12 +0900830 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900831
832 zipRule.Temporary(snapshotOutputList)
833
834 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800835 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900836 FlagWithOutput("-o ", zipPath).
837 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
838 FlagWithInput("-l ", snapshotOutputList)
839
Colin Crossf1a035e2020-11-16 17:32:30 -0800840 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900841 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900842 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900843}
Jooyung Han097087b2019-10-22 19:32:18 +0900844
Jooyung Han0302a842019-10-30 18:43:49 +0900845func getVndkFileName(m *Module) (string, error) {
846 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900847 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900848 }
849 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900850 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900851 }
852 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900853}
854
855func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900856 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900857 // Since each target have different set of libclang_rt.* files,
858 // keep the common set of files in vndk.libraries.txt
Colin Cross78212242021-01-06 14:51:30 -0800859 _, llndk := vndkModuleListRemover(llndkLibraries, "libclang_rt.")(ctx)
860 _, vndkcore := vndkModuleListRemover(vndkCoreLibraries, "libclang_rt.")(ctx)
861 _, vndksp := vndkSPLibraries(ctx)
862 _, vndkprivate := vndkPrivateLibraries(ctx)
863 _, vndkproduct := vndkModuleListRemover(vndkProductLibraries, "libclang_rt.")(ctx)
Jooyung Han0302a842019-10-30 18:43:49 +0900864 var merged []string
Colin Cross78212242021-01-06 14:51:30 -0800865 merged = append(merged, addPrefix(llndk, "LLNDK: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900866 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800867 merged = append(merged, addPrefix(vndkcore, "VNDK-core: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900868 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800869 merged = append(merged, addPrefix(vndkproduct, "VNDK-product: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900870 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800871 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900872}
Jooyung Han097087b2019-10-22 19:32:18 +0900873
Jooyung Han0302a842019-10-30 18:43:49 +0900874func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
875 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
876 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700877 movedToApexLlndkLibraries := make(map[string]bool)
878 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800879 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
880 // Skip bionic libs, they are handled in different manner
881 name := library.implementationModuleName(module.(*Module).BaseModuleName())
882 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
883 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700884 }
Jooyung Han0302a842019-10-30 18:43:49 +0900885 }
Colin Cross56a83212020-09-15 18:30:11 -0700886 })
887
888 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
889 strings.Join(android.SortedStringKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900890
Jooyung Han0302a842019-10-30 18:43:49 +0900891 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900892 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900893}