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