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