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" |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 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" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 27 | "android/soong/etc" |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 28 | "android/soong/snapshot" |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 29 | |
| 30 | "github.com/google/blueprint" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 31 | ) |
| 32 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 33 | const ( |
| 34 | llndkLibrariesTxt = "llndk.libraries.txt" |
| 35 | vndkCoreLibrariesTxt = "vndkcore.libraries.txt" |
| 36 | vndkSpLibrariesTxt = "vndksp.libraries.txt" |
| 37 | vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 38 | vndkProductLibrariesTxt = "vndkproduct.libraries.txt" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 39 | vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt" |
| 40 | ) |
| 41 | |
| 42 | func VndkLibrariesTxtModules(vndkVersion string) []string { |
| 43 | if vndkVersion == "current" { |
| 44 | return []string{ |
| 45 | llndkLibrariesTxt, |
| 46 | vndkCoreLibrariesTxt, |
| 47 | vndkSpLibrariesTxt, |
| 48 | vndkPrivateLibrariesTxt, |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 49 | vndkProductLibrariesTxt, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | // Snapshot vndks have their own *.libraries.VER.txt files. |
| 53 | // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt" |
| 54 | return []string{ |
| 55 | insertVndkVersion(llndkLibrariesTxt, vndkVersion), |
| 56 | insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion), |
| 57 | insertVndkVersion(vndkSpLibrariesTxt, vndkVersion), |
| 58 | insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion), |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 59 | insertVndkVersion(vndkProductLibrariesTxt, vndkVersion), |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 63 | type VndkProperties struct { |
| 64 | Vndk struct { |
| 65 | // declared as a VNDK or VNDK-SP module. The vendor variant |
| 66 | // will be installed in /system instead of /vendor partition. |
| 67 | // |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 68 | // `vendor_available` and `product_available` must be explicitly |
| 69 | // set to either true or false together with `vndk: {enabled: true}`. |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 70 | Enabled *bool |
| 71 | |
| 72 | // declared as a VNDK-SP module, which is a subset of VNDK. |
| 73 | // |
| 74 | // `vndk: { enabled: true }` must set together. |
| 75 | // |
| 76 | // All these modules are allowed to link to VNDK-SP or LL-NDK |
| 77 | // modules only. Other dependency will cause link-type errors. |
| 78 | // |
| 79 | // If `support_system_process` is not set or set to false, |
| 80 | // the module is VNDK-core and can link to other VNDK-core, |
| 81 | // VNDK-SP or LL-NDK modules only. |
| 82 | Support_system_process *bool |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 83 | |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 84 | // declared as a VNDK-private module. |
| 85 | // This module still creates the vendor and product variants refering |
| 86 | // to the `vendor_available: true` and `product_available: true` |
| 87 | // properties. However, it is only available to the other VNDK modules |
| 88 | // but not to the non-VNDK vendor or product modules. |
| 89 | Private *bool |
| 90 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 91 | // Extending another module |
| 92 | Extends *string |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | type vndkdep struct { |
| 97 | Properties VndkProperties |
| 98 | } |
| 99 | |
| 100 | func (vndk *vndkdep) props() []interface{} { |
| 101 | return []interface{}{&vndk.Properties} |
| 102 | } |
| 103 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 104 | func (vndk *vndkdep) isVndk() bool { |
| 105 | return Bool(vndk.Properties.Vndk.Enabled) |
| 106 | } |
| 107 | |
| 108 | func (vndk *vndkdep) isVndkSp() bool { |
| 109 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 110 | } |
| 111 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 112 | func (vndk *vndkdep) isVndkExt() bool { |
| 113 | return vndk.Properties.Vndk.Extends != nil |
| 114 | } |
| 115 | |
| 116 | func (vndk *vndkdep) getVndkExtendsModuleName() string { |
| 117 | return String(vndk.Properties.Vndk.Extends) |
| 118 | } |
| 119 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 120 | func (vndk *vndkdep) typeName() string { |
| 121 | if !vndk.isVndk() { |
| 122 | return "native:vendor" |
| 123 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 124 | if !vndk.isVndkExt() { |
| 125 | if !vndk.isVndkSp() { |
| 126 | return "native:vendor:vndk" |
| 127 | } |
| 128 | return "native:vendor:vndksp" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 129 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 130 | if !vndk.isVndkSp() { |
| 131 | return "native:vendor:vndkext" |
| 132 | } |
| 133 | return "native:vendor:vndkspext" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 134 | } |
| 135 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 136 | // VNDK link type check from a module with UseVndk() == true. |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 137 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 138 | if to.linker == nil { |
| 139 | return |
| 140 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 141 | if !vndk.isVndk() { |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 142 | // Non-VNDK modules those installed to /vendor, /system/vendor, |
| 143 | // /product or /system/product cannot depend on VNDK-private modules |
| 144 | // that include VNDK-core-private, VNDK-SP-private and LLNDK-private. |
| 145 | if to.IsVndkPrivate() { |
| 146 | ctx.ModuleErrorf("non-VNDK module should not link to %q which has `private: true`", to.Name()) |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 147 | } |
| 148 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 149 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 150 | // Check only shared libraries. |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 151 | // Other (static) libraries are allowed to link. |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 152 | return |
| 153 | } |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 154 | |
| 155 | if to.IsLlndk() { |
| 156 | // LL-NDK libraries are allowed to link |
| 157 | return |
| 158 | } |
| 159 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 160 | if !to.UseVndk() { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 161 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 162 | vndk.typeName(), to.Name()) |
| 163 | return |
| 164 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 165 | if tag == vndkExtDepTag { |
| 166 | // Ensure `extends: "name"` property refers a vndk module that has vendor_available |
| 167 | // and has identical vndk properties. |
| 168 | if to.vndkdep == nil || !to.vndkdep.isVndk() { |
| 169 | ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name()) |
| 170 | return |
| 171 | } |
| 172 | if vndk.isVndkSp() != to.vndkdep.isVndkSp() { |
| 173 | ctx.ModuleErrorf( |
| 174 | "`extends` refers a module %q with mismatched support_system_process", |
| 175 | to.Name()) |
| 176 | return |
| 177 | } |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 178 | if to.IsVndkPrivate() { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 179 | ctx.ModuleErrorf( |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 180 | "`extends` refers module %q which has `private: true`", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 181 | to.Name()) |
| 182 | return |
| 183 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 184 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 185 | if to.vndkdep == nil { |
| 186 | return |
| 187 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 188 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 189 | // Check the dependencies of VNDK shared libraries. |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 190 | if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil { |
| 191 | ctx.ModuleErrorf("(%s) should not link to %q (%s): %v", |
| 192 | vndk.typeName(), to.Name(), to.vndkdep.typeName(), err) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 193 | return |
| 194 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 195 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 196 | |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 197 | func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 198 | // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules. |
| 199 | if from.isVndkExt() { |
| 200 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 201 | if to.isVndk() && !to.isVndkSp() { |
| 202 | return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions") |
| 203 | } |
| 204 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 205 | } |
| 206 | // 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] | 207 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 208 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 209 | if from.isVndk() { |
| 210 | if to.isVndkExt() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 211 | 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] | 212 | } |
| 213 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 214 | if !to.isVndkSp() { |
| 215 | return errors.New("VNDK-SP must only depend on VNDK-SP") |
| 216 | } |
| 217 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 218 | } |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 219 | if !to.isVndk() { |
| 220 | return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP") |
| 221 | } |
| 222 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 223 | } |
| 224 | // 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] | 225 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 226 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 227 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 228 | type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string) |
| 229 | |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 230 | var ( |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 231 | llndkLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsLLNDK && !m.Header() }) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 232 | vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP }) |
| 233 | vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore }) |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 234 | vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate }) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 235 | vndkProductLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKProduct }) |
| 236 | vndkUsingCoreVariantLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKUsingCoreVariant }) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 237 | ) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 238 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 239 | // vndkModuleLister takes a predicate that operates on a Module and returns a moduleListerFunc |
| 240 | // that produces a list of module names and output file names for which the predicate returns true. |
| 241 | func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc { |
| 242 | return func(ctx android.SingletonContext) (moduleNames, fileNames []string) { |
| 243 | ctx.VisitAllModules(func(m android.Module) { |
Jooyung Han | e3f0281 | 2023-05-08 13:54:50 +0900 | [diff] [blame] | 244 | if c, ok := m.(*Module); ok && predicate(c) && !c.IsVndkPrebuiltLibrary() { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 245 | filename, err := getVndkFileName(c) |
| 246 | if err != nil { |
| 247 | ctx.ModuleErrorf(m, "%s", err) |
| 248 | } |
| 249 | moduleNames = append(moduleNames, ctx.ModuleName(m)) |
| 250 | fileNames = append(fileNames, filename) |
| 251 | } |
| 252 | }) |
| 253 | moduleNames = android.SortedUniqueStrings(moduleNames) |
| 254 | fileNames = android.SortedUniqueStrings(fileNames) |
| 255 | return |
| 256 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 257 | } |
| 258 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 259 | // vndkModuleListRemover takes a moduleListerFunc and a prefix and returns a moduleListerFunc |
| 260 | // that returns the same lists as the input moduleListerFunc, but with modules with the |
| 261 | // given prefix removed. |
| 262 | func vndkModuleListRemover(lister moduleListerFunc, prefix string) moduleListerFunc { |
| 263 | return func(ctx android.SingletonContext) (moduleNames, fileNames []string) { |
| 264 | moduleNames, fileNames = lister(ctx) |
| 265 | filter := func(in []string) []string { |
| 266 | out := make([]string, 0, len(in)) |
| 267 | for _, lib := range in { |
| 268 | if strings.HasPrefix(lib, prefix) { |
| 269 | continue |
| 270 | } |
| 271 | out = append(out, lib) |
| 272 | } |
| 273 | return out |
| 274 | } |
| 275 | return filter(moduleNames), filter(fileNames) |
| 276 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 277 | } |
| 278 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 279 | var vndkMustUseVendorVariantListKey = android.NewOnceKey("vndkMustUseVendorVariantListKey") |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 280 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 281 | func vndkMustUseVendorVariantList(cfg android.Config) []string { |
| 282 | return cfg.Once(vndkMustUseVendorVariantListKey, func() interface{} { |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 283 | return config.VndkMustUseVendorVariantList |
| 284 | }).([]string) |
| 285 | } |
| 286 | |
| 287 | // test may call this to override global configuration(config.VndkMustUseVendorVariantList) |
| 288 | // when it is called, it must be before the first call to vndkMustUseVendorVariantList() |
| 289 | func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendorVariantList []string) { |
Jooyung Han | a463f72 | 2019-11-01 08:45:59 +0900 | [diff] [blame] | 290 | config.Once(vndkMustUseVendorVariantListKey, func() interface{} { |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 291 | return mustUseVendorVariantList |
| 292 | }) |
| 293 | } |
| 294 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 295 | func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 296 | if m.InProduct() { |
| 297 | // We may skip the steps for the product variants because they |
| 298 | // are already covered by the vendor variants. |
| 299 | return |
| 300 | } |
| 301 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 302 | name := m.BaseModuleName() |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 303 | |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 304 | if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" { |
Jiyong Park | 2478e4e | 2020-05-18 09:30:14 +0000 | [diff] [blame] | 305 | // b/155456180 libz is the ONLY exception here. We don't want to make |
| 306 | // libz an LLNDK library because we in general can't guarantee that |
| 307 | // libz will behave consistently especially about the compression. |
| 308 | // i.e. the compressed output might be different across releases. |
| 309 | // As the library is an external one, it's risky to keep the compatibility |
| 310 | // promise if it becomes an LLNDK. |
Jiyong Park | ea97f51 | 2020-03-31 15:31:17 +0900 | [diff] [blame] | 311 | mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK") |
| 312 | } |
| 313 | |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 314 | if inList(name, vndkMustUseVendorVariantList(mctx.Config())) { |
| 315 | m.Properties.MustUseVendorVariant = true |
| 316 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 317 | if mctx.DeviceConfig().VndkUseCoreVariant() && !m.Properties.MustUseVendorVariant { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 318 | m.VendorProperties.IsVNDKUsingCoreVariant = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 319 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 320 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 321 | if m.vndkdep.isVndkSp() { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 322 | m.VendorProperties.IsVNDKSP = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 323 | } else { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 324 | m.VendorProperties.IsVNDKCore = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 325 | } |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 326 | if m.IsVndkPrivate() { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 327 | m.VendorProperties.IsVNDKPrivate = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 328 | } |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 329 | if Bool(m.VendorProperties.Product_available) { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 330 | m.VendorProperties.IsVNDKProduct = true |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 331 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 332 | } |
| 333 | |
Yo Chiang | 08fac0c | 2020-07-29 01:08:20 +0800 | [diff] [blame] | 334 | // Check for modules that mustn't be VNDK |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 335 | func shouldSkipVndkMutator(m *Module) bool { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 336 | if !m.Enabled() { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 337 | return true |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 338 | } |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 339 | if !m.Device() { |
| 340 | // Skip non-device modules |
| 341 | return true |
Jooyung Han | 87a7f30 | 2019-10-29 05:18:21 +0900 | [diff] [blame] | 342 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 343 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 344 | // Skip native_bridge modules |
| 345 | return true |
| 346 | } |
| 347 | return false |
| 348 | } |
| 349 | |
| 350 | func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool { |
| 351 | if shouldSkipVndkMutator(m) { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 352 | return false |
| 353 | } |
| 354 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 355 | // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared |
| 356 | // When b/142675459 is landed, remove following check |
Justin Yun | f14beaf | 2023-08-18 17:51:14 +0900 | [diff] [blame^] | 357 | if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { |
| 358 | // prebuilt vndk modules should match with device |
| 359 | if !p.MatchesWithDevice(mctx.DeviceConfig()) { |
| 360 | return false |
| 361 | } |
| 362 | |
| 363 | // ignore prebuilt vndk modules that are newer than or equal to the platform vndk version |
| 364 | platformVndkApiLevel := android.ApiLevelOrPanic(mctx, mctx.DeviceConfig().PlatformVndkVersion()) |
| 365 | if platformVndkApiLevel.LessThanOrEqualTo(android.ApiLevelOrPanic(mctx, p.Version())) { |
| 366 | return false |
| 367 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | if lib, ok := m.linker.(libraryInterface); ok { |
Jooyung Han | 73d20d0 | 2020-03-27 16:06:55 +0900 | [diff] [blame] | 371 | // VNDK APEX for VNDK-Lite devices will have VNDK-SP libraries from core variants |
| 372 | if mctx.DeviceConfig().VndkVersion() == "" { |
| 373 | // b/73296261: filter out libz.so because it is considered as LLNDK for VNDK-lite devices |
| 374 | if mctx.ModuleName() == "libz" { |
| 375 | return false |
| 376 | } |
Jooyung Han | 7d6e79b | 2021-06-24 01:53:43 +0900 | [diff] [blame] | 377 | return m.ImageVariation().Variation == android.CoreVariation && lib.shared() && m.IsVndkSp() && !m.IsVndkExt() |
Jooyung Han | 73d20d0 | 2020-03-27 16:06:55 +0900 | [diff] [blame] | 378 | } |
Jooyung Han | 1724d58 | 2022-12-21 10:17:44 +0900 | [diff] [blame] | 379 | // VNDK APEX doesn't need stub variants |
| 380 | if lib.buildStubs() { |
| 381 | return false |
| 382 | } |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 383 | useCoreVariant := m.VndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() && |
Jooyung Han | 87a7f30 | 2019-10-29 05:18:21 +0900 | [diff] [blame] | 384 | mctx.DeviceConfig().VndkUseCoreVariant() && !m.MustUseVendorVariant() |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 385 | return lib.shared() && m.InVendor() && m.IsVndk() && !m.IsVndkExt() && !useCoreVariant |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 386 | } |
| 387 | return false |
| 388 | } |
| 389 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 390 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 391 | func VndkMutator(mctx android.BottomUpMutatorContext) { |
| 392 | m, ok := mctx.Module().(*Module) |
| 393 | if !ok { |
| 394 | return |
| 395 | } |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 396 | |
| 397 | if shouldSkipVndkMutator(m) { |
Justin Yun | 7390ea3 | 2019-09-08 11:34:06 +0900 | [diff] [blame] | 398 | return |
| 399 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 400 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 401 | lib, isLib := m.linker.(*libraryDecorator) |
| 402 | prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 403 | |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 404 | if m.UseVndk() && isLib && lib.hasLLNDKStubs() { |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 405 | m.VendorProperties.IsLLNDK = true |
| 406 | m.VendorProperties.IsVNDKPrivate = Bool(lib.Properties.Llndk.Private) |
| 407 | } |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 408 | if m.UseVndk() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() { |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 409 | m.VendorProperties.IsLLNDK = true |
| 410 | m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private) |
| 411 | } |
| 412 | |
Jooyung Han | e3f0281 | 2023-05-08 13:54:50 +0900 | [diff] [blame] | 413 | if m.IsVndkPrebuiltLibrary() && !m.IsVndk() { |
| 414 | m.VendorProperties.IsLLNDK = true |
| 415 | // TODO(b/280697209): copy "llndk.private" flag to vndk_prebuilt_shared |
| 416 | } |
| 417 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 418 | if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) { |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 419 | if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 420 | processVndkLibrary(mctx, m) |
| 421 | return |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | func init() { |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 427 | RegisterVndkLibraryTxtTypes(android.InitRegistrationContext) |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 428 | android.RegisterParallelSingletonType("vndk-snapshot", VndkSnapshotSingleton) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 429 | } |
| 430 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 431 | func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) { |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 432 | ctx.RegisterParallelSingletonModuleType("llndk_libraries_txt", llndkLibrariesTxtFactory) |
| 433 | ctx.RegisterParallelSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory) |
| 434 | ctx.RegisterParallelSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory) |
| 435 | ctx.RegisterParallelSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory) |
| 436 | ctx.RegisterParallelSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory) |
| 437 | ctx.RegisterParallelSingletonModuleType("vndkcorevariant_libraries_txt", vndkUsingCoreVariantLibrariesTxtFactory) |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 440 | type vndkLibrariesTxt struct { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 441 | android.SingletonModuleBase |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 442 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 443 | lister moduleListerFunc |
| 444 | makeVarName string |
| 445 | filterOutFromMakeVar string |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 446 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 447 | properties VndkLibrariesTxtProperties |
| 448 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 449 | outputFile android.OutputPath |
| 450 | moduleNames []string |
| 451 | fileNames []string |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 452 | } |
| 453 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 454 | type VndkLibrariesTxtProperties struct { |
| 455 | Insert_vndk_version *bool |
| 456 | } |
| 457 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 458 | var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{} |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 459 | var _ android.OutputFileProducer = &vndkLibrariesTxt{} |
| 460 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 461 | // llndk_libraries_txt is a singleton module whose content is a list of LLNDK libraries |
| 462 | // generated by Soong but can be referenced by other modules. |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 463 | // For example, apex_vndk can depend on these files as prebuilt. |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 464 | // Make uses LLNDK_LIBRARIES to determine which libraries to install. |
| 465 | // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN. |
| 466 | // Therefore, by removing the library here, we cause it to only be installed if libc |
| 467 | // depends on it. |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 468 | func llndkLibrariesTxtFactory() android.SingletonModule { |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 469 | return newVndkLibrariesWithMakeVarFilter(llndkLibraries, "LLNDK_LIBRARIES", "libclang_rt.hwasan") |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | // vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries |
| 473 | // generated by Soong but can be referenced by other modules. |
| 474 | // For example, apex_vndk can depend on these files as prebuilt. |
| 475 | func vndkSPLibrariesTxtFactory() android.SingletonModule { |
| 476 | return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES") |
| 477 | } |
| 478 | |
| 479 | // vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries |
| 480 | // generated by Soong but can be referenced by other modules. |
| 481 | // For example, apex_vndk can depend on these files as prebuilt. |
| 482 | func vndkCoreLibrariesTxtFactory() android.SingletonModule { |
| 483 | return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES") |
| 484 | } |
| 485 | |
| 486 | // vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries |
| 487 | // generated by Soong but can be referenced by other modules. |
| 488 | // For example, apex_vndk can depend on these files as prebuilt. |
| 489 | func vndkPrivateLibrariesTxtFactory() android.SingletonModule { |
| 490 | return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES") |
| 491 | } |
| 492 | |
| 493 | // vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product libraries |
| 494 | // generated by Soong but can be referenced by other modules. |
| 495 | // For example, apex_vndk can depend on these files as prebuilt. |
| 496 | func vndkProductLibrariesTxtFactory() android.SingletonModule { |
| 497 | return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES") |
| 498 | } |
| 499 | |
| 500 | // vndkcorevariant_libraries_txt is a singleton module whose content is a list of VNDK libraries |
| 501 | // that are using the core variant, generated by Soong but can be referenced by other modules. |
| 502 | // For example, apex_vndk can depend on these files as prebuilt. |
| 503 | func vndkUsingCoreVariantLibrariesTxtFactory() android.SingletonModule { |
| 504 | return newVndkLibrariesTxt(vndkUsingCoreVariantLibraries, "VNDK_USING_CORE_VARIANT_LIBRARIES") |
| 505 | } |
| 506 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 507 | func newVndkLibrariesWithMakeVarFilter(lister moduleListerFunc, makeVarName string, filter string) android.SingletonModule { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 508 | m := &vndkLibrariesTxt{ |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 509 | lister: lister, |
| 510 | makeVarName: makeVarName, |
| 511 | filterOutFromMakeVar: filter, |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 512 | } |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 513 | m.AddProperties(&m.properties) |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 514 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 515 | return m |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 516 | } |
| 517 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 518 | func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule { |
| 519 | return newVndkLibrariesWithMakeVarFilter(lister, makeVarName, "") |
| 520 | } |
| 521 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 522 | func insertVndkVersion(filename string, vndkVersion string) string { |
| 523 | if index := strings.LastIndex(filename, "."); index != -1 { |
| 524 | return filename[:index] + "." + vndkVersion + filename[index:] |
| 525 | } |
| 526 | return filename |
| 527 | } |
| 528 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 529 | func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 530 | var filename string |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 531 | if BoolDefault(txt.properties.Insert_vndk_version, true) { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 532 | filename = insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion()) |
| 533 | } else { |
| 534 | filename = txt.Name() |
| 535 | } |
| 536 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 537 | txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 538 | |
| 539 | installPath := android.PathForModuleInstall(ctx, "etc") |
| 540 | ctx.InstallFile(installPath, filename, txt.outputFile) |
| 541 | } |
| 542 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 543 | func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) { |
| 544 | txt.moduleNames, txt.fileNames = txt.lister(ctx) |
| 545 | android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n")) |
| 546 | } |
| 547 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 548 | func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries { |
| 549 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 550 | Class: "ETC", |
| 551 | OutputFile: android.OptionalPathForPath(txt.outputFile), |
| 552 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 553 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 554 | entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base()) |
| 555 | }, |
| 556 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 557 | }} |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 558 | } |
| 559 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 560 | func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) { |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 561 | filter := func(modules []string, prefix string) []string { |
| 562 | if prefix == "" { |
| 563 | return modules |
| 564 | } |
| 565 | var result []string |
| 566 | for _, module := range modules { |
| 567 | if strings.HasPrefix(module, prefix) { |
| 568 | continue |
| 569 | } else { |
| 570 | result = append(result, module) |
| 571 | } |
| 572 | } |
| 573 | return result |
| 574 | } |
| 575 | ctx.Strict(txt.makeVarName, strings.Join(filter(txt.moduleNames, txt.filterOutFromMakeVar), " ")) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 576 | } |
| 577 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 578 | // PrebuiltEtcModule interface |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 579 | func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath { |
| 580 | return txt.outputFile |
| 581 | } |
| 582 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 583 | // PrebuiltEtcModule interface |
| 584 | func (txt *vndkLibrariesTxt) BaseDir() string { |
| 585 | return "etc" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 586 | } |
| 587 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 588 | // PrebuiltEtcModule interface |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 589 | func (txt *vndkLibrariesTxt) SubDir() string { |
| 590 | return "" |
| 591 | } |
| 592 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 593 | func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) { |
| 594 | return android.Paths{txt.outputFile}, nil |
| 595 | } |
| 596 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 597 | func VndkSnapshotSingleton() android.Singleton { |
| 598 | return &vndkSnapshotSingleton{} |
| 599 | } |
| 600 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 601 | type vndkSnapshotSingleton struct { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 602 | vndkLibrariesFile android.OutputPath |
| 603 | vndkSnapshotZipFile android.OptionalPath |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 604 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 605 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 606 | func isVndkSnapshotAware(config android.DeviceConfig, m LinkableInterface, |
| 607 | apexInfo android.ApexInfo) (vndkType string, isVndkSnapshotLib bool) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 608 | |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 609 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 610 | return "", false |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 611 | } |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 612 | // !inVendor: There's product/vendor variants for VNDK libs. We only care about vendor variants. |
| 613 | // !installable: Snapshot only cares about "installable" modules. |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 614 | // !m.IsLlndk: llndk stubs are required for building against snapshots. |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 615 | // IsSnapshotPrebuilt: Snapshotting a snapshot doesn't make sense. |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 616 | // !outputFile.Valid: Snapshot requires valid output file. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 617 | if !m.InVendor() || (!installable(m, apexInfo) && !m.IsLlndk()) || m.IsSnapshotPrebuilt() || !m.OutputFile().Valid() { |
| 618 | return "", false |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 619 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 620 | if !m.IsSnapshotLibrary() || !m.Shared() { |
| 621 | return "", false |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 622 | } |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 623 | if m.VndkVersion() == config.PlatformVndkVersion() { |
| 624 | if m.IsVndk() && !m.IsVndkExt() { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 625 | if m.IsVndkSp() { |
| 626 | return "vndk-sp", true |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 627 | } else { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 628 | return "vndk-core", true |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 629 | } |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 630 | } else if m.HasLlndkStubs() && m.StubsVersion() == "" { |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 631 | // Use default version for the snapshot. |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 632 | return "llndk-stub", true |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 636 | return "", false |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 637 | } |
| 638 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 639 | func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 640 | // build these files even if PlatformVndkVersion or BoardVndkVersion is not set |
| 641 | c.buildVndkLibrariesTxtFiles(ctx) |
| 642 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 643 | // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot. |
| 644 | if ctx.DeviceConfig().VndkVersion() != "current" { |
| 645 | return |
| 646 | } |
| 647 | |
| 648 | if ctx.DeviceConfig().PlatformVndkVersion() == "" { |
| 649 | return |
| 650 | } |
| 651 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 652 | var snapshotOutputs android.Paths |
| 653 | |
| 654 | /* |
| 655 | VNDK snapshot zipped artifacts directory structure: |
| 656 | {SNAPSHOT_ARCH}/ |
| 657 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 658 | shared/ |
| 659 | vndk-core/ |
| 660 | (VNDK-core libraries, e.g. libbinder.so) |
| 661 | vndk-sp/ |
| 662 | (VNDK-SP libraries, e.g. libc++.so) |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 663 | llndk-stub/ |
| 664 | (LLNDK stub libraries) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 665 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 666 | shared/ |
| 667 | vndk-core/ |
| 668 | (VNDK-core libraries, e.g. libbinder.so) |
| 669 | vndk-sp/ |
| 670 | (VNDK-SP libraries, e.g. libc++.so) |
Justin Yun | 450ae72 | 2021-04-16 19:58:18 +0900 | [diff] [blame] | 671 | llndk-stub/ |
| 672 | (LLNDK stub libraries) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 673 | binder32/ |
| 674 | (This directory is newly introduced in v28 (Android P) to hold |
| 675 | prebuilts built for 32-bit binder interface.) |
| 676 | arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/ |
| 677 | ... |
| 678 | configs/ |
| 679 | (various *.txt configuration files) |
| 680 | include/ |
| 681 | (header files of same directory structure with source tree) |
| 682 | NOTICE_FILES/ |
| 683 | (notice files of libraries, e.g. libcutils.so.txt) |
| 684 | */ |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 685 | |
| 686 | snapshotDir := "vndk-snapshot" |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 687 | snapshotArchDir := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch()) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 688 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 689 | configsDir := filepath.Join(snapshotArchDir, "configs") |
Justin Yun | 1871f90 | 2023-04-07 20:13:19 +0900 | [diff] [blame] | 690 | noticeDir := filepath.Join(snapshotArchDir, "NOTICE_FILES") |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 691 | includeDir := filepath.Join(snapshotArchDir, "include") |
| 692 | |
Justin Yun | 1871f90 | 2023-04-07 20:13:19 +0900 | [diff] [blame] | 693 | // set of notice files copied. |
| 694 | noticeBuilt := make(map[string]bool) |
| 695 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 696 | // paths of VNDK modules for GPL license checking |
| 697 | modulePaths := make(map[string]string) |
| 698 | |
| 699 | // actual module names of .so files |
| 700 | // e.g. moduleNames["libprotobuf-cpp-full-3.9.1.so"] = "libprotobuf-cpp-full" |
| 701 | moduleNames := make(map[string]string) |
| 702 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 703 | var headers android.Paths |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 704 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 705 | // installVndkSnapshotLib copies built .so file from the module. |
| 706 | // Also, if the build artifacts is on, write a json file which contains all exported flags |
| 707 | // with FlagExporterInfo. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 708 | installVndkSnapshotLib := func(m *Module, vndkType string) (android.Paths, bool) { |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 709 | var ret android.Paths |
| 710 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 711 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 712 | if m.Target().Arch.ArchVariant != "" { |
| 713 | targetArch += "-" + m.Target().Arch.ArchVariant |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 714 | } |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 715 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 716 | libPath := m.outputFile.Path() |
| 717 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "shared", vndkType, libPath.Base()) |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 718 | ret = append(ret, snapshot.CopyFileRule(pctx, ctx, libPath, snapshotLibOut)) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 719 | |
Justin Yun | 1871f90 | 2023-04-07 20:13:19 +0900 | [diff] [blame] | 720 | // json struct to export snapshot information |
| 721 | prop := struct { |
Inseob Kim | 5860f82 | 2023-04-18 11:30:22 +0900 | [diff] [blame] | 722 | MinSdkVersion string `json:",omitempty"` |
Justin Yun | 1871f90 | 2023-04-07 20:13:19 +0900 | [diff] [blame] | 723 | LicenseKinds []string `json:",omitempty"` |
| 724 | LicenseTexts []string `json:",omitempty"` |
| 725 | ExportedDirs []string `json:",omitempty"` |
| 726 | ExportedSystemDirs []string `json:",omitempty"` |
| 727 | ExportedFlags []string `json:",omitempty"` |
| 728 | RelativeInstallPath string `json:",omitempty"` |
| 729 | }{} |
| 730 | |
| 731 | prop.LicenseKinds = m.EffectiveLicenseKinds() |
| 732 | prop.LicenseTexts = m.EffectiveLicenseFiles().Strings() |
Inseob Kim | 5860f82 | 2023-04-18 11:30:22 +0900 | [diff] [blame] | 733 | prop.MinSdkVersion = m.MinSdkVersion() |
Justin Yun | 1871f90 | 2023-04-07 20:13:19 +0900 | [diff] [blame] | 734 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 735 | if ctx.Config().VndkSnapshotBuildArtifacts() { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 736 | exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) |
| 737 | prop.ExportedFlags = exportedInfo.Flags |
| 738 | prop.ExportedDirs = exportedInfo.IncludeDirs.Strings() |
| 739 | prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings() |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 740 | prop.RelativeInstallPath = m.RelativeInstallPath() |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 741 | } |
Justin Yun | 1871f90 | 2023-04-07 20:13:19 +0900 | [diff] [blame] | 742 | |
| 743 | propOut := snapshotLibOut + ".json" |
| 744 | |
| 745 | j, err := json.Marshal(prop) |
| 746 | if err != nil { |
| 747 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 748 | return nil, false |
| 749 | } |
| 750 | ret = append(ret, snapshot.WriteStringToFileRule(ctx, string(j), propOut)) |
| 751 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 752 | return ret, true |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 753 | } |
| 754 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 755 | ctx.VisitAllModules(func(module android.Module) { |
| 756 | m, ok := module.(*Module) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 757 | if !ok || !m.Enabled() { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 758 | return |
| 759 | } |
| 760 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 761 | apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
| 762 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 763 | vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 764 | if !ok { |
dimitry | 51ea18a | 2019-05-20 10:39:52 +0200 | [diff] [blame] | 765 | return |
| 766 | } |
| 767 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 768 | // For all snapshot candidates, the followings are captured. |
| 769 | // - .so files |
| 770 | // - notice files |
| 771 | // |
| 772 | // The followings are also captured if VNDK_SNAPSHOT_BUILD_ARTIFACTS. |
| 773 | // - .json files containing exported flags |
| 774 | // - exported headers from collectHeadersForSnapshot() |
| 775 | // |
| 776 | // Headers are deduplicated after visiting all modules. |
| 777 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 778 | // install .so files for appropriate modules. |
| 779 | // Also install .json files if VNDK_SNAPSHOT_BUILD_ARTIFACTS |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 780 | libs, ok := installVndkSnapshotLib(m, vndkType) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 781 | if !ok { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 782 | return |
| 783 | } |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 784 | snapshotOutputs = append(snapshotOutputs, libs...) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 785 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 786 | // These are for generating module_names.txt and module_paths.txt |
| 787 | stem := m.outputFile.Path().Base() |
| 788 | moduleNames[stem] = ctx.ModuleName(m) |
| 789 | modulePaths[stem] = ctx.ModuleDir(m) |
| 790 | |
Justin Yun | 1871f90 | 2023-04-07 20:13:19 +0900 | [diff] [blame] | 791 | for _, notice := range m.EffectiveLicenseFiles() { |
| 792 | if _, ok := noticeBuilt[notice.String()]; !ok { |
| 793 | noticeBuilt[notice.String()] = true |
| 794 | snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule( |
| 795 | pctx, ctx, notice, filepath.Join(noticeDir, notice.String()))) |
| 796 | } |
| 797 | } |
| 798 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 799 | if ctx.Config().VndkSnapshotBuildArtifacts() { |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 800 | headers = append(headers, m.SnapshotHeaders()...) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 801 | } |
| 802 | }) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 803 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 804 | // install all headers after removing duplicates |
| 805 | for _, header := range android.FirstUniquePaths(headers) { |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 806 | snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule( |
| 807 | pctx, ctx, header, filepath.Join(includeDir, header.String()))) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 808 | } |
| 809 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 810 | // install *.libraries.txt except vndkcorevariant.libraries.txt |
| 811 | ctx.VisitAllModules(func(module android.Module) { |
| 812 | m, ok := module.(*vndkLibrariesTxt) |
| 813 | if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt { |
| 814 | return |
| 815 | } |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 816 | snapshotOutputs = append(snapshotOutputs, snapshot.CopyFileRule( |
| 817 | pctx, ctx, m.OutputFile(), filepath.Join(configsDir, m.Name()))) |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 818 | }) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 819 | |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 820 | /* |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 821 | module_paths.txt contains paths on which VNDK modules are defined. |
| 822 | e.g., |
Baligh Uddin | 637df8e | 2020-10-26 14:34:53 +0000 | [diff] [blame] | 823 | libbase.so system/libbase |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 824 | libc.so bionic/libc |
| 825 | ... |
| 826 | */ |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 827 | snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, modulePaths, filepath.Join(configsDir, "module_paths.txt"))) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 828 | |
| 829 | /* |
| 830 | module_names.txt contains names as which VNDK modules are defined, |
| 831 | because output filename and module name can be different with stem and suffix properties. |
| 832 | |
| 833 | e.g., |
| 834 | libcutils.so libcutils |
| 835 | libprotobuf-cpp-full-3.9.2.so libprotobuf-cpp-full |
| 836 | ... |
| 837 | */ |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 838 | snapshotOutputs = append(snapshotOutputs, installMapListFileRule(ctx, moduleNames, filepath.Join(configsDir, "module_names.txt"))) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 839 | |
| 840 | // All artifacts are ready. Sort them to normalize ninja and then zip. |
| 841 | sort.Slice(snapshotOutputs, func(i, j int) bool { |
| 842 | return snapshotOutputs[i].String() < snapshotOutputs[j].String() |
| 843 | }) |
| 844 | |
| 845 | zipPath := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+".zip") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 846 | zipRule := android.NewRuleBuilder(pctx, ctx) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 847 | |
Inseob Kim | de5744a | 2020-12-02 13:14:28 +0900 | [diff] [blame] | 848 | // filenames in rspfile from FlagWithRspFileInputList might be single-quoted. Remove it with tr |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 849 | snapshotOutputList := android.PathForOutput(ctx, snapshotDir, "android-vndk-"+ctx.DeviceConfig().DeviceArch()+"_list") |
Colin Cross | 70c4741 | 2021-03-12 17:48:14 -0800 | [diff] [blame] | 850 | rspFile := snapshotOutputList.ReplaceExtension(ctx, "rsp") |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 851 | zipRule.Command(). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 852 | Text("tr"). |
| 853 | FlagWithArg("-d ", "\\'"). |
Colin Cross | 70c4741 | 2021-03-12 17:48:14 -0800 | [diff] [blame] | 854 | FlagWithRspFileInputList("< ", rspFile, snapshotOutputs). |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 855 | FlagWithOutput("> ", snapshotOutputList) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 856 | |
| 857 | zipRule.Temporary(snapshotOutputList) |
| 858 | |
| 859 | zipRule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 860 | BuiltTool("soong_zip"). |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 861 | FlagWithOutput("-o ", zipPath). |
| 862 | FlagWithArg("-C ", android.PathForOutput(ctx, snapshotDir).String()). |
| 863 | FlagWithInput("-l ", snapshotOutputList) |
| 864 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 865 | zipRule.Build(zipPath.String(), "vndk snapshot "+zipPath.String()) |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 866 | zipRule.DeleteTemporaryFiles() |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 867 | c.vndkSnapshotZipFile = android.OptionalPathForPath(zipPath) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 868 | } |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 869 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 870 | func getVndkFileName(m *Module) (string, error) { |
| 871 | if library, ok := m.linker.(*libraryDecorator); ok { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 872 | return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 873 | } |
| 874 | if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 875 | return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 876 | } |
| 877 | 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] | 878 | } |
| 879 | |
| 880 | func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 881 | // Build list of vndk libs as merged & tagged & filter-out(libclang_rt): |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 882 | // Since each target have different set of libclang_rt.* files, |
| 883 | // keep the common set of files in vndk.libraries.txt |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 884 | _, llndk := vndkModuleListRemover(llndkLibraries, "libclang_rt.")(ctx) |
| 885 | _, vndkcore := vndkModuleListRemover(vndkCoreLibraries, "libclang_rt.")(ctx) |
| 886 | _, vndksp := vndkSPLibraries(ctx) |
| 887 | _, vndkprivate := vndkPrivateLibraries(ctx) |
| 888 | _, vndkproduct := vndkModuleListRemover(vndkProductLibraries, "libclang_rt.")(ctx) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 889 | var merged []string |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 890 | merged = append(merged, addPrefix(llndk, "LLNDK: ")...) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 891 | merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 892 | merged = append(merged, addPrefix(vndkcore, "VNDK-core: ")...) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 893 | merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 894 | merged = append(merged, addPrefix(vndkproduct, "VNDK-product: ")...) |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 895 | c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 896 | android.WriteFileRule(ctx, c.vndkLibrariesFile, strings.Join(merged, "\n")) |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 897 | } |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 898 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 899 | func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 900 | // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if |
| 901 | // they been moved to an apex. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 902 | movedToApexLlndkLibraries := make(map[string]bool) |
| 903 | ctx.VisitAllModules(func(module android.Module) { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 904 | if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() { |
| 905 | // Skip bionic libs, they are handled in different manner |
| 906 | name := library.implementationModuleName(module.(*Module).BaseModuleName()) |
| 907 | if module.(android.ApexModule).DirectlyInAnyApex() && !isBionic(name) { |
| 908 | movedToApexLlndkLibraries[name] = true |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 909 | } |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 910 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 911 | }) |
| 912 | |
| 913 | ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", |
Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 914 | strings.Join(android.SortedKeys(movedToApexLlndkLibraries), " ")) |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 915 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 916 | ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String()) |
Inseob Kim | 242ef0c | 2019-10-22 20:15:20 +0900 | [diff] [blame] | 917 | ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String()) |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 918 | } |