blob: 548992d3718cb1fc5b890905223e0f47b99bbeef [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 (
Martin Stjernholm257eb0c2018-10-15 13:05:27 +010018 "errors"
Jooyung Han0302a842019-10-30 18:43:49 +090019 "fmt"
Jiyong Parkd5b18a52017-08-03 21:22:50 +090020 "strings"
Jiyong Parkd5b18a52017-08-03 21:22:50 +090021
Justin Yun8effde42017-06-23 19:24:43 +090022 "android/soong/android"
Vic Yangefd249e2018-11-12 20:19:56 -080023 "android/soong/cc/config"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070024 "android/soong/etc"
Colin Cross6e511a92020-07-27 21:26:48 -070025
26 "github.com/google/blueprint"
Justin Yund5784122023-10-25 13:25:32 +090027 "github.com/google/blueprint/proptools"
Justin Yun8effde42017-06-23 19:24:43 +090028)
29
Jooyung Han39edb6c2019-11-06 16:53:07 +090030const (
31 llndkLibrariesTxt = "llndk.libraries.txt"
Justin Yund5784122023-10-25 13:25:32 +090032 llndkLibrariesTxtForApex = "llndk.libraries.txt.apex"
Jooyung Han39edb6c2019-11-06 16:53:07 +090033 vndkCoreLibrariesTxt = "vndkcore.libraries.txt"
34 vndkSpLibrariesTxt = "vndksp.libraries.txt"
35 vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt"
Justin Yun8a2600c2020-12-07 12:44:03 +090036 vndkProductLibrariesTxt = "vndkproduct.libraries.txt"
Jooyung Han39edb6c2019-11-06 16:53:07 +090037 vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt"
38)
39
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090040func VndkLibrariesTxtModules(vndkVersion string, ctx android.BaseModuleContext) []string {
Jooyung Han39edb6c2019-11-06 16:53:07 +090041 // Snapshot vndks have their own *.libraries.VER.txt files.
42 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090043 result := []string{
Jooyung Han39edb6c2019-11-06 16:53:07 +090044 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
45 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
46 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
Justin Yun8a2600c2020-12-07 12:44:03 +090047 insertVndkVersion(vndkProductLibrariesTxt, vndkVersion),
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090048 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
Jooyung Han39edb6c2019-11-06 16:53:07 +090049 }
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090050
51 return result
Jooyung Han39edb6c2019-11-06 16:53:07 +090052}
53
Justin Yun8effde42017-06-23 19:24:43 +090054type VndkProperties struct {
55 Vndk struct {
56 // declared as a VNDK or VNDK-SP module. The vendor variant
57 // will be installed in /system instead of /vendor partition.
58 //
Justin Yun63e9ec72020-10-29 16:49:43 +090059 // `vendor_available` and `product_available` must be explicitly
60 // set to either true or false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090061 Enabled *bool
62
63 // declared as a VNDK-SP module, which is a subset of VNDK.
64 //
65 // `vndk: { enabled: true }` must set together.
66 //
67 // All these modules are allowed to link to VNDK-SP or LL-NDK
68 // modules only. Other dependency will cause link-type errors.
69 //
70 // If `support_system_process` is not set or set to false,
71 // the module is VNDK-core and can link to other VNDK-core,
72 // VNDK-SP or LL-NDK modules only.
73 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080074
Justin Yunfd9e8042020-12-23 18:23:14 +090075 // declared as a VNDK-private module.
76 // This module still creates the vendor and product variants refering
77 // to the `vendor_available: true` and `product_available: true`
78 // properties. However, it is only available to the other VNDK modules
79 // but not to the non-VNDK vendor or product modules.
80 Private *bool
81
Logan Chienf3511742017-10-31 18:04:35 +080082 // Extending another module
83 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090084 }
85}
86
87type vndkdep struct {
88 Properties VndkProperties
89}
90
91func (vndk *vndkdep) props() []interface{} {
92 return []interface{}{&vndk.Properties}
93}
94
Justin Yun8effde42017-06-23 19:24:43 +090095func (vndk *vndkdep) isVndk() bool {
96 return Bool(vndk.Properties.Vndk.Enabled)
97}
98
99func (vndk *vndkdep) isVndkSp() bool {
100 return Bool(vndk.Properties.Vndk.Support_system_process)
101}
102
Logan Chienf3511742017-10-31 18:04:35 +0800103func (vndk *vndkdep) isVndkExt() bool {
104 return vndk.Properties.Vndk.Extends != nil
105}
106
107func (vndk *vndkdep) getVndkExtendsModuleName() string {
108 return String(vndk.Properties.Vndk.Extends)
109}
110
Justin Yun8effde42017-06-23 19:24:43 +0900111func (vndk *vndkdep) typeName() string {
112 if !vndk.isVndk() {
113 return "native:vendor"
114 }
Logan Chienf3511742017-10-31 18:04:35 +0800115 if !vndk.isVndkExt() {
116 if !vndk.isVndkSp() {
117 return "native:vendor:vndk"
118 }
119 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900120 }
Logan Chienf3511742017-10-31 18:04:35 +0800121 if !vndk.isVndkSp() {
122 return "native:vendor:vndkext"
123 }
124 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900125}
126
Justin Yun63e9ec72020-10-29 16:49:43 +0900127// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900128func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900129 if to.linker == nil {
130 return
131 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900132 if !vndk.isVndk() {
Justin Yunfd9e8042020-12-23 18:23:14 +0900133 // Non-VNDK modules those installed to /vendor, /system/vendor,
134 // /product or /system/product cannot depend on VNDK-private modules
135 // that include VNDK-core-private, VNDK-SP-private and LLNDK-private.
136 if to.IsVndkPrivate() {
137 ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name())
Jiyong Park82e2bf32017-08-16 14:05:54 +0900138 }
139 }
Justin Yun8effde42017-06-23 19:24:43 +0900140 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
141 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800142 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900143 return
144 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800145
146 if to.IsLlndk() {
147 // LL-NDK libraries are allowed to link
148 return
149 }
150
Ivan Lozano52767be2019-10-18 14:49:46 -0700151 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900152 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
153 vndk.typeName(), to.Name())
154 return
155 }
Logan Chienf3511742017-10-31 18:04:35 +0800156 if tag == vndkExtDepTag {
157 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
158 // and has identical vndk properties.
159 if to.vndkdep == nil || !to.vndkdep.isVndk() {
160 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
161 return
162 }
163 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
164 ctx.ModuleErrorf(
165 "`extends` refers a module %q with mismatched support_system_process",
166 to.Name())
167 return
168 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900169 if to.IsVndkPrivate() {
Logan Chienf3511742017-10-31 18:04:35 +0800170 ctx.ModuleErrorf(
Justin Yunfd9e8042020-12-23 18:23:14 +0900171 "`extends` refers module %q which has `private: true`",
Justin Yun6977e8a2020-10-29 18:24:11 +0900172 to.Name())
173 return
174 }
Logan Chienf3511742017-10-31 18:04:35 +0800175 }
Justin Yun8effde42017-06-23 19:24:43 +0900176 if to.vndkdep == nil {
177 return
178 }
Logan Chienf3511742017-10-31 18:04:35 +0800179
Logan Chiend3c59a22018-03-29 14:08:15 +0800180 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100181 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
182 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
183 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800184 return
185 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800186}
Logan Chienf3511742017-10-31 18:04:35 +0800187
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100188func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800189 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
190 if from.isVndkExt() {
191 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100192 if to.isVndk() && !to.isVndkSp() {
193 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
194 }
195 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800196 }
197 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100198 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900199 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800200 if from.isVndk() {
201 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100202 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800203 }
204 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100205 if !to.isVndkSp() {
206 return errors.New("VNDK-SP must only depend on VNDK-SP")
207 }
208 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800209 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100210 if !to.isVndk() {
211 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
212 }
213 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800214 }
215 // Vendor modules 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}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900218
Colin Cross78212242021-01-06 14:51:30 -0800219type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string)
220
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900221var (
Colin Cross78212242021-01-06 14:51:30 -0800222 vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP })
223 vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore })
Colin Cross203b4212021-04-26 17:19:41 -0700224 vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate })
Colin Cross78212242021-01-06 14:51:30 -0800225 vndkProductLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKProduct })
226 vndkUsingCoreVariantLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKUsingCoreVariant })
Inseob Kimae553032019-05-14 18:52:49 +0900227)
Inseob Kim1f086e22019-05-09 13:29:15 +0900228
Colin Cross78212242021-01-06 14:51:30 -0800229// vndkModuleLister takes a predicate that operates on a Module and returns a moduleListerFunc
230// that produces a list of module names and output file names for which the predicate returns true.
231func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc {
232 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
233 ctx.VisitAllModules(func(m android.Module) {
Jooyung Hane3f02812023-05-08 13:54:50 +0900234 if c, ok := m.(*Module); ok && predicate(c) && !c.IsVndkPrebuiltLibrary() {
Colin Cross78212242021-01-06 14:51:30 -0800235 filename, err := getVndkFileName(c)
236 if err != nil {
237 ctx.ModuleErrorf(m, "%s", err)
238 }
239 moduleNames = append(moduleNames, ctx.ModuleName(m))
240 fileNames = append(fileNames, filename)
241 }
242 })
243 moduleNames = android.SortedUniqueStrings(moduleNames)
244 fileNames = android.SortedUniqueStrings(fileNames)
245 return
246 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900247}
248
Colin Cross78212242021-01-06 14:51:30 -0800249// vndkModuleListRemover takes a moduleListerFunc and a prefix and returns a moduleListerFunc
250// that returns the same lists as the input moduleListerFunc, but with modules with the
251// given prefix removed.
252func vndkModuleListRemover(lister moduleListerFunc, prefix string) moduleListerFunc {
253 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
254 moduleNames, fileNames = lister(ctx)
255 filter := func(in []string) []string {
256 out := make([]string, 0, len(in))
257 for _, lib := range in {
258 if strings.HasPrefix(lib, prefix) {
259 continue
260 }
261 out = append(out, lib)
262 }
263 return out
264 }
265 return filter(moduleNames), filter(fileNames)
266 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900267}
268
Colin Cross78212242021-01-06 14:51:30 -0800269var vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
Inseob Kim9516ee92019-05-09 10:56:13 +0900270
Jooyung Han097087b2019-10-22 19:32:18 +0900271func vndkMustUseVendorVariantList(cfg android.Config) []string {
272 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900273 return config.VndkMustUseVendorVariantList
274 }).([]string)
275}
276
277// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
278// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
279func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900280 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900281 return mustUseVendorVariantList
282 })
283}
284
Inseob Kim1f086e22019-05-09 13:29:15 +0900285func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Justin Yun8a2600c2020-12-07 12:44:03 +0900286 if m.InProduct() {
287 // We may skip the steps for the product variants because they
288 // are already covered by the vendor variants.
289 return
290 }
291
Jooyung Han0302a842019-10-30 18:43:49 +0900292 name := m.BaseModuleName()
Inseob Kim1f086e22019-05-09 13:29:15 +0900293
Colin Cross31076b32020-10-23 17:22:06 -0700294 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000295 // b/155456180 libz is the ONLY exception here. We don't want to make
296 // libz an LLNDK library because we in general can't guarantee that
297 // libz will behave consistently especially about the compression.
298 // i.e. the compressed output might be different across releases.
299 // As the library is an external one, it's risky to keep the compatibility
300 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900301 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
302 }
303
Jooyung Han097087b2019-10-22 19:32:18 +0900304 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
305 m.Properties.MustUseVendorVariant = true
306 }
Jooyung Han0302a842019-10-30 18:43:49 +0900307 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
Colin Cross78212242021-01-06 14:51:30 -0800308 m.VendorProperties.IsVNDKUsingCoreVariant = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900309 }
Jooyung Han0302a842019-10-30 18:43:49 +0900310
Inseob Kim1f086e22019-05-09 13:29:15 +0900311 if m.vndkdep.isVndkSp() {
Colin Cross78212242021-01-06 14:51:30 -0800312 m.VendorProperties.IsVNDKSP = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900313 } else {
Colin Cross78212242021-01-06 14:51:30 -0800314 m.VendorProperties.IsVNDKCore = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900315 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900316 if m.IsVndkPrivate() {
Colin Cross78212242021-01-06 14:51:30 -0800317 m.VendorProperties.IsVNDKPrivate = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900318 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900319 if Bool(m.VendorProperties.Product_available) {
Colin Cross78212242021-01-06 14:51:30 -0800320 m.VendorProperties.IsVNDKProduct = true
Justin Yun8a2600c2020-12-07 12:44:03 +0900321 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900322}
323
Yo Chiang08fac0c2020-07-29 01:08:20 +0800324// Check for modules that mustn't be VNDK
Cole Fausta963b942024-04-11 17:43:00 -0700325func shouldSkipVndkMutator(ctx android.ConfigAndErrorContext, m *Module) bool {
326 if !m.Enabled(ctx) {
Yo Chiangbba545e2020-06-09 16:15:37 +0800327 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900328 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800329 if !m.Device() {
330 // Skip non-device modules
331 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900332 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900333 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800334 // Skip native_bridge modules
335 return true
336 }
337 return false
338}
339
340func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
Cole Fausta963b942024-04-11 17:43:00 -0700341 if shouldSkipVndkMutator(mctx, m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900342 return false
343 }
344
Jooyung Han31c470b2019-10-18 16:26:59 +0900345 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
346 // When b/142675459 is landed, remove following check
Justin Yunf14beaf2023-08-18 17:51:14 +0900347 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
348 // prebuilt vndk modules should match with device
349 if !p.MatchesWithDevice(mctx.DeviceConfig()) {
350 return false
351 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900352 }
353
354 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han1724d582022-12-21 10:17:44 +0900355 // VNDK APEX doesn't need stub variants
356 if lib.buildStubs() {
357 return false
358 }
Kiyoung Kimfa13ff12024-03-18 16:01:19 +0900359 useCoreVariant := mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500360 return lib.shared() && m.InVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900361 }
362 return false
363}
364
Inseob Kim1f086e22019-05-09 13:29:15 +0900365// gather list of vndk-core, vndk-sp, and ll-ndk libs
366func VndkMutator(mctx android.BottomUpMutatorContext) {
367 m, ok := mctx.Module().(*Module)
368 if !ok {
369 return
370 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800371
Cole Fausta963b942024-04-11 17:43:00 -0700372 if shouldSkipVndkMutator(mctx, m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900373 return
374 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900375
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800376 lib, isLib := m.linker.(*libraryDecorator)
377 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900378
Kiyoung Kimaa394802024-01-08 12:55:45 +0900379 if m.InVendorOrProduct() && isLib && lib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800380 m.VendorProperties.IsVNDKPrivate = Bool(lib.Properties.Llndk.Private)
381 }
Kiyoung Kimaa394802024-01-08 12:55:45 +0900382 if m.InVendorOrProduct() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800383 m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private)
384 }
385
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800386 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900387 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900388 processVndkLibrary(mctx, m)
389 return
390 }
391 }
392}
393
394func init() {
Colin Crosse4e44bc2020-12-28 13:50:21 -0800395 RegisterVndkLibraryTxtTypes(android.InitRegistrationContext)
Inseob Kim1f086e22019-05-09 13:29:15 +0900396}
397
Colin Crosse4e44bc2020-12-28 13:50:21 -0800398func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) {
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000399 ctx.RegisterParallelSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory)
400 ctx.RegisterParallelSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory)
401 ctx.RegisterParallelSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory)
402 ctx.RegisterParallelSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory)
403 ctx.RegisterParallelSingletonModuleType("vndkcorevariant_libraries_txt", vndkUsingCoreVariantLibrariesTxtFactory)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800404}
405
Jooyung Han2216fb12019-11-06 16:46:15 +0900406type vndkLibrariesTxt struct {
Colin Cross78212242021-01-06 14:51:30 -0800407 android.SingletonModuleBase
Colin Crosse4e44bc2020-12-28 13:50:21 -0800408
Justin Yun611e8862021-05-24 18:17:33 +0900409 lister moduleListerFunc
410 makeVarName string
411 filterOutFromMakeVar string
Colin Cross78212242021-01-06 14:51:30 -0800412
Colin Crosse4e44bc2020-12-28 13:50:21 -0800413 properties VndkLibrariesTxtProperties
414
Colin Cross78212242021-01-06 14:51:30 -0800415 outputFile android.OutputPath
416 moduleNames []string
417 fileNames []string
Jooyung Han2216fb12019-11-06 16:46:15 +0900418}
419
Colin Crosse4e44bc2020-12-28 13:50:21 -0800420type VndkLibrariesTxtProperties struct {
421 Insert_vndk_version *bool
Justin Yund5784122023-10-25 13:25:32 +0900422 Stem *string
Colin Crosse4e44bc2020-12-28 13:50:21 -0800423}
424
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700425var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900426var _ android.OutputFileProducer = &vndkLibrariesTxt{}
427
Colin Cross78212242021-01-06 14:51:30 -0800428// vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries
429// generated by Soong but can be referenced by other modules.
430// For example, apex_vndk can depend on these files as prebuilt.
431func vndkSPLibrariesTxtFactory() android.SingletonModule {
432 return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES")
433}
434
435// vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries
436// generated by Soong but can be referenced by other modules.
437// For example, apex_vndk can depend on these files as prebuilt.
438func vndkCoreLibrariesTxtFactory() android.SingletonModule {
439 return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES")
440}
441
442// vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries
443// generated by Soong but can be referenced by other modules.
444// For example, apex_vndk can depend on these files as prebuilt.
445func vndkPrivateLibrariesTxtFactory() android.SingletonModule {
446 return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES")
447}
448
449// vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product libraries
450// generated by Soong but can be referenced by other modules.
451// For example, apex_vndk can depend on these files as prebuilt.
452func vndkProductLibrariesTxtFactory() android.SingletonModule {
453 return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES")
454}
455
456// vndkcorevariant_libraries_txt is a singleton module whose content is a list of VNDK libraries
457// that are using the core variant, generated by Soong but can be referenced by other modules.
458// For example, apex_vndk can depend on these files as prebuilt.
459func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule {
460 return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES")
461}
462
Justin Yun611e8862021-05-24 18:17:33 +0900463func newVndkLibrariesWithMakeVarFilter(lister moduleListerFunc, makeVarName string, filter string) android.SingletonModule {
Colin Cross78212242021-01-06 14:51:30 -0800464 m := &vndkLibrariesTxt{
Justin Yun611e8862021-05-24 18:17:33 +0900465 lister: lister,
466 makeVarName: makeVarName,
467 filterOutFromMakeVar: filter,
Colin Crosse4e44bc2020-12-28 13:50:21 -0800468 }
Colin Cross78212242021-01-06 14:51:30 -0800469 m.AddProperties(&m.properties)
Colin Cross45bce852021-11-11 22:47:54 -0800470 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
Colin Cross78212242021-01-06 14:51:30 -0800471 return m
Jooyung Han2216fb12019-11-06 16:46:15 +0900472}
473
Justin Yun611e8862021-05-24 18:17:33 +0900474func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule {
475 return newVndkLibrariesWithMakeVarFilter(lister, makeVarName, "")
476}
477
Jooyung Han2216fb12019-11-06 16:46:15 +0900478func insertVndkVersion(filename string, vndkVersion string) string {
479 if index := strings.LastIndex(filename, "."); index != -1 {
480 return filename[:index] + "." + vndkVersion + filename[index:]
481 }
482 return filename
483}
484
Colin Crosse4e44bc2020-12-28 13:50:21 -0800485func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Justin Yund5784122023-10-25 13:25:32 +0900486 filename := proptools.StringDefault(txt.properties.Stem, txt.Name())
Kiyoung Kima2d6dee2023-08-11 10:14:43 +0900487
Jooyung Han2216fb12019-11-06 16:46:15 +0900488 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Jooyung Han2216fb12019-11-06 16:46:15 +0900489
490 installPath := android.PathForModuleInstall(ctx, "etc")
491 ctx.InstallFile(installPath, filename, txt.outputFile)
492}
493
Colin Cross78212242021-01-06 14:51:30 -0800494func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) {
495 txt.moduleNames, txt.fileNames = txt.lister(ctx)
496 android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n"))
497}
498
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900499func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
500 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900501 Class: "ETC",
502 OutputFile: android.OptionalPathForPath(txt.outputFile),
503 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700504 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900505 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
506 },
507 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900508 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900509}
510
Colin Cross78212242021-01-06 14:51:30 -0800511func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) {
Justin Yund5784122023-10-25 13:25:32 +0900512 if txt.makeVarName == "" {
513 return
514 }
515
Justin Yun611e8862021-05-24 18:17:33 +0900516 filter := func(modules []string, prefix string) []string {
517 if prefix == "" {
518 return modules
519 }
520 var result []string
521 for _, module := range modules {
522 if strings.HasPrefix(module, prefix) {
523 continue
524 } else {
525 result = append(result, module)
526 }
527 }
528 return result
529 }
530 ctx.Strict(txt.makeVarName, strings.Join(filter(txt.moduleNames, txt.filterOutFromMakeVar), " "))
Colin Cross78212242021-01-06 14:51:30 -0800531}
532
Jooyung Han0703fd82020-08-26 22:11:53 +0900533// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900534func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
535 return txt.outputFile
536}
537
Jooyung Han0703fd82020-08-26 22:11:53 +0900538// PrebuiltEtcModule interface
539func (txt *vndkLibrariesTxt) BaseDir() string {
540 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900541}
542
Jooyung Han0703fd82020-08-26 22:11:53 +0900543// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900544func (txt *vndkLibrariesTxt) SubDir() string {
545 return ""
546}
547
Jooyung Han0703fd82020-08-26 22:11:53 +0900548func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
549 return android.Paths{txt.outputFile}, nil
550}
Cole Fausta963b942024-04-11 17:43:00 -0700551
Jooyung Han0302a842019-10-30 18:43:49 +0900552func getVndkFileName(m *Module) (string, error) {
553 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900554 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900555 }
556 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900557 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900558 }
559 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900560}