blob: ad0dcf3635e327349449912a48cdb11feb0f0fa0 [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 {
Jooyung Han39edb6c2019-11-06 16:53:07 +090045 // Snapshot vndks have their own *.libraries.VER.txt files.
46 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090047 result := []string{
Jooyung Han39edb6c2019-11-06 16:53:07 +090048 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
49 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
50 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
Justin Yun8a2600c2020-12-07 12:44:03 +090051 insertVndkVersion(vndkProductLibrariesTxt, vndkVersion),
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090052 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
Jooyung Han39edb6c2019-11-06 16:53:07 +090053 }
Kiyoung Kima2d6dee2023-08-11 10:14:43 +090054
55 return result
Jooyung Han39edb6c2019-11-06 16:53:07 +090056}
57
Justin Yun8effde42017-06-23 19:24:43 +090058type VndkProperties struct {
59 Vndk struct {
60 // declared as a VNDK or VNDK-SP module. The vendor variant
61 // will be installed in /system instead of /vendor partition.
62 //
Justin Yun63e9ec72020-10-29 16:49:43 +090063 // `vendor_available` and `product_available` must be explicitly
64 // set to either true or false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090065 Enabled *bool
66
67 // declared as a VNDK-SP module, which is a subset of VNDK.
68 //
69 // `vndk: { enabled: true }` must set together.
70 //
71 // All these modules are allowed to link to VNDK-SP or LL-NDK
72 // modules only. Other dependency will cause link-type errors.
73 //
74 // If `support_system_process` is not set or set to false,
75 // the module is VNDK-core and can link to other VNDK-core,
76 // VNDK-SP or LL-NDK modules only.
77 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080078
Justin Yunfd9e8042020-12-23 18:23:14 +090079 // declared as a VNDK-private module.
80 // This module still creates the vendor and product variants refering
81 // to the `vendor_available: true` and `product_available: true`
82 // properties. However, it is only available to the other VNDK modules
83 // but not to the non-VNDK vendor or product modules.
84 Private *bool
85
Logan Chienf3511742017-10-31 18:04:35 +080086 // Extending another module
87 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090088 }
89}
90
91type vndkdep struct {
92 Properties VndkProperties
93}
94
95func (vndk *vndkdep) props() []interface{} {
96 return []interface{}{&vndk.Properties}
97}
98
Justin Yun8effde42017-06-23 19:24:43 +090099func (vndk *vndkdep) isVndk() bool {
100 return Bool(vndk.Properties.Vndk.Enabled)
101}
102
103func (vndk *vndkdep) isVndkSp() bool {
104 return Bool(vndk.Properties.Vndk.Support_system_process)
105}
106
Logan Chienf3511742017-10-31 18:04:35 +0800107func (vndk *vndkdep) isVndkExt() bool {
108 return vndk.Properties.Vndk.Extends != nil
109}
110
111func (vndk *vndkdep) getVndkExtendsModuleName() string {
112 return String(vndk.Properties.Vndk.Extends)
113}
114
Justin Yun8effde42017-06-23 19:24:43 +0900115func (vndk *vndkdep) typeName() string {
116 if !vndk.isVndk() {
117 return "native:vendor"
118 }
Logan Chienf3511742017-10-31 18:04:35 +0800119 if !vndk.isVndkExt() {
120 if !vndk.isVndkSp() {
121 return "native:vendor:vndk"
122 }
123 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900124 }
Logan Chienf3511742017-10-31 18:04:35 +0800125 if !vndk.isVndkSp() {
126 return "native:vendor:vndkext"
127 }
128 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900129}
130
Justin Yun63e9ec72020-10-29 16:49:43 +0900131// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900132func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900133 if to.linker == nil {
134 return
135 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900136 if !vndk.isVndk() {
Justin Yunfd9e8042020-12-23 18:23:14 +0900137 // Non-VNDK modules those installed to /vendor, /system/vendor,
138 // /product or /system/product cannot depend on VNDK-private modules
139 // that include VNDK-core-private, VNDK-SP-private and LLNDK-private.
140 if to.IsVndkPrivate() {
141 ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name())
Jiyong Park82e2bf32017-08-16 14:05:54 +0900142 }
143 }
Justin Yun8effde42017-06-23 19:24:43 +0900144 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
145 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800146 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900147 return
148 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800149
150 if to.IsLlndk() {
151 // LL-NDK libraries are allowed to link
152 return
153 }
154
Ivan Lozano52767be2019-10-18 14:49:46 -0700155 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900156 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
157 vndk.typeName(), to.Name())
158 return
159 }
Logan Chienf3511742017-10-31 18:04:35 +0800160 if tag == vndkExtDepTag {
161 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
162 // and has identical vndk properties.
163 if to.vndkdep == nil || !to.vndkdep.isVndk() {
164 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
165 return
166 }
167 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
168 ctx.ModuleErrorf(
169 "`extends` refers a module %q with mismatched support_system_process",
170 to.Name())
171 return
172 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900173 if to.IsVndkPrivate() {
Logan Chienf3511742017-10-31 18:04:35 +0800174 ctx.ModuleErrorf(
Justin Yunfd9e8042020-12-23 18:23:14 +0900175 "`extends` refers module %q which has `private: true`",
Justin Yun6977e8a2020-10-29 18:24:11 +0900176 to.Name())
177 return
178 }
Logan Chienf3511742017-10-31 18:04:35 +0800179 }
Justin Yun8effde42017-06-23 19:24:43 +0900180 if to.vndkdep == nil {
181 return
182 }
Logan Chienf3511742017-10-31 18:04:35 +0800183
Logan Chiend3c59a22018-03-29 14:08:15 +0800184 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100185 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
186 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
187 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800188 return
189 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800190}
Logan Chienf3511742017-10-31 18:04:35 +0800191
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100192func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800193 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
194 if from.isVndkExt() {
195 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100196 if to.isVndk() && !to.isVndkSp() {
197 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
198 }
199 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800200 }
201 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100202 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900203 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800204 if from.isVndk() {
205 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100206 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800207 }
208 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100209 if !to.isVndkSp() {
210 return errors.New("VNDK-SP must only depend on VNDK-SP")
211 }
212 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800213 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100214 if !to.isVndk() {
215 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
216 }
217 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800218 }
219 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100220 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900221}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900222
Colin Cross78212242021-01-06 14:51:30 -0800223type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string)
224
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900225var (
Colin Cross203b4212021-04-26 17:19:41 -0700226 llndkLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsLLNDK && !m.Header() })
Colin Cross78212242021-01-06 14:51:30 -0800227 vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP })
228 vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore })
Colin Cross203b4212021-04-26 17:19:41 -0700229 vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate })
Colin Cross78212242021-01-06 14:51:30 -0800230 vndkProductLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKProduct })
231 vndkUsingCoreVariantLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKUsingCoreVariant })
Inseob Kimae553032019-05-14 18:52:49 +0900232)
Inseob Kim1f086e22019-05-09 13:29:15 +0900233
Colin Cross78212242021-01-06 14:51:30 -0800234// vndkModuleLister takes a predicate that operates on a Module and returns a moduleListerFunc
235// that produces a list of module names and output file names for which the predicate returns true.
236func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc {
237 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
238 ctx.VisitAllModules(func(m android.Module) {
Jooyung Hane3f02812023-05-08 13:54:50 +0900239 if c, ok := m.(*Module); ok && predicate(c) && !c.IsVndkPrebuiltLibrary() {
Colin Cross78212242021-01-06 14:51:30 -0800240 filename, err := getVndkFileName(c)
241 if err != nil {
242 ctx.ModuleErrorf(m, "%s", err)
243 }
244 moduleNames = append(moduleNames, ctx.ModuleName(m))
245 fileNames = append(fileNames, filename)
246 }
247 })
248 moduleNames = android.SortedUniqueStrings(moduleNames)
249 fileNames = android.SortedUniqueStrings(fileNames)
250 return
251 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900252}
253
Colin Cross78212242021-01-06 14:51:30 -0800254// vndkModuleListRemover takes a moduleListerFunc and a prefix and returns a moduleListerFunc
255// that returns the same lists as the input moduleListerFunc, but with modules with the
256// given prefix removed.
257func vndkModuleListRemover(lister moduleListerFunc, prefix string) moduleListerFunc {
258 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
259 moduleNames, fileNames = lister(ctx)
260 filter := func(in []string) []string {
261 out := make([]string, 0, len(in))
262 for _, lib := range in {
263 if strings.HasPrefix(lib, prefix) {
264 continue
265 }
266 out = append(out, lib)
267 }
268 return out
269 }
270 return filter(moduleNames), filter(fileNames)
271 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900272}
273
Colin Cross78212242021-01-06 14:51:30 -0800274var vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
Inseob Kim9516ee92019-05-09 10:56:13 +0900275
Jooyung Han097087b2019-10-22 19:32:18 +0900276func vndkMustUseVendorVariantList(cfg android.Config) []string {
277 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900278 return config.VndkMustUseVendorVariantList
279 }).([]string)
280}
281
282// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
283// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
284func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900285 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900286 return mustUseVendorVariantList
287 })
288}
289
Inseob Kim1f086e22019-05-09 13:29:15 +0900290func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Justin Yun8a2600c2020-12-07 12:44:03 +0900291 if m.InProduct() {
292 // We may skip the steps for the product variants because they
293 // are already covered by the vendor variants.
294 return
295 }
296
Jooyung Han0302a842019-10-30 18:43:49 +0900297 name := m.BaseModuleName()
Inseob Kim1f086e22019-05-09 13:29:15 +0900298
Colin Cross31076b32020-10-23 17:22:06 -0700299 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000300 // b/155456180 libz is the ONLY exception here. We don't want to make
301 // libz an LLNDK library because we in general can't guarantee that
302 // libz will behave consistently especially about the compression.
303 // i.e. the compressed output might be different across releases.
304 // As the library is an external one, it's risky to keep the compatibility
305 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900306 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
307 }
308
Jooyung Han097087b2019-10-22 19:32:18 +0900309 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
310 m.Properties.MustUseVendorVariant = true
311 }
Jooyung Han0302a842019-10-30 18:43:49 +0900312 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
Colin Cross78212242021-01-06 14:51:30 -0800313 m.VendorProperties.IsVNDKUsingCoreVariant = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900314 }
Jooyung Han0302a842019-10-30 18:43:49 +0900315
Inseob Kim1f086e22019-05-09 13:29:15 +0900316 if m.vndkdep.isVndkSp() {
Colin Cross78212242021-01-06 14:51:30 -0800317 m.VendorProperties.IsVNDKSP = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900318 } else {
Colin Cross78212242021-01-06 14:51:30 -0800319 m.VendorProperties.IsVNDKCore = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900320 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900321 if m.IsVndkPrivate() {
Colin Cross78212242021-01-06 14:51:30 -0800322 m.VendorProperties.IsVNDKPrivate = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900323 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900324 if Bool(m.VendorProperties.Product_available) {
Colin Cross78212242021-01-06 14:51:30 -0800325 m.VendorProperties.IsVNDKProduct = true
Justin Yun8a2600c2020-12-07 12:44:03 +0900326 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900327}
328
Yo Chiang08fac0c2020-07-29 01:08:20 +0800329// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800330func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900331 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800332 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900333 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800334 if !m.Device() {
335 // Skip non-device modules
336 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900337 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900338 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800339 // Skip native_bridge modules
340 return true
341 }
342 return false
343}
344
345func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
346 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900347 return false
348 }
349
Jooyung Han31c470b2019-10-18 16:26:59 +0900350 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
351 // When b/142675459 is landed, remove following check
Justin Yunf14beaf2023-08-18 17:51:14 +0900352 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
353 // prebuilt vndk modules should match with device
354 if !p.MatchesWithDevice(mctx.DeviceConfig()) {
355 return false
356 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900357 }
358
359 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han1724d582022-12-21 10:17:44 +0900360 // VNDK APEX doesn't need stub variants
361 if lib.buildStubs() {
362 return false
363 }
Kiyoung Kimfa13ff12024-03-18 16:01:19 +0900364 useCoreVariant := mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500365 return lib.shared() && m.InVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900366 }
367 return false
368}
369
Inseob Kim1f086e22019-05-09 13:29:15 +0900370// gather list of vndk-core, vndk-sp, and ll-ndk libs
371func VndkMutator(mctx android.BottomUpMutatorContext) {
372 m, ok := mctx.Module().(*Module)
373 if !ok {
374 return
375 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800376
377 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900378 return
379 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900380
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800381 lib, isLib := m.linker.(*libraryDecorator)
382 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900383
Kiyoung Kimaa394802024-01-08 12:55:45 +0900384 if m.InVendorOrProduct() && isLib && lib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800385 m.VendorProperties.IsLLNDK = true
386 m.VendorProperties.IsVNDKPrivate = Bool(lib.Properties.Llndk.Private)
387 }
Kiyoung Kimaa394802024-01-08 12:55:45 +0900388 if m.InVendorOrProduct() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() {
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800389 m.VendorProperties.IsLLNDK = true
390 m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private)
391 }
392
Jooyung Hane3f02812023-05-08 13:54:50 +0900393 if m.IsVndkPrebuiltLibrary() && !m.IsVndk() {
394 m.VendorProperties.IsLLNDK = true
395 // TODO(b/280697209): copy "llndk.private" flag to vndk_prebuilt_shared
396 }
397
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800398 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900399 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900400 processVndkLibrary(mctx, m)
401 return
402 }
403 }
404}
405
406func init() {
Colin Crosse4e44bc2020-12-28 13:50:21 -0800407 RegisterVndkLibraryTxtTypes(android.InitRegistrationContext)
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000408 android.RegisterParallelSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900409}
410
Colin Crosse4e44bc2020-12-28 13:50:21 -0800411func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) {
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000412 ctx.RegisterParallelSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory)
Justin Yund5784122023-10-25 13:25:32 +0900413 ctx.RegisterParallelSingletonModuleType("llndk_libraries_txt_for_apex", llndkLibrariesTxtApexOnlyFactory)
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000414 ctx.RegisterParallelSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory)
415 ctx.RegisterParallelSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory)
416 ctx.RegisterParallelSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory)
417 ctx.RegisterParallelSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory)
418 ctx.RegisterParallelSingletonModuleType("vndkcorevariant_libraries_txt", vndkUsingCoreVariantLibrariesTxtFactory)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800419}
420
Jooyung Han2216fb12019-11-06 16:46:15 +0900421type vndkLibrariesTxt struct {
Colin Cross78212242021-01-06 14:51:30 -0800422 android.SingletonModuleBase
Colin Crosse4e44bc2020-12-28 13:50:21 -0800423
Justin Yun611e8862021-05-24 18:17:33 +0900424 lister moduleListerFunc
425 makeVarName string
426 filterOutFromMakeVar string
Colin Cross78212242021-01-06 14:51:30 -0800427
Colin Crosse4e44bc2020-12-28 13:50:21 -0800428 properties VndkLibrariesTxtProperties
429
Colin Cross78212242021-01-06 14:51:30 -0800430 outputFile android.OutputPath
431 moduleNames []string
432 fileNames []string
Jooyung Han2216fb12019-11-06 16:46:15 +0900433}
434
Colin Crosse4e44bc2020-12-28 13:50:21 -0800435type VndkLibrariesTxtProperties struct {
436 Insert_vndk_version *bool
Justin Yund5784122023-10-25 13:25:32 +0900437 Stem *string
Colin Crosse4e44bc2020-12-28 13:50:21 -0800438}
439
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700440var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900441var _ android.OutputFileProducer = &vndkLibrariesTxt{}
442
Colin Cross78212242021-01-06 14:51:30 -0800443// llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries
Justin Yund5784122023-10-25 13:25:32 +0900444// generated by Soong.
Justin Yun611e8862021-05-24 18:17:33 +0900445// Make uses LLNDK_LIBRARIES to determine which libraries to install.
Justin Yund5784122023-10-25 13:25:32 +0900446// HWASAN is only part of the LLNDK in builds in which libc depends on HWASAN.
Justin Yun611e8862021-05-24 18:17:33 +0900447// Therefore, by removing the library here, we cause it to only be installed if libc
448// depends on it.
Colin Cross78212242021-01-06 14:51:30 -0800449func llndkLibrariesTxtFactory() android.SingletonModule {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800450 return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "LLNDK_LIBRARIES", "libclang_rt.hwasan")
Colin Cross78212242021-01-06 14:51:30 -0800451}
452
Justin Yund5784122023-10-25 13:25:32 +0900453// llndk_libraries_txt_for_apex is a singleton module that provide the same LLNDK libraries list
454// with the llndk_libraries_txt, but skips setting make variable LLNDK_LIBRARIES. So, it must not
455// be used without installing llndk_libraries_txt singleton.
456// We include llndk_libraries_txt by default to install the llndk.libraries.txt file to system/etc.
457// This singleton module is to install the llndk.libraries.<ver>.txt file to vndk apex.
458func llndkLibrariesTxtApexOnlyFactory() android.SingletonModule {
459 return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "", "libclang_rt.hwasan")
460}
461
Colin Cross78212242021-01-06 14:51:30 -0800462// vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries
463// generated by Soong but can be referenced by other modules.
464// For example, apex_vndk can depend on these files as prebuilt.
465func vndkSPLibrariesTxtFactory() android.SingletonModule {
466 return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES")
467}
468
469// vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries
470// generated by Soong but can be referenced by other modules.
471// For example, apex_vndk can depend on these files as prebuilt.
472func vndkCoreLibrariesTxtFactory() android.SingletonModule {
473 return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES")
474}
475
476// vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries
477// generated by Soong but can be referenced by other modules.
478// For example, apex_vndk can depend on these files as prebuilt.
479func vndkPrivateLibrariesTxtFactory() android.SingletonModule {
480 return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES")
481}
482
483// vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product libraries
484// generated by Soong but can be referenced by other modules.
485// For example, apex_vndk can depend on these files as prebuilt.
486func vndkProductLibrariesTxtFactory() android.SingletonModule {
487 return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES")
488}
489
490// vndkcorevariant_libraries_txt is a singleton module whose content is a list of VNDK libraries
491// that are using the core variant, generated by Soong but can be referenced by other modules.
492// For example, apex_vndk can depend on these files as prebuilt.
493func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule {
494 return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES")
495}
496
Justin Yun611e8862021-05-24 18:17:33 +0900497func newVndkLibrariesWithMakeVarFilter(lister moduleListerFunc, makeVarName string, filter string) android.SingletonModule {
Colin Cross78212242021-01-06 14:51:30 -0800498 m := &vndkLibrariesTxt{
Justin Yun611e8862021-05-24 18:17:33 +0900499 lister: lister,
500 makeVarName: makeVarName,
501 filterOutFromMakeVar: filter,
Colin Crosse4e44bc2020-12-28 13:50:21 -0800502 }
Colin Cross78212242021-01-06 14:51:30 -0800503 m.AddProperties(&m.properties)
Colin Cross45bce852021-11-11 22:47:54 -0800504 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
Colin Cross78212242021-01-06 14:51:30 -0800505 return m
Jooyung Han2216fb12019-11-06 16:46:15 +0900506}
507
Justin Yun611e8862021-05-24 18:17:33 +0900508func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule {
509 return newVndkLibrariesWithMakeVarFilter(lister, makeVarName, "")
510}
511
Jooyung Han2216fb12019-11-06 16:46:15 +0900512func insertVndkVersion(filename string, vndkVersion string) string {
513 if index := strings.LastIndex(filename, "."); index != -1 {
514 return filename[:index] + "." + vndkVersion + filename[index:]
515 }
516 return filename
517}
518
Colin Crosse4e44bc2020-12-28 13:50:21 -0800519func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Justin Yund5784122023-10-25 13:25:32 +0900520 filename := proptools.StringDefault(txt.properties.Stem, txt.Name())
Kiyoung Kima2d6dee2023-08-11 10:14:43 +0900521
Jooyung Han2216fb12019-11-06 16:46:15 +0900522 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Jooyung Han2216fb12019-11-06 16:46:15 +0900523
524 installPath := android.PathForModuleInstall(ctx, "etc")
525 ctx.InstallFile(installPath, filename, txt.outputFile)
526}
527
Colin Cross78212242021-01-06 14:51:30 -0800528func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) {
529 txt.moduleNames, txt.fileNames = txt.lister(ctx)
530 android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n"))
531}
532
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900533func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
534 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900535 Class: "ETC",
536 OutputFile: android.OptionalPathForPath(txt.outputFile),
537 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700538 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900539 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
540 },
541 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900542 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900543}
544
Colin Cross78212242021-01-06 14:51:30 -0800545func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) {
Justin Yund5784122023-10-25 13:25:32 +0900546 if txt.makeVarName == "" {
547 return
548 }
549
Justin Yun611e8862021-05-24 18:17:33 +0900550 filter := func(modules []string, prefix string) []string {
551 if prefix == "" {
552 return modules
553 }
554 var result []string
555 for _, module := range modules {
556 if strings.HasPrefix(module, prefix) {
557 continue
558 } else {
559 result = append(result, module)
560 }
561 }
562 return result
563 }
564 ctx.Strict(txt.makeVarName, strings.Join(filter(txt.moduleNames, txt.filterOutFromMakeVar), " "))
Colin Cross78212242021-01-06 14:51:30 -0800565}
566
Jooyung Han0703fd82020-08-26 22:11:53 +0900567// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900568func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
569 return txt.outputFile
570}
571
Jooyung Han0703fd82020-08-26 22:11:53 +0900572// PrebuiltEtcModule interface
573func (txt *vndkLibrariesTxt) BaseDir() string {
574 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900575}
576
Jooyung Han0703fd82020-08-26 22:11:53 +0900577// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900578func (txt *vndkLibrariesTxt) SubDir() string {
579 return ""
580}
581
Jooyung Han0703fd82020-08-26 22:11:53 +0900582func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
583 return android.Paths{txt.outputFile}, nil
584}
585
Inseob Kim1f086e22019-05-09 13:29:15 +0900586func VndkSnapshotSingleton() android.Singleton {
587 return &vndkSnapshotSingleton{}
588}
589
Jooyung Han0302a842019-10-30 18:43:49 +0900590type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900591 vndkLibrariesFile android.OutputPath
592 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900593}
Inseob Kim1f086e22019-05-09 13:29:15 +0900594
Ivan Lozanod7586b62021-04-01 09:49:36 -0400595func isVndkSnapshotAware(config android.DeviceConfig, m LinkableInterface,
596 apexInfo android.ApexInfo) (vndkType string, isVndkSnapshotLib bool) {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400597 return "", false
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900598}
599
Inseob Kim1f086e22019-05-09 13:29:15 +0900600func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900601 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
602 c.buildVndkLibrariesTxtFiles(ctx)
603
Inseob Kim1f086e22019-05-09 13:29:15 +0900604 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
605 if ctx.DeviceConfig().VndkVersion() != "current" {
606 return
607 }
608
Inseob Kim242ef0c2019-10-22 20:15:20 +0900609 var snapshotOutputs android.Paths
610
611 /*
612 VNDK snapshot zipped artifacts directory structure:
613 {SNAPSHOT_ARCH}/
614 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
615 shared/
616 vndk-core/
617 (VNDK-core libraries, e.g. libbinder.so)
618 vndk-sp/
619 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900620 llndk-stub/
621 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900622 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
623 shared/
624 vndk-core/
625 (VNDK-core libraries, e.g. libbinder.so)
626 vndk-sp/
627 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900628 llndk-stub/
629 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900630 binder32/
631 (This directory is newly introduced in v28 (Android P) to hold
632 prebuilts built for 32-bit binder interface.)
633 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
634 ...
635 configs/
636 (various *.txt configuration files)
637 include/
638 (header files of same directory structure with source tree)
639 NOTICE_FILES/
640 (notice files of libraries, e.g. libcutils.so.txt)
641 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900642
643 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900644 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900645
Inseob Kim242ef0c2019-10-22 20:15:20 +0900646 configsDir := filepath.Join(snapshotArchDir, "configs")
Justin Yun1871f902023-04-07 20:13:19 +0900647 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
Inseob Kim242ef0c2019-10-22 20:15:20 +0900648 includeDir := filepath.Join(snapshotArchDir, "include")
649
Justin Yun1871f902023-04-07 20:13:19 +0900650 // set of notice files copied.
651 noticeBuilt := make(map[string]bool)
652
Inseob Kim242ef0c2019-10-22 20:15:20 +0900653 // paths of VNDK modules for GPL license checking
654 modulePaths := make(map[string]string)
655
656 // actual module names of .so files
657 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
658 moduleNames := make(map[string]string)
659
Inseob Kim8471cda2019-11-15 09:59:12 +0900660 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900661
Inseob Kimde5744a2020-12-02 13:14:28 +0900662 // installVndkSnapshotLib copies built .so file from the module.
663 // Also, if the build artifacts is on, write a json file which contains all exported flags
664 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700665 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900666 var ret android.Paths
667
Inseob Kim8471cda2019-11-15 09:59:12 +0900668 targetArch := "arch-" + m.Target().Arch.ArchType.String()
669 if m.Target().Arch.ArchVariant != "" {
670 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900671 }
Inseob Kimae553032019-05-14 18:52:49 +0900672
Inseob Kim8471cda2019-11-15 09:59:12 +0900673 libPath := m.outputFile.Path()
674 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Kiyoung Kimae11c232021-07-19 11:38:04 +0900675 ret = append(ret, snapshot.CopyFileRule(pctx, ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900676
Justin Yun1871f902023-04-07 20:13:19 +0900677 // json struct to export snapshot information
678 prop := struct {
Inseob Kim5860f822023-04-18 11:30:22 +0900679 MinSdkVersion string `json:",omitempty"`
Justin Yun1871f902023-04-07 20:13:19 +0900680 LicenseKinds []string `json:",omitempty"`
681 LicenseTexts []string `json:",omitempty"`
682 ExportedDirs []string `json:",omitempty"`
683 ExportedSystemDirs []string `json:",omitempty"`
684 ExportedFlags []string `json:",omitempty"`
685 RelativeInstallPath string `json:",omitempty"`
686 }{}
687
688 prop.LicenseKinds = m.EffectiveLicenseKinds()
689 prop.LicenseTexts = m.EffectiveLicenseFiles().Strings()
Inseob Kim5860f822023-04-18 11:30:22 +0900690 prop.MinSdkVersion = m.MinSdkVersion()
Justin Yun1871f902023-04-07 20:13:19 +0900691
Inseob Kimae553032019-05-14 18:52:49 +0900692 if ctx.Config().VndkSnapshotBuildArtifacts() {
Colin Cross5a377182023-12-14 14:46:23 -0800693 exportedInfo, _ := android.SingletonModuleProvider(ctx, m, FlagExporterInfoProvider)
Colin Cross0de8a1e2020-09-18 14:15:30 -0700694 prop.ExportedFlags = exportedInfo.Flags
695 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
696 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900697 prop.RelativeInstallPath = m.RelativeInstallPath()
Inseob Kimae553032019-05-14 18:52:49 +0900698 }
Justin Yun1871f902023-04-07 20:13:19 +0900699
700 propOut := snapshotLibOut + ".json"
701
702 j, err := json.Marshal(prop)
703 if err != nil {
704 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
705 return nil, false
706 }
707 ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut))
708
Inseob Kim242ef0c2019-10-22 20:15:20 +0900709 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900710 }
711
Inseob Kim1f086e22019-05-09 13:29:15 +0900712 ctx.VisitAllModules(func(module android.Module) {
713 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900714 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900715 return
716 }
717
Colin Cross5a377182023-12-14 14:46:23 -0800718 apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider)
Colin Cross56a83212020-09-15 18:30:11 -0700719
Ivan Lozanod7586b62021-04-01 09:49:36 -0400720 vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900721 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200722 return
723 }
724
Inseob Kimde5744a2020-12-02 13:14:28 +0900725 // For all snapshot candidates, the followings are captured.
726 // - .so files
727 // - notice files
728 //
729 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
730 // - .json files containing exported flags
731 // - exported headers from collectHeadersForSnapshot()
732 //
733 // Headers are deduplicated after visiting all modules.
734
Inseob Kim8471cda2019-11-15 09:59:12 +0900735 // install .so files for appropriate modules.
736 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700737 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900738 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900739 return
740 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900741 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900742
Inseob Kim8471cda2019-11-15 09:59:12 +0900743 // These are for generating module_names.txt and module_paths.txt
744 stem := m.outputFile.Path().Base()
745 moduleNames[stem] = ctx.ModuleName(m)
746 modulePaths[stem] = ctx.ModuleDir(m)
747
Justin Yun1871f902023-04-07 20:13:19 +0900748 for _, notice := range m.EffectiveLicenseFiles() {
749 if _, ok := noticeBuilt[notice.String()]; !ok {
750 noticeBuilt[notice.String()] = true
751 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
752 pctx, ctx, notice, filepath.Join(noticeDir, notice.String())))
753 }
754 }
755
Inseob Kim8471cda2019-11-15 09:59:12 +0900756 if ctx.Config().VndkSnapshotBuildArtifacts() {
Ivan Lozanod7586b62021-04-01 09:49:36 -0400757 headers = append(headers, m.SnapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900758 }
759 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900760
Inseob Kim8471cda2019-11-15 09:59:12 +0900761 // install all headers after removing duplicates
762 for _, header := range android.FirstUniquePaths(headers) {
Kiyoung Kimae11c232021-07-19 11:38:04 +0900763 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
764 pctx, ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900765 }
766
Jooyung Han39edb6c2019-11-06 16:53:07 +0900767 // install *.libraries.txt except vndkcorevariant.libraries.txt
768 ctx.VisitAllModules(func(module android.Module) {
769 m, ok := module.(*vndkLibrariesTxt)
770 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
771 return
772 }
Kiyoung Kimae11c232021-07-19 11:38:04 +0900773 snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule(
774 pctx, ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900775 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900776
Inseob Kim242ef0c2019-10-22 20:15:20 +0900777 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900778 module_paths.txt contains paths on which VNDK modules are defined.
779 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000780 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900781 libc.so bionic/libc
782 ...
783 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900784 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900785
786 /*
787 module_names.txt contains names as which VNDK modules are defined,
788 because output filename and module name can be different with stem and suffix properties.
789
790 e.g.,
791 libcutils.so libcutils
792 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
793 ...
794 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900795 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900796
797 // All artifacts are ready. Sort them to normalize ninja and then zip.
798 sort.Slice(snapshotOutputs, func(i, j int) bool {
799 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
800 })
801
802 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800803 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900804
Inseob Kimde5744a2020-12-02 13:14:28 +0900805 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900806 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
Colin Cross70c47412021-03-12 17:48:14 -0800807 rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp")
Inseob Kim242ef0c2019-10-22 20:15:20 +0900808 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900809 Text("tr").
810 FlagWithArg("-d ", "\\'").
Colin Cross70c47412021-03-12 17:48:14 -0800811 FlagWithRspFileInputList("< ", rspFile, snapshotOutputs).
Inseob Kim8471cda2019-11-15 09:59:12 +0900812 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900813
814 zipRule.Temporary(snapshotOutputList)
815
816 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800817 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900818 FlagWithOutput("-o ", zipPath).
819 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
820 FlagWithInput("-l ", snapshotOutputList)
821
Colin Crossf1a035e2020-11-16 17:32:30 -0800822 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900823 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900824 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900825}
Jooyung Han097087b2019-10-22 19:32:18 +0900826
Jooyung Han0302a842019-10-30 18:43:49 +0900827func getVndkFileName(m *Module) (string, error) {
828 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900829 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900830 }
831 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900832 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900833 }
834 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900835}
836
837func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900838 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900839 // Since each target have different set of libclang_rt.* files,
840 // keep the common set of files in vndk.libraries.txt
Colin Cross78212242021-01-06 14:51:30 -0800841 _, llndk := vndkModuleListRemover(llndkLibraries, "libclang_rt.")(ctx)
842 _, vndkcore := vndkModuleListRemover(vndkCoreLibraries, "libclang_rt.")(ctx)
843 _, vndksp := vndkSPLibraries(ctx)
844 _, vndkprivate := vndkPrivateLibraries(ctx)
845 _, vndkproduct := vndkModuleListRemover(vndkProductLibraries, "libclang_rt.")(ctx)
Jooyung Han0302a842019-10-30 18:43:49 +0900846 var merged []string
Colin Cross78212242021-01-06 14:51:30 -0800847 merged = append(merged, addPrefix(llndk, "LLNDK: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900848 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800849 merged = append(merged, addPrefix(vndkcore, "VNDK-core: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900850 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800851 merged = append(merged, addPrefix(vndkproduct, "VNDK-product: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900852 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800853 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900854}
Jooyung Han097087b2019-10-22 19:32:18 +0900855
Jooyung Han0302a842019-10-30 18:43:49 +0900856func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
857 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
858 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700859 movedToApexLlndkLibraries := make(map[string]bool)
860 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800861 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
862 // Skip bionic libs, they are handled in different manner
863 name := library.implementationModuleName(module.(*Module).BaseModuleName())
864 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
865 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700866 }
Jooyung Han0302a842019-10-30 18:43:49 +0900867 }
Colin Cross56a83212020-09-15 18:30:11 -0700868 })
869
870 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
Cole Faust18994c72023-02-28 16:02:16 -0800871 strings.Join(android.SortedKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900872
Jooyung Han0302a842019-10-30 18:43:49 +0900873 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900874 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900875}