blob: 2b2ea6458fffef4bc7332e8dcbc724545e8c0fc4 [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"
Kiyoung Kimae11c232021-07-19 11:38:04 +090028 "android/soong/snapshot"
Colin Cross6e511a92020-07-27 21:26:48 -070029
30 "github.com/google/blueprint"
Justin Yund5784122023-10-25 13:25:32 +090031 "github.com/google/blueprint/proptools"
Justin Yun8effde42017-06-23 19:24:43 +090032)
33
Jooyung Han39edb6c2019-11-06 16:53:07 +090034const (
35 llndkLibrariesTxt = "llndk.libraries.txt"
Justin Yund5784122023-10-25 13:25:32 +090036 llndkLibrariesTxtForApex = "llndk.libraries.txt.apex"
Jooyung Han39edb6c2019-11-06 16:53:07 +090037 vndkCoreLibrariesTxt = "vndkcore.libraries.txt"
38 vndkSpLibrariesTxt = "vndksp.libraries.txt"
39 vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt"
Justin Yun8a2600c2020-12-07 12:44:03 +090040 vndkProductLibrariesTxt = "vndkproduct.libraries.txt"
Jooyung Han39edb6c2019-11-06 16:53:07 +090041 vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt"
42)
43
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090044func VndkLibrariesTxtModules(vndkVersion string, ctx android.BaseModuleContext) []string {
Justin Yund5784122023-10-25 13:25:32 +090045 // Return the list of vndk txt files for the vndk apex of the vndkVersion.
Jooyung Han39edb6c2019-11-06 16:53:07 +090046 if vndkVersion == "current" {
Justin Yun74217d92023-08-21 20:51:45 +090047 // We can assume all txt files are snapshotted if we find one of them.
48 currentVndkSnapshotted := ctx.OtherModuleExists(insertVndkVersion(llndkLibrariesTxt, ctx.DeviceConfig().PlatformVndkVersion()))
49 if currentVndkSnapshotted {
50 // If the current VNDK is already snapshotted (which can happen with
51 // the `next` config), use the prebuilt txt files in the snapshot.
52 // This is because the txt files built from source are probably be
53 // for the in-development version.
54 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
55 } else {
56 // Use the txt files generated from the source
Justin Yund5784122023-10-25 13:25:32 +090057 return []string{
58 llndkLibrariesTxtForApex,
Justin Yun74217d92023-08-21 20:51:45 +090059 vndkCoreLibrariesTxt,
60 vndkSpLibrariesTxt,
61 vndkPrivateLibrariesTxt,
62 vndkProductLibrariesTxt,
63 }
Justin Yun74217d92023-08-21 20:51:45 +090064 }
Jooyung Han39edb6c2019-11-06 16:53:07 +090065 }
Justin Yun74217d92023-08-21 20:51:45 +090066
Jooyung Han39edb6c2019-11-06 16:53:07 +090067 // Snapshot vndks have their own *.libraries.VER.txt files.
68 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090069 result := []string{
Jooyung Han39edb6c2019-11-06 16:53:07 +090070 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
71 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
72 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
Justin Yun8a2600c2020-12-07 12:44:03 +090073 insertVndkVersion(vndkProductLibrariesTxt, vndkVersion),
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090074 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
Jooyung Han39edb6c2019-11-06 16:53:07 +090075 }
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090076
77 return result
Jooyung Han39edb6c2019-11-06 16:53:07 +090078}
79
Justin Yun8effde42017-06-23 19:24:43 +090080type VndkProperties struct {
81 Vndk struct {
82 // declared as a VNDK or VNDK-SP module. The vendor variant
83 // will be installed in /system instead of /vendor partition.
84 //
Justin Yun63e9ec72020-10-29 16:49:43 +090085 // `vendor_available` and `product_available` must be explicitly
86 // set to either true or false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090087 Enabled *bool
88
89 // declared as a VNDK-SP module, which is a subset of VNDK.
90 //
91 // `vndk: { enabled: true }` must set together.
92 //
93 // All these modules are allowed to link to VNDK-SP or LL-NDK
94 // modules only. Other dependency will cause link-type errors.
95 //
96 // If `support_system_process` is not set or set to false,
97 // the module is VNDK-core and can link to other VNDK-core,
98 // VNDK-SP or LL-NDK modules only.
99 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +0800100
Justin Yunfd9e8042020-12-23 18:23:14 +0900101 // declared as a VNDK-private module.
102 // This module still creates the vendor and product variants refering
103 // to the `vendor_available: true` and `product_available: true`
104 // properties. However, it is only available to the other VNDK modules
105 // but not to the non-VNDK vendor or product modules.
106 Private *bool
107
Logan Chienf3511742017-10-31 18:04:35 +0800108 // Extending another module
109 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +0900110 }
111}
112
113type vndkdep struct {
114 Properties VndkProperties
115}
116
117func (vndk *vndkdep) props() []interface{} {
118 return []interface{}{&vndk.Properties}
119}
120
Justin Yun8effde42017-06-23 19:24:43 +0900121func (vndk *vndkdep) isVndk() bool {
122 return Bool(vndk.Properties.Vndk.Enabled)
123}
124
125func (vndk *vndkdep) isVndkSp() bool {
126 return Bool(vndk.Properties.Vndk.Support_system_process)
127}
128
Logan Chienf3511742017-10-31 18:04:35 +0800129func (vndk *vndkdep) isVndkExt() bool {
130 return vndk.Properties.Vndk.Extends != nil
131}
132
133func (vndk *vndkdep) getVndkExtendsModuleName() string {
134 return String(vndk.Properties.Vndk.Extends)
135}
136
Justin Yun8effde42017-06-23 19:24:43 +0900137func (vndk *vndkdep) typeName() string {
138 if !vndk.isVndk() {
139 return "native:vendor"
140 }
Logan Chienf3511742017-10-31 18:04:35 +0800141 if !vndk.isVndkExt() {
142 if !vndk.isVndkSp() {
143 return "native:vendor:vndk"
144 }
145 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900146 }
Logan Chienf3511742017-10-31 18:04:35 +0800147 if !vndk.isVndkSp() {
148 return "native:vendor:vndkext"
149 }
150 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900151}
152
Justin Yun63e9ec72020-10-29 16:49:43 +0900153// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900154func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900155 if to.linker == nil {
156 return
157 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900158 if !vndk.isVndk() {
Justin Yunfd9e8042020-12-23 18:23:14 +0900159 // Non-VNDK modules those installed to /vendor, /system/vendor,
160 // /product or /system/product cannot depend on VNDK-private modules
161 // that include VNDK-core-private, VNDK-SP-private and LLNDK-private.
162 if to.IsVndkPrivate() {
163 ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name())
Jiyong Park82e2bf32017-08-16 14:05:54 +0900164 }
165 }
Justin Yun8effde42017-06-23 19:24:43 +0900166 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
167 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800168 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900169 return
170 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800171
172 if to.IsLlndk() {
173 // LL-NDK libraries are allowed to link
174 return
175 }
176
Ivan Lozano52767be2019-10-18 14:49:46 -0700177 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900178 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
179 vndk.typeName(), to.Name())
180 return
181 }
Logan Chienf3511742017-10-31 18:04:35 +0800182 if tag == vndkExtDepTag {
183 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
184 // and has identical vndk properties.
185 if to.vndkdep == nil || !to.vndkdep.isVndk() {
186 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
187 return
188 }
189 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
190 ctx.ModuleErrorf(
191 "`extends` refers a module %q with mismatched support_system_process",
192 to.Name())
193 return
194 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900195 if to.IsVndkPrivate() {
Logan Chienf3511742017-10-31 18:04:35 +0800196 ctx.ModuleErrorf(
Justin Yunfd9e8042020-12-23 18:23:14 +0900197 "`extends` refers module %q which has `private: true`",
Justin Yun6977e8a2020-10-29 18:24:11 +0900198 to.Name())
199 return
200 }
Logan Chienf3511742017-10-31 18:04:35 +0800201 }
Justin Yun8effde42017-06-23 19:24:43 +0900202 if to.vndkdep == nil {
203 return
204 }
Logan Chienf3511742017-10-31 18:04:35 +0800205
Logan Chiend3c59a22018-03-29 14:08:15 +0800206 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100207 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
208 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
209 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800210 return
211 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800212}
Logan Chienf3511742017-10-31 18:04:35 +0800213
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100214func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800215 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
216 if from.isVndkExt() {
217 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100218 if to.isVndk() && !to.isVndkSp() {
219 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
220 }
221 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800222 }
223 // VNDK-Ext 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 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800226 if from.isVndk() {
227 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100228 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800229 }
230 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100231 if !to.isVndkSp() {
232 return errors.New("VNDK-SP must only depend on VNDK-SP")
233 }
234 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800235 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100236 if !to.isVndk() {
237 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
238 }
239 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800240 }
241 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100242 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900243}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900244
Colin Cross78212242021-01-06 14:51:30 -0800245type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string)
246
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900247var (
Colin Cross203b4212021-04-26 17:19:41 -0700248 llndkLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsLLNDK && !m.Header() })
Colin Cross78212242021-01-06 14:51:30 -0800249 vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP })
250 vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore })
Colin Cross203b4212021-04-26 17:19:41 -0700251 vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate })
Colin Cross78212242021-01-06 14:51:30 -0800252 vndkProductLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKProduct })
253 vndkUsingCoreVariantLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKUsingCoreVariant })
Inseob Kimae553032019-05-14 18:52:49 +0900254)
Inseob Kim1f086e22019-05-09 13:29:15 +0900255
Colin Cross78212242021-01-06 14:51:30 -0800256// vndkModuleLister takes a predicate that operates on a Module and returns a moduleListerFunc
257// that produces a list of module names and output file names for which the predicate returns true.
258func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc {
259 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
260 ctx.VisitAllModules(func(m android.Module) {
Jooyung Hane3f02812023-05-08 13:54:50 +0900261 if c, ok := m.(*Module); ok && predicate(c) && !c.IsVndkPrebuiltLibrary() {
Colin Cross78212242021-01-06 14:51:30 -0800262 filename, err := getVndkFileName(c)
263 if err != nil {
264 ctx.ModuleErrorf(m, "%s", err)
265 }
266 moduleNames = append(moduleNames, ctx.ModuleName(m))
267 fileNames = append(fileNames, filename)
268 }
269 })
270 moduleNames = android.SortedUniqueStrings(moduleNames)
271 fileNames = android.SortedUniqueStrings(fileNames)
272 return
273 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900274}
275
Colin Cross78212242021-01-06 14:51:30 -0800276// vndkModuleListRemover takes a moduleListerFunc and a prefix and returns a moduleListerFunc
277// that returns the same lists as the input moduleListerFunc, but with modules with the
278// given prefix removed.
279func vndkModuleListRemover(lister moduleListerFunc, prefix string) moduleListerFunc {
280 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
281 moduleNames, fileNames = lister(ctx)
282 filter := func(in []string) []string {
283 out := make([]string, 0, len(in))
284 for _, lib := range in {
285 if strings.HasPrefix(lib, prefix) {
286 continue
287 }
288 out = append(out, lib)
289 }
290 return out
291 }
292 return filter(moduleNames), filter(fileNames)
293 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900294}
295
Colin Cross78212242021-01-06 14:51:30 -0800296var vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
Inseob Kim9516ee92019-05-09 10:56:13 +0900297
Jooyung Han097087b2019-10-22 19:32:18 +0900298func vndkMustUseVendorVariantList(cfg android.Config) []string {
299 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900300 return config.VndkMustUseVendorVariantList
301 }).([]string)
302}
303
304// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
305// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
306func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900307 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900308 return mustUseVendorVariantList
309 })
310}
311
Inseob Kim1f086e22019-05-09 13:29:15 +0900312func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Justin Yun8a2600c2020-12-07 12:44:03 +0900313 if m.InProduct() {
314 // We may skip the steps for the product variants because they
315 // are already covered by the vendor variants.
316 return
317 }
318
Jooyung Han0302a842019-10-30 18:43:49 +0900319 name := m.BaseModuleName()
Inseob Kim1f086e22019-05-09 13:29:15 +0900320
Colin Cross31076b32020-10-23 17:22:06 -0700321 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000322 // b/155456180 libz is the ONLY exception here. We don't want to make
323 // libz an LLNDK library because we in general can't guarantee that
324 // libz will behave consistently especially about the compression.
325 // i.e. the compressed output might be different across releases.
326 // As the library is an external one, it's risky to keep the compatibility
327 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900328 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
329 }
330
Jooyung Han097087b2019-10-22 19:32:18 +0900331 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
332 m.Properties.MustUseVendorVariant = true
333 }
Jooyung Han0302a842019-10-30 18:43:49 +0900334 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
Colin Cross78212242021-01-06 14:51:30 -0800335 m.VendorProperties.IsVNDKUsingCoreVariant = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900336 }
Jooyung Han0302a842019-10-30 18:43:49 +0900337
Inseob Kim1f086e22019-05-09 13:29:15 +0900338 if m.vndkdep.isVndkSp() {
Colin Cross78212242021-01-06 14:51:30 -0800339 m.VendorProperties.IsVNDKSP = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900340 } else {
Colin Cross78212242021-01-06 14:51:30 -0800341 m.VendorProperties.IsVNDKCore = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900342 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900343 if m.IsVndkPrivate() {
Colin Cross78212242021-01-06 14:51:30 -0800344 m.VendorProperties.IsVNDKPrivate = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900345 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900346 if Bool(m.VendorProperties.Product_available) {
Colin Cross78212242021-01-06 14:51:30 -0800347 m.VendorProperties.IsVNDKProduct = true
Justin Yun8a2600c2020-12-07 12:44:03 +0900348 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900349}
350
Yo Chiang08fac0c2020-07-29 01:08:20 +0800351// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800352func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900353 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800354 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900355 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800356 if !m.Device() {
357 // Skip non-device modules
358 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900359 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900360 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800361 // Skip native_bridge modules
362 return true
363 }
364 return false
365}
366
367func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
368 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900369 return false
370 }
371
Jooyung Han31c470b2019-10-18 16:26:59 +0900372 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
373 // When b/142675459 is landed, remove following check
Justin Yunf14beaf2023-08-18 17:51:14 +0900374 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
375 // prebuilt vndk modules should match with device
376 if !p.MatchesWithDevice(mctx.DeviceConfig()) {
377 return false
378 }
379
Kiyoung Kim0fcadd82024-01-31 17:20:17 +0900380 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
381 if platformVndkVersion != "" {
382 // ignore prebuilt vndk modules that are newer than or equal to the platform vndk version
383 platformVndkApiLevel := android.ApiLevelOrPanic(mctx, platformVndkVersion)
384 if platformVndkApiLevel.LessThanOrEqualTo(android.ApiLevelOrPanic(mctx, p.Version())) {
385 return false
386 }
Justin Yunf14beaf2023-08-18 17:51:14 +0900387 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900388 }
389
390 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han1724d582022-12-21 10:17:44 +0900391 // VNDK APEX doesn't need stub variants
392 if lib.buildStubs() {
393 return false
394 }
Justin Yun5f7f7e82019-11-18 19:52:14 +0900395 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900396 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500397 return lib.shared() && m.InVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900398 }
399 return false
400}
401
Inseob Kim1f086e22019-05-09 13:29:15 +0900402// gather list of vndk-core, vndk-sp, and ll-ndk libs
403func VndkMutator(mctx android.BottomUpMutatorContext) {
404 m, ok := mctx.Module().(*Module)
405 if !ok {
406 return
407 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800408
409 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900410 return
411 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900412
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800413 lib, isLib := m.linker.(*libraryDecorator)
414 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900415
Kiyoung Kimaa394802024-01-08 12:55:45 +0900416 if m.InVendorOrProduct() && isLib && lib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800417 m.VendorProperties.IsLLNDK = true
418 m.VendorProperties.IsVNDKPrivate = Bool(lib.Properties.Llndk.Private)
419 }
Kiyoung Kimaa394802024-01-08 12:55:45 +0900420 if m.InVendorOrProduct() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800421 m.VendorProperties.IsLLNDK = true
422 m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private)
423 }
424
Jooyung Hane3f02812023-05-08 13:54:50 +0900425 if m.IsVndkPrebuiltLibrary() && !m.IsVndk() {
426 m.VendorProperties.IsLLNDK = true
427 // TODO(b/280697209): copy "llndk.private" flag to vndk_prebuilt_shared
428 }
429
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800430 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900431 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900432 processVndkLibrary(mctx, m)
433 return
434 }
435 }
436}
437
438func init() {
Colin Crosse4e44bc2020-12-28 13:50:21 -0800439 RegisterVndkLibraryTxtTypes(android.InitRegistrationContext)
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000440 android.RegisterParallelSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900441}
442
Colin Crosse4e44bc2020-12-28 13:50:21 -0800443func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) {
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000444 ctx.RegisterParallelSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory)
Justin Yund5784122023-10-25 13:25:32 +0900445 ctx.RegisterParallelSingletonModuleType("llndk_libraries_txt_for_apex", llndkLibrariesTxtApexOnlyFactory)
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000446 ctx.RegisterParallelSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory)
447 ctx.RegisterParallelSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory)
448 ctx.RegisterParallelSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory)
449 ctx.RegisterParallelSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory)
450 ctx.RegisterParallelSingletonModuleType("vndkcorevariant_libraries_txt", vndkUsingCoreVariantLibrariesTxtFactory)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800451}
452
Jooyung Han2216fb12019-11-06 16:46:15 +0900453type vndkLibrariesTxt struct {
Colin Cross78212242021-01-06 14:51:30 -0800454 android.SingletonModuleBase
Colin Crosse4e44bc2020-12-28 13:50:21 -0800455
Justin Yun611e8862021-05-24 18:17:33 +0900456 lister moduleListerFunc
457 makeVarName string
458 filterOutFromMakeVar string
Colin Cross78212242021-01-06 14:51:30 -0800459
Colin Crosse4e44bc2020-12-28 13:50:21 -0800460 properties VndkLibrariesTxtProperties
461
Colin Cross78212242021-01-06 14:51:30 -0800462 outputFile android.OutputPath
463 moduleNames []string
464 fileNames []string
Jooyung Han2216fb12019-11-06 16:46:15 +0900465}
466
Colin Crosse4e44bc2020-12-28 13:50:21 -0800467type VndkLibrariesTxtProperties struct {
468 Insert_vndk_version *bool
Justin Yund5784122023-10-25 13:25:32 +0900469 Stem *string
Colin Crosse4e44bc2020-12-28 13:50:21 -0800470}
471
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700472var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900473var _ android.OutputFileProducer = &vndkLibrariesTxt{}
474
Colin Cross78212242021-01-06 14:51:30 -0800475// llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries
Justin Yund5784122023-10-25 13:25:32 +0900476// generated by Soong.
Justin Yun611e8862021-05-24 18:17:33 +0900477// Make uses LLNDK_LIBRARIES to determine which libraries to install.
Justin Yund5784122023-10-25 13:25:32 +0900478// HWASAN is only part of the LLNDK in builds in which libc depends on HWASAN.
Justin Yun611e8862021-05-24 18:17:33 +0900479// Therefore, by removing the library here, we cause it to only be installed if libc
480// depends on it.
Colin Cross78212242021-01-06 14:51:30 -0800481func llndkLibrariesTxtFactory() android.SingletonModule {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800482 return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "LLNDK_LIBRARIES", "libclang_rt.hwasan")
Colin Cross78212242021-01-06 14:51:30 -0800483}
484
Justin Yund5784122023-10-25 13:25:32 +0900485// llndk_libraries_txt_for_apex is a singleton module that provide the same LLNDK libraries list
486// with the llndk_libraries_txt, but skips setting make variable LLNDK_LIBRARIES. So, it must not
487// be used without installing llndk_libraries_txt singleton.
488// We include llndk_libraries_txt by default to install the llndk.libraries.txt file to system/etc.
489// This singleton module is to install the llndk.libraries.<ver>.txt file to vndk apex.
490func llndkLibrariesTxtApexOnlyFactory() android.SingletonModule {
491 return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "", "libclang_rt.hwasan")
492}
493
Colin Cross78212242021-01-06 14:51:30 -0800494// vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries
495// generated by Soong but can be referenced by other modules.
496// For example, apex_vndk can depend on these files as prebuilt.
497func vndkSPLibrariesTxtFactory() android.SingletonModule {
498 return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES")
499}
500
501// vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries
502// generated by Soong but can be referenced by other modules.
503// For example, apex_vndk can depend on these files as prebuilt.
504func vndkCoreLibrariesTxtFactory() android.SingletonModule {
505 return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES")
506}
507
508// vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries
509// generated by Soong but can be referenced by other modules.
510// For example, apex_vndk can depend on these files as prebuilt.
511func vndkPrivateLibrariesTxtFactory() android.SingletonModule {
512 return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES")
513}
514
515// vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product libraries
516// generated by Soong but can be referenced by other modules.
517// For example, apex_vndk can depend on these files as prebuilt.
518func vndkProductLibrariesTxtFactory() android.SingletonModule {
519 return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES")
520}
521
522// vndkcorevariant_libraries_txt is a singleton module whose content is a list of VNDK libraries
523// that are using the core variant, generated by Soong but can be referenced by other modules.
524// For example, apex_vndk can depend on these files as prebuilt.
525func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule {
526 return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES")
527}
528
Justin Yun611e8862021-05-24 18:17:33 +0900529func newVndkLibrariesWithMakeVarFilter(lister moduleListerFunc, makeVarName string, filter string) android.SingletonModule {
Colin Cross78212242021-01-06 14:51:30 -0800530 m := &vndkLibrariesTxt{
Justin Yun611e8862021-05-24 18:17:33 +0900531 lister: lister,
532 makeVarName: makeVarName,
533 filterOutFromMakeVar: filter,
Colin Crosse4e44bc2020-12-28 13:50:21 -0800534 }
Colin Cross78212242021-01-06 14:51:30 -0800535 m.AddProperties(&m.properties)
Colin Cross45bce852021-11-11 22:47:54 -0800536 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
Colin Cross78212242021-01-06 14:51:30 -0800537 return m
Jooyung Han2216fb12019-11-06 16:46:15 +0900538}
539
Justin Yun611e8862021-05-24 18:17:33 +0900540func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule {
541 return newVndkLibrariesWithMakeVarFilter(lister, makeVarName, "")
542}
543
Jooyung Han2216fb12019-11-06 16:46:15 +0900544func insertVndkVersion(filename string, vndkVersion string) string {
545 if index := strings.LastIndex(filename, "."); index != -1 {
546 return filename[:index] + "." + vndkVersion + filename[index:]
547 }
548 return filename
549}
550
Justin Yun74217d92023-08-21 20:51:45 +0900551func (txt *vndkLibrariesTxt) DepsMutator(mctx android.BottomUpMutatorContext) {
552 versionedName := insertVndkVersion(txt.Name(), mctx.DeviceConfig().PlatformVndkVersion())
553 if mctx.OtherModuleExists(versionedName) {
554 // If the prebuilt vndk libraries txt files exist, install them instead.
555 txt.HideFromMake()
556 mctx.AddDependency(txt, nil, versionedName)
557 }
558}
559
Colin Crosse4e44bc2020-12-28 13:50:21 -0800560func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Justin Yund5784122023-10-25 13:25:32 +0900561 filename := proptools.StringDefault(txt.properties.Stem, txt.Name())
Kiyoung Kima2d6dee2023-08-11 10:14:43 +0900562
Justin Yund5784122023-10-25 13:25:32 +0900563 if Bool(txt.properties.Insert_vndk_version) {
564 filename = insertVndkVersion(filename, ctx.DeviceConfig().PlatformVndkVersion())
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900565 }
566
Jooyung Han2216fb12019-11-06 16:46:15 +0900567 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Jooyung Han2216fb12019-11-06 16:46:15 +0900568
569 installPath := android.PathForModuleInstall(ctx, "etc")
570 ctx.InstallFile(installPath, filename, txt.outputFile)
571}
572
Colin Cross78212242021-01-06 14:51:30 -0800573func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) {
574 txt.moduleNames, txt.fileNames = txt.lister(ctx)
575 android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n"))
576}
577
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900578func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
579 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900580 Class: "ETC",
581 OutputFile: android.OptionalPathForPath(txt.outputFile),
582 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700583 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900584 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
585 },
586 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900587 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900588}
589
Colin Cross78212242021-01-06 14:51:30 -0800590func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) {
Justin Yund5784122023-10-25 13:25:32 +0900591 if txt.makeVarName == "" {
592 return
593 }
594
Justin Yun611e8862021-05-24 18:17:33 +0900595 filter := func(modules []string, prefix string) []string {
596 if prefix == "" {
597 return modules
598 }
599 var result []string
600 for _, module := range modules {
601 if strings.HasPrefix(module, prefix) {
602 continue
603 } else {
604 result = append(result, module)
605 }
606 }
607 return result
608 }
609 ctx.Strict(txt.makeVarName, strings.Join(filter(txt.moduleNames, txt.filterOutFromMakeVar), " "))
Colin Cross78212242021-01-06 14:51:30 -0800610}
611
Jooyung Han0703fd82020-08-26 22:11:53 +0900612// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900613func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
614 return txt.outputFile
615}
616
Jooyung Han0703fd82020-08-26 22:11:53 +0900617// PrebuiltEtcModule interface
618func (txt *vndkLibrariesTxt) BaseDir() string {
619 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900620}
621
Jooyung Han0703fd82020-08-26 22:11:53 +0900622// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900623func (txt *vndkLibrariesTxt) SubDir() string {
624 return ""
625}
626
Jooyung Han0703fd82020-08-26 22:11:53 +0900627func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
628 return android.Paths{txt.outputFile}, nil
629}
630
Inseob Kim1f086e22019-05-09 13:29:15 +0900631func VndkSnapshotSingleton() android.Singleton {
632 return &vndkSnapshotSingleton{}
633}
634
Jooyung Han0302a842019-10-30 18:43:49 +0900635type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900636 vndkLibrariesFile android.OutputPath
637 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900638}
Inseob Kim1f086e22019-05-09 13:29:15 +0900639
Ivan Lozanod7586b62021-04-01 09:49:36 -0400640func isVndkSnapshotAware(config android.DeviceConfig, m LinkableInterface,
641 apexInfo android.ApexInfo) (vndkType string, isVndkSnapshotLib bool) {
Colin Cross56a83212020-09-15 18:30:11 -0700642
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900643 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400644 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900645 }
Jooyung Han261e1582020-10-20 18:54:21 +0900646 // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
647 // !installable: Snapshot only cares about "installable" modules.
Justin Yun450ae722021-04-16 19:58:18 +0900648 // !m.IsLlndk: llndk stubs are required for building against snapshots.
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400649 // IsSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
Justin Yun450ae722021-04-16 19:58:18 +0900650 // !outputFile.Valid: Snapshot requires valid output file.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400651 if !m.InVendor() || (!installable(m, apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.OutputFile().Valid() {
652 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900653 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400654 if !m.IsSnapshotLibrary() || !m.Shared() {
655 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900656 }
Justin Yun450ae722021-04-16 19:58:18 +0900657 if m.VndkVersion() == config.PlatformVndkVersion() {
658 if m.IsVndk() && !m.IsVndkExt() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400659 if m.IsVndkSp() {
660 return "vndk-sp", true
Justin Yun450ae722021-04-16 19:58:18 +0900661 } else {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400662 return "vndk-core", true
Justin Yun450ae722021-04-16 19:58:18 +0900663 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400664 } else if m.HasLlndkStubs() && m.StubsVersion() == "" {
Justin Yun450ae722021-04-16 19:58:18 +0900665 // Use default version for the snapshot.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400666 return "llndk-stub", true
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900667 }
668 }
669
Ivan Lozanod7586b62021-04-01 09:49:36 -0400670 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900671}
672
Inseob Kim1f086e22019-05-09 13:29:15 +0900673func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900674 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
675 c.buildVndkLibrariesTxtFiles(ctx)
676
Inseob Kim1f086e22019-05-09 13:29:15 +0900677 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
678 if ctx.DeviceConfig().VndkVersion() != "current" {
679 return
680 }
681
682 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
683 return
684 }
685
Inseob Kim242ef0c2019-10-22 20:15:20 +0900686 var snapshotOutputs android.Paths
687
688 /*
689 VNDK snapshot zipped artifacts directory structure:
690 {SNAPSHOT_ARCH}/
691 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
692 shared/
693 vndk-core/
694 (VNDK-core libraries, e.g. libbinder.so)
695 vndk-sp/
696 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900697 llndk-stub/
698 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900699 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
700 shared/
701 vndk-core/
702 (VNDK-core libraries, e.g. libbinder.so)
703 vndk-sp/
704 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900705 llndk-stub/
706 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900707 binder32/
708 (This directory is newly introduced in v28 (Android P) to hold
709 prebuilts built for 32-bit binder interface.)
710 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
711 ...
712 configs/
713 (various *.txt configuration files)
714 include/
715 (header files of same directory structure with source tree)
716 NOTICE_FILES/
717 (notice files of libraries, e.g. libcutils.so.txt)
718 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900719
720 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900721 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900722
Inseob Kim242ef0c2019-10-22 20:15:20 +0900723 configsDir := filepath.Join(snapshotArchDir, "configs")
Justin Yun1871f902023-04-07 20:13:19 +0900724 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
Inseob Kim242ef0c2019-10-22 20:15:20 +0900725 includeDir := filepath.Join(snapshotArchDir, "include")
726
Justin Yun1871f902023-04-07 20:13:19 +0900727 // set of notice files copied.
728 noticeBuilt := make(map[string]bool)
729
Inseob Kim242ef0c2019-10-22 20:15:20 +0900730 // paths of VNDK modules for GPL license checking
731 modulePaths := make(map[string]string)
732
733 // actual module names of .so files
734 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
735 moduleNames := make(map[string]string)
736
Inseob Kim8471cda2019-11-15 09:59:12 +0900737 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900738
Inseob Kimde5744a2020-12-02 13:14:28 +0900739 // installVndkSnapshotLib copies built .so file from the module.
740 // Also, if the build artifacts is on, write a json file which contains all exported flags
741 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700742 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900743 var ret android.Paths
744
Inseob Kim8471cda2019-11-15 09:59:12 +0900745 targetArch := "arch-" + m.Target().Arch.ArchType.String()
746 if m.Target().Arch.ArchVariant != "" {
747 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900748 }
Inseob Kimae553032019-05-14 18:52:49 +0900749
Inseob Kim8471cda2019-11-15 09:59:12 +0900750 libPath := m.outputFile.Path()
751 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Kiyoung Kimae11c232021-07-19 11:38:04 +0900752 ret = append(ret, snapshot.CopyFileRule(pctx, ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900753
Justin Yun1871f902023-04-07 20:13:19 +0900754 // json struct to export snapshot information
755 prop := struct {
Inseob Kim5860f822023-04-18 11:30:22 +0900756 MinSdkVersion string `json:",omitempty"`
Justin Yun1871f902023-04-07 20:13:19 +0900757 LicenseKinds []string `json:",omitempty"`
758 LicenseTexts []string `json:",omitempty"`
759 ExportedDirs []string `json:",omitempty"`
760 ExportedSystemDirs []string `json:",omitempty"`
761 ExportedFlags []string `json:",omitempty"`
762 RelativeInstallPath string `json:",omitempty"`
763 }{}
764
765 prop.LicenseKinds = m.EffectiveLicenseKinds()
766 prop.LicenseTexts = m.EffectiveLicenseFiles().Strings()
Inseob Kim5860f822023-04-18 11:30:22 +0900767 prop.MinSdkVersion = m.MinSdkVersion()
Justin Yun1871f902023-04-07 20:13:19 +0900768
Inseob Kimae553032019-05-14 18:52:49 +0900769 if ctx.Config().VndkSnapshotBuildArtifacts() {
Colin Cross5a377182023-12-14 14:46:23 -0800770 exportedInfo, _ := android.SingletonModuleProvider(ctx, m, FlagExporterInfoProvider)
Colin Cross0de8a1e2020-09-18 14:15:30 -0700771 prop.ExportedFlags = exportedInfo.Flags
772 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
773 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900774 prop.RelativeInstallPath = m.RelativeInstallPath()
Inseob Kimae553032019-05-14 18:52:49 +0900775 }
Justin Yun1871f902023-04-07 20:13:19 +0900776
777 propOut := snapshotLibOut + ".json"
778
779 j, err := json.Marshal(prop)
780 if err != nil {
781 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
782 return nil, false
783 }
784 ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
785
Inseob Kim242ef0c2019-10-22 20:15:20 +0900786 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900787 }
788
Inseob Kim1f086e22019-05-09 13:29:15 +0900789 ctx.VisitAllModules(func(module android.Module) {
790 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900791 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900792 return
793 }
794
Colin Cross5a377182023-12-14 14:46:23 -0800795 apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider)
Colin Cross56a83212020-09-15 18:30:11 -0700796
Ivan Lozanod7586b62021-04-01 09:49:36 -0400797 vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900798 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200799 return
800 }
801
Inseob Kimde5744a2020-12-02 13:14:28 +0900802 // For all snapshot candidates, the followings are captured.
803 // - .so files
804 // - notice files
805 //
806 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
807 // - .json files containing exported flags
808 // - exported headers from collectHeadersForSnapshot()
809 //
810 // Headers are deduplicated after visiting all modules.
811
Inseob Kim8471cda2019-11-15 09:59:12 +0900812 // install .so files for appropriate modules.
813 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700814 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900815 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900816 return
817 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900818 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900819
Inseob Kim8471cda2019-11-15 09:59:12 +0900820 // These are for generating module_names.txt and module_paths.txt
821 stem := m.outputFile.Path().Base()
822 moduleNames[stem] = ctx.ModuleName(m)
823 modulePaths[stem] = ctx.ModuleDir(m)
824
Justin Yun1871f902023-04-07 20:13:19 +0900825 for _, notice := range m.EffectiveLicenseFiles() {
826 if _, ok := noticeBuilt[notice.String()]; !ok {
827 noticeBuilt[notice.String()] = true
828 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
829 pctx, ctx, notice, filepath.Join(noticeDir, notice.String())))
830 }
831 }
832
Inseob Kim8471cda2019-11-15 09:59:12 +0900833 if ctx.Config().VndkSnapshotBuildArtifacts() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400834 headers = append(headers, m.SnapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900835 }
836 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900837
Inseob Kim8471cda2019-11-15 09:59:12 +0900838 // install all headers after removing duplicates
839 for _, header := range android.FirstUniquePaths(headers) {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900840 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
841 pctx, ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900842 }
843
Jooyung Han39edb6c2019-11-06 16:53:07 +0900844 // install *.libraries.txt except vndkcorevariant.libraries.txt
845 ctx.VisitAllModules(func(module android.Module) {
846 m, ok := module.(*vndkLibrariesTxt)
847 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
848 return
849 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900850 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
851 pctx, ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900852 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900853
Inseob Kim242ef0c2019-10-22 20:15:20 +0900854 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900855 module_paths.txt contains paths on which VNDK modules are defined.
856 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000857 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900858 libc.so bionic/libc
859 ...
860 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900861 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900862
863 /*
864 module_names.txt contains names as which VNDK modules are defined,
865 because output filename and module name can be different with stem and suffix properties.
866
867 e.g.,
868 libcutils.so libcutils
869 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
870 ...
871 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900872 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900873
874 // All artifacts are ready. Sort them to normalize ninja and then zip.
875 sort.Slice(snapshotOutputs, func(i, j int) bool {
876 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
877 })
878
879 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800880 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900881
Inseob Kimde5744a2020-12-02 13:14:28 +0900882 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900883 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
Colin Cross70c47412021-03-12 17:48:14 -0800884 rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp")
Inseob Kim242ef0c2019-10-22 20:15:20 +0900885 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900886 Text("tr").
887 FlagWithArg("-d ", "\\'").
Colin Cross70c47412021-03-12 17:48:14 -0800888 FlagWithRspFileInputList("< ", rspFile, snapshotOutputs).
Inseob Kim8471cda2019-11-15 09:59:12 +0900889 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900890
891 zipRule.Temporary(snapshotOutputList)
892
893 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800894 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900895 FlagWithOutput("-o ", zipPath).
896 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
897 FlagWithInput("-l ", snapshotOutputList)
898
Colin Crossf1a035e2020-11-16 17:32:30 -0800899 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900900 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900901 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900902}
Jooyung Han097087b2019-10-22 19:32:18 +0900903
Jooyung Han0302a842019-10-30 18:43:49 +0900904func getVndkFileName(m *Module) (string, error) {
905 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900906 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900907 }
908 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900909 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900910 }
911 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900912}
913
914func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900915 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900916 // Since each target have different set of libclang_rt.* files,
917 // keep the common set of files in vndk.libraries.txt
Colin Cross78212242021-01-06 14:51:30 -0800918 _, llndk := vndkModuleListRemover(llndkLibraries, "libclang_rt.")(ctx)
919 _, vndkcore := vndkModuleListRemover(vndkCoreLibraries, "libclang_rt.")(ctx)
920 _, vndksp := vndkSPLibraries(ctx)
921 _, vndkprivate := vndkPrivateLibraries(ctx)
922 _, vndkproduct := vndkModuleListRemover(vndkProductLibraries, "libclang_rt.")(ctx)
Jooyung Han0302a842019-10-30 18:43:49 +0900923 var merged []string
Colin Cross78212242021-01-06 14:51:30 -0800924 merged = append(merged, addPrefix(llndk, "LLNDK: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900925 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800926 merged = append(merged, addPrefix(vndkcore, "VNDK-core: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900927 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800928 merged = append(merged, addPrefix(vndkproduct, "VNDK-product: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900929 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800930 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900931}
Jooyung Han097087b2019-10-22 19:32:18 +0900932
Jooyung Han0302a842019-10-30 18:43:49 +0900933func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
934 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
935 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700936 movedToApexLlndkLibraries := make(map[string]bool)
937 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800938 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
939 // Skip bionic libs, they are handled in different manner
940 name := library.implementationModuleName(module.(*Module).BaseModuleName())
941 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
942 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700943 }
Jooyung Han0302a842019-10-30 18:43:49 +0900944 }
Colin Cross56a83212020-09-15 18:30:11 -0700945 })
946
947 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
Cole Faust18994c72023-02-28 16:02:16 -0800948 strings.Join(android.SortedKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900949
Jooyung Han0302a842019-10-30 18:43:49 +0900950 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900951 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900952}