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