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