blob: 95a5a4f47a829db50d8dfb208d60a05b6886e46f [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 Yun8effde42017-06-23 19:24:43 +090031)
32
Jooyung Han39edb6c2019-11-06 16:53:07 +090033const (
34 llndkLibrariesTxt = "llndk.libraries.txt"
35 vndkCoreLibrariesTxt = "vndkcore.libraries.txt"
36 vndkSpLibrariesTxt = "vndksp.libraries.txt"
37 vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt"
Justin Yun8a2600c2020-12-07 12:44:03 +090038 vndkProductLibrariesTxt = "vndkproduct.libraries.txt"
Jooyung Han39edb6c2019-11-06 16:53:07 +090039 vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt"
40)
41
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090042func VndkLibrariesTxtModules(vndkVersion string, ctx android.BaseModuleContext) []string {
Jooyung Han39edb6c2019-11-06 16:53:07 +090043 if vndkVersion == "current" {
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090044 result := []string{
Jooyung Han39edb6c2019-11-06 16:53:07 +090045 vndkCoreLibrariesTxt,
46 vndkSpLibrariesTxt,
47 vndkPrivateLibrariesTxt,
Justin Yun8a2600c2020-12-07 12:44:03 +090048 vndkProductLibrariesTxt,
Jooyung Han39edb6c2019-11-06 16:53:07 +090049 }
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090050
51 // TODO(b/290159430) This part will not be required once deprecation of VNDK
52 // is handled with 'ro.vndk.version' property
53 if !ctx.Config().IsVndkDeprecated() {
54 result = append(result, llndkLibrariesTxt)
55 }
56
57 return result
Jooyung Han39edb6c2019-11-06 16:53:07 +090058 }
59 // Snapshot vndks have their own *.libraries.VER.txt files.
60 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090061 result := []string{
Jooyung Han39edb6c2019-11-06 16:53:07 +090062 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
63 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
64 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
Justin Yun8a2600c2020-12-07 12:44:03 +090065 insertVndkVersion(vndkProductLibrariesTxt, vndkVersion),
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090066 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
Jooyung Han39edb6c2019-11-06 16:53:07 +090067 }
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090068
69 return result
Jooyung Han39edb6c2019-11-06 16:53:07 +090070}
71
Justin Yun8effde42017-06-23 19:24:43 +090072type VndkProperties struct {
73 Vndk struct {
74 // declared as a VNDK or VNDK-SP module. The vendor variant
75 // will be installed in /system instead of /vendor partition.
76 //
Justin Yun63e9ec72020-10-29 16:49:43 +090077 // `vendor_available` and `product_available` must be explicitly
78 // set to either true or false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090079 Enabled *bool
80
81 // declared as a VNDK-SP module, which is a subset of VNDK.
82 //
83 // `vndk: { enabled: true }` must set together.
84 //
85 // All these modules are allowed to link to VNDK-SP or LL-NDK
86 // modules only. Other dependency will cause link-type errors.
87 //
88 // If `support_system_process` is not set or set to false,
89 // the module is VNDK-core and can link to other VNDK-core,
90 // VNDK-SP or LL-NDK modules only.
91 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080092
Justin Yunfd9e8042020-12-23 18:23:14 +090093 // declared as a VNDK-private module.
94 // This module still creates the vendor and product variants refering
95 // to the `vendor_available: true` and `product_available: true`
96 // properties. However, it is only available to the other VNDK modules
97 // but not to the non-VNDK vendor or product modules.
98 Private *bool
99
Logan Chienf3511742017-10-31 18:04:35 +0800100 // Extending another module
101 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +0900102 }
103}
104
105type vndkdep struct {
106 Properties VndkProperties
107}
108
109func (vndk *vndkdep) props() []interface{} {
110 return []interface{}{&vndk.Properties}
111}
112
Justin Yun8effde42017-06-23 19:24:43 +0900113func (vndk *vndkdep) isVndk() bool {
114 return Bool(vndk.Properties.Vndk.Enabled)
115}
116
117func (vndk *vndkdep) isVndkSp() bool {
118 return Bool(vndk.Properties.Vndk.Support_system_process)
119}
120
Logan Chienf3511742017-10-31 18:04:35 +0800121func (vndk *vndkdep) isVndkExt() bool {
122 return vndk.Properties.Vndk.Extends != nil
123}
124
125func (vndk *vndkdep) getVndkExtendsModuleName() string {
126 return String(vndk.Properties.Vndk.Extends)
127}
128
Justin Yun8effde42017-06-23 19:24:43 +0900129func (vndk *vndkdep) typeName() string {
130 if !vndk.isVndk() {
131 return "native:vendor"
132 }
Logan Chienf3511742017-10-31 18:04:35 +0800133 if !vndk.isVndkExt() {
134 if !vndk.isVndkSp() {
135 return "native:vendor:vndk"
136 }
137 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900138 }
Logan Chienf3511742017-10-31 18:04:35 +0800139 if !vndk.isVndkSp() {
140 return "native:vendor:vndkext"
141 }
142 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900143}
144
Justin Yun63e9ec72020-10-29 16:49:43 +0900145// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900146func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900147 if to.linker == nil {
148 return
149 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900150 if !vndk.isVndk() {
Justin Yunfd9e8042020-12-23 18:23:14 +0900151 // Non-VNDK modules those installed to /vendor, /system/vendor,
152 // /product or /system/product cannot depend on VNDK-private modules
153 // that include VNDK-core-private, VNDK-SP-private and LLNDK-private.
154 if to.IsVndkPrivate() {
155 ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name())
Jiyong Park82e2bf32017-08-16 14:05:54 +0900156 }
157 }
Justin Yun8effde42017-06-23 19:24:43 +0900158 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
159 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800160 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900161 return
162 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800163
164 if to.IsLlndk() {
165 // LL-NDK libraries are allowed to link
166 return
167 }
168
Ivan Lozano52767be2019-10-18 14:49:46 -0700169 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900170 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
171 vndk.typeName(), to.Name())
172 return
173 }
Logan Chienf3511742017-10-31 18:04:35 +0800174 if tag == vndkExtDepTag {
175 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
176 // and has identical vndk properties.
177 if to.vndkdep == nil || !to.vndkdep.isVndk() {
178 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
179 return
180 }
181 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
182 ctx.ModuleErrorf(
183 "`extends` refers a module %q with mismatched support_system_process",
184 to.Name())
185 return
186 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900187 if to.IsVndkPrivate() {
Logan Chienf3511742017-10-31 18:04:35 +0800188 ctx.ModuleErrorf(
Justin Yunfd9e8042020-12-23 18:23:14 +0900189 "`extends` refers module %q which has `private: true`",
Justin Yun6977e8a2020-10-29 18:24:11 +0900190 to.Name())
191 return
192 }
Logan Chienf3511742017-10-31 18:04:35 +0800193 }
Justin Yun8effde42017-06-23 19:24:43 +0900194 if to.vndkdep == nil {
195 return
196 }
Logan Chienf3511742017-10-31 18:04:35 +0800197
Logan Chiend3c59a22018-03-29 14:08:15 +0800198 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100199 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
200 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
201 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800202 return
203 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800204}
Logan Chienf3511742017-10-31 18:04:35 +0800205
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100206func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800207 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
208 if from.isVndkExt() {
209 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100210 if to.isVndk() && !to.isVndkSp() {
211 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
212 }
213 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800214 }
215 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100216 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900217 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800218 if from.isVndk() {
219 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100220 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800221 }
222 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100223 if !to.isVndkSp() {
224 return errors.New("VNDK-SP must only depend on VNDK-SP")
225 }
226 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800227 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100228 if !to.isVndk() {
229 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
230 }
231 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800232 }
233 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100234 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900235}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900236
Colin Cross78212242021-01-06 14:51:30 -0800237type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string)
238
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900239var (
Colin Cross203b4212021-04-26 17:19:41 -0700240 llndkLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsLLNDK && !m.Header() })
Colin Cross78212242021-01-06 14:51:30 -0800241 vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP })
242 vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore })
Colin Cross203b4212021-04-26 17:19:41 -0700243 vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate })
Colin Cross78212242021-01-06 14:51:30 -0800244 vndkProductLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKProduct })
245 vndkUsingCoreVariantLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKUsingCoreVariant })
Inseob Kimae553032019-05-14 18:52:49 +0900246)
Inseob Kim1f086e22019-05-09 13:29:15 +0900247
Colin Cross78212242021-01-06 14:51:30 -0800248// vndkModuleLister takes a predicate that operates on a Module and returns a moduleListerFunc
249// that produces a list of module names and output file names for which the predicate returns true.
250func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc {
251 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
252 ctx.VisitAllModules(func(m android.Module) {
Jooyung Hane3f02812023-05-08 13:54:50 +0900253 if c, ok := m.(*Module); ok && predicate(c) && !c.IsVndkPrebuiltLibrary() {
Colin Cross78212242021-01-06 14:51:30 -0800254 filename, err := getVndkFileName(c)
255 if err != nil {
256 ctx.ModuleErrorf(m, "%s", err)
257 }
258 moduleNames = append(moduleNames, ctx.ModuleName(m))
259 fileNames = append(fileNames, filename)
260 }
261 })
262 moduleNames = android.SortedUniqueStrings(moduleNames)
263 fileNames = android.SortedUniqueStrings(fileNames)
264 return
265 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900266}
267
Colin Cross78212242021-01-06 14:51:30 -0800268// vndkModuleListRemover takes a moduleListerFunc and a prefix and returns a moduleListerFunc
269// that returns the same lists as the input moduleListerFunc, but with modules with the
270// given prefix removed.
271func vndkModuleListRemover(lister moduleListerFunc, prefix string) moduleListerFunc {
272 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
273 moduleNames, fileNames = lister(ctx)
274 filter := func(in []string) []string {
275 out := make([]string, 0, len(in))
276 for _, lib := range in {
277 if strings.HasPrefix(lib, prefix) {
278 continue
279 }
280 out = append(out, lib)
281 }
282 return out
283 }
284 return filter(moduleNames), filter(fileNames)
285 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900286}
287
Colin Cross78212242021-01-06 14:51:30 -0800288var vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
Inseob Kim9516ee92019-05-09 10:56:13 +0900289
Jooyung Han097087b2019-10-22 19:32:18 +0900290func vndkMustUseVendorVariantList(cfg android.Config) []string {
291 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900292 return config.VndkMustUseVendorVariantList
293 }).([]string)
294}
295
296// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
297// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
298func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900299 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900300 return mustUseVendorVariantList
301 })
302}
303
Inseob Kim1f086e22019-05-09 13:29:15 +0900304func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Justin Yun8a2600c2020-12-07 12:44:03 +0900305 if m.InProduct() {
306 // We may skip the steps for the product variants because they
307 // are already covered by the vendor variants.
308 return
309 }
310
Jooyung Han0302a842019-10-30 18:43:49 +0900311 name := m.BaseModuleName()
Inseob Kim1f086e22019-05-09 13:29:15 +0900312
Colin Cross31076b32020-10-23 17:22:06 -0700313 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000314 // b/155456180 libz is the ONLY exception here. We don't want to make
315 // libz an LLNDK library because we in general can't guarantee that
316 // libz will behave consistently especially about the compression.
317 // i.e. the compressed output might be different across releases.
318 // As the library is an external one, it's risky to keep the compatibility
319 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900320 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
321 }
322
Jooyung Han097087b2019-10-22 19:32:18 +0900323 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
324 m.Properties.MustUseVendorVariant = true
325 }
Jooyung Han0302a842019-10-30 18:43:49 +0900326 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
Colin Cross78212242021-01-06 14:51:30 -0800327 m.VendorProperties.IsVNDKUsingCoreVariant = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900328 }
Jooyung Han0302a842019-10-30 18:43:49 +0900329
Inseob Kim1f086e22019-05-09 13:29:15 +0900330 if m.vndkdep.isVndkSp() {
Colin Cross78212242021-01-06 14:51:30 -0800331 m.VendorProperties.IsVNDKSP = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900332 } else {
Colin Cross78212242021-01-06 14:51:30 -0800333 m.VendorProperties.IsVNDKCore = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900334 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900335 if m.IsVndkPrivate() {
Colin Cross78212242021-01-06 14:51:30 -0800336 m.VendorProperties.IsVNDKPrivate = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900337 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900338 if Bool(m.VendorProperties.Product_available) {
Colin Cross78212242021-01-06 14:51:30 -0800339 m.VendorProperties.IsVNDKProduct = true
Justin Yun8a2600c2020-12-07 12:44:03 +0900340 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900341}
342
Yo Chiang08fac0c2020-07-29 01:08:20 +0800343// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800344func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900345 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800346 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900347 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800348 if !m.Device() {
349 // Skip non-device modules
350 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900351 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900352 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800353 // Skip native_bridge modules
354 return true
355 }
356 return false
357}
358
359func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
360 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900361 return false
362 }
363
364 // prebuilt vndk modules should match with device
365 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
366 // When b/142675459 is landed, remove following check
Ivan Lozanod1dec542021-05-26 15:33:11 -0400367 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.MatchesWithDevice(mctx.DeviceConfig()) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900368 return false
369 }
370
371 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han73d20d02020-03-27 16:06:55 +0900372 // VNDK APEX for VNDK-Lite devices will have VNDK-SP libraries from core variants
373 if mctx.DeviceConfig().VndkVersion() == "" {
374 // b/73296261: filter out libz.so because it is considered as LLNDK for VNDK-lite devices
375 if mctx.ModuleName() == "libz" {
376 return false
377 }
Jooyung Han7d6e79b2021-06-24 01:53:43 +0900378 return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.IsVndkSp() && !m.IsVndkExt()
Jooyung Han73d20d02020-03-27 16:06:55 +0900379 }
Jooyung Han1724d582022-12-21 10:17:44 +0900380 // VNDK APEX doesn't need stub variants
381 if lib.buildStubs() {
382 return false
383 }
Justin Yun5f7f7e82019-11-18 19:52:14 +0900384 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900385 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500386 return lib.shared() && m.InVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900387 }
388 return false
389}
390
Inseob Kim1f086e22019-05-09 13:29:15 +0900391// gather list of vndk-core, vndk-sp, and ll-ndk libs
392func VndkMutator(mctx android.BottomUpMutatorContext) {
393 m, ok := mctx.Module().(*Module)
394 if !ok {
395 return
396 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800397
398 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900399 return
400 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900401
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800402 lib, isLib := m.linker.(*libraryDecorator)
403 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900404
Colin Cross203b4212021-04-26 17:19:41 -0700405 if m.UseVndk() && isLib && lib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800406 m.VendorProperties.IsLLNDK = true
407 m.VendorProperties.IsVNDKPrivate = Bool(lib.Properties.Llndk.Private)
408 }
Colin Cross203b4212021-04-26 17:19:41 -0700409 if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800410 m.VendorProperties.IsLLNDK = true
411 m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private)
412 }
413
Jooyung Hane3f02812023-05-08 13:54:50 +0900414 if m.IsVndkPrebuiltLibrary() && !m.IsVndk() {
415 m.VendorProperties.IsLLNDK = true
416 // TODO(b/280697209): copy "llndk.private" flag to vndk_prebuilt_shared
417 }
418
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800419 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900420 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900421 processVndkLibrary(mctx, m)
422 return
423 }
424 }
425}
426
427func init() {
Colin Crosse4e44bc2020-12-28 13:50:21 -0800428 RegisterVndkLibraryTxtTypes(android.InitRegistrationContext)
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000429 android.RegisterParallelSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900430}
431
Colin Crosse4e44bc2020-12-28 13:50:21 -0800432func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) {
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000433 ctx.RegisterParallelSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory)
434 ctx.RegisterParallelSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory)
435 ctx.RegisterParallelSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory)
436 ctx.RegisterParallelSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory)
437 ctx.RegisterParallelSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory)
438 ctx.RegisterParallelSingletonModuleType("vndkcorevariant_libraries_txt", vndkUsingCoreVariantLibrariesTxtFactory)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800439}
440
Jooyung Han2216fb12019-11-06 16:46:15 +0900441type vndkLibrariesTxt struct {
Colin Cross78212242021-01-06 14:51:30 -0800442 android.SingletonModuleBase
Colin Crosse4e44bc2020-12-28 13:50:21 -0800443
Justin Yun611e8862021-05-24 18:17:33 +0900444 lister moduleListerFunc
445 makeVarName string
446 filterOutFromMakeVar string
Colin Cross78212242021-01-06 14:51:30 -0800447
Colin Crosse4e44bc2020-12-28 13:50:21 -0800448 properties VndkLibrariesTxtProperties
449
Colin Cross78212242021-01-06 14:51:30 -0800450 outputFile android.OutputPath
451 moduleNames []string
452 fileNames []string
Jooyung Han2216fb12019-11-06 16:46:15 +0900453}
454
Colin Crosse4e44bc2020-12-28 13:50:21 -0800455type VndkLibrariesTxtProperties struct {
456 Insert_vndk_version *bool
457}
458
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700459var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900460var _ android.OutputFileProducer = &vndkLibrariesTxt{}
461
Colin Cross78212242021-01-06 14:51:30 -0800462// llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries
463// generated by Soong but can be referenced by other modules.
Jooyung Han2216fb12019-11-06 16:46:15 +0900464// For example, apex_vndk can depend on these files as prebuilt.
Justin Yun611e8862021-05-24 18:17:33 +0900465// Make uses LLNDK_LIBRARIES to determine which libraries to install.
466// HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
467// Therefore, by removing the library here, we cause it to only be installed if libc
468// depends on it.
Colin Cross78212242021-01-06 14:51:30 -0800469func llndkLibrariesTxtFactory() android.SingletonModule {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800470 return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "LLNDK_LIBRARIES", "libclang_rt.hwasan")
Colin Cross78212242021-01-06 14:51:30 -0800471}
472
473// vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries
474// generated by Soong but can be referenced by other modules.
475// For example, apex_vndk can depend on these files as prebuilt.
476func vndkSPLibrariesTxtFactory() android.SingletonModule {
477 return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES")
478}
479
480// vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries
481// generated by Soong but can be referenced by other modules.
482// For example, apex_vndk can depend on these files as prebuilt.
483func vndkCoreLibrariesTxtFactory() android.SingletonModule {
484 return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES")
485}
486
487// vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries
488// generated by Soong but can be referenced by other modules.
489// For example, apex_vndk can depend on these files as prebuilt.
490func vndkPrivateLibrariesTxtFactory() android.SingletonModule {
491 return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES")
492}
493
494// vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product 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 vndkProductLibrariesTxtFactory() android.SingletonModule {
498 return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES")
499}
500
501// vndkcorevariant_libraries_txt is a singleton module whose content is a list of VNDK libraries
502// that are using the core variant, generated by Soong but can be referenced by other modules.
503// For example, apex_vndk can depend on these files as prebuilt.
504func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule {
505 return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES")
506}
507
Justin Yun611e8862021-05-24 18:17:33 +0900508func newVndkLibrariesWithMakeVarFilter(lister moduleListerFunc, makeVarName string, filter string) android.SingletonModule {
Colin Cross78212242021-01-06 14:51:30 -0800509 m := &vndkLibrariesTxt{
Justin Yun611e8862021-05-24 18:17:33 +0900510 lister: lister,
511 makeVarName: makeVarName,
512 filterOutFromMakeVar: filter,
Colin Crosse4e44bc2020-12-28 13:50:21 -0800513 }
Colin Cross78212242021-01-06 14:51:30 -0800514 m.AddProperties(&m.properties)
Colin Cross45bce852021-11-11 22:47:54 -0800515 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
Colin Cross78212242021-01-06 14:51:30 -0800516 return m
Jooyung Han2216fb12019-11-06 16:46:15 +0900517}
518
Justin Yun611e8862021-05-24 18:17:33 +0900519func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule {
520 return newVndkLibrariesWithMakeVarFilter(lister, makeVarName, "")
521}
522
Jooyung Han2216fb12019-11-06 16:46:15 +0900523func insertVndkVersion(filename string, vndkVersion string) string {
524 if index := strings.LastIndex(filename, "."); index != -1 {
525 return filename[:index] + "." + vndkVersion + filename[index:]
526 }
527 return filename
528}
529
Colin Crosse4e44bc2020-12-28 13:50:21 -0800530func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Kiyoung Kima2d6dee2023-08-11 10:14:43 +0900531 filename := txt.Name()
532
533 shouldInsertVndkVersion := BoolDefault(txt.properties.Insert_vndk_version, true)
534 // llndk.libraries.txt file installed in the system image should not contain version info.
535 if ctx.Config().IsVndkDeprecated() && txt.Name() == llndkLibrariesTxt {
536 shouldInsertVndkVersion = false
537 }
538 if shouldInsertVndkVersion {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900539 filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900540 }
541
Jooyung Han2216fb12019-11-06 16:46:15 +0900542 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Jooyung Han2216fb12019-11-06 16:46:15 +0900543
544 installPath := android.PathForModuleInstall(ctx, "etc")
545 ctx.InstallFile(installPath, filename, txt.outputFile)
546}
547
Colin Cross78212242021-01-06 14:51:30 -0800548func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) {
549 txt.moduleNames, txt.fileNames = txt.lister(ctx)
550 android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n"))
551}
552
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900553func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
554 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900555 Class: "ETC",
556 OutputFile: android.OptionalPathForPath(txt.outputFile),
557 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700558 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900559 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
560 },
561 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900562 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900563}
564
Colin Cross78212242021-01-06 14:51:30 -0800565func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) {
Justin Yun611e8862021-05-24 18:17:33 +0900566 filter := func(modules []string, prefix string) []string {
567 if prefix == "" {
568 return modules
569 }
570 var result []string
571 for _, module := range modules {
572 if strings.HasPrefix(module, prefix) {
573 continue
574 } else {
575 result = append(result, module)
576 }
577 }
578 return result
579 }
580 ctx.Strict(txt.makeVarName, strings.Join(filter(txt.moduleNames, txt.filterOutFromMakeVar), " "))
Colin Cross78212242021-01-06 14:51:30 -0800581}
582
Jooyung Han0703fd82020-08-26 22:11:53 +0900583// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900584func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
585 return txt.outputFile
586}
587
Jooyung Han0703fd82020-08-26 22:11:53 +0900588// PrebuiltEtcModule interface
589func (txt *vndkLibrariesTxt) BaseDir() string {
590 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900591}
592
Jooyung Han0703fd82020-08-26 22:11:53 +0900593// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900594func (txt *vndkLibrariesTxt) SubDir() string {
595 return ""
596}
597
Jooyung Han0703fd82020-08-26 22:11:53 +0900598func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
599 return android.Paths{txt.outputFile}, nil
600}
601
Inseob Kim1f086e22019-05-09 13:29:15 +0900602func VndkSnapshotSingleton() android.Singleton {
603 return &vndkSnapshotSingleton{}
604}
605
Jooyung Han0302a842019-10-30 18:43:49 +0900606type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900607 vndkLibrariesFile android.OutputPath
608 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900609}
Inseob Kim1f086e22019-05-09 13:29:15 +0900610
Ivan Lozanod7586b62021-04-01 09:49:36 -0400611func isVndkSnapshotAware(config android.DeviceConfig, m LinkableInterface,
612 apexInfo android.ApexInfo) (vndkType string, isVndkSnapshotLib bool) {
Colin Cross56a83212020-09-15 18:30:11 -0700613
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900614 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400615 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900616 }
Jooyung Han261e1582020-10-20 18:54:21 +0900617 // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
618 // !installable: Snapshot only cares about "installable" modules.
Justin Yun450ae722021-04-16 19:58:18 +0900619 // !m.IsLlndk: llndk stubs are required for building against snapshots.
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400620 // IsSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
Justin Yun450ae722021-04-16 19:58:18 +0900621 // !outputFile.Valid: Snapshot requires valid output file.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400622 if !m.InVendor() || (!installable(m, apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.OutputFile().Valid() {
623 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900624 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400625 if !m.IsSnapshotLibrary() || !m.Shared() {
626 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900627 }
Justin Yun450ae722021-04-16 19:58:18 +0900628 if m.VndkVersion() == config.PlatformVndkVersion() {
629 if m.IsVndk() && !m.IsVndkExt() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400630 if m.IsVndkSp() {
631 return "vndk-sp", true
Justin Yun450ae722021-04-16 19:58:18 +0900632 } else {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400633 return "vndk-core", true
Justin Yun450ae722021-04-16 19:58:18 +0900634 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400635 } else if m.HasLlndkStubs() && m.StubsVersion() == "" {
Justin Yun450ae722021-04-16 19:58:18 +0900636 // Use default version for the snapshot.
Ivan Lozanod7586b62021-04-01 09:49:36 -0400637 return "llndk-stub", true
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900638 }
639 }
640
Ivan Lozanod7586b62021-04-01 09:49:36 -0400641 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900642}
643
Inseob Kim1f086e22019-05-09 13:29:15 +0900644func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900645 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
646 c.buildVndkLibrariesTxtFiles(ctx)
647
Inseob Kim1f086e22019-05-09 13:29:15 +0900648 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
649 if ctx.DeviceConfig().VndkVersion() != "current" {
650 return
651 }
652
653 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
654 return
655 }
656
Inseob Kim242ef0c2019-10-22 20:15:20 +0900657 var snapshotOutputs android.Paths
658
659 /*
660 VNDK snapshot zipped artifacts directory structure:
661 {SNAPSHOT_ARCH}/
662 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
663 shared/
664 vndk-core/
665 (VNDK-core libraries, e.g. libbinder.so)
666 vndk-sp/
667 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900668 llndk-stub/
669 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900670 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
671 shared/
672 vndk-core/
673 (VNDK-core libraries, e.g. libbinder.so)
674 vndk-sp/
675 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900676 llndk-stub/
677 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900678 binder32/
679 (This directory is newly introduced in v28 (Android P) to hold
680 prebuilts built for 32-bit binder interface.)
681 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
682 ...
683 configs/
684 (various *.txt configuration files)
685 include/
686 (header files of same directory structure with source tree)
687 NOTICE_FILES/
688 (notice files of libraries, e.g. libcutils.so.txt)
689 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900690
691 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900692 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900693
Inseob Kim242ef0c2019-10-22 20:15:20 +0900694 configsDir := filepath.Join(snapshotArchDir, "configs")
Justin Yun1871f902023-04-07 20:13:19 +0900695 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
Inseob Kim242ef0c2019-10-22 20:15:20 +0900696 includeDir := filepath.Join(snapshotArchDir, "include")
697
Justin Yun1871f902023-04-07 20:13:19 +0900698 // set of notice files copied.
699 noticeBuilt := make(map[string]bool)
700
Inseob Kim242ef0c2019-10-22 20:15:20 +0900701 // paths of VNDK modules for GPL license checking
702 modulePaths := make(map[string]string)
703
704 // actual module names of .so files
705 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
706 moduleNames := make(map[string]string)
707
Inseob Kim8471cda2019-11-15 09:59:12 +0900708 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900709
Inseob Kimde5744a2020-12-02 13:14:28 +0900710 // installVndkSnapshotLib copies built .so file from the module.
711 // Also, if the build artifacts is on, write a json file which contains all exported flags
712 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700713 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900714 var ret android.Paths
715
Inseob Kim8471cda2019-11-15 09:59:12 +0900716 targetArch := "arch-" + m.Target().Arch.ArchType.String()
717 if m.Target().Arch.ArchVariant != "" {
718 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900719 }
Inseob Kimae553032019-05-14 18:52:49 +0900720
Inseob Kim8471cda2019-11-15 09:59:12 +0900721 libPath := m.outputFile.Path()
722 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Kiyoung Kimae11c232021-07-19 11:38:04 +0900723 ret = append(ret, snapshot.CopyFileRule(pctx, ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900724
Justin Yun1871f902023-04-07 20:13:19 +0900725 // json struct to export snapshot information
726 prop := struct {
Inseob Kim5860f822023-04-18 11:30:22 +0900727 MinSdkVersion string `json:",omitempty"`
Justin Yun1871f902023-04-07 20:13:19 +0900728 LicenseKinds []string `json:",omitempty"`
729 LicenseTexts []string `json:",omitempty"`
730 ExportedDirs []string `json:",omitempty"`
731 ExportedSystemDirs []string `json:",omitempty"`
732 ExportedFlags []string `json:",omitempty"`
733 RelativeInstallPath string `json:",omitempty"`
734 }{}
735
736 prop.LicenseKinds = m.EffectiveLicenseKinds()
737 prop.LicenseTexts = m.EffectiveLicenseFiles().Strings()
Inseob Kim5860f822023-04-18 11:30:22 +0900738 prop.MinSdkVersion = m.MinSdkVersion()
Justin Yun1871f902023-04-07 20:13:19 +0900739
Inseob Kimae553032019-05-14 18:52:49 +0900740 if ctx.Config().VndkSnapshotBuildArtifacts() {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700741 exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
742 prop.ExportedFlags = exportedInfo.Flags
743 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
744 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900745 prop.RelativeInstallPath = m.RelativeInstallPath()
Inseob Kimae553032019-05-14 18:52:49 +0900746 }
Justin Yun1871f902023-04-07 20:13:19 +0900747
748 propOut := snapshotLibOut + ".json"
749
750 j, err := json.Marshal(prop)
751 if err != nil {
752 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
753 return nil, false
754 }
755 ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
756
Inseob Kim242ef0c2019-10-22 20:15:20 +0900757 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900758 }
759
Inseob Kim1f086e22019-05-09 13:29:15 +0900760 ctx.VisitAllModules(func(module android.Module) {
761 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900762 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900763 return
764 }
765
Colin Cross56a83212020-09-15 18:30:11 -0700766 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
767
Ivan Lozanod7586b62021-04-01 09:49:36 -0400768 vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900769 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200770 return
771 }
772
Inseob Kimde5744a2020-12-02 13:14:28 +0900773 // For all snapshot candidates, the followings are captured.
774 // - .so files
775 // - notice files
776 //
777 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
778 // - .json files containing exported flags
779 // - exported headers from collectHeadersForSnapshot()
780 //
781 // Headers are deduplicated after visiting all modules.
782
Inseob Kim8471cda2019-11-15 09:59:12 +0900783 // install .so files for appropriate modules.
784 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700785 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900786 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900787 return
788 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900789 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900790
Inseob Kim8471cda2019-11-15 09:59:12 +0900791 // These are for generating module_names.txt and module_paths.txt
792 stem := m.outputFile.Path().Base()
793 moduleNames[stem] = ctx.ModuleName(m)
794 modulePaths[stem] = ctx.ModuleDir(m)
795
Justin Yun1871f902023-04-07 20:13:19 +0900796 for _, notice := range m.EffectiveLicenseFiles() {
797 if _, ok := noticeBuilt[notice.String()]; !ok {
798 noticeBuilt[notice.String()] = true
799 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
800 pctx, ctx, notice, filepath.Join(noticeDir, notice.String())))
801 }
802 }
803
Inseob Kim8471cda2019-11-15 09:59:12 +0900804 if ctx.Config().VndkSnapshotBuildArtifacts() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400805 headers = append(headers, m.SnapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900806 }
807 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900808
Inseob Kim8471cda2019-11-15 09:59:12 +0900809 // install all headers after removing duplicates
810 for _, header := range android.FirstUniquePaths(headers) {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900811 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
812 pctx, ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900813 }
814
Jooyung Han39edb6c2019-11-06 16:53:07 +0900815 // install *.libraries.txt except vndkcorevariant.libraries.txt
816 ctx.VisitAllModules(func(module android.Module) {
817 m, ok := module.(*vndkLibrariesTxt)
818 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
819 return
820 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900821 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
822 pctx, ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900823 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900824
Inseob Kim242ef0c2019-10-22 20:15:20 +0900825 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900826 module_paths.txt contains paths on which VNDK modules are defined.
827 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000828 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900829 libc.so bionic/libc
830 ...
831 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900832 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900833
834 /*
835 module_names.txt contains names as which VNDK modules are defined,
836 because output filename and module name can be different with stem and suffix properties.
837
838 e.g.,
839 libcutils.so libcutils
840 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
841 ...
842 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900843 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900844
845 // All artifacts are ready. Sort them to normalize ninja and then zip.
846 sort.Slice(snapshotOutputs, func(i, j int) bool {
847 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
848 })
849
850 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800851 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900852
Inseob Kimde5744a2020-12-02 13:14:28 +0900853 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900854 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
Colin Cross70c47412021-03-12 17:48:14 -0800855 rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp")
Inseob Kim242ef0c2019-10-22 20:15:20 +0900856 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900857 Text("tr").
858 FlagWithArg("-d ", "\\'").
Colin Cross70c47412021-03-12 17:48:14 -0800859 FlagWithRspFileInputList("< ", rspFile, snapshotOutputs).
Inseob Kim8471cda2019-11-15 09:59:12 +0900860 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900861
862 zipRule.Temporary(snapshotOutputList)
863
864 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800865 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900866 FlagWithOutput("-o ", zipPath).
867 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
868 FlagWithInput("-l ", snapshotOutputList)
869
Colin Crossf1a035e2020-11-16 17:32:30 -0800870 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900871 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900872 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900873}
Jooyung Han097087b2019-10-22 19:32:18 +0900874
Jooyung Han0302a842019-10-30 18:43:49 +0900875func getVndkFileName(m *Module) (string, error) {
876 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900877 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900878 }
879 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900880 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900881 }
882 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900883}
884
885func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900886 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900887 // Since each target have different set of libclang_rt.* files,
888 // keep the common set of files in vndk.libraries.txt
Colin Cross78212242021-01-06 14:51:30 -0800889 _, llndk := vndkModuleListRemover(llndkLibraries, "libclang_rt.")(ctx)
890 _, vndkcore := vndkModuleListRemover(vndkCoreLibraries, "libclang_rt.")(ctx)
891 _, vndksp := vndkSPLibraries(ctx)
892 _, vndkprivate := vndkPrivateLibraries(ctx)
893 _, vndkproduct := vndkModuleListRemover(vndkProductLibraries, "libclang_rt.")(ctx)
Jooyung Han0302a842019-10-30 18:43:49 +0900894 var merged []string
Colin Cross78212242021-01-06 14:51:30 -0800895 merged = append(merged, addPrefix(llndk, "LLNDK: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900896 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800897 merged = append(merged, addPrefix(vndkcore, "VNDK-core: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900898 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800899 merged = append(merged, addPrefix(vndkproduct, "VNDK-product: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900900 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800901 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900902}
Jooyung Han097087b2019-10-22 19:32:18 +0900903
Jooyung Han0302a842019-10-30 18:43:49 +0900904func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
905 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
906 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700907 movedToApexLlndkLibraries := make(map[string]bool)
908 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800909 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
910 // Skip bionic libs, they are handled in different manner
911 name := library.implementationModuleName(module.(*Module).BaseModuleName())
912 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
913 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700914 }
Jooyung Han0302a842019-10-30 18:43:49 +0900915 }
Colin Cross56a83212020-09-15 18:30:11 -0700916 })
917
918 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
Cole Faust18994c72023-02-28 16:02:16 -0800919 strings.Join(android.SortedKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900920
Jooyung Han0302a842019-10-30 18:43:49 +0900921 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900922 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900923}