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" |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 22 | "strings" |
| 23 | "sync" |
| 24 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 25 | "android/soong/android" |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 26 | "android/soong/cc/config" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | type VndkProperties struct { |
| 30 | Vndk struct { |
| 31 | // declared as a VNDK or VNDK-SP module. The vendor variant |
| 32 | // will be installed in /system instead of /vendor partition. |
| 33 | // |
Roland Levillain | dfe75b3 | 2019-07-23 16:53:32 +0100 | [diff] [blame] | 34 | // `vendor_available` must be explicitly set to either true or |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 35 | // false together with `vndk: {enabled: true}`. |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 36 | Enabled *bool |
| 37 | |
| 38 | // declared as a VNDK-SP module, which is a subset of VNDK. |
| 39 | // |
| 40 | // `vndk: { enabled: true }` must set together. |
| 41 | // |
| 42 | // All these modules are allowed to link to VNDK-SP or LL-NDK |
| 43 | // modules only. Other dependency will cause link-type errors. |
| 44 | // |
| 45 | // If `support_system_process` is not set or set to false, |
| 46 | // the module is VNDK-core and can link to other VNDK-core, |
| 47 | // VNDK-SP or LL-NDK modules only. |
| 48 | Support_system_process *bool |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 49 | |
| 50 | // Extending another module |
| 51 | Extends *string |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
| 55 | type vndkdep struct { |
| 56 | Properties VndkProperties |
| 57 | } |
| 58 | |
| 59 | func (vndk *vndkdep) props() []interface{} { |
| 60 | return []interface{}{&vndk.Properties} |
| 61 | } |
| 62 | |
| 63 | func (vndk *vndkdep) begin(ctx BaseModuleContext) {} |
| 64 | |
| 65 | func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 66 | return deps |
| 67 | } |
| 68 | |
| 69 | func (vndk *vndkdep) isVndk() bool { |
| 70 | return Bool(vndk.Properties.Vndk.Enabled) |
| 71 | } |
| 72 | |
| 73 | func (vndk *vndkdep) isVndkSp() bool { |
| 74 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 75 | } |
| 76 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 77 | func (vndk *vndkdep) isVndkExt() bool { |
| 78 | return vndk.Properties.Vndk.Extends != nil |
| 79 | } |
| 80 | |
| 81 | func (vndk *vndkdep) getVndkExtendsModuleName() string { |
| 82 | return String(vndk.Properties.Vndk.Extends) |
| 83 | } |
| 84 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 85 | func (vndk *vndkdep) typeName() string { |
| 86 | if !vndk.isVndk() { |
| 87 | return "native:vendor" |
| 88 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 89 | if !vndk.isVndkExt() { |
| 90 | if !vndk.isVndkSp() { |
| 91 | return "native:vendor:vndk" |
| 92 | } |
| 93 | return "native:vendor:vndksp" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 94 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 95 | if !vndk.isVndkSp() { |
| 96 | return "native:vendor:vndkext" |
| 97 | } |
| 98 | return "native:vendor:vndkspext" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 99 | } |
| 100 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 101 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag DependencyTag) { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 102 | if to.linker == nil { |
| 103 | return |
| 104 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 105 | if !vndk.isVndk() { |
| 106 | // Non-VNDK modules (those installed to /vendor) can't depend on modules marked with |
| 107 | // vendor_available: false. |
| 108 | violation := false |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 109 | if lib, ok := to.linker.(*llndkStubDecorator); ok && !Bool(lib.Properties.Vendor_available) { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 110 | violation = true |
| 111 | } else { |
| 112 | if _, ok := to.linker.(libraryInterface); ok && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) { |
| 113 | // Vendor_available == nil && !Bool(Vendor_available) should be okay since |
| 114 | // it means a vendor-only library which is a valid dependency for non-VNDK |
| 115 | // modules. |
| 116 | violation = true |
| 117 | } |
| 118 | } |
| 119 | if violation { |
| 120 | ctx.ModuleErrorf("Vendor module that is not VNDK should not link to %q which is marked as `vendor_available: false`", to.Name()) |
| 121 | } |
| 122 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 123 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 124 | // Check only shared libraries. |
| 125 | // Other (static and LL-NDK) libraries are allowed to link. |
| 126 | return |
| 127 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 128 | if !to.UseVndk() { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 129 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 130 | vndk.typeName(), to.Name()) |
| 131 | return |
| 132 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 133 | if tag == vndkExtDepTag { |
| 134 | // Ensure `extends: "name"` property refers a vndk module that has vendor_available |
| 135 | // and has identical vndk properties. |
| 136 | if to.vndkdep == nil || !to.vndkdep.isVndk() { |
| 137 | ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name()) |
| 138 | return |
| 139 | } |
| 140 | if vndk.isVndkSp() != to.vndkdep.isVndkSp() { |
| 141 | ctx.ModuleErrorf( |
| 142 | "`extends` refers a module %q with mismatched support_system_process", |
| 143 | to.Name()) |
| 144 | return |
| 145 | } |
| 146 | if !Bool(to.VendorProperties.Vendor_available) { |
| 147 | ctx.ModuleErrorf( |
| 148 | "`extends` refers module %q which does not have `vendor_available: true`", |
| 149 | to.Name()) |
| 150 | return |
| 151 | } |
| 152 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 153 | if to.vndkdep == nil { |
| 154 | return |
| 155 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 156 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 157 | // Check the dependencies of VNDK shared libraries. |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 158 | if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil { |
| 159 | ctx.ModuleErrorf("(%s) should not link to %q (%s): %v", |
| 160 | vndk.typeName(), to.Name(), to.vndkdep.typeName(), err) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 161 | return |
| 162 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 163 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 164 | |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 165 | func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 166 | // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules. |
| 167 | if from.isVndkExt() { |
| 168 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 169 | if to.isVndk() && !to.isVndkSp() { |
| 170 | return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions") |
| 171 | } |
| 172 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 173 | } |
| 174 | // 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] | 175 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 176 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 177 | if from.isVndk() { |
| 178 | if to.isVndkExt() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 179 | 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] | 180 | } |
| 181 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 182 | if !to.isVndkSp() { |
| 183 | return errors.New("VNDK-SP must only depend on VNDK-SP") |
| 184 | } |
| 185 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 186 | } |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 187 | if !to.isVndk() { |
| 188 | return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP") |
| 189 | } |
| 190 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 191 | } |
| 192 | // 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] | 193 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 194 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 195 | |
| 196 | var ( |
Jooyung Han | a463f72 | 2019-11-01 08:45:59 +0900 | [diff] [blame] | 197 | vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires") |
| 198 | vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires") |
| 199 | llndkLibrariesKey = android.NewOnceKey("llndkLibrarires") |
| 200 | vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires") |
| 201 | vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibrarires") |
| 202 | modulePathsKey = android.NewOnceKey("modulePaths") |
| 203 | vndkSnapshotOutputsKey = android.NewOnceKey("vndkSnapshotOutputs") |
| 204 | vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey") |
| 205 | vndkLibrariesLock sync.Mutex |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 206 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 207 | headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"} |
| 208 | ) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 209 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 210 | func vndkCoreLibraries(config android.Config) map[string]string { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 211 | return config.Once(vndkCoreLibrariesKey, func() interface{} { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 212 | return make(map[string]string) |
| 213 | }).(map[string]string) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 214 | } |
| 215 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 216 | func vndkSpLibraries(config android.Config) map[string]string { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 217 | return config.Once(vndkSpLibrariesKey, func() interface{} { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 218 | return make(map[string]string) |
| 219 | }).(map[string]string) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 220 | } |
| 221 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 222 | func isLlndkLibrary(baseModuleName string, config android.Config) bool { |
| 223 | _, ok := llndkLibraries(config)[baseModuleName] |
| 224 | return ok |
| 225 | } |
| 226 | |
| 227 | func llndkLibraries(config android.Config) map[string]string { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 228 | return config.Once(llndkLibrariesKey, func() interface{} { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 229 | return make(map[string]string) |
| 230 | }).(map[string]string) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 231 | } |
| 232 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 233 | func isVndkPrivateLibrary(baseModuleName string, config android.Config) bool { |
| 234 | _, ok := vndkPrivateLibraries(config)[baseModuleName] |
| 235 | return ok |
| 236 | } |
| 237 | |
| 238 | func vndkPrivateLibraries(config android.Config) map[string]string { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 239 | return config.Once(vndkPrivateLibrariesKey, func() interface{} { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 240 | return make(map[string]string) |
| 241 | }).(map[string]string) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 242 | } |
| 243 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 244 | func vndkUsingCoreVariantLibraries(config android.Config) map[string]string { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 245 | return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 246 | return make(map[string]string) |
| 247 | }).(map[string]string) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 248 | } |
| 249 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 250 | func modulePaths(config android.Config) map[string]string { |
| 251 | return config.Once(modulePathsKey, func() interface{} { |
| 252 | return make(map[string]string) |
| 253 | }).(map[string]string) |
| 254 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 255 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 256 | func vndkSnapshotOutputs(config android.Config) *android.RuleBuilderInstalls { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 257 | return config.Once(vndkSnapshotOutputsKey, func() interface{} { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 258 | return &android.RuleBuilderInstalls{} |
| 259 | }).(*android.RuleBuilderInstalls) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 260 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 261 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 262 | func vndkMustUseVendorVariantList(cfg android.Config) []string { |
| 263 | return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} { |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 264 | return config.VndkMustUseVendorVariantList |
| 265 | }).([]string) |
| 266 | } |
| 267 | |
| 268 | // test may call this to override global configuration(config.VndkMustUseVendorVariantList) |
| 269 | // when it is called, it must be before the first call to vndkMustUseVendorVariantList() |
| 270 | func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) { |
Jooyung Han | a463f72 | 2019-11-01 08:45:59 +0900 | [diff] [blame] | 271 | config.Once(vndkMustUseVendorVariantListKey, func() interface{} { |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 272 | return mustUseVendorVariantList |
| 273 | }) |
| 274 | } |
| 275 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 276 | func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
| 277 | lib := m.linker.(*llndkStubDecorator) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 278 | name := m.BaseModuleName() |
| 279 | filename := m.BaseModuleName() + ".so" |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 280 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 281 | vndkLibrariesLock.Lock() |
| 282 | defer vndkLibrariesLock.Unlock() |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 283 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 284 | llndkLibraries(mctx.Config())[name] = filename |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 285 | if !Bool(lib.Properties.Vendor_available) { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 286 | vndkPrivateLibraries(mctx.Config())[name] = filename |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 287 | } |
| 288 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 289 | |
| 290 | func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 291 | name := m.BaseModuleName() |
| 292 | filename, err := getVndkFileName(m) |
| 293 | if err != nil { |
| 294 | panic(err) |
| 295 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 296 | |
| 297 | vndkLibrariesLock.Lock() |
| 298 | defer vndkLibrariesLock.Unlock() |
| 299 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 300 | modulePaths(mctx.Config())[name] = mctx.ModuleDir() |
| 301 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 302 | if inList(name, vndkMustUseVendorVariantList(mctx.Config())) { |
| 303 | m.Properties.MustUseVendorVariant = true |
| 304 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 305 | if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant { |
| 306 | vndkUsingCoreVariantLibraries(mctx.Config())[name] = filename |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 307 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 308 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 309 | if m.vndkdep.isVndkSp() { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 310 | vndkSpLibraries(mctx.Config())[name] = filename |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 311 | } else { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 312 | vndkCoreLibraries(mctx.Config())[name] = filename |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 313 | } |
| 314 | if !Bool(m.VendorProperties.Vendor_available) { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 315 | vndkPrivateLibraries(mctx.Config())[name] = filename |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 319 | func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool { |
| 320 | if !m.Enabled() { |
| 321 | return false |
| 322 | } |
| 323 | |
Jooyung Han | 87a7f30 | 2019-10-29 05:18:21 +0900 | [diff] [blame] | 324 | if !mctx.Device() { |
| 325 | return false |
| 326 | } |
| 327 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 328 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 329 | return false |
| 330 | } |
| 331 | |
| 332 | // prebuilt vndk modules should match with device |
| 333 | // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared |
| 334 | // When b/142675459 is landed, remove following check |
| 335 | if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok && !p.matchesWithDevice(mctx.DeviceConfig()) { |
| 336 | return false |
| 337 | } |
| 338 | |
| 339 | if lib, ok := m.linker.(libraryInterface); ok { |
| 340 | useCoreVariant := m.vndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() && |
Jooyung Han | 87a7f30 | 2019-10-29 05:18:21 +0900 | [diff] [blame] | 341 | mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 342 | return lib.shared() && m.UseVndk() && m.IsVndk() && !m.isVndkExt() && !useCoreVariant |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 343 | } |
| 344 | return false |
| 345 | } |
| 346 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 347 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 348 | func VndkMutator(mctx android.BottomUpMutatorContext) { |
| 349 | m, ok := mctx.Module().(*Module) |
| 350 | if !ok { |
| 351 | return |
| 352 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 353 | if !m.Enabled() { |
| 354 | return |
| 355 | } |
Justin Yun | 7390ea3 | 2019-09-08 11:34:06 +0900 | [diff] [blame] | 356 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 357 | // Skip native_bridge modules |
| 358 | return |
| 359 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 360 | |
| 361 | if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 362 | processLlndkLibrary(mctx, m) |
| 363 | return |
| 364 | } |
| 365 | |
| 366 | lib, is_lib := m.linker.(*libraryDecorator) |
| 367 | prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker) |
| 368 | |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 369 | if (is_lib && lib.buildShared()) || (is_prebuilt_lib && prebuilt_lib.buildShared()) { |
| 370 | if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 371 | processVndkLibrary(mctx, m) |
| 372 | return |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | func init() { |
| 378 | android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) |
| 379 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 380 | outputs := vndkSnapshotOutputs(ctx.Config()) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 381 | ctx.Strict("SOONG_VNDK_SNAPSHOT_FILES", outputs.String()) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 382 | }) |
| 383 | } |
| 384 | |
| 385 | func VndkSnapshotSingleton() android.Singleton { |
| 386 | return &vndkSnapshotSingleton{} |
| 387 | } |
| 388 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 389 | type vndkSnapshotSingleton struct { |
| 390 | installedLlndkLibraries []string |
| 391 | llnkdLibrariesFile android.Path |
| 392 | vndkSpLibrariesFile android.Path |
| 393 | vndkCoreLibrariesFile android.Path |
| 394 | vndkPrivateLibrariesFile android.Path |
| 395 | vndkCoreVariantLibrariesFile android.Path |
| 396 | vndkLibrariesFile android.Path |
| 397 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 398 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 399 | func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 400 | // build these files even if PlatformVndkVersion or BoardVndkVersion is not set |
| 401 | c.buildVndkLibrariesTxtFiles(ctx) |
| 402 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 403 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot. |
| 404 | if ctx.DeviceConfig().VndkVersion() != "current" { |
| 405 | return |
| 406 | } |
| 407 | |
| 408 | if ctx.DeviceConfig().PlatformVndkVersion() == "" { |
| 409 | return |
| 410 | } |
| 411 | |
| 412 | if ctx.DeviceConfig().BoardVndkRuntimeDisable() { |
| 413 | return |
| 414 | } |
| 415 | |
| 416 | outputs := vndkSnapshotOutputs(ctx.Config()) |
| 417 | |
| 418 | snapshotDir := "vndk-snapshot" |
| 419 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 420 | vndkLibDir := make(map[android.ArchType]string) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 421 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 422 | snapshotVariantDir := ctx.DeviceConfig().DeviceArch() |
| 423 | for _, target := range ctx.Config().Targets[android.Android] { |
| 424 | dir := snapshotVariantDir |
| 425 | if ctx.DeviceConfig().BinderBitness() == "32" { |
| 426 | dir = filepath.Join(dir, "binder32") |
| 427 | } |
| 428 | arch := "arch-" + target.Arch.ArchType.String() |
| 429 | if target.Arch.ArchVariant != "" { |
| 430 | arch += "-" + target.Arch.ArchVariant |
| 431 | } |
| 432 | dir = filepath.Join(dir, arch) |
| 433 | vndkLibDir[target.Arch.ArchType] = dir |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 434 | } |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 435 | configsDir := filepath.Join(snapshotVariantDir, "configs") |
| 436 | noticeDir := filepath.Join(snapshotVariantDir, "NOTICE_FILES") |
| 437 | includeDir := filepath.Join(snapshotVariantDir, "include") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 438 | noticeBuilt := make(map[string]bool) |
| 439 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 440 | installSnapshotFileFromPath := func(path android.Path, out string) { |
| 441 | ctx.Build(pctx, android.BuildParams{ |
| 442 | Rule: android.Cp, |
| 443 | Input: path, |
| 444 | Output: android.PathForOutput(ctx, snapshotDir, out), |
| 445 | Description: "vndk snapshot " + out, |
| 446 | Args: map[string]string{ |
| 447 | "cpFlags": "-f -L", |
| 448 | }, |
| 449 | }) |
| 450 | *outputs = append(*outputs, android.RuleBuilderInstall{ |
| 451 | From: android.PathForOutput(ctx, snapshotDir, out), |
| 452 | To: out, |
| 453 | }) |
| 454 | } |
| 455 | installSnapshotFileFromContent := func(content, out string) { |
| 456 | ctx.Build(pctx, android.BuildParams{ |
| 457 | Rule: android.WriteFile, |
| 458 | Output: android.PathForOutput(ctx, snapshotDir, out), |
| 459 | Description: "vndk snapshot " + out, |
| 460 | Args: map[string]string{ |
| 461 | "content": content, |
| 462 | }, |
| 463 | }) |
| 464 | *outputs = append(*outputs, android.RuleBuilderInstall{ |
| 465 | From: android.PathForOutput(ctx, snapshotDir, out), |
| 466 | To: out, |
| 467 | }) |
| 468 | } |
| 469 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 470 | tryBuildNotice := func(m *Module) { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 471 | name := ctx.ModuleName(m) + ".so.txt" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 472 | |
| 473 | if _, ok := noticeBuilt[name]; ok { |
| 474 | return |
| 475 | } |
| 476 | |
| 477 | noticeBuilt[name] = true |
| 478 | |
| 479 | if m.NoticeFile().Valid() { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 480 | installSnapshotFileFromPath(m.NoticeFile().Path(), filepath.Join(noticeDir, name)) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 484 | vndkCoreLibraries := android.SortedStringKeys(vndkCoreLibraries(ctx.Config())) |
| 485 | vndkSpLibraries := android.SortedStringKeys(vndkSpLibraries(ctx.Config())) |
| 486 | vndkPrivateLibraries := android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 487 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 488 | var generatedHeaders android.Paths |
| 489 | includeDirs := make(map[string]bool) |
| 490 | |
| 491 | type vndkSnapshotLibraryInterface interface { |
| 492 | exportedFlagsProducer |
| 493 | libraryInterface |
| 494 | } |
| 495 | |
| 496 | var _ vndkSnapshotLibraryInterface = (*prebuiltLibraryLinker)(nil) |
| 497 | var _ vndkSnapshotLibraryInterface = (*libraryDecorator)(nil) |
| 498 | |
| 499 | installVndkSnapshotLib := func(m *Module, l vndkSnapshotLibraryInterface, dir string) bool { |
| 500 | name := ctx.ModuleName(m) |
| 501 | libOut := filepath.Join(dir, name+".so") |
| 502 | |
| 503 | installSnapshotFileFromPath(m.outputFile.Path(), libOut) |
| 504 | tryBuildNotice(m) |
| 505 | |
| 506 | if ctx.Config().VndkSnapshotBuildArtifacts() { |
| 507 | prop := struct { |
| 508 | ExportedDirs []string `json:",omitempty"` |
| 509 | ExportedSystemDirs []string `json:",omitempty"` |
| 510 | ExportedFlags []string `json:",omitempty"` |
| 511 | RelativeInstallPath string `json:",omitempty"` |
| 512 | }{} |
| 513 | prop.ExportedFlags = l.exportedFlags() |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame] | 514 | prop.ExportedDirs = l.exportedDirs().Strings() |
| 515 | prop.ExportedSystemDirs = l.exportedSystemDirs().Strings() |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 516 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 517 | |
| 518 | propOut := libOut + ".json" |
| 519 | |
| 520 | j, err := json.Marshal(prop) |
| 521 | if err != nil { |
| 522 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 523 | return false |
| 524 | } |
| 525 | |
| 526 | installSnapshotFileFromContent(string(j), propOut) |
| 527 | } |
| 528 | return true |
| 529 | } |
| 530 | |
| 531 | isVndkSnapshotLibrary := func(m *Module) (i vndkSnapshotLibraryInterface, libDir string, isVndkSnapshotLib bool) { |
| 532 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 533 | return nil, "", false |
| 534 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 535 | if !m.UseVndk() || !m.IsForPlatform() || !m.installable() { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 536 | return nil, "", false |
| 537 | } |
| 538 | l, ok := m.linker.(vndkSnapshotLibraryInterface) |
| 539 | if !ok || !l.shared() { |
| 540 | return nil, "", false |
| 541 | } |
| 542 | name := ctx.ModuleName(m) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 543 | if inList(name, vndkCoreLibraries) { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 544 | return l, filepath.Join("shared", "vndk-core"), true |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 545 | } else if inList(name, vndkSpLibraries) { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 546 | return l, filepath.Join("shared", "vndk-sp"), true |
| 547 | } else { |
| 548 | return nil, "", false |
| 549 | } |
| 550 | } |
| 551 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 552 | ctx.VisitAllModules(func(module android.Module) { |
| 553 | m, ok := module.(*Module) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 554 | if !ok || !m.Enabled() { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 555 | return |
| 556 | } |
| 557 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 558 | baseDir, ok := vndkLibDir[m.Target().Arch.ArchType] |
| 559 | if !ok { |
dimitry | 51ea18a | 2019-05-20 10:39:52 +0200 | [diff] [blame] | 560 | return |
| 561 | } |
| 562 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 563 | l, libDir, ok := isVndkSnapshotLibrary(m) |
| 564 | if !ok { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 565 | return |
| 566 | } |
| 567 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 568 | if !installVndkSnapshotLib(m, l, filepath.Join(baseDir, libDir)) { |
| 569 | return |
| 570 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 571 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 572 | generatedHeaders = append(generatedHeaders, l.exportedDeps()...) |
| 573 | for _, dir := range append(l.exportedDirs(), l.exportedSystemDirs()...) { |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame] | 574 | includeDirs[dir.String()] = true |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 575 | } |
| 576 | }) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 577 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 578 | if ctx.Config().VndkSnapshotBuildArtifacts() { |
| 579 | headers := make(map[string]bool) |
| 580 | |
| 581 | for _, dir := range android.SortedStringKeys(includeDirs) { |
| 582 | // workaround to determine if dir is under output directory |
| 583 | if strings.HasPrefix(dir, android.PathForOutput(ctx).String()) { |
| 584 | continue |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 585 | } |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 586 | exts := headerExts |
| 587 | // Glob all files under this special directory, because of C++ headers. |
| 588 | if strings.HasPrefix(dir, "external/libcxx/include") { |
| 589 | exts = []string{""} |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 590 | } |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 591 | for _, ext := range exts { |
| 592 | glob, err := ctx.GlobWithDeps(dir+"/**/*"+ext, nil) |
| 593 | if err != nil { |
| 594 | ctx.Errorf("%#v\n", err) |
| 595 | return |
| 596 | } |
| 597 | for _, header := range glob { |
| 598 | if strings.HasSuffix(header, "/") { |
| 599 | continue |
| 600 | } |
| 601 | headers[header] = true |
| 602 | } |
| 603 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 604 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 605 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 606 | for _, header := range android.SortedStringKeys(headers) { |
| 607 | installSnapshotFileFromPath(android.PathForSource(ctx, header), |
| 608 | filepath.Join(includeDir, header)) |
| 609 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 610 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 611 | isHeader := func(path string) bool { |
| 612 | for _, ext := range headerExts { |
| 613 | if strings.HasSuffix(path, ext) { |
| 614 | return true |
| 615 | } |
| 616 | } |
| 617 | return false |
| 618 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 619 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 620 | for _, path := range android.PathsToDirectorySortedPaths(android.FirstUniquePaths(generatedHeaders)) { |
| 621 | header := path.String() |
| 622 | |
| 623 | if !isHeader(header) { |
| 624 | continue |
| 625 | } |
| 626 | |
| 627 | installSnapshotFileFromPath(path, filepath.Join(includeDir, header)) |
| 628 | } |
| 629 | } |
| 630 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 631 | installSnapshotFileFromContent(android.JoinWithSuffix(vndkCoreLibraries, ".so", "\\n"), |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 632 | filepath.Join(configsDir, "vndkcore.libraries.txt")) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 633 | installSnapshotFileFromContent(android.JoinWithSuffix(vndkPrivateLibraries, ".so", "\\n"), |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 634 | filepath.Join(configsDir, "vndkprivate.libraries.txt")) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 635 | |
| 636 | var modulePathTxtBuilder strings.Builder |
| 637 | |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame] | 638 | modulePaths := modulePaths(ctx.Config()) |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame] | 639 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 640 | first := true |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 641 | for _, lib := range android.SortedStringKeys(modulePaths) { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 642 | if first { |
| 643 | first = false |
| 644 | } else { |
| 645 | modulePathTxtBuilder.WriteString("\\n") |
| 646 | } |
| 647 | modulePathTxtBuilder.WriteString(lib) |
| 648 | modulePathTxtBuilder.WriteString(".so ") |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame] | 649 | modulePathTxtBuilder.WriteString(modulePaths[lib]) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 650 | } |
| 651 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 652 | installSnapshotFileFromContent(modulePathTxtBuilder.String(), |
| 653 | filepath.Join(configsDir, "module_paths.txt")) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 654 | } |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 655 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 656 | func getVndkFileName(m *Module) (string, error) { |
| 657 | if library, ok := m.linker.(*libraryDecorator); ok { |
| 658 | return library.getLibNameHelper(m.BaseModuleName(), true) + ".so", nil |
| 659 | } |
| 660 | if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok { |
| 661 | return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true) + ".so", nil |
| 662 | } |
| 663 | 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] | 664 | } |
| 665 | |
| 666 | func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 667 | // Make uses LLNDK_LIBRARIES to determine which libraries to install. |
| 668 | // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN. |
| 669 | // Therefore, by removing the library here, we cause it to only be installed if libc |
| 670 | // depends on it. |
| 671 | installedLlndkLibraries := make(map[string]string) |
| 672 | for lib, filename := range llndkLibraries(ctx.Config()) { |
| 673 | if strings.HasPrefix(lib, "libclang_rt.hwasan-") { |
| 674 | continue |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 675 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 676 | installedLlndkLibraries[lib] = filename |
| 677 | } |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 678 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 679 | installListFile := func(list []string, fileName string) android.Path { |
| 680 | out := android.PathForOutput(ctx, "vndk", fileName) |
| 681 | ctx.Build(pctx, android.BuildParams{ |
| 682 | Rule: android.WriteFile, |
| 683 | Output: out, |
| 684 | Description: "Writing " + out.String(), |
| 685 | Args: map[string]string{ |
| 686 | "content": strings.Join(list, "\\n"), |
| 687 | }, |
| 688 | }) |
| 689 | return out |
| 690 | } |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 691 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 692 | c.installedLlndkLibraries = android.SortedStringKeys(installedLlndkLibraries) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 693 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 694 | llndk := android.SortedStringMapValues(installedLlndkLibraries) |
| 695 | vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config())) |
| 696 | vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config())) |
| 697 | vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config())) |
| 698 | vndkcorevariant := android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config())) |
| 699 | |
| 700 | c.llnkdLibrariesFile = installListFile(llndk, "llndk.libraries.txt") |
| 701 | c.vndkCoreLibrariesFile = installListFile(vndkcore, "vndkcore.libraries.txt") |
| 702 | c.vndkSpLibrariesFile = installListFile(vndksp, "vndksp.libraries.txt") |
| 703 | c.vndkPrivateLibrariesFile = installListFile(vndkprivate, "vndkprivate.libraries.txt") |
| 704 | c.vndkCoreVariantLibrariesFile = installListFile(vndkcorevariant, "vndkcorevariant.libraries.txt") |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 705 | |
| 706 | // merged & tagged & filtered-out(libclang_rt) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 707 | // Since each target have different set of libclang_rt.* files, |
| 708 | // keep the common set of files in vndk.libraries.txt |
| 709 | var merged []string |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 710 | filterOutLibClangRt := func(libList []string) (filtered []string) { |
| 711 | for _, lib := range libList { |
| 712 | if !strings.HasPrefix(lib, "libclang_rt.") { |
| 713 | filtered = append(filtered, lib) |
| 714 | } |
| 715 | } |
| 716 | return |
| 717 | } |
| 718 | merged = append(merged, addPrefix(filterOutLibClangRt(llndk), "LLNDK: ")...) |
| 719 | merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...) |
| 720 | merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...) |
| 721 | merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 722 | c.vndkLibrariesFile = installListFile(merged, "vndk.libraries.txt") |
| 723 | } |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 724 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 725 | func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 726 | // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if |
| 727 | // they been moved to an apex. |
| 728 | movedToApexLlndkLibraries := []string{} |
| 729 | for _, lib := range c.installedLlndkLibraries { |
| 730 | // Skip bionic libs, they are handled in different manner |
| 731 | if android.DirectlyInAnyApex(¬OnHostContext{}, lib) && !isBionic(lib) { |
| 732 | movedToApexLlndkLibraries = append(movedToApexLlndkLibraries, lib) |
| 733 | } |
| 734 | } |
| 735 | ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", strings.Join(movedToApexLlndkLibraries, " ")) |
| 736 | ctx.Strict("LLNDK_LIBRARIES", strings.Join(c.installedLlndkLibraries, " ")) |
| 737 | ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkCoreLibraries(ctx.Config())), " ")) |
| 738 | ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(android.SortedStringKeys(vndkSpLibraries(ctx.Config())), " ")) |
| 739 | ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())), " ")) |
| 740 | ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(android.SortedStringKeys(vndkUsingCoreVariantLibraries(ctx.Config())), " ")) |
| 741 | |
| 742 | ctx.Strict("LLNDK_LIBRARIES_FILE", c.llnkdLibrariesFile.String()) |
| 743 | ctx.Strict("VNDKCORE_LIBRARIES_FILE", c.vndkCoreLibrariesFile.String()) |
| 744 | ctx.Strict("VNDKSP_LIBRARIES_FILE", c.vndkSpLibrariesFile.String()) |
| 745 | ctx.Strict("VNDKPRIVATE_LIBRARIES_FILE", c.vndkPrivateLibrariesFile.String()) |
| 746 | ctx.Strict("VNDKCOREVARIANT_LIBRARIES_FILE", c.vndkCoreVariantLibrariesFile.String()) |
| 747 | |
| 748 | ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String()) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 749 | } |