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