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