blob: e224e667370a349c1da746d19efc24058f3e8352 [file] [log] [blame]
Justin Yun8effde42017-06-23 19:24:43 +09001// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Inseob Kimae553032019-05-14 18:52:49 +090018 "encoding/json"
Martin Stjernholm257eb0c2018-10-15 13:05:27 +010019 "errors"
Jooyung Han0302a842019-10-30 18:43:49 +090020 "fmt"
Inseob Kim1f086e22019-05-09 13:29:15 +090021 "path/filepath"
Inseob Kim242ef0c2019-10-22 20:15:20 +090022 "sort"
Jiyong Parkd5b18a52017-08-03 21:22:50 +090023 "strings"
Jiyong Parkd5b18a52017-08-03 21:22:50 +090024
Justin Yun8effde42017-06-23 19:24:43 +090025 "android/soong/android"
Vic Yangefd249e2018-11-12 20:19:56 -080026 "android/soong/cc/config"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070027 "android/soong/etc"
Colin Cross6e511a92020-07-27 21:26:48 -070028
29 "github.com/google/blueprint"
Justin Yun8effde42017-06-23 19:24:43 +090030)
31
Jooyung Han39edb6c2019-11-06 16:53:07 +090032const (
33 llndkLibrariesTxt = "llndk.libraries.txt"
34 vndkCoreLibrariesTxt = "vndkcore.libraries.txt"
35 vndkSpLibrariesTxt = "vndksp.libraries.txt"
36 vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt"
Justin Yun8a2600c2020-12-07 12:44:03 +090037 vndkProductLibrariesTxt = "vndkproduct.libraries.txt"
Jooyung Han39edb6c2019-11-06 16:53:07 +090038 vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt"
39)
40
41func VndkLibrariesTxtModules(vndkVersion string) []string {
42 if vndkVersion == "current" {
43 return []string{
44 llndkLibrariesTxt,
45 vndkCoreLibrariesTxt,
46 vndkSpLibrariesTxt,
47 vndkPrivateLibrariesTxt,
Justin Yun8a2600c2020-12-07 12:44:03 +090048 vndkProductLibrariesTxt,
Jooyung Han39edb6c2019-11-06 16:53:07 +090049 }
50 }
51 // Snapshot vndks have their own *.libraries.VER.txt files.
52 // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
53 return []string{
54 insertVndkVersion(llndkLibrariesTxt, vndkVersion),
55 insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
56 insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
57 insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
Justin Yun8a2600c2020-12-07 12:44:03 +090058 insertVndkVersion(vndkProductLibrariesTxt, vndkVersion),
Jooyung Han39edb6c2019-11-06 16:53:07 +090059 }
60}
61
Justin Yun8effde42017-06-23 19:24:43 +090062type VndkProperties struct {
63 Vndk struct {
64 // declared as a VNDK or VNDK-SP module. The vendor variant
65 // will be installed in /system instead of /vendor partition.
66 //
Justin Yun63e9ec72020-10-29 16:49:43 +090067 // `vendor_available` and `product_available` must be explicitly
68 // set to either true or false together with `vndk: {enabled: true}`.
Justin Yun8effde42017-06-23 19:24:43 +090069 Enabled *bool
70
71 // declared as a VNDK-SP module, which is a subset of VNDK.
72 //
73 // `vndk: { enabled: true }` must set together.
74 //
75 // All these modules are allowed to link to VNDK-SP or LL-NDK
76 // modules only. Other dependency will cause link-type errors.
77 //
78 // If `support_system_process` is not set or set to false,
79 // the module is VNDK-core and can link to other VNDK-core,
80 // VNDK-SP or LL-NDK modules only.
81 Support_system_process *bool
Logan Chienf3511742017-10-31 18:04:35 +080082
Justin Yunfd9e8042020-12-23 18:23:14 +090083 // declared as a VNDK-private module.
84 // This module still creates the vendor and product variants refering
85 // to the `vendor_available: true` and `product_available: true`
86 // properties. However, it is only available to the other VNDK modules
87 // but not to the non-VNDK vendor or product modules.
88 Private *bool
89
Logan Chienf3511742017-10-31 18:04:35 +080090 // Extending another module
91 Extends *string
Justin Yun8effde42017-06-23 19:24:43 +090092 }
93}
94
95type vndkdep struct {
96 Properties VndkProperties
97}
98
99func (vndk *vndkdep) props() []interface{} {
100 return []interface{}{&vndk.Properties}
101}
102
103func (vndk *vndkdep) begin(ctx BaseModuleContext) {}
104
105func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps {
106 return deps
107}
108
109func (vndk *vndkdep) isVndk() bool {
110 return Bool(vndk.Properties.Vndk.Enabled)
111}
112
113func (vndk *vndkdep) isVndkSp() bool {
114 return Bool(vndk.Properties.Vndk.Support_system_process)
115}
116
Logan Chienf3511742017-10-31 18:04:35 +0800117func (vndk *vndkdep) isVndkExt() bool {
118 return vndk.Properties.Vndk.Extends != nil
119}
120
121func (vndk *vndkdep) getVndkExtendsModuleName() string {
122 return String(vndk.Properties.Vndk.Extends)
123}
124
Justin Yun8effde42017-06-23 19:24:43 +0900125func (vndk *vndkdep) typeName() string {
126 if !vndk.isVndk() {
127 return "native:vendor"
128 }
Logan Chienf3511742017-10-31 18:04:35 +0800129 if !vndk.isVndkExt() {
130 if !vndk.isVndkSp() {
131 return "native:vendor:vndk"
132 }
133 return "native:vendor:vndksp"
Justin Yun8effde42017-06-23 19:24:43 +0900134 }
Logan Chienf3511742017-10-31 18:04:35 +0800135 if !vndk.isVndkSp() {
136 return "native:vendor:vndkext"
137 }
138 return "native:vendor:vndkspext"
Justin Yun8effde42017-06-23 19:24:43 +0900139}
140
Justin Yun63e9ec72020-10-29 16:49:43 +0900141// VNDK link type check from a module with UseVndk() == true.
Jooyung Han479ca172020-10-19 18:51:07 +0900142func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
Justin Yun8effde42017-06-23 19:24:43 +0900143 if to.linker == nil {
144 return
145 }
Jiyong Park82e2bf32017-08-16 14:05:54 +0900146 if !vndk.isVndk() {
Justin Yunfd9e8042020-12-23 18:23:14 +0900147 // Non-VNDK modules those installed to /vendor, /system/vendor,
148 // /product or /system/product cannot depend on VNDK-private modules
149 // that include VNDK-core-private, VNDK-SP-private and LLNDK-private.
150 if to.IsVndkPrivate() {
151 ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name())
Jiyong Park82e2bf32017-08-16 14:05:54 +0900152 }
153 }
Justin Yun8effde42017-06-23 19:24:43 +0900154 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
155 // Check only shared libraries.
Colin Cross127bb8b2020-12-16 16:46:01 -0800156 // Other (static) libraries are allowed to link.
Justin Yun8effde42017-06-23 19:24:43 +0900157 return
158 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800159
160 if to.IsLlndk() {
161 // LL-NDK libraries are allowed to link
162 return
163 }
164
Ivan Lozano52767be2019-10-18 14:49:46 -0700165 if !to.UseVndk() {
Justin Yun8effde42017-06-23 19:24:43 +0900166 ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
167 vndk.typeName(), to.Name())
168 return
169 }
Logan Chienf3511742017-10-31 18:04:35 +0800170 if tag == vndkExtDepTag {
171 // Ensure `extends: "name"` property refers a vndk module that has vendor_available
172 // and has identical vndk properties.
173 if to.vndkdep == nil || !to.vndkdep.isVndk() {
174 ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name())
175 return
176 }
177 if vndk.isVndkSp() != to.vndkdep.isVndkSp() {
178 ctx.ModuleErrorf(
179 "`extends` refers a module %q with mismatched support_system_process",
180 to.Name())
181 return
182 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900183 if to.IsVndkPrivate() {
Logan Chienf3511742017-10-31 18:04:35 +0800184 ctx.ModuleErrorf(
Justin Yunfd9e8042020-12-23 18:23:14 +0900185 "`extends` refers module %q which has `private: true`",
Justin Yun6977e8a2020-10-29 18:24:11 +0900186 to.Name())
187 return
188 }
Logan Chienf3511742017-10-31 18:04:35 +0800189 }
Justin Yun8effde42017-06-23 19:24:43 +0900190 if to.vndkdep == nil {
191 return
192 }
Logan Chienf3511742017-10-31 18:04:35 +0800193
Logan Chiend3c59a22018-03-29 14:08:15 +0800194 // Check the dependencies of VNDK shared libraries.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100195 if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil {
196 ctx.ModuleErrorf("(%s) should not link to %q (%s): %v",
197 vndk.typeName(), to.Name(), to.vndkdep.typeName(), err)
Logan Chienf3511742017-10-31 18:04:35 +0800198 return
199 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800200}
Logan Chienf3511742017-10-31 18:04:35 +0800201
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100202func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
Logan Chiend3c59a22018-03-29 14:08:15 +0800203 // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules.
204 if from.isVndkExt() {
205 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100206 if to.isVndk() && !to.isVndkSp() {
207 return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions")
208 }
209 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800210 }
211 // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100212 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900213 }
Logan Chiend3c59a22018-03-29 14:08:15 +0800214 if from.isVndk() {
215 if to.isVndkExt() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100216 return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions")
Logan Chiend3c59a22018-03-29 14:08:15 +0800217 }
218 if from.isVndkSp() {
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100219 if !to.isVndkSp() {
220 return errors.New("VNDK-SP must only depend on VNDK-SP")
221 }
222 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800223 }
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100224 if !to.isVndk() {
225 return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP")
226 }
227 return nil
Logan Chiend3c59a22018-03-29 14:08:15 +0800228 }
229 // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs.
Martin Stjernholm257eb0c2018-10-15 13:05:27 +0100230 return nil
Justin Yun8effde42017-06-23 19:24:43 +0900231}
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900232
Colin Cross78212242021-01-06 14:51:30 -0800233type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string)
234
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900235var (
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800236 llndkLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsLLNDK && !isVestigialLLNDKModule(m) && !m.Header() })
Colin Cross78212242021-01-06 14:51:30 -0800237 llndkLibrariesWithoutHWASAN = vndkModuleListRemover(llndkLibraries, "libclang_rt.hwasan-")
238 vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP })
239 vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore })
240 vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate && !isVestigialLLNDKModule(m) })
241 vndkProductLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKProduct })
242 vndkUsingCoreVariantLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKUsingCoreVariant })
Inseob Kimae553032019-05-14 18:52:49 +0900243)
Inseob Kim1f086e22019-05-09 13:29:15 +0900244
Colin Cross78212242021-01-06 14:51:30 -0800245// vndkModuleLister takes a predicate that operates on a Module and returns a moduleListerFunc
246// that produces a list of module names and output file names for which the predicate returns true.
247func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc {
248 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
249 ctx.VisitAllModules(func(m android.Module) {
250 if c, ok := m.(*Module); ok && predicate(c) {
251 filename, err := getVndkFileName(c)
252 if err != nil {
253 ctx.ModuleErrorf(m, "%s", err)
254 }
255 moduleNames = append(moduleNames, ctx.ModuleName(m))
256 fileNames = append(fileNames, filename)
257 }
258 })
259 moduleNames = android.SortedUniqueStrings(moduleNames)
260 fileNames = android.SortedUniqueStrings(fileNames)
261 return
262 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900263}
264
Colin Cross78212242021-01-06 14:51:30 -0800265// vndkModuleListRemover takes a moduleListerFunc and a prefix and returns a moduleListerFunc
266// that returns the same lists as the input moduleListerFunc, but with modules with the
267// given prefix removed.
268func vndkModuleListRemover(lister moduleListerFunc, prefix string) moduleListerFunc {
269 return func(ctx android.SingletonContext) (moduleNames, fileNames []string) {
270 moduleNames, fileNames = lister(ctx)
271 filter := func(in []string) []string {
272 out := make([]string, 0, len(in))
273 for _, lib := range in {
274 if strings.HasPrefix(lib, prefix) {
275 continue
276 }
277 out = append(out, lib)
278 }
279 return out
280 }
281 return filter(moduleNames), filter(fileNames)
282 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900283}
284
Colin Cross78212242021-01-06 14:51:30 -0800285var vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey")
Inseob Kim9516ee92019-05-09 10:56:13 +0900286
Jooyung Han097087b2019-10-22 19:32:18 +0900287func vndkMustUseVendorVariantList(cfg android.Config) []string {
288 return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900289 return config.VndkMustUseVendorVariantList
290 }).([]string)
291}
292
293// test may call this to override global configuration(config.VndkMustUseVendorVariantList)
294// when it is called, it must be before the first call to vndkMustUseVendorVariantList()
295func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) {
Jooyung Hana463f722019-11-01 08:45:59 +0900296 config.Once(vndkMustUseVendorVariantListKey, func() interface{} {
Jooyung Han097087b2019-10-22 19:32:18 +0900297 return mustUseVendorVariantList
298 })
299}
300
Inseob Kim1f086e22019-05-09 13:29:15 +0900301func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
302 lib := m.linker.(*llndkStubDecorator)
Inseob Kim9516ee92019-05-09 10:56:13 +0900303
Colin Cross127bb8b2020-12-16 16:46:01 -0800304 m.VendorProperties.IsLLNDK = true
Justin Yunc0d8c492021-01-07 17:45:31 +0900305 if Bool(lib.Properties.Private) {
Colin Cross78212242021-01-06 14:51:30 -0800306 m.VendorProperties.IsVNDKPrivate = true
Jooyung Han61b66e92020-03-21 14:21:46 +0000307 }
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900308}
Inseob Kim1f086e22019-05-09 13:29:15 +0900309
310func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
Justin Yun8a2600c2020-12-07 12:44:03 +0900311 if m.InProduct() {
312 // We may skip the steps for the product variants because they
313 // are already covered by the vendor variants.
314 return
315 }
316
Jooyung Han0302a842019-10-30 18:43:49 +0900317 name := m.BaseModuleName()
Inseob Kim1f086e22019-05-09 13:29:15 +0900318
Colin Cross31076b32020-10-23 17:22:06 -0700319 if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
Jiyong Park2478e4e2020-05-18 09:30:14 +0000320 // b/155456180 libz is the ONLY exception here. We don't want to make
321 // libz an LLNDK library because we in general can't guarantee that
322 // libz will behave consistently especially about the compression.
323 // i.e. the compressed output might be different across releases.
324 // As the library is an external one, it's risky to keep the compatibility
325 // promise if it becomes an LLNDK.
Jiyong Parkea97f512020-03-31 15:31:17 +0900326 mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK")
327 }
328
Jooyung Han097087b2019-10-22 19:32:18 +0900329 if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
330 m.Properties.MustUseVendorVariant = true
331 }
Jooyung Han0302a842019-10-30 18:43:49 +0900332 if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant {
Colin Cross78212242021-01-06 14:51:30 -0800333 m.VendorProperties.IsVNDKUsingCoreVariant = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900334 }
Jooyung Han0302a842019-10-30 18:43:49 +0900335
Inseob Kim1f086e22019-05-09 13:29:15 +0900336 if m.vndkdep.isVndkSp() {
Colin Cross78212242021-01-06 14:51:30 -0800337 m.VendorProperties.IsVNDKSP = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900338 } else {
Colin Cross78212242021-01-06 14:51:30 -0800339 m.VendorProperties.IsVNDKCore = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900340 }
Justin Yunfd9e8042020-12-23 18:23:14 +0900341 if m.IsVndkPrivate() {
Colin Cross78212242021-01-06 14:51:30 -0800342 m.VendorProperties.IsVNDKPrivate = true
Inseob Kim1f086e22019-05-09 13:29:15 +0900343 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900344 if Bool(m.VendorProperties.Product_available) {
Colin Cross78212242021-01-06 14:51:30 -0800345 m.VendorProperties.IsVNDKProduct = true
Justin Yun8a2600c2020-12-07 12:44:03 +0900346 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900347}
348
Yo Chiang08fac0c2020-07-29 01:08:20 +0800349// Check for modules that mustn't be VNDK
Yo Chiangbba545e2020-06-09 16:15:37 +0800350func shouldSkipVndkMutator(m *Module) bool {
Jooyung Han31c470b2019-10-18 16:26:59 +0900351 if !m.Enabled() {
Yo Chiangbba545e2020-06-09 16:15:37 +0800352 return true
Jooyung Han31c470b2019-10-18 16:26:59 +0900353 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800354 if !m.Device() {
355 // Skip non-device modules
356 return true
Jooyung Han87a7f302019-10-29 05:18:21 +0900357 }
Jooyung Han31c470b2019-10-18 16:26:59 +0900358 if m.Target().NativeBridge == android.NativeBridgeEnabled {
Yo Chiangbba545e2020-06-09 16:15:37 +0800359 // Skip native_bridge modules
360 return true
361 }
362 return false
363}
364
365func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
366 if shouldSkipVndkMutator(m) {
Jooyung Han31c470b2019-10-18 16:26:59 +0900367 return false
368 }
369
370 // prebuilt vndk modules should match with device
371 // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared
372 // When b/142675459 is landed, remove following check
373 if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) {
374 return false
375 }
376
377 if lib, ok := m.linker.(libraryInterface); ok {
Jooyung Han73d20d02020-03-27 16:06:55 +0900378 // VNDK APEX for VNDK-Lite devices will have VNDK-SP libraries from core variants
379 if mctx.DeviceConfig().VndkVersion() == "" {
380 // b/73296261: filter out libz.so because it is considered as LLNDK for VNDK-lite devices
381 if mctx.ModuleName() == "libz" {
382 return false
383 }
384 return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.isVndkSp()
385 }
386
Justin Yun5f7f7e82019-11-18 19:52:14 +0900387 useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
Jooyung Han87a7f302019-10-29 05:18:21 +0900388 mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500389 return lib.shared() && m.InVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant
Jooyung Han31c470b2019-10-18 16:26:59 +0900390 }
391 return false
392}
393
Inseob Kim1f086e22019-05-09 13:29:15 +0900394// gather list of vndk-core, vndk-sp, and ll-ndk libs
395func VndkMutator(mctx android.BottomUpMutatorContext) {
396 m, ok := mctx.Module().(*Module)
397 if !ok {
398 return
399 }
Yo Chiangbba545e2020-06-09 16:15:37 +0800400
401 if shouldSkipVndkMutator(m) {
Justin Yun7390ea32019-09-08 11:34:06 +0900402 return
403 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900404
405 if _, ok := m.linker.(*llndkStubDecorator); ok {
406 processLlndkLibrary(mctx, m)
407 return
408 }
409
Colin Cross127bb8b2020-12-16 16:46:01 -0800410 // This is a temporary measure to copy the properties from an llndk_library into the cc_library
411 // that will actually build the stubs. It will be removed once the properties are moved into
412 // the cc_library in the Android.bp files.
413 mergeLLNDKToLib := func(llndk *Module, llndkProperties *llndkLibraryProperties, flagExporter *flagExporter) {
414 if llndkLib := moduleLibraryInterface(llndk); llndkLib != nil {
415 *llndkProperties = llndkLib.(*llndkStubDecorator).Properties
416 flagExporter.Properties = llndkLib.(*llndkStubDecorator).flagExporter.Properties
417
418 m.VendorProperties.IsLLNDK = llndk.VendorProperties.IsLLNDK
Colin Cross78212242021-01-06 14:51:30 -0800419 m.VendorProperties.IsVNDKPrivate = llndk.VendorProperties.IsVNDKPrivate
Colin Cross127bb8b2020-12-16 16:46:01 -0800420 }
421 }
422
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800423 lib, isLib := m.linker.(*libraryDecorator)
424 prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker)
Inseob Kim1f086e22019-05-09 13:29:15 +0900425
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800426 if m.UseVndk() && isLib && lib.hasVestigialLLNDKLibrary() {
Colin Cross127bb8b2020-12-16 16:46:01 -0800427 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(lib.Properties.Llndk_stubs))
428 mergeLLNDKToLib(llndk[0].(*Module), &lib.Properties.Llndk, &lib.flagExporter)
429 }
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800430 if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasVestigialLLNDKLibrary() {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800431 llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(prebuiltLib.Properties.Llndk_stubs))
432 mergeLLNDKToLib(llndk[0].(*Module), &prebuiltLib.Properties.Llndk, &prebuiltLib.flagExporter)
Colin Cross127bb8b2020-12-16 16:46:01 -0800433 }
434
Colin Cross0fb7fcd2021-03-02 11:00:07 -0800435 if m.UseVndk() && isLib && lib.hasLLNDKStubs() && !lib.hasVestigialLLNDKLibrary() {
436 m.VendorProperties.IsLLNDK = true
437 m.VendorProperties.IsVNDKPrivate = Bool(lib.Properties.Llndk.Private)
438 }
439 if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() && !prebuiltLib.hasVestigialLLNDKLibrary() {
440 m.VendorProperties.IsLLNDK = true
441 m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private)
442 }
443
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800444 if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) {
Inseob Kim64c43952019-08-26 16:52:35 +0900445 if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900446 processVndkLibrary(mctx, m)
447 return
448 }
449 }
450}
451
452func init() {
Colin Crosse4e44bc2020-12-28 13:50:21 -0800453 RegisterVndkLibraryTxtTypes(android.InitRegistrationContext)
Inseob Kim1f086e22019-05-09 13:29:15 +0900454 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
Inseob Kim1f086e22019-05-09 13:29:15 +0900455}
456
Colin Crosse4e44bc2020-12-28 13:50:21 -0800457func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) {
Colin Cross78212242021-01-06 14:51:30 -0800458 // Make uses LLNDK_LIBRARIES to determine which libraries to install.
459 // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
460 // Therefore, by removing the library here, we cause it to only be installed if libc
461 // depends on it.
462 ctx.RegisterSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory)
463 ctx.RegisterSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory)
464 ctx.RegisterSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory)
465 ctx.RegisterSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory)
466 ctx.RegisterSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory)
467 ctx.RegisterSingletonModuleType("vndkcorevariant_libraries_txt", vndkUsingCoreVariantLibrariesTxtFactory)
Colin Crosse4e44bc2020-12-28 13:50:21 -0800468}
469
Jooyung Han2216fb12019-11-06 16:46:15 +0900470type vndkLibrariesTxt struct {
Colin Cross78212242021-01-06 14:51:30 -0800471 android.SingletonModuleBase
Colin Crosse4e44bc2020-12-28 13:50:21 -0800472
Colin Cross78212242021-01-06 14:51:30 -0800473 lister moduleListerFunc
474 makeVarName string
475
Colin Crosse4e44bc2020-12-28 13:50:21 -0800476 properties VndkLibrariesTxtProperties
477
Colin Cross78212242021-01-06 14:51:30 -0800478 outputFile android.OutputPath
479 moduleNames []string
480 fileNames []string
Jooyung Han2216fb12019-11-06 16:46:15 +0900481}
482
Colin Crosse4e44bc2020-12-28 13:50:21 -0800483type VndkLibrariesTxtProperties struct {
484 Insert_vndk_version *bool
485}
486
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700487var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{}
Jooyung Han39edb6c2019-11-06 16:53:07 +0900488var _ android.OutputFileProducer = &vndkLibrariesTxt{}
489
Colin Cross78212242021-01-06 14:51:30 -0800490// llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries
491// generated by Soong but can be referenced by other modules.
Jooyung Han2216fb12019-11-06 16:46:15 +0900492// For example, apex_vndk can depend on these files as prebuilt.
Colin Cross78212242021-01-06 14:51:30 -0800493func llndkLibrariesTxtFactory() android.SingletonModule {
494 return newVndkLibrariesTxt(llndkLibrariesWithoutHWASAN, "LLNDK_LIBRARIES")
495}
496
497// vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries
498// generated by Soong but can be referenced by other modules.
499// For example, apex_vndk can depend on these files as prebuilt.
500func vndkSPLibrariesTxtFactory() android.SingletonModule {
501 return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES")
502}
503
504// vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries
505// generated by Soong but can be referenced by other modules.
506// For example, apex_vndk can depend on these files as prebuilt.
507func vndkCoreLibrariesTxtFactory() android.SingletonModule {
508 return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES")
509}
510
511// vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries
512// generated by Soong but can be referenced by other modules.
513// For example, apex_vndk can depend on these files as prebuilt.
514func vndkPrivateLibrariesTxtFactory() android.SingletonModule {
515 return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES")
516}
517
518// vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product libraries
519// generated by Soong but can be referenced by other modules.
520// For example, apex_vndk can depend on these files as prebuilt.
521func vndkProductLibrariesTxtFactory() android.SingletonModule {
522 return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES")
523}
524
525// vndkcorevariant_libraries_txt is a singleton module whose content is a list of VNDK libraries
526// that are using the core variant, generated by Soong but can be referenced by other modules.
527// For example, apex_vndk can depend on these files as prebuilt.
528func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule {
529 return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES")
530}
531
532func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule {
533 m := &vndkLibrariesTxt{
534 lister: lister,
535 makeVarName: makeVarName,
Colin Crosse4e44bc2020-12-28 13:50:21 -0800536 }
Colin Cross78212242021-01-06 14:51:30 -0800537 m.AddProperties(&m.properties)
538 android.InitAndroidModule(m)
539 return m
Jooyung Han2216fb12019-11-06 16:46:15 +0900540}
541
542func insertVndkVersion(filename string, vndkVersion string) string {
543 if index := strings.LastIndex(filename, "."); index != -1 {
544 return filename[:index] + "." + vndkVersion + filename[index:]
545 }
546 return filename
547}
548
Colin Crosse4e44bc2020-12-28 13:50:21 -0800549func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900550 var filename string
Colin Crosse4e44bc2020-12-28 13:50:21 -0800551 if BoolDefault(txt.properties.Insert_vndk_version, true) {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900552 filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
553 } else {
554 filename = txt.Name()
555 }
556
Jooyung Han2216fb12019-11-06 16:46:15 +0900557 txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
Jooyung Han2216fb12019-11-06 16:46:15 +0900558
559 installPath := android.PathForModuleInstall(ctx, "etc")
560 ctx.InstallFile(installPath, filename, txt.outputFile)
561}
562
Colin Cross78212242021-01-06 14:51:30 -0800563func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) {
564 txt.moduleNames, txt.fileNames = txt.lister(ctx)
565 android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n"))
566}
567
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900568func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries {
569 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han2216fb12019-11-06 16:46:15 +0900570 Class: "ETC",
571 OutputFile: android.OptionalPathForPath(txt.outputFile),
572 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700573 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900574 entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
575 },
576 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900577 }}
Jooyung Han2216fb12019-11-06 16:46:15 +0900578}
579
Colin Cross78212242021-01-06 14:51:30 -0800580func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) {
581 ctx.Strict(txt.makeVarName, strings.Join(txt.moduleNames, " "))
582
583}
584
Jooyung Han0703fd82020-08-26 22:11:53 +0900585// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900586func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
587 return txt.outputFile
588}
589
Jooyung Han0703fd82020-08-26 22:11:53 +0900590// PrebuiltEtcModule interface
591func (txt *vndkLibrariesTxt) BaseDir() string {
592 return "etc"
Jooyung Han39edb6c2019-11-06 16:53:07 +0900593}
594
Jooyung Han0703fd82020-08-26 22:11:53 +0900595// PrebuiltEtcModule interface
Jooyung Han39edb6c2019-11-06 16:53:07 +0900596func (txt *vndkLibrariesTxt) SubDir() string {
597 return ""
598}
599
Jooyung Han0703fd82020-08-26 22:11:53 +0900600func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
601 return android.Paths{txt.outputFile}, nil
602}
603
Inseob Kim1f086e22019-05-09 13:29:15 +0900604func VndkSnapshotSingleton() android.Singleton {
605 return &vndkSnapshotSingleton{}
606}
607
Jooyung Han0302a842019-10-30 18:43:49 +0900608type vndkSnapshotSingleton struct {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900609 vndkLibrariesFile android.OutputPath
610 vndkSnapshotZipFile android.OptionalPath
Jooyung Han0302a842019-10-30 18:43:49 +0900611}
Inseob Kim1f086e22019-05-09 13:29:15 +0900612
Inseob Kimde5744a2020-12-02 13:14:28 +0900613func isVndkSnapshotAware(config android.DeviceConfig, m *Module,
Colin Cross56a83212020-09-15 18:30:11 -0700614 apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) {
615
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900616 if m.Target().NativeBridge == android.NativeBridgeEnabled {
617 return nil, "", false
618 }
Jooyung Han261e1582020-10-20 18:54:21 +0900619 // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants.
620 // !installable: Snapshot only cares about "installable" modules.
Justin Yun450ae722021-04-16 19:58:18 +0900621 // !m.IsLlndk: llndk stubs are required for building against snapshots.
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400622 // IsSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense.
Justin Yun450ae722021-04-16 19:58:18 +0900623 // !outputFile.Valid: Snapshot requires valid output file.
624 if !m.InVendor() || (!m.installable(apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.outputFile.Valid() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900625 return nil, "", false
626 }
627 l, ok := m.linker.(snapshotLibraryInterface)
628 if !ok || !l.shared() {
629 return nil, "", false
630 }
Justin Yun450ae722021-04-16 19:58:18 +0900631 if m.VndkVersion() == config.PlatformVndkVersion() {
632 if m.IsVndk() && !m.IsVndkExt() {
633 if m.isVndkSp() {
634 return l, "vndk-sp", true
635 } else {
636 return l, "vndk-core", true
637 }
638 } else if l.hasLLNDKStubs() && l.stubsVersion() == "" {
639 // Use default version for the snapshot.
640 return l, "llndk-stub", true
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900641 }
642 }
643
644 return nil, "", false
645}
646
Inseob Kim1f086e22019-05-09 13:29:15 +0900647func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Jooyung Han0302a842019-10-30 18:43:49 +0900648 // build these files even if PlatformVndkVersion or BoardVndkVersion is not set
649 c.buildVndkLibrariesTxtFiles(ctx)
650
Inseob Kim1f086e22019-05-09 13:29:15 +0900651 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
652 if ctx.DeviceConfig().VndkVersion() != "current" {
653 return
654 }
655
656 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
657 return
658 }
659
Inseob Kim242ef0c2019-10-22 20:15:20 +0900660 var snapshotOutputs android.Paths
661
662 /*
663 VNDK snapshot zipped artifacts directory structure:
664 {SNAPSHOT_ARCH}/
665 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
666 shared/
667 vndk-core/
668 (VNDK-core libraries, e.g. libbinder.so)
669 vndk-sp/
670 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900671 llndk-stub/
672 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900673 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
674 shared/
675 vndk-core/
676 (VNDK-core libraries, e.g. libbinder.so)
677 vndk-sp/
678 (VNDK-SP libraries, e.g. libc++.so)
Justin Yun450ae722021-04-16 19:58:18 +0900679 llndk-stub/
680 (LLNDK stub libraries)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900681 binder32/
682 (This directory is newly introduced in v28 (Android P) to hold
683 prebuilts built for 32-bit binder interface.)
684 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
685 ...
686 configs/
687 (various *.txt configuration files)
688 include/
689 (header files of same directory structure with source tree)
690 NOTICE_FILES/
691 (notice files of libraries, e.g. libcutils.so.txt)
692 */
Inseob Kim1f086e22019-05-09 13:29:15 +0900693
694 snapshotDir := "vndk-snapshot"
Inseob Kim242ef0c2019-10-22 20:15:20 +0900695 snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
Inseob Kim1f086e22019-05-09 13:29:15 +0900696
Inseob Kim242ef0c2019-10-22 20:15:20 +0900697 configsDir := filepath.Join(snapshotArchDir, "configs")
698 noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES")
699 includeDir := filepath.Join(snapshotArchDir, "include")
700
Inseob Kim242ef0c2019-10-22 20:15:20 +0900701 // set of notice files copied.
Inseob Kim1f086e22019-05-09 13:29:15 +0900702 noticeBuilt := make(map[string]bool)
703
Inseob Kim242ef0c2019-10-22 20:15:20 +0900704 // paths of VNDK modules for GPL license checking
705 modulePaths := make(map[string]string)
706
707 // actual module names of .so files
708 // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full"
709 moduleNames := make(map[string]string)
710
Inseob Kim8471cda2019-11-15 09:59:12 +0900711 var headers android.Paths
Inseob Kim242ef0c2019-10-22 20:15:20 +0900712
Inseob Kimde5744a2020-12-02 13:14:28 +0900713 // installVndkSnapshotLib copies built .so file from the module.
714 // Also, if the build artifacts is on, write a json file which contains all exported flags
715 // with FlagExporterInfo.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700716 installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) {
Inseob Kim242ef0c2019-10-22 20:15:20 +0900717 var ret android.Paths
718
Inseob Kim8471cda2019-11-15 09:59:12 +0900719 targetArch := "arch-" + m.Target().Arch.ArchType.String()
720 if m.Target().Arch.ArchVariant != "" {
721 targetArch += "-" + m.Target().Arch.ArchVariant
Inseob Kim242ef0c2019-10-22 20:15:20 +0900722 }
Inseob Kimae553032019-05-14 18:52:49 +0900723
Inseob Kim8471cda2019-11-15 09:59:12 +0900724 libPath := m.outputFile.Path()
725 snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base())
Inseob Kimde5744a2020-12-02 13:14:28 +0900726 ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut))
Inseob Kim8471cda2019-11-15 09:59:12 +0900727
Inseob Kimae553032019-05-14 18:52:49 +0900728 if ctx.Config().VndkSnapshotBuildArtifacts() {
729 prop := struct {
730 ExportedDirs []string `json:",omitempty"`
731 ExportedSystemDirs []string `json:",omitempty"`
732 ExportedFlags []string `json:",omitempty"`
733 RelativeInstallPath string `json:",omitempty"`
734 }{}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700735 exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
736 prop.ExportedFlags = exportedInfo.Flags
737 prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
738 prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
Inseob Kimae553032019-05-14 18:52:49 +0900739 prop.RelativeInstallPath = m.RelativeInstallPath()
740
Inseob Kim242ef0c2019-10-22 20:15:20 +0900741 propOut := snapshotLibOut + ".json"
Inseob Kimae553032019-05-14 18:52:49 +0900742
743 j, err := json.Marshal(prop)
744 if err != nil {
745 ctx.Errorf("json marshal to %q failed: %#v", propOut, err)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900746 return nil, false
Inseob Kimae553032019-05-14 18:52:49 +0900747 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900748 ret = append(ret, writeStringToFileRule(ctx, string(j), propOut))
Inseob Kimae553032019-05-14 18:52:49 +0900749 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900750 return ret, true
Inseob Kimae553032019-05-14 18:52:49 +0900751 }
752
Inseob Kim1f086e22019-05-09 13:29:15 +0900753 ctx.VisitAllModules(func(module android.Module) {
754 m, ok := module.(*Module)
Inseob Kimae553032019-05-14 18:52:49 +0900755 if !ok || !m.Enabled() {
Inseob Kim1f086e22019-05-09 13:29:15 +0900756 return
757 }
758
Colin Cross56a83212020-09-15 18:30:11 -0700759 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
760
Inseob Kimde5744a2020-12-02 13:14:28 +0900761 l, vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
Inseob Kimae553032019-05-14 18:52:49 +0900762 if !ok {
dimitry51ea18a2019-05-20 10:39:52 +0200763 return
764 }
765
Inseob Kimde5744a2020-12-02 13:14:28 +0900766 // For all snapshot candidates, the followings are captured.
767 // - .so files
768 // - notice files
769 //
770 // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS.
771 // - .json files containing exported flags
772 // - exported headers from collectHeadersForSnapshot()
773 //
774 // Headers are deduplicated after visiting all modules.
775
Inseob Kim8471cda2019-11-15 09:59:12 +0900776 // install .so files for appropriate modules.
777 // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700778 libs, ok := installVndkSnapshotLib(m, vndkType)
Inseob Kimae553032019-05-14 18:52:49 +0900779 if !ok {
Inseob Kim1f086e22019-05-09 13:29:15 +0900780 return
781 }
Inseob Kim242ef0c2019-10-22 20:15:20 +0900782 snapshotOutputs = append(snapshotOutputs, libs...)
Inseob Kim1f086e22019-05-09 13:29:15 +0900783
Inseob Kim8471cda2019-11-15 09:59:12 +0900784 // These are for generating module_names.txt and module_paths.txt
785 stem := m.outputFile.Path().Base()
786 moduleNames[stem] = ctx.ModuleName(m)
787 modulePaths[stem] = ctx.ModuleDir(m)
788
Bob Badoura75b0572020-02-18 20:21:55 -0800789 if len(m.NoticeFiles()) > 0 {
Inseob Kim8471cda2019-11-15 09:59:12 +0900790 noticeName := stem + ".txt"
791 // skip already copied notice file
792 if _, ok := noticeBuilt[noticeName]; !ok {
793 noticeBuilt[noticeName] = true
Inseob Kimde5744a2020-12-02 13:14:28 +0900794 snapshotOutputs = append(snapshotOutputs, combineNoticesRule(
Bob Badoura75b0572020-02-18 20:21:55 -0800795 ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName)))
Inseob Kim8471cda2019-11-15 09:59:12 +0900796 }
797 }
798
799 if ctx.Config().VndkSnapshotBuildArtifacts() {
Inseob Kimeda2e9c2020-03-03 22:06:32 +0900800 headers = append(headers, l.snapshotHeaders()...)
Inseob Kimae553032019-05-14 18:52:49 +0900801 }
802 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900803
Inseob Kim8471cda2019-11-15 09:59:12 +0900804 // install all headers after removing duplicates
805 for _, header := range android.FirstUniquePaths(headers) {
Inseob Kimde5744a2020-12-02 13:14:28 +0900806 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900807 ctx, header, filepath.Join(includeDir, header.String())))
Inseob Kimae553032019-05-14 18:52:49 +0900808 }
809
Jooyung Han39edb6c2019-11-06 16:53:07 +0900810 // install *.libraries.txt except vndkcorevariant.libraries.txt
811 ctx.VisitAllModules(func(module android.Module) {
812 m, ok := module.(*vndkLibrariesTxt)
813 if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
814 return
815 }
Inseob Kimde5744a2020-12-02 13:14:28 +0900816 snapshotOutputs = append(snapshotOutputs, copyFileRule(
Inseob Kim8471cda2019-11-15 09:59:12 +0900817 ctx, m.OutputFile(), filepath.Join(configsDir, m.Name())))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900818 })
Inseob Kim1f086e22019-05-09 13:29:15 +0900819
Inseob Kim242ef0c2019-10-22 20:15:20 +0900820 /*
Inseob Kim242ef0c2019-10-22 20:15:20 +0900821 module_paths.txt contains paths on which VNDK modules are defined.
822 e.g.,
Baligh Uddin637df8e2020-10-26 14:34:53 +0000823 libbase.so system/libbase
Inseob Kim242ef0c2019-10-22 20:15:20 +0900824 libc.so bionic/libc
825 ...
826 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900827 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900828
829 /*
830 module_names.txt contains names as which VNDK modules are defined,
831 because output filename and module name can be different with stem and suffix properties.
832
833 e.g.,
834 libcutils.so libcutils
835 libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full
836 ...
837 */
Inseob Kimde5744a2020-12-02 13:14:28 +0900838 snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt")))
Inseob Kim242ef0c2019-10-22 20:15:20 +0900839
840 // All artifacts are ready. Sort them to normalize ninja and then zip.
841 sort.Slice(snapshotOutputs, func(i, j int) bool {
842 return snapshotOutputs[i].String() < snapshotOutputs[j].String()
843 })
844
845 zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip")
Colin Crossf1a035e2020-11-16 17:32:30 -0800846 zipRule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900847
Inseob Kimde5744a2020-12-02 13:14:28 +0900848 // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr
Inseob Kim242ef0c2019-10-22 20:15:20 +0900849 snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list")
Colin Cross70c47412021-03-12 17:48:14 -0800850 rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp")
Inseob Kim242ef0c2019-10-22 20:15:20 +0900851 zipRule.Command().
Inseob Kim8471cda2019-11-15 09:59:12 +0900852 Text("tr").
853 FlagWithArg("-d ", "\\'").
Colin Cross70c47412021-03-12 17:48:14 -0800854 FlagWithRspFileInputList("< ", rspFile, snapshotOutputs).
Inseob Kim8471cda2019-11-15 09:59:12 +0900855 FlagWithOutput("> ", snapshotOutputList)
Inseob Kim242ef0c2019-10-22 20:15:20 +0900856
857 zipRule.Temporary(snapshotOutputList)
858
859 zipRule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800860 BuiltTool("soong_zip").
Inseob Kim242ef0c2019-10-22 20:15:20 +0900861 FlagWithOutput("-o ", zipPath).
862 FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()).
863 FlagWithInput("-l ", snapshotOutputList)
864
Colin Crossf1a035e2020-11-16 17:32:30 -0800865 zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String())
Inseob Kim8471cda2019-11-15 09:59:12 +0900866 zipRule.DeleteTemporaryFiles()
Inseob Kim242ef0c2019-10-22 20:15:20 +0900867 c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath)
Inseob Kim1f086e22019-05-09 13:29:15 +0900868}
Jooyung Han097087b2019-10-22 19:32:18 +0900869
Jooyung Han0302a842019-10-30 18:43:49 +0900870func getVndkFileName(m *Module) (string, error) {
871 if library, ok := m.linker.(*libraryDecorator); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900872 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900873 }
874 if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok {
Justin Yun6977e8a2020-10-29 18:24:11 +0900875 return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
Jooyung Han0302a842019-10-30 18:43:49 +0900876 }
Colin Cross78212242021-01-06 14:51:30 -0800877 if library, ok := m.linker.(*llndkStubDecorator); ok {
878 return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil
879 }
Jooyung Han0302a842019-10-30 18:43:49 +0900880 return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker)
Jooyung Han097087b2019-10-22 19:32:18 +0900881}
882
883func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900884 // Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
Jooyung Han0302a842019-10-30 18:43:49 +0900885 // Since each target have different set of libclang_rt.* files,
886 // keep the common set of files in vndk.libraries.txt
Colin Cross78212242021-01-06 14:51:30 -0800887 _, llndk := vndkModuleListRemover(llndkLibraries, "libclang_rt.")(ctx)
888 _, vndkcore := vndkModuleListRemover(vndkCoreLibraries, "libclang_rt.")(ctx)
889 _, vndksp := vndkSPLibraries(ctx)
890 _, vndkprivate := vndkPrivateLibraries(ctx)
891 _, vndkproduct := vndkModuleListRemover(vndkProductLibraries, "libclang_rt.")(ctx)
Jooyung Han0302a842019-10-30 18:43:49 +0900892 var merged []string
Colin Cross78212242021-01-06 14:51:30 -0800893 merged = append(merged, addPrefix(llndk, "LLNDK: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900894 merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800895 merged = append(merged, addPrefix(vndkcore, "VNDK-core: ")...)
Jooyung Han097087b2019-10-22 19:32:18 +0900896 merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
Colin Cross78212242021-01-06 14:51:30 -0800897 merged = append(merged, addPrefix(vndkproduct, "VNDK-product: ")...)
Jooyung Han39edb6c2019-11-06 16:53:07 +0900898 c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
Colin Crosscf371cc2020-11-13 11:48:42 -0800899 android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n"))
Jooyung Han0302a842019-10-30 18:43:49 +0900900}
Jooyung Han097087b2019-10-22 19:32:18 +0900901
Jooyung Han0302a842019-10-30 18:43:49 +0900902func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
903 // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
904 // they been moved to an apex.
Colin Cross56a83212020-09-15 18:30:11 -0700905 movedToApexLlndkLibraries := make(map[string]bool)
906 ctx.VisitAllModules(func(module android.Module) {
Colin Cross127bb8b2020-12-16 16:46:01 -0800907 if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
908 // Skip bionic libs, they are handled in different manner
909 name := library.implementationModuleName(module.(*Module).BaseModuleName())
910 if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) {
911 movedToApexLlndkLibraries[name] = true
Colin Cross56a83212020-09-15 18:30:11 -0700912 }
Jooyung Han0302a842019-10-30 18:43:49 +0900913 }
Colin Cross56a83212020-09-15 18:30:11 -0700914 })
915
916 ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
917 strings.Join(android.SortedStringKeys(movedToApexLlndkLibraries), " "))
Jooyung Han39edb6c2019-11-06 16:53:07 +0900918
Jooyung Han0302a842019-10-30 18:43:49 +0900919 ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
Inseob Kim242ef0c2019-10-22 20:15:20 +0900920 ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
Jooyung Han097087b2019-10-22 19:32:18 +0900921}