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 ( |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 18 | "errors" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 19 | "fmt" |
| 20 | "path/filepath" |
Colin Cross | 766efbc | 2017-08-17 14:55:15 -0700 | [diff] [blame] | 21 | "sort" |
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 | // |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 34 | // `vendor_vailable` must be explicitly set to either true or |
| 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 |
Jooyung Han | 76106d9 | 2019-05-20 18:49:10 +0900 | [diff] [blame] | 52 | |
| 53 | // for vndk_prebuilt_shared, this is set by "version" property. |
| 54 | // Otherwise, this is set as PLATFORM_VNDK_VERSION. |
| 55 | Version string `blueprint:"mutated"` |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | type vndkdep struct { |
| 60 | Properties VndkProperties |
| 61 | } |
| 62 | |
| 63 | func (vndk *vndkdep) props() []interface{} { |
| 64 | return []interface{}{&vndk.Properties} |
| 65 | } |
| 66 | |
| 67 | func (vndk *vndkdep) begin(ctx BaseModuleContext) {} |
| 68 | |
| 69 | func (vndk *vndkdep) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 70 | return deps |
| 71 | } |
| 72 | |
| 73 | func (vndk *vndkdep) isVndk() bool { |
| 74 | return Bool(vndk.Properties.Vndk.Enabled) |
| 75 | } |
| 76 | |
| 77 | func (vndk *vndkdep) isVndkSp() bool { |
| 78 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 79 | } |
| 80 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 81 | func (vndk *vndkdep) isVndkExt() bool { |
| 82 | return vndk.Properties.Vndk.Extends != nil |
| 83 | } |
| 84 | |
| 85 | func (vndk *vndkdep) getVndkExtendsModuleName() string { |
| 86 | return String(vndk.Properties.Vndk.Extends) |
| 87 | } |
| 88 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 89 | func (vndk *vndkdep) typeName() string { |
| 90 | if !vndk.isVndk() { |
| 91 | return "native:vendor" |
| 92 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 93 | if !vndk.isVndkExt() { |
| 94 | if !vndk.isVndkSp() { |
| 95 | return "native:vendor:vndk" |
| 96 | } |
| 97 | return "native:vendor:vndksp" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 98 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 99 | if !vndk.isVndkSp() { |
| 100 | return "native:vendor:vndkext" |
| 101 | } |
| 102 | return "native:vendor:vndkspext" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 103 | } |
| 104 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 105 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag dependencyTag) { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 106 | if to.linker == nil { |
| 107 | return |
| 108 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 109 | if !vndk.isVndk() { |
| 110 | // Non-VNDK modules (those installed to /vendor) can't depend on modules marked with |
| 111 | // vendor_available: false. |
| 112 | violation := false |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 113 | if lib, ok := to.linker.(*llndkStubDecorator); ok && !Bool(lib.Properties.Vendor_available) { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 114 | violation = true |
| 115 | } else { |
| 116 | if _, ok := to.linker.(libraryInterface); ok && to.VendorProperties.Vendor_available != nil && !Bool(to.VendorProperties.Vendor_available) { |
| 117 | // Vendor_available == nil && !Bool(Vendor_available) should be okay since |
| 118 | // it means a vendor-only library which is a valid dependency for non-VNDK |
| 119 | // modules. |
| 120 | violation = true |
| 121 | } |
| 122 | } |
| 123 | if violation { |
| 124 | ctx.ModuleErrorf("Vendor module that is not VNDK should not link to %q which is marked as `vendor_available: false`", to.Name()) |
| 125 | } |
| 126 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 127 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 128 | // Check only shared libraries. |
| 129 | // Other (static and LL-NDK) libraries are allowed to link. |
| 130 | return |
| 131 | } |
| 132 | if !to.Properties.UseVndk { |
| 133 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 134 | vndk.typeName(), to.Name()) |
| 135 | return |
| 136 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 137 | if tag == vndkExtDepTag { |
| 138 | // Ensure `extends: "name"` property refers a vndk module that has vendor_available |
| 139 | // and has identical vndk properties. |
| 140 | if to.vndkdep == nil || !to.vndkdep.isVndk() { |
| 141 | ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name()) |
| 142 | return |
| 143 | } |
| 144 | if vndk.isVndkSp() != to.vndkdep.isVndkSp() { |
| 145 | ctx.ModuleErrorf( |
| 146 | "`extends` refers a module %q with mismatched support_system_process", |
| 147 | to.Name()) |
| 148 | return |
| 149 | } |
| 150 | if !Bool(to.VendorProperties.Vendor_available) { |
| 151 | ctx.ModuleErrorf( |
| 152 | "`extends` refers module %q which does not have `vendor_available: true`", |
| 153 | to.Name()) |
| 154 | return |
| 155 | } |
| 156 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 157 | if to.vndkdep == nil { |
| 158 | return |
| 159 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 160 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 161 | // Check the dependencies of VNDK shared libraries. |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 162 | if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil { |
| 163 | ctx.ModuleErrorf("(%s) should not link to %q (%s): %v", |
| 164 | vndk.typeName(), to.Name(), to.vndkdep.typeName(), err) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 165 | return |
| 166 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 167 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 168 | |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 169 | func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 170 | // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules. |
| 171 | if from.isVndkExt() { |
| 172 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 173 | if to.isVndk() && !to.isVndkSp() { |
| 174 | return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions") |
| 175 | } |
| 176 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 177 | } |
| 178 | // 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] | 179 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 180 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 181 | if from.isVndk() { |
| 182 | if to.isVndkExt() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 183 | 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] | 184 | } |
| 185 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 186 | if !to.isVndkSp() { |
| 187 | return errors.New("VNDK-SP must only depend on VNDK-SP") |
| 188 | } |
| 189 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 190 | } |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 191 | if !to.isVndk() { |
| 192 | return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP") |
| 193 | } |
| 194 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 195 | } |
| 196 | // 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] | 197 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 198 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 199 | |
| 200 | var ( |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 201 | vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires") |
| 202 | vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires") |
| 203 | llndkLibrariesKey = android.NewOnceKey("llndkLibrarires") |
| 204 | vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires") |
| 205 | vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibrarires") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 206 | modulePathsKey = android.NewOnceKey("modulePaths") |
| 207 | vndkSnapshotOutputsKey = android.NewOnceKey("vndkSnapshotOutputs") |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 208 | vndkLibrariesLock sync.Mutex |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 209 | ) |
| 210 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 211 | type vndkSnapshotOutputPaths struct { |
| 212 | configs android.Paths |
| 213 | notices android.Paths |
| 214 | vndkCoreLibs android.Paths |
| 215 | vndkCoreLibs2nd android.Paths |
| 216 | vndkSpLibs android.Paths |
| 217 | vndkSpLibs2nd android.Paths |
| 218 | } |
| 219 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 220 | func vndkCoreLibraries(config android.Config) *[]string { |
| 221 | return config.Once(vndkCoreLibrariesKey, func() interface{} { |
| 222 | return &[]string{} |
| 223 | }).(*[]string) |
| 224 | } |
| 225 | |
| 226 | func vndkSpLibraries(config android.Config) *[]string { |
| 227 | return config.Once(vndkSpLibrariesKey, func() interface{} { |
| 228 | return &[]string{} |
| 229 | }).(*[]string) |
| 230 | } |
| 231 | |
| 232 | func llndkLibraries(config android.Config) *[]string { |
| 233 | return config.Once(llndkLibrariesKey, func() interface{} { |
| 234 | return &[]string{} |
| 235 | }).(*[]string) |
| 236 | } |
| 237 | |
| 238 | func vndkPrivateLibraries(config android.Config) *[]string { |
| 239 | return config.Once(vndkPrivateLibrariesKey, func() interface{} { |
| 240 | return &[]string{} |
| 241 | }).(*[]string) |
| 242 | } |
| 243 | |
| 244 | func vndkUsingCoreVariantLibraries(config android.Config) *[]string { |
| 245 | return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} { |
| 246 | return &[]string{} |
| 247 | }).(*[]string) |
| 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 | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 256 | func vndkSnapshotOutputs(config android.Config) *vndkSnapshotOutputPaths { |
| 257 | return config.Once(vndkSnapshotOutputsKey, func() interface{} { |
| 258 | return &vndkSnapshotOutputPaths{} |
| 259 | }).(*vndkSnapshotOutputPaths) |
| 260 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 261 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 262 | func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
| 263 | lib := m.linker.(*llndkStubDecorator) |
| 264 | name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 265 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 266 | vndkLibrariesLock.Lock() |
| 267 | defer vndkLibrariesLock.Unlock() |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 268 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 269 | llndkLibraries := llndkLibraries(mctx.Config()) |
| 270 | if !inList(name, *llndkLibraries) { |
| 271 | *llndkLibraries = append(*llndkLibraries, name) |
| 272 | sort.Strings(*llndkLibraries) |
| 273 | } |
| 274 | if !Bool(lib.Properties.Vendor_available) { |
| 275 | vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config()) |
| 276 | if !inList(name, *vndkPrivateLibraries) { |
| 277 | *vndkPrivateLibraries = append(*vndkPrivateLibraries, name) |
| 278 | sort.Strings(*vndkPrivateLibraries) |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 282 | |
| 283 | func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
| 284 | name := strings.TrimPrefix(m.Name(), "prebuilt_") |
| 285 | |
| 286 | vndkLibrariesLock.Lock() |
| 287 | defer vndkLibrariesLock.Unlock() |
| 288 | |
| 289 | modulePaths := modulePaths(mctx.Config()) |
| 290 | if mctx.DeviceConfig().VndkUseCoreVariant() && !inList(name, config.VndkMustUseVendorVariantList) { |
| 291 | vndkUsingCoreVariantLibraries := vndkUsingCoreVariantLibraries(mctx.Config()) |
| 292 | if !inList(name, *vndkUsingCoreVariantLibraries) { |
| 293 | *vndkUsingCoreVariantLibraries = append(*vndkUsingCoreVariantLibraries, name) |
| 294 | sort.Strings(*vndkUsingCoreVariantLibraries) |
| 295 | } |
| 296 | } |
| 297 | if m.vndkdep.isVndkSp() { |
| 298 | vndkSpLibraries := vndkSpLibraries(mctx.Config()) |
| 299 | if !inList(name, *vndkSpLibraries) { |
| 300 | *vndkSpLibraries = append(*vndkSpLibraries, name) |
| 301 | sort.Strings(*vndkSpLibraries) |
| 302 | modulePaths[name] = mctx.ModuleDir() |
| 303 | } |
| 304 | } else { |
| 305 | vndkCoreLibraries := vndkCoreLibraries(mctx.Config()) |
| 306 | if !inList(name, *vndkCoreLibraries) { |
| 307 | *vndkCoreLibraries = append(*vndkCoreLibraries, name) |
| 308 | sort.Strings(*vndkCoreLibraries) |
| 309 | modulePaths[name] = mctx.ModuleDir() |
| 310 | } |
| 311 | } |
| 312 | if !Bool(m.VendorProperties.Vendor_available) { |
| 313 | vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config()) |
| 314 | if !inList(name, *vndkPrivateLibraries) { |
| 315 | *vndkPrivateLibraries = append(*vndkPrivateLibraries, name) |
| 316 | sort.Strings(*vndkPrivateLibraries) |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 322 | func VndkMutator(mctx android.BottomUpMutatorContext) { |
| 323 | m, ok := mctx.Module().(*Module) |
| 324 | if !ok { |
| 325 | return |
| 326 | } |
| 327 | |
| 328 | if !m.Enabled() { |
| 329 | return |
| 330 | } |
| 331 | |
Jooyung Han | 76106d9 | 2019-05-20 18:49:10 +0900 | [diff] [blame] | 332 | if m.isVndk() { |
| 333 | if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { |
| 334 | m.vndkdep.Properties.Vndk.Version = lib.version() |
| 335 | } else { |
| 336 | m.vndkdep.Properties.Vndk.Version = mctx.DeviceConfig().PlatformVndkVersion() |
| 337 | } |
| 338 | } |
| 339 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 340 | if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 341 | processLlndkLibrary(mctx, m) |
| 342 | return |
| 343 | } |
| 344 | |
| 345 | lib, is_lib := m.linker.(*libraryDecorator) |
| 346 | prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker) |
| 347 | |
| 348 | if (is_lib && lib.shared()) || (is_prebuilt_lib && prebuilt_lib.shared()) { |
| 349 | if m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { |
| 350 | processVndkLibrary(mctx, m) |
| 351 | return |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | func init() { |
| 357 | android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) |
| 358 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 359 | outputs := vndkSnapshotOutputs(ctx.Config()) |
| 360 | |
| 361 | ctx.Strict("SOONG_VNDK_SNAPSHOT_CONFIGS", strings.Join(outputs.configs.Strings(), " ")) |
| 362 | ctx.Strict("SOONG_VNDK_SNAPSHOT_NOTICES", strings.Join(outputs.notices.Strings(), " ")) |
| 363 | ctx.Strict("SOONG_VNDK_SNAPSHOT_CORE_LIBS", strings.Join(outputs.vndkCoreLibs.Strings(), " ")) |
| 364 | ctx.Strict("SOONG_VNDK_SNAPSHOT_SP_LIBS", strings.Join(outputs.vndkSpLibs.Strings(), " ")) |
| 365 | ctx.Strict("SOONG_VNDK_SNAPSHOT_CORE_LIBS_2ND", strings.Join(outputs.vndkCoreLibs2nd.Strings(), " ")) |
| 366 | ctx.Strict("SOONG_VNDK_SNAPSHOT_SP_LIBS_2ND", strings.Join(outputs.vndkSpLibs2nd.Strings(), " ")) |
| 367 | }) |
| 368 | } |
| 369 | |
| 370 | func VndkSnapshotSingleton() android.Singleton { |
| 371 | return &vndkSnapshotSingleton{} |
| 372 | } |
| 373 | |
| 374 | type vndkSnapshotSingleton struct{} |
| 375 | |
| 376 | func installVndkSnapshotLib(ctx android.SingletonContext, name string, module *Module, dir string) android.Path { |
| 377 | if !module.outputFile.Valid() { |
| 378 | panic(fmt.Errorf("module %s has no outputFile\n", name)) |
| 379 | } |
| 380 | |
| 381 | out := android.PathForOutput(ctx, dir, name+".so") |
| 382 | |
| 383 | ctx.Build(pctx, android.BuildParams{ |
| 384 | Rule: android.Cp, |
| 385 | Input: module.outputFile.Path(), |
| 386 | Output: out, |
| 387 | Description: "vndk snapshot " + dir + "/" + name + ".so", |
| 388 | Args: map[string]string{ |
| 389 | "cpFlags": "-f -L", |
| 390 | }, |
| 391 | }) |
| 392 | |
| 393 | return out |
| 394 | } |
| 395 | |
| 396 | func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 397 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot. |
| 398 | if ctx.DeviceConfig().VndkVersion() != "current" { |
| 399 | return |
| 400 | } |
| 401 | |
| 402 | if ctx.DeviceConfig().PlatformVndkVersion() == "" { |
| 403 | return |
| 404 | } |
| 405 | |
| 406 | if ctx.DeviceConfig().BoardVndkRuntimeDisable() { |
| 407 | return |
| 408 | } |
| 409 | |
| 410 | outputs := vndkSnapshotOutputs(ctx.Config()) |
| 411 | |
| 412 | snapshotDir := "vndk-snapshot" |
| 413 | |
| 414 | var vndkLibPath, vndkLib2ndPath string |
| 415 | |
| 416 | snapshotVariantPath := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) |
| 417 | if ctx.DeviceConfig().BinderBitness() == "32" { |
| 418 | vndkLibPath = filepath.Join(snapshotVariantPath, "binder32", fmt.Sprintf( |
| 419 | "arch-%s-%s", ctx.DeviceConfig().DeviceArch(), ctx.DeviceConfig().DeviceArchVariant())) |
| 420 | vndkLib2ndPath = filepath.Join(snapshotVariantPath, "binder32", fmt.Sprintf( |
| 421 | "arch-%s-%s", ctx.DeviceConfig().DeviceSecondaryArch(), ctx.DeviceConfig().DeviceSecondaryArchVariant())) |
| 422 | } else { |
| 423 | vndkLibPath = filepath.Join(snapshotVariantPath, fmt.Sprintf( |
| 424 | "arch-%s-%s", ctx.DeviceConfig().DeviceArch(), ctx.DeviceConfig().DeviceArchVariant())) |
| 425 | vndkLib2ndPath = filepath.Join(snapshotVariantPath, fmt.Sprintf( |
| 426 | "arch-%s-%s", ctx.DeviceConfig().DeviceSecondaryArch(), ctx.DeviceConfig().DeviceSecondaryArchVariant())) |
| 427 | } |
| 428 | |
| 429 | vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core") |
| 430 | vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp") |
| 431 | vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") |
| 432 | vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") |
| 433 | noticePath := filepath.Join(snapshotVariantPath, "NOTICE_FILES") |
| 434 | noticeBuilt := make(map[string]bool) |
| 435 | |
| 436 | tryBuildNotice := func(m *Module) { |
| 437 | name := ctx.ModuleName(m) |
| 438 | |
| 439 | if _, ok := noticeBuilt[name]; ok { |
| 440 | return |
| 441 | } |
| 442 | |
| 443 | noticeBuilt[name] = true |
| 444 | |
| 445 | if m.NoticeFile().Valid() { |
| 446 | out := android.PathForOutput(ctx, noticePath, name+".so.txt") |
| 447 | ctx.Build(pctx, android.BuildParams{ |
| 448 | Rule: android.Cp, |
| 449 | Input: m.NoticeFile().Path(), |
| 450 | Output: out, |
| 451 | Description: "vndk snapshot notice " + name + ".so.txt", |
| 452 | Args: map[string]string{ |
| 453 | "cpFlags": "-f -L", |
| 454 | }, |
| 455 | }) |
| 456 | outputs.notices = append(outputs.notices, out) |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | vndkCoreLibraries := vndkCoreLibraries(ctx.Config()) |
| 461 | vndkSpLibraries := vndkSpLibraries(ctx.Config()) |
| 462 | vndkPrivateLibraries := vndkPrivateLibraries(ctx.Config()) |
| 463 | |
| 464 | ctx.VisitAllModules(func(module android.Module) { |
| 465 | m, ok := module.(*Module) |
| 466 | if !ok || !m.Enabled() || !m.useVndk() || !m.installable() { |
| 467 | return |
| 468 | } |
| 469 | |
dimitry | 51ea18a | 2019-05-20 10:39:52 +0200 | [diff] [blame] | 470 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 471 | return |
| 472 | } |
| 473 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 474 | lib, is_lib := m.linker.(*libraryDecorator) |
| 475 | prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker) |
| 476 | |
| 477 | if !(is_lib && lib.shared()) && !(is_prebuilt_lib && prebuilt_lib.shared()) { |
| 478 | return |
| 479 | } |
| 480 | |
| 481 | is_2nd := m.Target().Arch.ArchType != ctx.Config().DevicePrimaryArchType() |
| 482 | |
| 483 | name := ctx.ModuleName(module) |
| 484 | |
| 485 | if inList(name, *vndkCoreLibraries) { |
| 486 | if is_2nd { |
| 487 | out := installVndkSnapshotLib(ctx, name, m, vndkCoreLib2ndPath) |
| 488 | outputs.vndkCoreLibs2nd = append(outputs.vndkCoreLibs2nd, out) |
| 489 | } else { |
| 490 | out := installVndkSnapshotLib(ctx, name, m, vndkCoreLibPath) |
| 491 | outputs.vndkCoreLibs = append(outputs.vndkCoreLibs, out) |
| 492 | } |
| 493 | tryBuildNotice(m) |
| 494 | } else if inList(name, *vndkSpLibraries) { |
| 495 | if is_2nd { |
| 496 | out := installVndkSnapshotLib(ctx, name, m, vndkSpLib2ndPath) |
| 497 | outputs.vndkSpLibs2nd = append(outputs.vndkSpLibs2nd, out) |
| 498 | } else { |
| 499 | out := installVndkSnapshotLib(ctx, name, m, vndkSpLibPath) |
| 500 | outputs.vndkSpLibs = append(outputs.vndkSpLibs, out) |
| 501 | } |
| 502 | tryBuildNotice(m) |
| 503 | } |
| 504 | }) |
| 505 | |
| 506 | configsPath := filepath.Join(snapshotVariantPath, "configs") |
| 507 | vndkCoreTxt := android.PathForOutput(ctx, configsPath, "vndkcore.libraries.txt") |
| 508 | vndkPrivateTxt := android.PathForOutput(ctx, configsPath, "vndkprivate.libraries.txt") |
| 509 | modulePathTxt := android.PathForOutput(ctx, configsPath, "module_paths.txt") |
| 510 | |
| 511 | ctx.Build(pctx, android.BuildParams{ |
| 512 | Rule: android.WriteFile, |
| 513 | Output: vndkCoreTxt, |
| 514 | Description: "vndk snapshot vndkcore.libraries.txt", |
| 515 | Args: map[string]string{ |
| 516 | "content": android.JoinWithSuffix(*vndkCoreLibraries, ".so", "\\n"), |
| 517 | }, |
| 518 | }) |
| 519 | outputs.configs = append(outputs.configs, vndkCoreTxt) |
| 520 | |
| 521 | ctx.Build(pctx, android.BuildParams{ |
| 522 | Rule: android.WriteFile, |
| 523 | Output: vndkPrivateTxt, |
| 524 | Description: "vndk snapshot vndkprivate.libraries.txt", |
| 525 | Args: map[string]string{ |
| 526 | "content": android.JoinWithSuffix(*vndkPrivateLibraries, ".so", "\\n"), |
| 527 | }, |
| 528 | }) |
| 529 | outputs.configs = append(outputs.configs, vndkPrivateTxt) |
| 530 | |
| 531 | var modulePathTxtBuilder strings.Builder |
| 532 | |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame^] | 533 | modulePaths := modulePaths(ctx.Config()) |
| 534 | var libs []string |
| 535 | for lib := range modulePaths { |
| 536 | libs = append(libs, lib) |
| 537 | } |
| 538 | sort.Strings(libs) |
| 539 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 540 | first := true |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame^] | 541 | for _, lib := range libs { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 542 | if first { |
| 543 | first = false |
| 544 | } else { |
| 545 | modulePathTxtBuilder.WriteString("\\n") |
| 546 | } |
| 547 | modulePathTxtBuilder.WriteString(lib) |
| 548 | modulePathTxtBuilder.WriteString(".so ") |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame^] | 549 | modulePathTxtBuilder.WriteString(modulePaths[lib]) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | ctx.Build(pctx, android.BuildParams{ |
| 553 | Rule: android.WriteFile, |
| 554 | Output: modulePathTxt, |
| 555 | Description: "vndk snapshot module_paths.txt", |
| 556 | Args: map[string]string{ |
| 557 | "content": modulePathTxtBuilder.String(), |
| 558 | }, |
| 559 | }) |
| 560 | outputs.configs = append(outputs.configs, modulePathTxt) |
| 561 | } |