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