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