Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 18 | "errors" |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 19 | "fmt" |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 20 | "strings" |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 21 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 22 | "android/soong/android" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 23 | "android/soong/etc" |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint" |
Justin Yun | d578412 | 2023-10-25 13:25:32 +0900 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 27 | ) |
| 28 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 29 | const ( |
| 30 | llndkLibrariesTxt = "llndk.libraries.txt" |
Justin Yun | d578412 | 2023-10-25 13:25:32 +0900 | [diff] [blame] | 31 | llndkLibrariesTxtForApex = "llndk.libraries.txt.apex" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 32 | vndkCoreLibrariesTxt = "vndkcore.libraries.txt" |
| 33 | vndkSpLibrariesTxt = "vndksp.libraries.txt" |
| 34 | vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt" |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 35 | vndkProductLibrariesTxt = "vndkproduct.libraries.txt" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 36 | vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt" |
| 37 | ) |
| 38 | |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 39 | func VndkLibrariesTxtModules(vndkVersion string, ctx android.BaseModuleContext) []string { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 40 | // Snapshot vndks have their own *.libraries.VER.txt files. |
| 41 | // Note that snapshots don't have "vndkcorevariant.libraries.VER.txt" |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 42 | result := []string{ |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 43 | insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion), |
| 44 | insertVndkVersion(vndkSpLibrariesTxt, vndkVersion), |
| 45 | insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion), |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 46 | insertVndkVersion(vndkProductLibrariesTxt, vndkVersion), |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 47 | insertVndkVersion(llndkLibrariesTxt, vndkVersion), |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 48 | } |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 49 | |
| 50 | return result |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 51 | } |
| 52 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 53 | type VndkProperties struct { |
| 54 | Vndk struct { |
| 55 | // declared as a VNDK or VNDK-SP module. The vendor variant |
| 56 | // will be installed in /system instead of /vendor partition. |
| 57 | // |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 58 | // `vendor_available` and `product_available` must be explicitly |
| 59 | // set to either true or false together with `vndk: {enabled: true}`. |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 60 | Enabled *bool |
| 61 | |
| 62 | // declared as a VNDK-SP module, which is a subset of VNDK. |
| 63 | // |
| 64 | // `vndk: { enabled: true }` must set together. |
| 65 | // |
| 66 | // All these modules are allowed to link to VNDK-SP or LL-NDK |
| 67 | // modules only. Other dependency will cause link-type errors. |
| 68 | // |
| 69 | // If `support_system_process` is not set or set to false, |
| 70 | // the module is VNDK-core and can link to other VNDK-core, |
| 71 | // VNDK-SP or LL-NDK modules only. |
| 72 | Support_system_process *bool |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 73 | |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 74 | // declared as a VNDK-private module. |
| 75 | // This module still creates the vendor and product variants refering |
| 76 | // to the `vendor_available: true` and `product_available: true` |
| 77 | // properties. However, it is only available to the other VNDK modules |
| 78 | // but not to the non-VNDK vendor or product modules. |
| 79 | Private *bool |
| 80 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 81 | // Extending another module |
| 82 | Extends *string |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | type vndkdep struct { |
| 87 | Properties VndkProperties |
| 88 | } |
| 89 | |
| 90 | func (vndk *vndkdep) props() []interface{} { |
| 91 | return []interface{}{&vndk.Properties} |
| 92 | } |
| 93 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 94 | func (vndk *vndkdep) isVndk() bool { |
| 95 | return Bool(vndk.Properties.Vndk.Enabled) |
| 96 | } |
| 97 | |
| 98 | func (vndk *vndkdep) isVndkSp() bool { |
| 99 | return Bool(vndk.Properties.Vndk.Support_system_process) |
| 100 | } |
| 101 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 102 | func (vndk *vndkdep) isVndkExt() bool { |
| 103 | return vndk.Properties.Vndk.Extends != nil |
| 104 | } |
| 105 | |
| 106 | func (vndk *vndkdep) getVndkExtendsModuleName() string { |
| 107 | return String(vndk.Properties.Vndk.Extends) |
| 108 | } |
| 109 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 110 | func (vndk *vndkdep) typeName() string { |
| 111 | if !vndk.isVndk() { |
| 112 | return "native:vendor" |
| 113 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 114 | if !vndk.isVndkExt() { |
| 115 | if !vndk.isVndkSp() { |
| 116 | return "native:vendor:vndk" |
| 117 | } |
| 118 | return "native:vendor:vndksp" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 119 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 120 | if !vndk.isVndkSp() { |
| 121 | return "native:vendor:vndkext" |
| 122 | } |
| 123 | return "native:vendor:vndkspext" |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 124 | } |
| 125 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 126 | // VNDK link type check from a module with UseVndk() == true. |
Jooyung Han | 479ca17 | 2020-10-19 18:51:07 +0900 | [diff] [blame] | 127 | func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 128 | if to.linker == nil { |
| 129 | return |
| 130 | } |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 131 | if !vndk.isVndk() { |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 132 | // Non-VNDK modules those installed to /vendor, /system/vendor, |
| 133 | // /product or /system/product cannot depend on VNDK-private modules |
| 134 | // that include VNDK-core-private, VNDK-SP-private and LLNDK-private. |
| 135 | if to.IsVndkPrivate() { |
| 136 | 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] | 137 | } |
| 138 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 139 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 140 | // Check only shared libraries. |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 141 | // Other (static) libraries are allowed to link. |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 142 | return |
| 143 | } |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 144 | |
| 145 | if to.IsLlndk() { |
| 146 | // LL-NDK libraries are allowed to link |
| 147 | return |
| 148 | } |
| 149 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 150 | if !to.UseVndk() { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 151 | ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", |
| 152 | vndk.typeName(), to.Name()) |
| 153 | return |
| 154 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 155 | if tag == vndkExtDepTag { |
| 156 | // Ensure `extends: "name"` property refers a vndk module that has vendor_available |
| 157 | // and has identical vndk properties. |
| 158 | if to.vndkdep == nil || !to.vndkdep.isVndk() { |
| 159 | ctx.ModuleErrorf("`extends` refers a non-vndk module %q", to.Name()) |
| 160 | return |
| 161 | } |
| 162 | if vndk.isVndkSp() != to.vndkdep.isVndkSp() { |
| 163 | ctx.ModuleErrorf( |
| 164 | "`extends` refers a module %q with mismatched support_system_process", |
| 165 | to.Name()) |
| 166 | return |
| 167 | } |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 168 | if to.IsVndkPrivate() { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 169 | ctx.ModuleErrorf( |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 170 | "`extends` refers module %q which has `private: true`", |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 171 | to.Name()) |
| 172 | return |
| 173 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 174 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 175 | if to.vndkdep == nil { |
| 176 | return |
| 177 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 178 | |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 179 | // Check the dependencies of VNDK shared libraries. |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 180 | if err := vndkIsVndkDepAllowed(vndk, to.vndkdep); err != nil { |
| 181 | ctx.ModuleErrorf("(%s) should not link to %q (%s): %v", |
| 182 | vndk.typeName(), to.Name(), to.vndkdep.typeName(), err) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 183 | return |
| 184 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 185 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 186 | |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 187 | func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error { |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 188 | // Check the dependencies of VNDK, VNDK-Ext, VNDK-SP, VNDK-SP-Ext and vendor modules. |
| 189 | if from.isVndkExt() { |
| 190 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 191 | if to.isVndk() && !to.isVndkSp() { |
| 192 | return errors.New("VNDK-SP extensions must not depend on VNDK or VNDK extensions") |
| 193 | } |
| 194 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 195 | } |
| 196 | // 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] | 197 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 198 | } |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 199 | if from.isVndk() { |
| 200 | if to.isVndkExt() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 201 | 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] | 202 | } |
| 203 | if from.isVndkSp() { |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 204 | if !to.isVndkSp() { |
| 205 | return errors.New("VNDK-SP must only depend on VNDK-SP") |
| 206 | } |
| 207 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 208 | } |
Martin Stjernholm | 257eb0c | 2018-10-15 13:05:27 +0100 | [diff] [blame] | 209 | if !to.isVndk() { |
| 210 | return errors.New("VNDK-core must only depend on VNDK-core or VNDK-SP") |
| 211 | } |
| 212 | return nil |
Logan Chien | d3c59a2 | 2018-03-29 14:08:15 +0800 | [diff] [blame] | 213 | } |
| 214 | // 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] | 215 | return nil |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 216 | } |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 217 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 218 | type moduleListerFunc func(ctx android.SingletonContext) (moduleNames, fileNames []string) |
| 219 | |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 220 | var ( |
Kiyoung Kim | 22152f6 | 2024-05-24 10:45:28 +0900 | [diff] [blame] | 221 | vndkSPLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKSP }) |
| 222 | vndkCoreLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKCore }) |
| 223 | vndkPrivateLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKPrivate }) |
| 224 | vndkProductLibraries = vndkModuleLister(func(m *Module) bool { return m.VendorProperties.IsVNDKProduct }) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 225 | ) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 226 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 227 | // vndkModuleLister takes a predicate that operates on a Module and returns a moduleListerFunc |
| 228 | // that produces a list of module names and output file names for which the predicate returns true. |
| 229 | func vndkModuleLister(predicate func(*Module) bool) moduleListerFunc { |
| 230 | return func(ctx android.SingletonContext) (moduleNames, fileNames []string) { |
| 231 | ctx.VisitAllModules(func(m android.Module) { |
Jooyung Han | e3f0281 | 2023-05-08 13:54:50 +0900 | [diff] [blame] | 232 | if c, ok := m.(*Module); ok && predicate(c) && !c.IsVndkPrebuiltLibrary() { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 233 | filename, err := getVndkFileName(c) |
| 234 | if err != nil { |
| 235 | ctx.ModuleErrorf(m, "%s", err) |
| 236 | } |
| 237 | moduleNames = append(moduleNames, ctx.ModuleName(m)) |
| 238 | fileNames = append(fileNames, filename) |
| 239 | } |
| 240 | }) |
| 241 | moduleNames = android.SortedUniqueStrings(moduleNames) |
| 242 | fileNames = android.SortedUniqueStrings(fileNames) |
| 243 | return |
| 244 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 245 | } |
| 246 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 247 | // vndkModuleListRemover takes a moduleListerFunc and a prefix and returns a moduleListerFunc |
| 248 | // that returns the same lists as the input moduleListerFunc, but with modules with the |
| 249 | // given prefix removed. |
| 250 | func vndkModuleListRemover(lister moduleListerFunc, prefix string) moduleListerFunc { |
| 251 | return func(ctx android.SingletonContext) (moduleNames, fileNames []string) { |
| 252 | moduleNames, fileNames = lister(ctx) |
| 253 | filter := func(in []string) []string { |
| 254 | out := make([]string, 0, len(in)) |
| 255 | for _, lib := range in { |
| 256 | if strings.HasPrefix(lib, prefix) { |
| 257 | continue |
| 258 | } |
| 259 | out = append(out, lib) |
| 260 | } |
| 261 | return out |
| 262 | } |
| 263 | return filter(moduleNames), filter(fileNames) |
| 264 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 265 | } |
| 266 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 267 | func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 268 | if m.InProduct() { |
| 269 | // We may skip the steps for the product variants because they |
| 270 | // are already covered by the vendor variants. |
| 271 | return |
| 272 | } |
| 273 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 274 | name := m.BaseModuleName() |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 275 | |
Colin Cross | 31076b3 | 2020-10-23 17:22:06 -0700 | [diff] [blame] | 276 | if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" { |
Jiyong Park | 2478e4e | 2020-05-18 09:30:14 +0000 | [diff] [blame] | 277 | // b/155456180 libz is the ONLY exception here. We don't want to make |
| 278 | // libz an LLNDK library because we in general can't guarantee that |
| 279 | // libz will behave consistently especially about the compression. |
| 280 | // i.e. the compressed output might be different across releases. |
| 281 | // As the library is an external one, it's risky to keep the compatibility |
| 282 | // promise if it becomes an LLNDK. |
Jiyong Park | ea97f51 | 2020-03-31 15:31:17 +0900 | [diff] [blame] | 283 | mctx.PropertyErrorf("vndk.enabled", "This library provides stubs. Shouldn't be VNDK. Consider making it as LLNDK") |
| 284 | } |
| 285 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 286 | if m.vndkdep.isVndkSp() { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 287 | m.VendorProperties.IsVNDKSP = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 288 | } else { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 289 | m.VendorProperties.IsVNDKCore = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 290 | } |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 291 | if m.IsVndkPrivate() { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 292 | m.VendorProperties.IsVNDKPrivate = true |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 293 | } |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 294 | if Bool(m.VendorProperties.Product_available) { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 295 | m.VendorProperties.IsVNDKProduct = true |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 296 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 297 | } |
| 298 | |
Yo Chiang | 08fac0c | 2020-07-29 01:08:20 +0800 | [diff] [blame] | 299 | // Check for modules that mustn't be VNDK |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 300 | func shouldSkipVndkMutator(ctx android.ConfigAndErrorContext, m *Module) bool { |
| 301 | if !m.Enabled(ctx) { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 302 | return true |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 303 | } |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 304 | if !m.Device() { |
| 305 | // Skip non-device modules |
| 306 | return true |
Jooyung Han | 87a7f30 | 2019-10-29 05:18:21 +0900 | [diff] [blame] | 307 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 308 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 309 | // Skip native_bridge modules |
| 310 | return true |
| 311 | } |
| 312 | return false |
| 313 | } |
| 314 | |
| 315 | func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 316 | if shouldSkipVndkMutator(mctx, m) { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 317 | return false |
| 318 | } |
| 319 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 320 | // TODO(b/142675459): Use enabled: to select target device in vndk_prebuilt_shared |
| 321 | // When b/142675459 is landed, remove following check |
Justin Yun | f14beaf | 2023-08-18 17:51:14 +0900 | [diff] [blame] | 322 | if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { |
| 323 | // prebuilt vndk modules should match with device |
| 324 | if !p.MatchesWithDevice(mctx.DeviceConfig()) { |
| 325 | return false |
| 326 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | if lib, ok := m.linker.(libraryInterface); ok { |
Jooyung Han | 1724d58 | 2022-12-21 10:17:44 +0900 | [diff] [blame] | 330 | // VNDK APEX doesn't need stub variants |
| 331 | if lib.buildStubs() { |
| 332 | return false |
| 333 | } |
Kiyoung Kim | 22152f6 | 2024-05-24 10:45:28 +0900 | [diff] [blame] | 334 | return lib.shared() && m.InVendor() && m.IsVndk() && !m.IsVndkExt() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 335 | } |
| 336 | return false |
| 337 | } |
| 338 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 339 | // gather list of vndk-core, vndk-sp, and ll-ndk libs |
| 340 | func VndkMutator(mctx android.BottomUpMutatorContext) { |
| 341 | m, ok := mctx.Module().(*Module) |
| 342 | if !ok { |
| 343 | return |
| 344 | } |
Yo Chiang | bba545e | 2020-06-09 16:15:37 +0800 | [diff] [blame] | 345 | |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 346 | if shouldSkipVndkMutator(mctx, m) { |
Justin Yun | 7390ea3 | 2019-09-08 11:34:06 +0900 | [diff] [blame] | 347 | return |
| 348 | } |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 349 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 350 | lib, isLib := m.linker.(*libraryDecorator) |
| 351 | prebuiltLib, isPrebuiltLib := m.linker.(*prebuiltLibraryLinker) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 352 | |
Kiyoung Kim | aa39480 | 2024-01-08 12:55:45 +0900 | [diff] [blame] | 353 | if m.InVendorOrProduct() && isLib && lib.hasLLNDKStubs() { |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 354 | m.VendorProperties.IsVNDKPrivate = Bool(lib.Properties.Llndk.Private) |
| 355 | } |
Kiyoung Kim | aa39480 | 2024-01-08 12:55:45 +0900 | [diff] [blame] | 356 | if m.InVendorOrProduct() && isPrebuiltLib && prebuiltLib.hasLLNDKStubs() { |
Colin Cross | 0fb7fcd | 2021-03-02 11:00:07 -0800 | [diff] [blame] | 357 | m.VendorProperties.IsVNDKPrivate = Bool(prebuiltLib.Properties.Llndk.Private) |
| 358 | } |
| 359 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 360 | if (isLib && lib.buildShared()) || (isPrebuiltLib && prebuiltLib.buildShared()) { |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 361 | if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 362 | processVndkLibrary(mctx, m) |
| 363 | return |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | func init() { |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 369 | RegisterVndkLibraryTxtTypes(android.InitRegistrationContext) |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 370 | } |
| 371 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 372 | func RegisterVndkLibraryTxtTypes(ctx android.RegistrationContext) { |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 373 | ctx.RegisterParallelSingletonModuleType("vndksp_libraries_txt", vndkSPLibrariesTxtFactory) |
| 374 | ctx.RegisterParallelSingletonModuleType("vndkcore_libraries_txt", vndkCoreLibrariesTxtFactory) |
| 375 | ctx.RegisterParallelSingletonModuleType("vndkprivate_libraries_txt", vndkPrivateLibrariesTxtFactory) |
| 376 | ctx.RegisterParallelSingletonModuleType("vndkproduct_libraries_txt", vndkProductLibrariesTxtFactory) |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 379 | type vndkLibrariesTxt struct { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 380 | android.SingletonModuleBase |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 381 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 382 | lister moduleListerFunc |
| 383 | makeVarName string |
| 384 | filterOutFromMakeVar string |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 385 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 386 | properties VndkLibrariesTxtProperties |
| 387 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 388 | outputFile android.OutputPath |
| 389 | moduleNames []string |
| 390 | fileNames []string |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 391 | } |
| 392 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 393 | type VndkLibrariesTxtProperties struct { |
| 394 | Insert_vndk_version *bool |
Justin Yun | d578412 | 2023-10-25 13:25:32 +0900 | [diff] [blame] | 395 | Stem *string |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 398 | var _ etc.PrebuiltEtcModule = &vndkLibrariesTxt{} |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 399 | var _ android.OutputFileProducer = &vndkLibrariesTxt{} |
| 400 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 401 | // vndksp_libraries_txt is a singleton module whose content is a list of VNDKSP libraries |
| 402 | // generated by Soong but can be referenced by other modules. |
| 403 | // For example, apex_vndk can depend on these files as prebuilt. |
| 404 | func vndkSPLibrariesTxtFactory() android.SingletonModule { |
| 405 | return newVndkLibrariesTxt(vndkSPLibraries, "VNDK_SAMEPROCESS_LIBRARIES") |
| 406 | } |
| 407 | |
| 408 | // vndkcore_libraries_txt is a singleton module whose content is a list of VNDK core libraries |
| 409 | // generated by Soong but can be referenced by other modules. |
| 410 | // For example, apex_vndk can depend on these files as prebuilt. |
| 411 | func vndkCoreLibrariesTxtFactory() android.SingletonModule { |
| 412 | return newVndkLibrariesTxt(vndkCoreLibraries, "VNDK_CORE_LIBRARIES") |
| 413 | } |
| 414 | |
| 415 | // vndkprivate_libraries_txt is a singleton module whose content is a list of VNDK private libraries |
| 416 | // generated by Soong but can be referenced by other modules. |
| 417 | // For example, apex_vndk can depend on these files as prebuilt. |
| 418 | func vndkPrivateLibrariesTxtFactory() android.SingletonModule { |
| 419 | return newVndkLibrariesTxt(vndkPrivateLibraries, "VNDK_PRIVATE_LIBRARIES") |
| 420 | } |
| 421 | |
| 422 | // vndkproduct_libraries_txt is a singleton module whose content is a list of VNDK product libraries |
| 423 | // generated by Soong but can be referenced by other modules. |
| 424 | // For example, apex_vndk can depend on these files as prebuilt. |
| 425 | func vndkProductLibrariesTxtFactory() android.SingletonModule { |
| 426 | return newVndkLibrariesTxt(vndkProductLibraries, "VNDK_PRODUCT_LIBRARIES") |
| 427 | } |
| 428 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 429 | func newVndkLibrariesWithMakeVarFilter(lister moduleListerFunc, makeVarName string, filter string) android.SingletonModule { |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 430 | m := &vndkLibrariesTxt{ |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 431 | lister: lister, |
| 432 | makeVarName: makeVarName, |
| 433 | filterOutFromMakeVar: filter, |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 434 | } |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 435 | m.AddProperties(&m.properties) |
Colin Cross | 45bce85 | 2021-11-11 22:47:54 -0800 | [diff] [blame] | 436 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 437 | return m |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 438 | } |
| 439 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 440 | func newVndkLibrariesTxt(lister moduleListerFunc, makeVarName string) android.SingletonModule { |
| 441 | return newVndkLibrariesWithMakeVarFilter(lister, makeVarName, "") |
| 442 | } |
| 443 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 444 | func insertVndkVersion(filename string, vndkVersion string) string { |
| 445 | if index := strings.LastIndex(filename, "."); index != -1 { |
| 446 | return filename[:index] + "." + vndkVersion + filename[index:] |
| 447 | } |
| 448 | return filename |
| 449 | } |
| 450 | |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 451 | func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Justin Yun | d578412 | 2023-10-25 13:25:32 +0900 | [diff] [blame] | 452 | filename := proptools.StringDefault(txt.properties.Stem, txt.Name()) |
Kiyoung Kim | a2d6dee | 2023-08-11 10:14:43 +0900 | [diff] [blame] | 453 | |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 454 | txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 455 | |
| 456 | installPath := android.PathForModuleInstall(ctx, "etc") |
| 457 | ctx.InstallFile(installPath, filename, txt.outputFile) |
| 458 | } |
| 459 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 460 | func (txt *vndkLibrariesTxt) GenerateSingletonBuildActions(ctx android.SingletonContext) { |
| 461 | txt.moduleNames, txt.fileNames = txt.lister(ctx) |
| 462 | android.WriteFileRule(ctx, txt.outputFile, strings.Join(txt.fileNames, "\n")) |
| 463 | } |
| 464 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 465 | func (txt *vndkLibrariesTxt) AndroidMkEntries() []android.AndroidMkEntries { |
| 466 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 467 | Class: "ETC", |
| 468 | OutputFile: android.OptionalPathForPath(txt.outputFile), |
| 469 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 470 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 471 | entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base()) |
| 472 | }, |
| 473 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 474 | }} |
Jooyung Han | 2216fb1 | 2019-11-06 16:46:15 +0900 | [diff] [blame] | 475 | } |
| 476 | |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 477 | func (txt *vndkLibrariesTxt) MakeVars(ctx android.MakeVarsContext) { |
Justin Yun | d578412 | 2023-10-25 13:25:32 +0900 | [diff] [blame] | 478 | if txt.makeVarName == "" { |
| 479 | return |
| 480 | } |
| 481 | |
Justin Yun | 611e886 | 2021-05-24 18:17:33 +0900 | [diff] [blame] | 482 | filter := func(modules []string, prefix string) []string { |
| 483 | if prefix == "" { |
| 484 | return modules |
| 485 | } |
| 486 | var result []string |
| 487 | for _, module := range modules { |
| 488 | if strings.HasPrefix(module, prefix) { |
| 489 | continue |
| 490 | } else { |
| 491 | result = append(result, module) |
| 492 | } |
| 493 | } |
| 494 | return result |
| 495 | } |
| 496 | ctx.Strict(txt.makeVarName, strings.Join(filter(txt.moduleNames, txt.filterOutFromMakeVar), " ")) |
Colin Cross | 7821224 | 2021-01-06 14:51:30 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 499 | // PrebuiltEtcModule interface |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 500 | func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath { |
| 501 | return txt.outputFile |
| 502 | } |
| 503 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 504 | // PrebuiltEtcModule interface |
| 505 | func (txt *vndkLibrariesTxt) BaseDir() string { |
| 506 | return "etc" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 507 | } |
| 508 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 509 | // PrebuiltEtcModule interface |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 510 | func (txt *vndkLibrariesTxt) SubDir() string { |
| 511 | return "" |
| 512 | } |
| 513 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 514 | func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) { |
| 515 | return android.Paths{txt.outputFile}, nil |
| 516 | } |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 517 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 518 | func getVndkFileName(m *Module) (string, error) { |
| 519 | if library, ok := m.linker.(*libraryDecorator); ok { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 520 | return library.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 521 | } |
| 522 | if prebuilt, ok := m.linker.(*prebuiltLibraryLinker); ok { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 523 | return prebuilt.libraryDecorator.getLibNameHelper(m.BaseModuleName(), true, false) + ".so", nil |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 524 | } |
| 525 | 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] | 526 | } |