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" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 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 | // |
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 |
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 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 210 | headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"} |
| 211 | ) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 212 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 213 | func vndkCoreLibraries(config android.Config) *[]string { |
| 214 | return config.Once(vndkCoreLibrariesKey, func() interface{} { |
| 215 | return &[]string{} |
| 216 | }).(*[]string) |
| 217 | } |
| 218 | |
| 219 | func vndkSpLibraries(config android.Config) *[]string { |
| 220 | return config.Once(vndkSpLibrariesKey, func() interface{} { |
| 221 | return &[]string{} |
| 222 | }).(*[]string) |
| 223 | } |
| 224 | |
| 225 | func llndkLibraries(config android.Config) *[]string { |
| 226 | return config.Once(llndkLibrariesKey, func() interface{} { |
| 227 | return &[]string{} |
| 228 | }).(*[]string) |
| 229 | } |
| 230 | |
| 231 | func vndkPrivateLibraries(config android.Config) *[]string { |
| 232 | return config.Once(vndkPrivateLibrariesKey, func() interface{} { |
| 233 | return &[]string{} |
| 234 | }).(*[]string) |
| 235 | } |
| 236 | |
| 237 | func vndkUsingCoreVariantLibraries(config android.Config) *[]string { |
| 238 | return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} { |
| 239 | return &[]string{} |
| 240 | }).(*[]string) |
| 241 | } |
| 242 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 243 | func modulePaths(config android.Config) map[string]string { |
| 244 | return config.Once(modulePathsKey, func() interface{} { |
| 245 | return make(map[string]string) |
| 246 | }).(map[string]string) |
| 247 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 248 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 249 | func vndkSnapshotOutputs(config android.Config) *android.RuleBuilderInstalls { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 250 | return config.Once(vndkSnapshotOutputsKey, func() interface{} { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 251 | return &android.RuleBuilderInstalls{} |
| 252 | }).(*android.RuleBuilderInstalls) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 253 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 254 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 255 | func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
| 256 | lib := m.linker.(*llndkStubDecorator) |
| 257 | name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 258 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 259 | vndkLibrariesLock.Lock() |
| 260 | defer vndkLibrariesLock.Unlock() |
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 | llndkLibraries := llndkLibraries(mctx.Config()) |
| 263 | if !inList(name, *llndkLibraries) { |
| 264 | *llndkLibraries = append(*llndkLibraries, name) |
| 265 | sort.Strings(*llndkLibraries) |
| 266 | } |
| 267 | if !Bool(lib.Properties.Vendor_available) { |
| 268 | vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config()) |
| 269 | if !inList(name, *vndkPrivateLibraries) { |
| 270 | *vndkPrivateLibraries = append(*vndkPrivateLibraries, name) |
| 271 | sort.Strings(*vndkPrivateLibraries) |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 275 | |
| 276 | func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
| 277 | name := strings.TrimPrefix(m.Name(), "prebuilt_") |
| 278 | |
| 279 | vndkLibrariesLock.Lock() |
| 280 | defer vndkLibrariesLock.Unlock() |
| 281 | |
| 282 | modulePaths := modulePaths(mctx.Config()) |
| 283 | if mctx.DeviceConfig().VndkUseCoreVariant() && !inList(name, config.VndkMustUseVendorVariantList) { |
| 284 | vndkUsingCoreVariantLibraries := vndkUsingCoreVariantLibraries(mctx.Config()) |
| 285 | if !inList(name, *vndkUsingCoreVariantLibraries) { |
| 286 | *vndkUsingCoreVariantLibraries = append(*vndkUsingCoreVariantLibraries, name) |
| 287 | sort.Strings(*vndkUsingCoreVariantLibraries) |
| 288 | } |
| 289 | } |
| 290 | if m.vndkdep.isVndkSp() { |
| 291 | vndkSpLibraries := vndkSpLibraries(mctx.Config()) |
| 292 | if !inList(name, *vndkSpLibraries) { |
| 293 | *vndkSpLibraries = append(*vndkSpLibraries, name) |
| 294 | sort.Strings(*vndkSpLibraries) |
| 295 | modulePaths[name] = mctx.ModuleDir() |
| 296 | } |
| 297 | } else { |
| 298 | vndkCoreLibraries := vndkCoreLibraries(mctx.Config()) |
| 299 | if !inList(name, *vndkCoreLibraries) { |
| 300 | *vndkCoreLibraries = append(*vndkCoreLibraries, name) |
| 301 | sort.Strings(*vndkCoreLibraries) |
| 302 | modulePaths[name] = mctx.ModuleDir() |
| 303 | } |
| 304 | } |
| 305 | if !Bool(m.VendorProperties.Vendor_available) { |
| 306 | vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config()) |
| 307 | if !inList(name, *vndkPrivateLibraries) { |
| 308 | *vndkPrivateLibraries = append(*vndkPrivateLibraries, name) |
| 309 | sort.Strings(*vndkPrivateLibraries) |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 315 | func VndkMutator(mctx android.BottomUpMutatorContext) { |
| 316 | m, ok := mctx.Module().(*Module) |
| 317 | if !ok { |
| 318 | return |
| 319 | } |
| 320 | |
| 321 | if !m.Enabled() { |
| 322 | return |
| 323 | } |
| 324 | |
Jooyung Han | 76106d9 | 2019-05-20 18:49:10 +0900 | [diff] [blame] | 325 | if m.isVndk() { |
| 326 | if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { |
| 327 | m.vndkdep.Properties.Vndk.Version = lib.version() |
| 328 | } else { |
| 329 | m.vndkdep.Properties.Vndk.Version = mctx.DeviceConfig().PlatformVndkVersion() |
| 330 | } |
| 331 | } |
| 332 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 333 | if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 334 | processLlndkLibrary(mctx, m) |
| 335 | return |
| 336 | } |
| 337 | |
| 338 | lib, is_lib := m.linker.(*libraryDecorator) |
| 339 | prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker) |
| 340 | |
| 341 | if (is_lib && lib.shared()) || (is_prebuilt_lib && prebuilt_lib.shared()) { |
| 342 | if m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { |
| 343 | processVndkLibrary(mctx, m) |
| 344 | return |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | func init() { |
| 350 | android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) |
| 351 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 352 | outputs := vndkSnapshotOutputs(ctx.Config()) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 353 | ctx.Strict("SOONG_VNDK_SNAPSHOT_FILES", outputs.String()) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 354 | }) |
| 355 | } |
| 356 | |
| 357 | func VndkSnapshotSingleton() android.Singleton { |
| 358 | return &vndkSnapshotSingleton{} |
| 359 | } |
| 360 | |
| 361 | type vndkSnapshotSingleton struct{} |
| 362 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 363 | func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 364 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot. |
| 365 | if ctx.DeviceConfig().VndkVersion() != "current" { |
| 366 | return |
| 367 | } |
| 368 | |
| 369 | if ctx.DeviceConfig().PlatformVndkVersion() == "" { |
| 370 | return |
| 371 | } |
| 372 | |
| 373 | if ctx.DeviceConfig().BoardVndkRuntimeDisable() { |
| 374 | return |
| 375 | } |
| 376 | |
| 377 | outputs := vndkSnapshotOutputs(ctx.Config()) |
| 378 | |
| 379 | snapshotDir := "vndk-snapshot" |
| 380 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 381 | vndkLibDir := make(map[android.ArchType]string) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 382 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 383 | snapshotVariantDir := ctx.DeviceConfig().DeviceArch() |
| 384 | for _, target := range ctx.Config().Targets[android.Android] { |
| 385 | dir := snapshotVariantDir |
| 386 | if ctx.DeviceConfig().BinderBitness() == "32" { |
| 387 | dir = filepath.Join(dir, "binder32") |
| 388 | } |
| 389 | arch := "arch-" + target.Arch.ArchType.String() |
| 390 | if target.Arch.ArchVariant != "" { |
| 391 | arch += "-" + target.Arch.ArchVariant |
| 392 | } |
| 393 | dir = filepath.Join(dir, arch) |
| 394 | vndkLibDir[target.Arch.ArchType] = dir |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 395 | } |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 396 | configsDir := filepath.Join(snapshotVariantDir, "configs") |
| 397 | noticeDir := filepath.Join(snapshotVariantDir, "NOTICE_FILES") |
| 398 | includeDir := filepath.Join(snapshotVariantDir, "include") |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 399 | noticeBuilt := make(map[string]bool) |
| 400 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 401 | installSnapshotFileFromPath := func(path android.Path, out string) { |
| 402 | ctx.Build(pctx, android.BuildParams{ |
| 403 | Rule: android.Cp, |
| 404 | Input: path, |
| 405 | Output: android.PathForOutput(ctx, snapshotDir, out), |
| 406 | Description: "vndk snapshot " + out, |
| 407 | Args: map[string]string{ |
| 408 | "cpFlags": "-f -L", |
| 409 | }, |
| 410 | }) |
| 411 | *outputs = append(*outputs, android.RuleBuilderInstall{ |
| 412 | From: android.PathForOutput(ctx, snapshotDir, out), |
| 413 | To: out, |
| 414 | }) |
| 415 | } |
| 416 | installSnapshotFileFromContent := func(content, out string) { |
| 417 | ctx.Build(pctx, android.BuildParams{ |
| 418 | Rule: android.WriteFile, |
| 419 | Output: android.PathForOutput(ctx, snapshotDir, out), |
| 420 | Description: "vndk snapshot " + out, |
| 421 | Args: map[string]string{ |
| 422 | "content": content, |
| 423 | }, |
| 424 | }) |
| 425 | *outputs = append(*outputs, android.RuleBuilderInstall{ |
| 426 | From: android.PathForOutput(ctx, snapshotDir, out), |
| 427 | To: out, |
| 428 | }) |
| 429 | } |
| 430 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 431 | tryBuildNotice := func(m *Module) { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 432 | name := ctx.ModuleName(m) + ".so.txt" |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 433 | |
| 434 | if _, ok := noticeBuilt[name]; ok { |
| 435 | return |
| 436 | } |
| 437 | |
| 438 | noticeBuilt[name] = true |
| 439 | |
| 440 | if m.NoticeFile().Valid() { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 441 | installSnapshotFileFromPath(m.NoticeFile().Path(), filepath.Join(noticeDir, name)) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
| 445 | vndkCoreLibraries := vndkCoreLibraries(ctx.Config()) |
| 446 | vndkSpLibraries := vndkSpLibraries(ctx.Config()) |
| 447 | vndkPrivateLibraries := vndkPrivateLibraries(ctx.Config()) |
| 448 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 449 | var generatedHeaders android.Paths |
| 450 | includeDirs := make(map[string]bool) |
| 451 | |
| 452 | type vndkSnapshotLibraryInterface interface { |
| 453 | exportedFlagsProducer |
| 454 | libraryInterface |
| 455 | } |
| 456 | |
| 457 | var _ vndkSnapshotLibraryInterface = (*prebuiltLibraryLinker)(nil) |
| 458 | var _ vndkSnapshotLibraryInterface = (*libraryDecorator)(nil) |
| 459 | |
| 460 | installVndkSnapshotLib := func(m *Module, l vndkSnapshotLibraryInterface, dir string) bool { |
| 461 | name := ctx.ModuleName(m) |
| 462 | libOut := filepath.Join(dir, name+".so") |
| 463 | |
| 464 | installSnapshotFileFromPath(m.outputFile.Path(), libOut) |
| 465 | tryBuildNotice(m) |
| 466 | |
| 467 | if ctx.Config().VndkSnapshotBuildArtifacts() { |
| 468 | prop := struct { |
| 469 | ExportedDirs []string `json:",omitempty"` |
| 470 | ExportedSystemDirs []string `json:",omitempty"` |
| 471 | ExportedFlags []string `json:",omitempty"` |
| 472 | RelativeInstallPath string `json:",omitempty"` |
| 473 | }{} |
| 474 | prop.ExportedFlags = l.exportedFlags() |
| 475 | prop.ExportedDirs = l.exportedDirs() |
| 476 | prop.ExportedSystemDirs = l.exportedSystemDirs() |
| 477 | prop.RelativeInstallPath = m.RelativeInstallPath() |
| 478 | |
| 479 | propOut := libOut + ".json" |
| 480 | |
| 481 | j, err := json.Marshal(prop) |
| 482 | if err != nil { |
| 483 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 484 | return false |
| 485 | } |
| 486 | |
| 487 | installSnapshotFileFromContent(string(j), propOut) |
| 488 | } |
| 489 | return true |
| 490 | } |
| 491 | |
| 492 | isVndkSnapshotLibrary := func(m *Module) (i vndkSnapshotLibraryInterface, libDir string, isVndkSnapshotLib bool) { |
| 493 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 494 | return nil, "", false |
| 495 | } |
| 496 | if !m.useVndk() || !m.IsForPlatform() || !m.installable() { |
| 497 | return nil, "", false |
| 498 | } |
| 499 | l, ok := m.linker.(vndkSnapshotLibraryInterface) |
| 500 | if !ok || !l.shared() { |
| 501 | return nil, "", false |
| 502 | } |
| 503 | name := ctx.ModuleName(m) |
| 504 | if inList(name, *vndkCoreLibraries) { |
| 505 | return l, filepath.Join("shared", "vndk-core"), true |
| 506 | } else if inList(name, *vndkSpLibraries) { |
| 507 | return l, filepath.Join("shared", "vndk-sp"), true |
| 508 | } else { |
| 509 | return nil, "", false |
| 510 | } |
| 511 | } |
| 512 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 513 | ctx.VisitAllModules(func(module android.Module) { |
| 514 | m, ok := module.(*Module) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 515 | if !ok || !m.Enabled() { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 516 | return |
| 517 | } |
| 518 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 519 | baseDir, ok := vndkLibDir[m.Target().Arch.ArchType] |
| 520 | if !ok { |
dimitry | 51ea18a | 2019-05-20 10:39:52 +0200 | [diff] [blame] | 521 | return |
| 522 | } |
| 523 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 524 | l, libDir, ok := isVndkSnapshotLibrary(m) |
| 525 | if !ok { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 526 | return |
| 527 | } |
| 528 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 529 | if !installVndkSnapshotLib(m, l, filepath.Join(baseDir, libDir)) { |
| 530 | return |
| 531 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 532 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 533 | generatedHeaders = append(generatedHeaders, l.exportedDeps()...) |
| 534 | for _, dir := range append(l.exportedDirs(), l.exportedSystemDirs()...) { |
| 535 | includeDirs[dir] = true |
| 536 | } |
| 537 | }) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 538 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 539 | if ctx.Config().VndkSnapshotBuildArtifacts() { |
| 540 | headers := make(map[string]bool) |
| 541 | |
| 542 | for _, dir := range android.SortedStringKeys(includeDirs) { |
| 543 | // workaround to determine if dir is under output directory |
| 544 | if strings.HasPrefix(dir, android.PathForOutput(ctx).String()) { |
| 545 | continue |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 546 | } |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 547 | exts := headerExts |
| 548 | // Glob all files under this special directory, because of C++ headers. |
| 549 | if strings.HasPrefix(dir, "external/libcxx/include") { |
| 550 | exts = []string{""} |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 551 | } |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 552 | for _, ext := range exts { |
| 553 | glob, err := ctx.GlobWithDeps(dir+"/**/*"+ext, nil) |
| 554 | if err != nil { |
| 555 | ctx.Errorf("%#v\n", err) |
| 556 | return |
| 557 | } |
| 558 | for _, header := range glob { |
| 559 | if strings.HasSuffix(header, "/") { |
| 560 | continue |
| 561 | } |
| 562 | headers[header] = true |
| 563 | } |
| 564 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 565 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 566 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 567 | for _, header := range android.SortedStringKeys(headers) { |
| 568 | installSnapshotFileFromPath(android.PathForSource(ctx, header), |
| 569 | filepath.Join(includeDir, header)) |
| 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 | isHeader := func(path string) bool { |
| 573 | for _, ext := range headerExts { |
| 574 | if strings.HasSuffix(path, ext) { |
| 575 | return true |
| 576 | } |
| 577 | } |
| 578 | return false |
| 579 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 580 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 581 | for _, path := range android.PathsToDirectorySortedPaths(android.FirstUniquePaths(generatedHeaders)) { |
| 582 | header := path.String() |
| 583 | |
| 584 | if !isHeader(header) { |
| 585 | continue |
| 586 | } |
| 587 | |
| 588 | installSnapshotFileFromPath(path, filepath.Join(includeDir, header)) |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | installSnapshotFileFromContent(android.JoinWithSuffix(*vndkCoreLibraries, ".so", "\\n"), |
| 593 | filepath.Join(configsDir, "vndkcore.libraries.txt")) |
| 594 | installSnapshotFileFromContent(android.JoinWithSuffix(*vndkPrivateLibraries, ".so", "\\n"), |
| 595 | filepath.Join(configsDir, "vndkprivate.libraries.txt")) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 596 | |
| 597 | var modulePathTxtBuilder strings.Builder |
| 598 | |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame] | 599 | modulePaths := modulePaths(ctx.Config()) |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame] | 600 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 601 | first := true |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 602 | for _, lib := range android.SortedStringKeys(modulePaths) { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 603 | if first { |
| 604 | first = false |
| 605 | } else { |
| 606 | modulePathTxtBuilder.WriteString("\\n") |
| 607 | } |
| 608 | modulePathTxtBuilder.WriteString(lib) |
| 609 | modulePathTxtBuilder.WriteString(".so ") |
Colin Cross | 4c2c46f | 2019-06-03 15:26:05 -0700 | [diff] [blame] | 610 | modulePathTxtBuilder.WriteString(modulePaths[lib]) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 611 | } |
| 612 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame^] | 613 | installSnapshotFileFromContent(modulePathTxtBuilder.String(), |
| 614 | filepath.Join(configsDir, "module_paths.txt")) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 615 | } |