Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 18 | "encoding/json" |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 19 | "errors" |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 20 | "fmt" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 21 | "path/filepath" |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 22 | "sort" |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 23 | "strings" |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 24 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 25 | "android/soong/android" |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 26 | "android/soong/cc/config" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 27 | "android/soong/etc" |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 28 | |
| 29 | "github.com/google/blueprint" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 30 | ) |
| 31 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 32 | const ( |
| 33 | llndkLibrariesTxt = "llndk.libraries.txt" |
| 34 | vndkCoreLibrariesTxt = "vndkcore.libraries.txt" |
| 35 | vndkSpLibrariesTxt = "vndksp.libraries.txt" |
| 36 | vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 37 | vndkProductLibrariesTxt = "vndkproduct.libraries.txt" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 38 | vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt" |
| 39 | ) |
| 40 | |
| 41 | func VndkLibrariesTxtModules(vndkVersion string) []string { |
| 42 | if vndkVersion == "current" { |
| 43 | return []string{ |
| 44 | llndkLibrariesTxt, |
| 45 | vndkCoreLibrariesTxt, |
| 46 | vndkSpLibrariesTxt, |
| 47 | vndkPrivateLibrariesTxt, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 48 | vndkProductLibrariesTxt, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 49 | } |
| 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 Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 58 | insertVndkVersion(vndkProductLibrariesTxt, vndkVersion), |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 62 | type 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 Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 67 | // `vendor_available` and `product_available` must be explicitly |
| 68 | // set to either true or false together with `vndk: {enabled: true}`. |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 69 | 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 Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 82 | |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 83 | // 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 Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 90 | // Extending another module |
| 91 | Extends *string |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | type vndkdep struct { |
| 96 | Properties VndkProperties |
| 97 | } |
| 98 | |
| 99 | func (vndk *vndkdep) props() []interface{} { |
| 100 | return []interface{}{&vndk.Properties} |
| 101 | } |
| 102 | |
| 103 | func (vndk *vndkdep) begin(ctx BaseModuleContext) {} |
| 104 | |
| 105 | func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 106 | return deps |
| 107 | } |
| 108 | |
| 109 | func (vndk *vndkdep) isVndk() bool { |
| 110 | return Bool(vndk.Properties.Vndk.Enabled) |
| 111 | } |
| 112 | |
| 113 | func (vndk *vndkdep) isVndkSp() bool { |
| 114 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 115 | } |
| 116 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 117 | func (vndk *vndkdep) isVndkExt() bool { |
| 118 | return vndk.Properties.Vndk.Extends != nil |
| 119 | } |
| 120 | |
| 121 | func (vndk *vndkdep) getVndkExtendsModuleName() string { |
| 122 | return String(vndk.Properties.Vndk.Extends) |
| 123 | } |
| 124 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 125 | func (vndk *vndkdep) typeName() string { |
| 126 | if !vndk.isVndk() { |
| 127 | return "native:vendor" |
| 128 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 129 | if !vndk.isVndkExt() { |
| 130 | if !vndk.isVndkSp() { |
| 131 | return "native:vendor:vndk" |
| 132 | } |
| 133 | return "native:vendor:vndksp" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 134 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 135 | if !vndk.isVndkSp() { |
| 136 | return "native:vendor:vndkext" |
| 137 | } |
| 138 | return "native:vendor:vndkspext" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 139 | } |
| 140 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 141 | // VNDK link type check from a module with UseVndk() == true. |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 142 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 143 | if to.linker == nil { |
| 144 | return |
| 145 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 146 | if !vndk.isVndk() { |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 147 | // 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 Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 152 | } |
| 153 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 154 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 155 | // Check only shared libraries. |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 156 | // Other (static) libraries are allowed to link. |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 157 | return |
| 158 | } |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 159 | |
| 160 | if to.IsLlndk() { |
| 161 | // LL-NDK libraries are allowed to link |
| 162 | return |
| 163 | } |
| 164 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 165 | if !to.UseVndk() { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 166 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 167 | vndk.typeName(), to.Name()) |
| 168 | return |
| 169 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 170 | 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 Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 183 | if to.IsVndkPrivate() { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 184 | ctx.ModuleErrorf( |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 185 | "`extends` refers module %q which has `private: true`", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 186 | to.Name()) |
| 187 | return |
| 188 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 189 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 190 | if to.vndkdep == nil { |
| 191 | return |
| 192 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 193 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 194 | // Check the dependencies of VNDK shared libraries. |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 195 | 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 Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 198 | return |
| 199 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 200 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 201 | |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 202 | func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 203 | // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules. |
| 204 | if from.isVndkExt() { |
| 205 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 206 | 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 Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 210 | } |
| 211 | // VNDK-Ext may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs. |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 212 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 213 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 214 | if from.isVndk() { |
| 215 | if to.isVndkExt() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 216 | return errors.New("VNDK-core and VNDK-SP must not depend on VNDK extensions") |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 217 | } |
| 218 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 219 | if !to.isVndkSp() { |
| 220 | return errors.New("VNDK-SP must only depend on VNDK-SP") |
| 221 | } |
| 222 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 223 | } |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 224 | if !to.isVndk() { |
| 225 | return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP") |
| 226 | } |
| 227 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 228 | } |
| 229 | // Vendor modules may depend on VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext, or vendor libs. |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 230 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 231 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 232 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 233 | type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string) |
| 234 | |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 235 | var ( |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 236 | llndkLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsLLNDK && !isVestigialLLNDKModule(m) }) |
| 237 | 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 Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 243 | ) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 244 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 245 | // 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. |
| 247 | func 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 Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 263 | } |
| 264 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 265 | // 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. |
| 268 | func 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 Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 283 | } |
| 284 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 285 | var vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey") |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 286 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 287 | func vndkMustUseVendorVariantList(cfg android.Config) []string { |
| 288 | return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} { |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 289 | 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() |
| 295 | func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) { |
Jooyung Han | a463f72 | 2019-11-01 08:45:59 +0900 | [diff] [blame] | 296 | config.Once(vndkMustUseVendorVariantListKey, func() interface{} { |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 297 | return mustUseVendorVariantList |
| 298 | }) |
| 299 | } |
| 300 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 301 | func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
| 302 | lib := m.linker.(*llndkStubDecorator) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 303 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 304 | m.VendorProperties.IsLLNDK = true |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 305 | if Bool(lib.Properties.Private) { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 306 | m.VendorProperties.IsVNDKPrivate = true |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 307 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 308 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 309 | |
| 310 | func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 311 | 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 Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 317 | name := m.BaseModuleName() |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 318 | |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 319 | if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" { |
Jiyong Park | 2478e4e | 2020-05-18 09:30:14 +0000 | [diff] [blame] | 320 | // 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 Park | ea97f51 | 2020-03-31 15:31:17 +0900 | [diff] [blame] | 326 | mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK") |
| 327 | } |
| 328 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 329 | if inList(name, vndkMustUseVendorVariantList(mctx.Config())) { |
| 330 | m.Properties.MustUseVendorVariant = true |
| 331 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 332 | if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 333 | m.VendorProperties.IsVNDKUsingCoreVariant = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 334 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 335 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 336 | if m.vndkdep.isVndkSp() { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 337 | m.VendorProperties.IsVNDKSP = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 338 | } else { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 339 | m.VendorProperties.IsVNDKCore = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 340 | } |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 341 | if m.IsVndkPrivate() { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 342 | m.VendorProperties.IsVNDKPrivate = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 343 | } |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 344 | if Bool(m.VendorProperties.Product_available) { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 345 | m.VendorProperties.IsVNDKProduct = true |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 346 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 347 | } |
| 348 | |
Yo Chiang | 08fac0c | 2020-07-29 01:08:20 +0800 | [diff] [blame] | 349 | // Check for modules that mustn't be VNDK |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 350 | func shouldSkipVndkMutator(m *Module) bool { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 351 | if !m.Enabled() { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 352 | return true |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 353 | } |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 354 | if !m.Device() { |
| 355 | // Skip non-device modules |
| 356 | return true |
Jooyung Han | 87a7f30 | 2019-10-29 05:18:21 +0900 | [diff] [blame] | 357 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 358 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 359 | // Skip native_bridge modules |
| 360 | return true |
| 361 | } |
| 362 | return false |
| 363 | } |
| 364 | |
| 365 | func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool { |
| 366 | if shouldSkipVndkMutator(m) { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 367 | 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 Han | 73d20d0 | 2020-03-27 16:06:55 +0900 | [diff] [blame] | 378 | // 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 Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 387 | useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() && |
Jooyung Han | 87a7f30 | 2019-10-29 05:18:21 +0900 | [diff] [blame] | 388 | mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant() |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 389 | return lib.shared() && m.inVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 390 | } |
| 391 | return false |
| 392 | } |
| 393 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 394 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 395 | func VndkMutator(mctx android.BottomUpMutatorContext) { |
| 396 | m, ok := mctx.Module().(*Module) |
| 397 | if !ok { |
| 398 | return |
| 399 | } |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 400 | |
| 401 | if shouldSkipVndkMutator(m) { |
Justin Yun | 7390ea3 | 2019-09-08 11:34:06 +0900 | [diff] [blame] | 402 | return |
| 403 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 404 | |
| 405 | if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 406 | processLlndkLibrary(mctx, m) |
| 407 | return |
| 408 | } |
| 409 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 410 | // 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 Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 419 | m.VendorProperties.IsVNDKPrivate = llndk.VendorProperties.IsVNDKPrivate |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 423 | lib, isLib := m.linker.(*libraryDecorator) |
| 424 | prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 425 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 426 | if m.UseVndk() && isLib && lib.hasLLNDKStubs() { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 427 | llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(lib.Properties.Llndk_stubs)) |
| 428 | mergeLLNDKToLib(llndk[0].(*Module), &lib.Properties.Llndk, &lib.flagExporter) |
| 429 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 430 | if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() { |
| 431 | llndk := mctx.AddVariationDependencies(nil, llndkStubDepTag, String(prebuiltLib.Properties.Llndk_stubs)) |
| 432 | mergeLLNDKToLib(llndk[0].(*Module), &prebuiltLib.Properties.Llndk, &prebuiltLib.flagExporter) |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 435 | if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) { |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 436 | if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 437 | processVndkLibrary(mctx, m) |
| 438 | return |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | func init() { |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 444 | RegisterVndkLibraryTxtTypes(android.InitRegistrationContext) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 445 | android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 446 | } |
| 447 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 448 | func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 449 | // Make uses LLNDK_LIBRARIES to determine which libraries to install. |
| 450 | // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN. |
| 451 | // Therefore, by removing the library here, we cause it to only be installed if libc |
| 452 | // depends on it. |
| 453 | ctx.RegisterSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory) |
| 454 | ctx.RegisterSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory) |
| 455 | ctx.RegisterSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory) |
| 456 | ctx.RegisterSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory) |
| 457 | ctx.RegisterSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory) |
| 458 | ctx.RegisterSingletonModuleType("vndkcorevariant_libraries_txt", vndkUsingCoreVariantLibrariesTxtFactory) |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 461 | type vndkLibrariesTxt struct { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 462 | android.SingletonModuleBase |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 463 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 464 | lister moduleListerFunc |
| 465 | makeVarName string |
| 466 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 467 | properties VndkLibrariesTxtProperties |
| 468 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 469 | outputFile android.OutputPath |
| 470 | moduleNames []string |
| 471 | fileNames []string |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 472 | } |
| 473 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 474 | type VndkLibrariesTxtProperties struct { |
| 475 | Insert_vndk_version *bool |
| 476 | } |
| 477 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 478 | var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{} |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 479 | var _ android.OutputFileProducer = &vndkLibrariesTxt{} |
| 480 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 481 | // llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries |
| 482 | // generated by Soong but can be referenced by other modules. |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 483 | // For example, apex_vndk can depend on these files as prebuilt. |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 484 | func llndkLibrariesTxtFactory() android.SingletonModule { |
| 485 | return newVndkLibrariesTxt(llndkLibrariesWithoutHWASAN, "LLNDK_LIBRARIES") |
| 486 | } |
| 487 | |
| 488 | // vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries |
| 489 | // generated by Soong but can be referenced by other modules. |
| 490 | // For example, apex_vndk can depend on these files as prebuilt. |
| 491 | func vndkSPLibrariesTxtFactory() android.SingletonModule { |
| 492 | return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES") |
| 493 | } |
| 494 | |
| 495 | // vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries |
| 496 | // generated by Soong but can be referenced by other modules. |
| 497 | // For example, apex_vndk can depend on these files as prebuilt. |
| 498 | func vndkCoreLibrariesTxtFactory() android.SingletonModule { |
| 499 | return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES") |
| 500 | } |
| 501 | |
| 502 | // vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries |
| 503 | // generated by Soong but can be referenced by other modules. |
| 504 | // For example, apex_vndk can depend on these files as prebuilt. |
| 505 | func vndkPrivateLibrariesTxtFactory() android.SingletonModule { |
| 506 | return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES") |
| 507 | } |
| 508 | |
| 509 | // vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product libraries |
| 510 | // generated by Soong but can be referenced by other modules. |
| 511 | // For example, apex_vndk can depend on these files as prebuilt. |
| 512 | func vndkProductLibrariesTxtFactory() android.SingletonModule { |
| 513 | return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES") |
| 514 | } |
| 515 | |
| 516 | // vndkcorevariant_libraries_txt is a singleton module whose content is a list of VNDK libraries |
| 517 | // that are using the core variant, generated by Soong but can be referenced by other modules. |
| 518 | // For example, apex_vndk can depend on these files as prebuilt. |
| 519 | func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule { |
| 520 | return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES") |
| 521 | } |
| 522 | |
| 523 | func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule { |
| 524 | m := &vndkLibrariesTxt{ |
| 525 | lister: lister, |
| 526 | makeVarName: makeVarName, |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 527 | } |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 528 | m.AddProperties(&m.properties) |
| 529 | android.InitAndroidModule(m) |
| 530 | return m |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | func insertVndkVersion(filename string, vndkVersion string) string { |
| 534 | if index := strings.LastIndex(filename, "."); index != -1 { |
| 535 | return filename[:index] + "." + vndkVersion + filename[index:] |
| 536 | } |
| 537 | return filename |
| 538 | } |
| 539 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 540 | func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 541 | var filename string |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 542 | if BoolDefault(txt.properties.Insert_vndk_version, true) { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 543 | filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion()) |
| 544 | } else { |
| 545 | filename = txt.Name() |
| 546 | } |
| 547 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 548 | txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 549 | |
| 550 | installPath := android.PathForModuleInstall(ctx, "etc") |
| 551 | ctx.InstallFile(installPath, filename, txt.outputFile) |
| 552 | } |
| 553 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 554 | func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) { |
| 555 | txt.moduleNames, txt.fileNames = txt.lister(ctx) |
| 556 | android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n")) |
| 557 | } |
| 558 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 559 | func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries { |
| 560 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 561 | Class: "ETC", |
| 562 | OutputFile: android.OptionalPathForPath(txt.outputFile), |
| 563 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 564 | func(entries *android.AndroidMkEntries) { |
| 565 | entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base()) |
| 566 | }, |
| 567 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 568 | }} |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 569 | } |
| 570 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 571 | func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) { |
| 572 | ctx.Strict(txt.makeVarName, strings.Join(txt.moduleNames, " ")) |
| 573 | |
| 574 | } |
| 575 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 576 | // PrebuiltEtcModule interface |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 577 | func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath { |
| 578 | return txt.outputFile |
| 579 | } |
| 580 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 581 | // PrebuiltEtcModule interface |
| 582 | func (txt *vndkLibrariesTxt) BaseDir() string { |
| 583 | return "etc" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 584 | } |
| 585 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 586 | // PrebuiltEtcModule interface |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 587 | func (txt *vndkLibrariesTxt) SubDir() string { |
| 588 | return "" |
| 589 | } |
| 590 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 591 | func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) { |
| 592 | return android.Paths{txt.outputFile}, nil |
| 593 | } |
| 594 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 595 | func VndkSnapshotSingleton() android.Singleton { |
| 596 | return &vndkSnapshotSingleton{} |
| 597 | } |
| 598 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 599 | type vndkSnapshotSingleton struct { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 600 | vndkLibrariesFile android.OutputPath |
| 601 | vndkSnapshotZipFile android.OptionalPath |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 602 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 603 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 604 | func isVndkSnapshotAware(config android.DeviceConfig, m *Module, |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 605 | apexInfo android.ApexInfo) (i snapshotLibraryInterface, vndkType string, isVndkSnapshotLib bool) { |
| 606 | |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 607 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 608 | return nil, "", false |
| 609 | } |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 610 | // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants. |
| 611 | // !installable: Snapshot only cares about "installable" modules. |
| 612 | // isSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 613 | if !m.inVendor() || !m.installable(apexInfo) || m.isSnapshotPrebuilt() { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 614 | return nil, "", false |
| 615 | } |
| 616 | l, ok := m.linker.(snapshotLibraryInterface) |
| 617 | if !ok || !l.shared() { |
| 618 | return nil, "", false |
| 619 | } |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 620 | if m.VndkVersion() == config.PlatformVndkVersion() && m.IsVndk() && !m.IsVndkExt() { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 621 | if m.isVndkSp() { |
| 622 | return l, "vndk-sp", true |
| 623 | } else { |
| 624 | return l, "vndk-core", true |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | return nil, "", false |
| 629 | } |
| 630 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 631 | func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 632 | // build these files even if PlatformVndkVersion or BoardVndkVersion is not set |
| 633 | c.buildVndkLibrariesTxtFiles(ctx) |
| 634 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 635 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot. |
| 636 | if ctx.DeviceConfig().VndkVersion() != "current" { |
| 637 | return |
| 638 | } |
| 639 | |
| 640 | if ctx.DeviceConfig().PlatformVndkVersion() == "" { |
| 641 | return |
| 642 | } |
| 643 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 644 | var snapshotOutputs android.Paths |
| 645 | |
| 646 | /* |
| 647 | VNDK snapshot zipped artifacts directory structure: |
| 648 | {SNAPSHOT_ARCH}/ |
| 649 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 650 | shared/ |
| 651 | vndk-core/ |
| 652 | (VNDK-core libraries, e.g. libbinder.so) |
| 653 | vndk-sp/ |
| 654 | (VNDK-SP libraries, e.g. libc++.so) |
| 655 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 656 | shared/ |
| 657 | vndk-core/ |
| 658 | (VNDK-core libraries, e.g. libbinder.so) |
| 659 | vndk-sp/ |
| 660 | (VNDK-SP libraries, e.g. libc++.so) |
| 661 | binder32/ |
| 662 | (This directory is newly introduced in v28 (Android P) to hold |
| 663 | prebuilts built for 32-bit binder interface.) |
| 664 | arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/ |
| 665 | ... |
| 666 | configs/ |
| 667 | (various *.txt configuration files) |
| 668 | include/ |
| 669 | (header files of same directory structure with source tree) |
| 670 | NOTICE_FILES/ |
| 671 | (notice files of libraries, e.g. libcutils.so.txt) |
| 672 | */ |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 673 | |
| 674 | snapshotDir := "vndk-snapshot" |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 675 | snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 676 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 677 | configsDir := filepath.Join(snapshotArchDir, "configs") |
| 678 | noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") |
| 679 | includeDir := filepath.Join(snapshotArchDir, "include") |
| 680 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 681 | // set of notice files copied. |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 682 | noticeBuilt := make(map[string]bool) |
| 683 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 684 | // paths of VNDK modules for GPL license checking |
| 685 | modulePaths := make(map[string]string) |
| 686 | |
| 687 | // actual module names of .so files |
| 688 | // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full" |
| 689 | moduleNames := make(map[string]string) |
| 690 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 691 | var headers android.Paths |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 692 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 693 | // installVndkSnapshotLib copies built .so file from the module. |
| 694 | // Also, if the build artifacts is on, write a json file which contains all exported flags |
| 695 | // with FlagExporterInfo. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 696 | installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) { |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 697 | var ret android.Paths |
| 698 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 699 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 700 | if m.Target().Arch.ArchVariant != "" { |
| 701 | targetArch += "-" + m.Target().Arch.ArchVariant |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 702 | } |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 703 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 704 | libPath := m.outputFile.Path() |
| 705 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base()) |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 706 | ret = append(ret, copyFileRule(ctx, libPath, snapshotLibOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 707 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 708 | if ctx.Config().VndkSnapshotBuildArtifacts() { |
| 709 | prop := struct { |
| 710 | ExportedDirs []string `json:",omitempty"` |
| 711 | ExportedSystemDirs []string `json:",omitempty"` |
| 712 | ExportedFlags []string `json:",omitempty"` |
| 713 | RelativeInstallPath string `json:",omitempty"` |
| 714 | }{} |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 715 | exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) |
| 716 | prop.ExportedFlags = exportedInfo.Flags |
| 717 | prop.ExportedDirs = exportedInfo.IncludeDirs.Strings() |
| 718 | prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings() |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 719 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 720 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 721 | propOut := snapshotLibOut + ".json" |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 722 | |
| 723 | j, err := json.Marshal(prop) |
| 724 | if err != nil { |
| 725 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 726 | return nil, false |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 727 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 728 | ret = append(ret, writeStringToFileRule(ctx, string(j), propOut)) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 729 | } |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 730 | return ret, true |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 731 | } |
| 732 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 733 | ctx.VisitAllModules(func(module android.Module) { |
| 734 | m, ok := module.(*Module) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 735 | if !ok || !m.Enabled() { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 736 | return |
| 737 | } |
| 738 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 739 | apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
| 740 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 741 | l, vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 742 | if !ok { |
dimitry | 51ea18a | 2019-05-20 10:39:52 +0200 | [diff] [blame] | 743 | return |
| 744 | } |
| 745 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 746 | // For all snapshot candidates, the followings are captured. |
| 747 | // - .so files |
| 748 | // - notice files |
| 749 | // |
| 750 | // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS. |
| 751 | // - .json files containing exported flags |
| 752 | // - exported headers from collectHeadersForSnapshot() |
| 753 | // |
| 754 | // Headers are deduplicated after visiting all modules. |
| 755 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 756 | // install .so files for appropriate modules. |
| 757 | // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 758 | libs, ok := installVndkSnapshotLib(m, vndkType) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 759 | if !ok { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 760 | return |
| 761 | } |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 762 | snapshotOutputs = append(snapshotOutputs, libs...) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 763 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 764 | // These are for generating module_names.txt and module_paths.txt |
| 765 | stem := m.outputFile.Path().Base() |
| 766 | moduleNames[stem] = ctx.ModuleName(m) |
| 767 | modulePaths[stem] = ctx.ModuleDir(m) |
| 768 | |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 769 | if len(m.NoticeFiles()) > 0 { |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 770 | noticeName := stem + ".txt" |
| 771 | // skip already copied notice file |
| 772 | if _, ok := noticeBuilt[noticeName]; !ok { |
| 773 | noticeBuilt[noticeName] = true |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 774 | snapshotOutputs = append(snapshotOutputs, combineNoticesRule( |
Bob Badour | a75b057 | 2020-02-18 20:21:55 -0800 | [diff] [blame] | 775 | ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName))) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| 779 | if ctx.Config().VndkSnapshotBuildArtifacts() { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 780 | headers = append(headers, l.snapshotHeaders()...) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 781 | } |
| 782 | }) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 783 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 784 | // install all headers after removing duplicates |
| 785 | for _, header := range android.FirstUniquePaths(headers) { |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 786 | snapshotOutputs = append(snapshotOutputs, copyFileRule( |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 787 | ctx, header, filepath.Join(includeDir, header.String()))) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 788 | } |
| 789 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 790 | // install *.libraries.txt except vndkcorevariant.libraries.txt |
| 791 | ctx.VisitAllModules(func(module android.Module) { |
| 792 | m, ok := module.(*vndkLibrariesTxt) |
| 793 | if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt { |
| 794 | return |
| 795 | } |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 796 | snapshotOutputs = append(snapshotOutputs, copyFileRule( |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 797 | ctx, m.OutputFile(), filepath.Join(configsDir, m.Name()))) |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 798 | }) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 799 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 800 | /* |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 801 | module_paths.txt contains paths on which VNDK modules are defined. |
| 802 | e.g., |
Baligh Uddin | 637df8e | 2020-10-26 14:34:53 +0000 | [diff] [blame] | 803 | libbase.so system/libbase |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 804 | libc.so bionic/libc |
| 805 | ... |
| 806 | */ |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 807 | snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt"))) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 808 | |
| 809 | /* |
| 810 | module_names.txt contains names as which VNDK modules are defined, |
| 811 | because output filename and module name can be different with stem and suffix properties. |
| 812 | |
| 813 | e.g., |
| 814 | libcutils.so libcutils |
| 815 | libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full |
| 816 | ... |
| 817 | */ |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 818 | snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt"))) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 819 | |
| 820 | // All artifacts are ready. Sort them to normalize ninja and then zip. |
| 821 | sort.Slice(snapshotOutputs, func(i, j int) bool { |
| 822 | return snapshotOutputs[i].String() < snapshotOutputs[j].String() |
| 823 | }) |
| 824 | |
| 825 | zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 826 | zipRule := android.NewRuleBuilder(pctx, ctx) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 827 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 828 | // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 829 | snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list") |
| 830 | zipRule.Command(). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 831 | Text("tr"). |
| 832 | FlagWithArg("-d ", "\\'"). |
| 833 | FlagWithRspFileInputList("< ", snapshotOutputs). |
| 834 | FlagWithOutput("> ", snapshotOutputList) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 835 | |
| 836 | zipRule.Temporary(snapshotOutputList) |
| 837 | |
| 838 | zipRule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 839 | BuiltTool("soong_zip"). |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 840 | FlagWithOutput("-o ", zipPath). |
| 841 | FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()). |
| 842 | FlagWithInput("-l ", snapshotOutputList) |
| 843 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 844 | zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String()) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 845 | zipRule.DeleteTemporaryFiles() |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 846 | c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 847 | } |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 848 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 849 | func getVndkFileName(m *Module) (string, error) { |
| 850 | if library, ok := m.linker.(*libraryDecorator); ok { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 851 | return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 852 | } |
| 853 | if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 854 | return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 855 | } |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 856 | if library, ok := m.linker.(*llndkStubDecorator); ok { |
| 857 | return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil |
| 858 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 859 | return "", fmt.Errorf("VNDK library should have libraryDecorator or prebuiltLibraryLinker as linker: %T", m.linker) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 863 | // Build list of vndk libs as merged & tagged & filter-out(libclang_rt): |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 864 | // Since each target have different set of libclang_rt.* files, |
| 865 | // keep the common set of files in vndk.libraries.txt |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 866 | _, llndk := vndkModuleListRemover(llndkLibraries, "libclang_rt.")(ctx) |
| 867 | _, vndkcore := vndkModuleListRemover(vndkCoreLibraries, "libclang_rt.")(ctx) |
| 868 | _, vndksp := vndkSPLibraries(ctx) |
| 869 | _, vndkprivate := vndkPrivateLibraries(ctx) |
| 870 | _, vndkproduct := vndkModuleListRemover(vndkProductLibraries, "libclang_rt.")(ctx) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 871 | var merged []string |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 872 | merged = append(merged, addPrefix(llndk, "LLNDK: ")...) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 873 | merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 874 | merged = append(merged, addPrefix(vndkcore, "VNDK-core: ")...) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 875 | merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame^] | 876 | merged = append(merged, addPrefix(vndkproduct, "VNDK-product: ")...) |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 877 | c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 878 | android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n")) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 879 | } |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 880 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 881 | func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 882 | // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if |
| 883 | // they been moved to an apex. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 884 | movedToApexLlndkLibraries := make(map[string]bool) |
| 885 | ctx.VisitAllModules(func(module android.Module) { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 886 | if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() { |
| 887 | // Skip bionic libs, they are handled in different manner |
| 888 | name := library.implementationModuleName(module.(*Module).BaseModuleName()) |
| 889 | if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) { |
| 890 | movedToApexLlndkLibraries[name] = true |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 891 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 892 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 893 | }) |
| 894 | |
| 895 | ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", |
| 896 | strings.Join(android.SortedStringKeys(movedToApexLlndkLibraries), " ")) |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 897 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 898 | ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String()) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 899 | ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String()) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 900 | } |